summaryrefslogtreecommitdiff
path: root/lib/vm.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/vm.js')
-rw-r--r--lib/vm.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/vm.js b/lib/vm.js
index 5266dbd29f..ca7b6f3396 100644
--- a/lib/vm.js
+++ b/lib/vm.js
@@ -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) {