sandbox-runner
Eval a piece of javascript text in a sandbox environment Could be useful to test code generation or test javascript without proper module encapsulation.
Install
Install using npm.
$ npm install sandbox-runner
Usage
var fs = ;var sandbox = ; var codeSnippet = fs; /* Content of templates.jsthis.Templates = this.Templates != null ? this.Templates : {};this.Templates["hello"] = function (name) { return 'hello ' + name + '!'; };this.Templates["foo"] = function () { return 'foo'; };*/ var context = sandbox; contextTemplatesshould;
API
sanbox.run(script, context = {})
run the script snippet, a
context
is provided asthis
pointer.
- script The script text to be executed
- context The context that used in execution. An empty object will be provide if omitted.
** HINT ** Exception is thrown when error occurs in script. Remember to catch the exception in async code.
sandbox.moduleRun(script, filename = '')
run the script snippet as a node.js module
- script The script text to be executed
- filenae The fake file name that of the module in file system.
License
MIT