safer-eval
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -68,7 +68,20 @@ 'use strict'; | ||
function cloneFunctions(context) { | ||
;['clearImmediate', 'clearInterval', 'clearTimeout', 'setImmediate', 'setInterval', 'setTimeout'].forEach(function (str) { | ||
;['clearImmediate', 'clearInterval', 'clearTimeout'].forEach(function (str) { | ||
try { | ||
var fn = new Function('return ' + str)(); // eslint-disable-line no-new-func | ||
context[str] = fn ? clones(fn) : undefined; | ||
context[str] = fn ? function () { | ||
return fn.apply(null, [].slice.call(arguments)); | ||
} : undefined; | ||
} catch (e) {} | ||
});['setImmediate', 'setInterval', 'setTimeout'].forEach(function (str) { | ||
try { | ||
var fn = new Function('return ' + str)(); // eslint-disable-line no-new-func | ||
context[str] = fn ? function (f) { | ||
if (typeof f === 'function') { | ||
return fn.apply(null, [].slice.call(arguments)); | ||
} else { | ||
throw new Error(str + ' requires function as argument'); | ||
} | ||
} : undefined; | ||
} catch (e) {} | ||
}); | ||
@@ -79,2 +92,3 @@ } | ||
* wraps up build-in objects using a cloned copy | ||
* protect object against overwriting | ||
* @private | ||
@@ -81,0 +95,0 @@ */ |
{ | ||
"name": "safer-eval", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "a safer eval", | ||
"author": "commenthol <commenthol@gmail.com>", | ||
"license": "MIT", | ||
"main": "lib/index.js", | ||
"browser": "lib/browser.js", | ||
"main": "./lib/index.js", | ||
"browser": { | ||
"./lib/index.js": "./lib/browser.js" | ||
}, | ||
"repository": { | ||
@@ -10,0 +12,0 @@ "type": "git", |
@@ -71,3 +71,15 @@ 'use strict' | ||
'clearInterval', | ||
'clearTimeout', | ||
'clearTimeout' | ||
].forEach((str) => { | ||
try { | ||
let fn = new Function(`return ${str}`)() // eslint-disable-line no-new-func | ||
context[str] = fn | ||
? function () { | ||
return fn.apply(null, [].slice.call(arguments)) | ||
} | ||
: undefined | ||
} catch (e) {} | ||
}) | ||
;[ | ||
'setImmediate', | ||
@@ -79,3 +91,11 @@ 'setInterval', | ||
let fn = new Function(`return ${str}`)() // eslint-disable-line no-new-func | ||
context[str] = fn ? clones(fn) : undefined | ||
context[str] = fn | ||
? function (f) { | ||
if (typeof f === 'function') { | ||
return fn.apply(null, [].slice.call(arguments)) | ||
} else { | ||
throw new Error(str + ' requires function as argument') | ||
} | ||
} | ||
: undefined | ||
} catch (e) {} | ||
@@ -87,2 +107,3 @@ }) | ||
* wraps up build-in objects using a cloned copy | ||
* protect object against overwriting | ||
* @private | ||
@@ -89,0 +110,0 @@ */ |
23203
560
8