diff options
Diffstat (limited to 'lib/vm.js')
-rw-r--r-- | lib/vm.js | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -26,10 +26,13 @@ const { kParsingContext, makeContext, - isContext, + isContext: _isContext, } = process.binding('contextify'); -const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes; +const { + ERR_INVALID_ARG_TYPE, + ERR_MISSING_ARGS +} = require('internal/errors').codes; // The binding provides a few useful primitives: // - Script(code, { filename = "evalmachine.anonymous", @@ -119,6 +122,19 @@ function getContextOptions(options) { return {}; } +function isContext(sandbox) { + if (arguments.length < 1) { + throw new ERR_MISSING_ARGS('sandbox'); + } + + if (typeof sandbox !== 'object' && typeof sandbox !== 'function' || + sandbox === null) { + throw new ERR_INVALID_ARG_TYPE('sandbox', 'object', sandbox); + } + + return _isContext(sandbox); +} + let defaultContextNameIndex = 1; function createContext(sandbox, options) { if (sandbox === undefined) { |