Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secure practice for Content Security Policy and dependancies update #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,19 @@ TextLayout.prototype.computeMetrics = function(text, start, end, width) {

function addGetter(name) {
Object.defineProperty(TextLayout.prototype, name, {
get: wrapper(name),
// We return the private var in an anonymous getter function
// because the alternative is to have a scoped dynamic function name
// and those need to use the Function constructor or the eval opperator
// and those are both unsecure and not accepted by safe websites
// with no unsafe-eval Content Security Policy
// See : https://developer.chrome.com/extensions/contentSecurityPolicy
get: function () {
return this['_'+name]
},
configurable: true
})
}

//create lookups for private vars
function wrapper(name) {
return (new Function([
'return function '+name+'() {',
' return this._'+name,
'}'
].join('\n')))()
}

function getGlyphById(font, id) {
if (!font.chars || font.chars.length === 0)
return null
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"budo": "^1.2.2",
"canvas-testbed": "^1.0.3",
"clamp": "^1.0.1",
"garnish": "^5.2.0",
"img": "^1.0.0",
"indexof-property": "^1.1.1",
"lerp": "^1.0.3",
"smoothstep": "^1.0.1",
"tape": "^3.5.0",
Expand Down