From 4f8ff0c5a6e06161352d3e4755fdc79e4da849e4 Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Wed, 11 Oct 2017 00:50:40 -0400 Subject: [PATCH] Revert "vm: support parsing a script in a specific context" This reverts commit 7d95dc385cd05ad0ad7862a18cd32f1c254edf59. It causes breakages in the Browserify test suite --- lib/vm.js | 41 ++++------------ src/env.h | 1 - src/node_contextify.cc | 49 ------------------- .../test-scriptparsed-context.js | 0 4 files changed, 9 insertions(+), 82 deletions(-) rename test/{inspector => known_issues}/test-scriptparsed-context.js (100%) diff --git a/lib/vm.js b/lib/vm.js index e7fccc97493bcb..5bee450becec8b 100644 --- a/lib/vm.js +++ b/lib/vm.js @@ -21,14 +21,8 @@ 'use strict'; -const { - ContextifyScript: Script, - kParsingContext, - - makeContext, - isContext, - runInDebugContext -} = process.binding('contextify'); +const binding = process.binding('contextify'); +const Script = binding.ContextifyScript; // The binding provides a few useful primitives: // - Script(code, { filename = "evalmachine.anonymous", @@ -68,11 +62,11 @@ Script.prototype.runInNewContext = function(sandbox, options) { function createContext(sandbox) { if (sandbox === undefined) { sandbox = {}; - } else if (isContext(sandbox)) { + } else if (binding.isContext(sandbox)) { return sandbox; } - makeContext(sandbox); + binding.makeContext(sandbox); return sandbox; } @@ -105,33 +99,16 @@ 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); } @@ -147,5 +124,5 @@ module.exports = { runInContext, runInNewContext, runInThisContext, - isContext + isContext: binding.isContext }; diff --git a/src/env.h b/src/env.h index e37a0eb6311a41..97187cd5fd19df 100644 --- a/src/env.h +++ b/src/env.h @@ -326,7 +326,6 @@ class ModuleWrap; V(tls_wrap_constructor_function, v8::Function) \ V(tty_constructor_template, v8::FunctionTemplate) \ V(udp_constructor_function, v8::Function) \ - V(vm_parsing_context_symbol, v8::Symbol) \ V(url_constructor_function, v8::Function) \ V(write_wrap_constructor_function, v8::Function) \ diff --git a/src/node_contextify.cc b/src/node_contextify.cc index dc939c6cf98fe3..a8137510bb869e 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -56,7 +56,6 @@ using v8::Script; using v8::ScriptCompiler; using v8::ScriptOrigin; using v8::String; -using v8::Symbol; using v8::TryCatch; using v8::Uint8Array; using v8::UnboundScript; @@ -527,16 +526,6 @@ class ContextifyScript : public BaseObject { target->Set(class_name, script_tmpl->GetFunction()); env->set_script_context_constructor_template(script_tmpl); - - Local parsing_context_symbol = - Symbol::New(env->isolate(), - FIXED_ONE_BYTE_STRING(env->isolate(), - "script parsing context")); - env->set_vm_parsing_context_symbol(parsing_context_symbol); - target->Set(env->context(), - FIXED_ONE_BYTE_STRING(env->isolate(), "kParsingContext"), - parsing_context_symbol) - .FromJust(); } @@ -561,7 +550,6 @@ class ContextifyScript : public BaseObject { Maybe maybe_display_errors = GetDisplayErrorsArg(env, options); MaybeLocal cached_data_buf = GetCachedData(env, options); Maybe maybe_produce_cached_data = GetProduceCachedData(env, options); - MaybeLocal maybe_context = GetContext(env, options); if (try_catch.HasCaught()) { try_catch.ReThrow(); return; @@ -590,8 +578,6 @@ class ContextifyScript : public BaseObject { else if (produce_cached_data) compile_options = ScriptCompiler::kProduceCodeCache; - Context::Scope scope(maybe_context.FromMaybe(env->context())); - MaybeLocal v8_script = ScriptCompiler::CompileUnboundScript( env->isolate(), &source, @@ -944,41 +930,6 @@ class ContextifyScript : public BaseObject { return value->ToInteger(env->context()); } - static MaybeLocal GetContext(Environment* env, - Local options) { - if (!options->IsObject()) - return MaybeLocal(); - - MaybeLocal maybe_value = - options.As()->Get(env->context(), - env->vm_parsing_context_symbol()); - Local value; - if (!maybe_value.ToLocal(&value)) - return MaybeLocal(); - - if (!value->IsObject()) { - if (!value->IsNullOrUndefined()) { - env->ThrowTypeError( - "contextifiedSandbox argument must be an object."); - } - return MaybeLocal(); - } - - ContextifyContext* sandbox = - ContextifyContext::ContextFromContextifiedSandbox( - env, value.As()); - if (!sandbox) { - env->ThrowTypeError( - "sandbox argument must have been converted to a context."); - return MaybeLocal(); - } - - Local context = sandbox->context(); - if (context.IsEmpty()) - return MaybeLocal(); - return context; - } - static bool EvalMachine(Environment* env, const int64_t timeout, diff --git a/test/inspector/test-scriptparsed-context.js b/test/known_issues/test-scriptparsed-context.js similarity index 100% rename from test/inspector/test-scriptparsed-context.js rename to test/known_issues/test-scriptparsed-context.js