diff options
Diffstat (limited to 'lib/vm.js')
-rw-r--r-- | lib/vm.js | 41 |
1 files changed, 32 insertions, 9 deletions
@@ -21,8 +21,14 @@ 'use strict'; -const binding = process.binding('contextify'); -const Script = binding.ContextifyScript; +const { + ContextifyScript: Script, + kParsingContext, + + makeContext, + isContext, + runInDebugContext +} = process.binding('contextify'); // The binding provides a few useful primitives: // - Script(code, { filename = "evalmachine.anonymous", @@ -62,11 +68,11 @@ Script.prototype.runInNewContext = function(sandbox, options) { function createContext(sandbox) { if (sandbox === undefined) { sandbox = {}; - } else if (binding.isContext(sandbox)) { + } else if (isContext(sandbox)) { return sandbox; } - binding.makeContext(sandbox); + makeContext(sandbox); return sandbox; } @@ -99,16 +105,33 @@ function sigintHandlersWrap(fn, thisArg, argsArray) { } } -function runInDebugContext(code) { - return binding.runInDebugContext(code); -} - function runInContext(code, contextifiedSandbox, options) { + if (typeof options === 'string') { + options = { + filename: options, + [kParsingContext]: contextifiedSandbox + }; + } else { + options = Object.assign({}, options, { + [kParsingContext]: contextifiedSandbox + }); + } return createScript(code, options) .runInContext(contextifiedSandbox, options); } function runInNewContext(code, sandbox, options) { + sandbox = createContext(sandbox); + if (typeof options === 'string') { + options = { + filename: options, + [kParsingContext]: sandbox + }; + } else { + options = Object.assign({}, options, { + [kParsingContext]: sandbox + }); + } return createScript(code, options).runInNewContext(sandbox, options); } @@ -124,5 +147,5 @@ module.exports = { runInContext, runInNewContext, runInThisContext, - isContext: binding.isContext + isContext }; |