diff --git a/src/debug-agent.cc b/src/debug-agent.cc index 425a08716dc1d5..2e51c89c987075 100644 --- a/src/debug-agent.cc +++ b/src/debug-agent.cc @@ -120,11 +120,12 @@ bool Agent::Start(int port, bool wait) { void Agent::Enable() { - v8::Debug::SetMessageHandler(MessageHandler); + v8::Debug::SetMessageHandler(parent_env()->isolate(), MessageHandler); // Assign environment to the debugger's context // NOTE: The debugger context is created after `SetMessageHandler()` call - parent_env()->AssignToContext(v8::Debug::GetDebugContext()); + auto debug_context = v8::Debug::GetDebugContext(parent_env()->isolate()); + parent_env()->AssignToContext(debug_context); } @@ -135,7 +136,7 @@ void Agent::Stop() { return; } - v8::Debug::SetMessageHandler(nullptr); + v8::Debug::SetMessageHandler(parent_env()->isolate(), nullptr); // Send empty message to terminate things EnqueueMessage(new AgentMessage(nullptr, 0)); diff --git a/src/node.cc b/src/node.cc index 807cb6a91d1858..2a5fe73333913a 100644 --- a/src/node.cc +++ b/src/node.cc @@ -114,6 +114,7 @@ using v8::Integer; using v8::Isolate; using v8::Local; using v8::Locker; +using v8::MaybeLocal; using v8::Message; using v8::Number; using v8::Object; @@ -121,6 +122,7 @@ using v8::ObjectTemplate; using v8::Promise; using v8::PromiseRejectMessage; using v8::PropertyCallbackInfo; +using v8::ScriptOrigin; using v8::SealHandleScope; using v8::StackFrame; using v8::StackTrace; @@ -1042,7 +1044,8 @@ void SetupDomainUse(const FunctionCallbackInfo& args) { // Do a little housekeeping. env->process_object()->Delete( - FIXED_ONE_BYTE_STRING(args.GetIsolate(), "_setupDomainUse")); + env->context(), + FIXED_ONE_BYTE_STRING(args.GetIsolate(), "_setupDomainUse")).FromJust(); uint32_t* const fields = env->domain_flag()->fields(); uint32_t const fields_count = env->domain_flag()->fields_count(); @@ -1065,7 +1068,8 @@ void SetupProcessObject(const FunctionCallbackInfo& args) { env->set_push_values_to_array_function(args[0].As()); env->process_object()->Delete( - FIXED_ONE_BYTE_STRING(env->isolate(), "_setupProcessObject")); + env->context(), + FIXED_ONE_BYTE_STRING(env->isolate(), "_setupProcessObject")).FromJust(); } @@ -1081,7 +1085,8 @@ void SetupNextTick(const FunctionCallbackInfo& args) { // Do a little housekeeping. env->process_object()->Delete( - FIXED_ONE_BYTE_STRING(args.GetIsolate(), "_setupNextTick")); + env->context(), + FIXED_ONE_BYTE_STRING(args.GetIsolate(), "_setupNextTick")).FromJust(); // Values use to cross communicate with processNextTick. uint32_t* const fields = env->tick_info()->fields(); @@ -1121,7 +1126,8 @@ void SetupPromises(const FunctionCallbackInfo& args) { env->set_promise_reject_function(args[0].As()); env->process_object()->Delete( - FIXED_ONE_BYTE_STRING(args.GetIsolate(), "_setupPromises")); + env->context(), + FIXED_ONE_BYTE_STRING(args.GetIsolate(), "_setupPromises")).FromJust(); } @@ -1461,8 +1467,8 @@ void AppendExceptionLine(Environment* env, // sourceline to 78 characters, and we end up not providing very much // useful debugging info to the user if we remove 62 characters. - int start = message->GetStartColumn(); - int end = message->GetEndColumn(); + int start = message->GetStartColumn(env->context()).FromJust(); + int end = message->GetEndColumn(env->context()).FromJust(); char arrow[1024]; int max_off = sizeof(arrow) - 2; @@ -1607,13 +1613,15 @@ static Local ExecuteString(Environment* env, // we will handle exceptions ourself. try_catch.SetVerbose(false); - Local script = v8::Script::Compile(source, filename); + ScriptOrigin origin(filename); + MaybeLocal script = + v8::Script::Compile(env->context(), source, &origin); if (script.IsEmpty()) { ReportException(env, try_catch); exit(3); } - Local result = script->Run(); + Local result = script.ToLocalChecked()->Run(); if (result.IsEmpty()) { ReportException(env, try_catch); exit(4); @@ -2371,7 +2379,7 @@ static void Binding(const FunctionCallbackInfo& args) { Local cache = env->binding_cache_object(); Local exports; - if (cache->Has(module)) { + if (cache->Has(env->context(), module).FromJust()) { exports = cache->Get(module)->ToObject(env->isolate()); args.GetReturnValue().Set(exports); return; @@ -2788,15 +2796,20 @@ void StopProfilerIdleNotifier(const FunctionCallbackInfo& args) { #define READONLY_PROPERTY(obj, str, var) \ do { \ - obj->ForceSet(OneByteString(env->isolate(), str), var, v8::ReadOnly); \ + obj->DefineOwnProperty(env->context(), \ + OneByteString(env->isolate(), str), \ + var, \ + v8::ReadOnly).FromJust(); \ } while (0) #define READONLY_DONT_ENUM_PROPERTY(obj, str, var) \ do { \ - obj->ForceSet(OneByteString(env->isolate(), str), \ - var, \ - static_cast(v8::ReadOnly | \ - v8::DontEnum)); \ + obj->DefineOwnProperty(env->context(), \ + OneByteString(env->isolate(), str), \ + var, \ + static_cast(v8::ReadOnly | \ + v8::DontEnum)) \ + .FromJust(); \ } while (0) @@ -3539,7 +3552,7 @@ static void DispatchDebugMessagesAsyncCallback(uv_async_t* handle) { } Isolate::Scope isolate_scope(isolate); - v8::Debug::ProcessDebugMessages(); + v8::Debug::ProcessDebugMessages(isolate); CHECK_EQ(nullptr, node_isolate.exchange(isolate)); } diff --git a/src/node.h b/src/node.h index ef1f629d20aa0e..1a67cad420bf70 100644 --- a/src/node.h +++ b/src/node.h @@ -221,13 +221,17 @@ NODE_EXTERN void RunAtExit(Environment* env); #define NODE_DEFINE_CONSTANT(target, constant) \ do { \ v8::Isolate* isolate = target->GetIsolate(); \ + v8::Local context = isolate->GetCurrentContext(); \ v8::Local constant_name = \ v8::String::NewFromUtf8(isolate, #constant); \ v8::Local constant_value = \ v8::Number::New(isolate, static_cast(constant)); \ v8::PropertyAttribute constant_attributes = \ static_cast(v8::ReadOnly | v8::DontDelete); \ - (target)->ForceSet(constant_name, constant_value, constant_attributes); \ + (target)->DefineOwnProperty(context, \ + constant_name, \ + constant_value, \ + constant_attributes).FromJust(); \ } \ while (0) diff --git a/src/node_contextify.cc b/src/node_contextify.cc index b3e3d3d051375f..342b46b3517a79 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -140,7 +140,7 @@ class ContextifyContext { int length = names->Length(); for (int i = 0; i < length; i++) { Local key = names->Get(i)->ToString(env()->isolate()); - bool has = sandbox->HasOwnProperty(key); + bool has = sandbox->HasOwnProperty(context, key).FromJust(); if (!has) { // Could also do this like so: // @@ -167,9 +167,8 @@ class ContextifyContext { " }\n" "})"); - Local fname = FIXED_ONE_BYTE_STRING(env()->isolate(), - "binding:script"); - Local