| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d7563a5 commit ba444a9
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,6 @@ const { | |||
| 8 | 8 | const { | |
| 9 | 9 | ContextifyScript, | |
| 10 | 10 | compileFunction, | |
| 11 | - isContext: _isContext, | ||
| 12 | 11 | } = internalBinding('contextify'); | |
| 13 | 12 | const { | |
| 14 | 13 | runInContext, | |
@@ -21,18 +20,19 @@ const { | |||
| 21 | 20 | } = internalBinding('symbols'); | |
| 22 | 21 | const { | |
| 23 | 22 | validateFunction, | |
| 24 | - validateObject, | ||
| 25 | - kValidateObjectAllowArray, | ||
| 26 | 23 | } = require('internal/validators'); | |
| 27 | 24 | ||
| 28 | 25 | const { | |
| 29 | 26 | getOptionValue, | |
| 30 | 27 | } = require('internal/options'); | |
| 28 | + const { | ||
| 29 | + privateSymbols: { | ||
| 30 | + contextify_context_private_symbol, | ||
| 31 | + }, | ||
| 32 | + } = internalBinding('util'); | ||
| 31 | 33 | ||
| 32 | 34 | function isContext(object) { | |
| 33 | - validateObject(object, 'object', kValidateObjectAllowArray); | ||
| 34 | - | ||
| 35 | - return _isContext(object); | ||
| 35 | + return object[contextify_context_private_symbol] !== undefined; | ||
| 36 | 36 | } | |
| 37 | 37 | ||
| 38 | 38 | function getHostDefinedOptionId(importModuleDynamically, hint) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,6 @@ const { | |||
| 17 | 17 | TypeError, | |
| 18 | 18 | } = primordials; | |
| 19 | 19 | ||
| 20 | - const { isContext } = internalBinding('contextify'); | ||
| 21 | 20 | const { | |
| 22 | 21 | isModuleNamespaceObject, | |
| 23 | 22 | } = require('internal/util/types'); | |
@@ -75,6 +74,8 @@ const kContext = Symbol('kContext'); | |||
| 75 | 74 | const kPerContextModuleId = Symbol('kPerContextModuleId'); | |
| 76 | 75 | const kLink = Symbol('kLink'); | |
| 77 | 76 | ||
| 77 | + const { isContext } = require('internal/vm'); | ||
| 78 | + | ||
| 78 | 79 | class Module { | |
| 79 | 80 | constructor(options) { | |
| 80 | 81 | emitExperimentalWarning('VM Modules'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,6 +49,7 @@ const { | |||
| 49 | 49 | validateString, | |
| 50 | 50 | validateStringArray, | |
| 51 | 51 | validateUint32, | |
| 52 | + kValidateObjectAllowArray, | ||
| 52 | 53 | kValidateObjectAllowNullable, | |
| 53 | 54 | } = require('internal/validators'); | |
| 54 | 55 | const { | |
@@ -59,14 +60,26 @@ const { | |||
| 59 | 60 | const { | |
| 60 | 61 | getHostDefinedOptionId, | |
| 61 | 62 | internalCompileFunction, | |
| 62 | - isContext, | ||
| 63 | + isContext: _isContext, | ||
| 63 | 64 | registerImportModuleDynamically, | |
| 64 | 65 | } = require('internal/vm'); | |
| 65 | 66 | const { | |
| 66 | 67 | vm_dynamic_import_main_context_default, | |
| 67 | 68 | } = internalBinding('symbols'); | |
| 68 | 69 | const kParsingContext = Symbol('script parsing context'); | |
| 69 | 70 | ||
| 71 | + /** | ||
| 72 | + * Check if object is a context object created by vm.createContext(). | ||
| 73 | + * @throws {TypeError} If object is not an object in the first place, throws TypeError. | ||
| 74 | + * @param {object} object Object to check. | ||
| 75 | + * @returns {boolean} | ||
| 76 | + */ | ||
| 77 | + function isContext(object) { | ||
| 78 | + validateObject(object, 'object', kValidateObjectAllowArray); | ||
| 79 | + | ||
| 80 | + return _isContext(object); | ||
| 81 | + } | ||
| 82 | + | ||
| 70 | 83 | class Script extends ContextifyScript { | |
| 71 | 84 | constructor(code, options = kEmptyObject) { | |
| 72 | 85 | code = `${code}`; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -342,15 +342,13 @@ void ContextifyContext::CreatePerIsolateProperties( | |||
| 342 | 342 | IsolateData* isolate_data, Local<ObjectTemplate> target) { | |
| 343 | 343 | Isolate* isolate = isolate_data->isolate(); | |
| 344 | 344 | SetMethod(isolate, target, "makeContext", MakeContext); | |
| 345 | - SetMethod(isolate, target, "isContext", IsContext); | ||
| 346 | 345 | SetMethod(isolate, target, "compileFunction", CompileFunction); | |
| 347 | 346 | SetMethod(isolate, target, "containsModuleSyntax", ContainsModuleSyntax); | |
| 348 | 347 | } | |
| 349 | 348 | ||
| 350 | 349 | void ContextifyContext::RegisterExternalReferences( | |
| 351 | 350 | ExternalReferenceRegistry* registry) { | |
| 352 | 351 | registry->Register(MakeContext); | |
| 353 | - registry->Register(IsContext); | ||
| 354 | 352 | registry->Register(CompileFunction); | |
| 355 | 353 | registry->Register(ContainsModuleSyntax); | |
| 356 | 354 | registry->Register(PropertyGetterCallback); | |
@@ -415,20 +413,6 @@ void ContextifyContext::MakeContext(const FunctionCallbackInfo<Value>& args) { | |||
| 415 | 413 | } | |
| 416 | 414 | } | |
| 417 | 415 | ||
| 418 | - | ||
| 419 | - void ContextifyContext::IsContext(const FunctionCallbackInfo<Value>& args) { | ||
| 420 | - Environment* env = Environment::GetCurrent(args); | ||
| 421 | - | ||
| 422 | - CHECK(args[0]->IsObject()); | ||
| 423 | - Local<Object> sandbox = args[0].As<Object>(); | ||
| 424 | - | ||
| 425 | - Maybe<bool> result = | ||
| 426 | - sandbox->HasPrivate(env->context(), | ||
| 427 | - env->contextify_context_private_symbol()); | ||
| 428 | - args.GetReturnValue().Set(result.FromJust()); | ||
| 429 | - } | ||
| 430 | - | ||
| 431 | - | ||
| 432 | 416 | void ContextifyContext::WeakCallback( | |
| 433 | 417 | const WeakCallbackInfo<ContextifyContext>& data) { | |
| 434 | 418 | ContextifyContext* context = data.GetParameter(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments