Skip to content

(vee-eight-4.9) replace usage of deprecated V8 APIs #5159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/debug-agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand All @@ -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));
Expand Down
43 changes: 28 additions & 15 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,15 @@ using v8::Integer;
using v8::Isolate;
using v8::Local;
using v8::Locker;
using v8::MaybeLocal;
using v8::Message;
using v8::Number;
using v8::Object;
using v8::ObjectTemplate;
using v8::Promise;
using v8::PromiseRejectMessage;
using v8::PropertyCallbackInfo;
using v8::ScriptOrigin;
using v8::SealHandleScope;
using v8::StackFrame;
using v8::StackTrace;
Expand Down Expand Up @@ -1042,7 +1044,8 @@ void SetupDomainUse(const FunctionCallbackInfo<Value>& 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();
Expand All @@ -1065,7 +1068,8 @@ void SetupProcessObject(const FunctionCallbackInfo<Value>& args) {

env->set_push_values_to_array_function(args[0].As<Function>());
env->process_object()->Delete(
FIXED_ONE_BYTE_STRING(env->isolate(), "_setupProcessObject"));
env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "_setupProcessObject")).FromJust();
}


Expand All @@ -1081,7 +1085,8 @@ void SetupNextTick(const FunctionCallbackInfo<Value>& 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();
Expand Down Expand Up @@ -1121,7 +1126,8 @@ void SetupPromises(const FunctionCallbackInfo<Value>& args) {
env->set_promise_reject_function(args[0].As<Function>());

env->process_object()->Delete(
FIXED_ONE_BYTE_STRING(args.GetIsolate(), "_setupPromises"));
env->context(),
FIXED_ONE_BYTE_STRING(args.GetIsolate(), "_setupPromises")).FromJust();
}


Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1607,13 +1613,15 @@ static Local<Value> ExecuteString(Environment* env,
// we will handle exceptions ourself.
try_catch.SetVerbose(false);

Local<v8::Script> script = v8::Script::Compile(source, filename);
ScriptOrigin origin(filename);
MaybeLocal<v8::Script> script =
v8::Script::Compile(env->context(), source, &origin);
if (script.IsEmpty()) {
ReportException(env, try_catch);
exit(3);
}

Local<Value> result = script->Run();
Local<Value> result = script.ToLocalChecked()->Run();
if (result.IsEmpty()) {
ReportException(env, try_catch);
exit(4);
Expand Down Expand Up @@ -2371,7 +2379,7 @@ static void Binding(const FunctionCallbackInfo<Value>& args) {
Local<Object> cache = env->binding_cache_object();
Local<Object> exports;

if (cache->Has(module)) {
if (cache->Has(env->context(), module).FromJust()) {
exports = cache->Get(module)->ToObject(env->isolate());
args.GetReturnValue().Set(exports);
return;
Expand Down Expand Up @@ -2788,15 +2796,20 @@ void StopProfilerIdleNotifier(const FunctionCallbackInfo<Value>& 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::PropertyAttribute>(v8::ReadOnly | \
v8::DontEnum)); \
obj->DefineOwnProperty(env->context(), \
OneByteString(env->isolate(), str), \
var, \
static_cast<v8::PropertyAttribute>(v8::ReadOnly | \
v8::DontEnum)) \
.FromJust(); \
} while (0)


Expand Down Expand Up @@ -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));
}

Expand Down
6 changes: 5 additions & 1 deletion src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,17 @@ NODE_EXTERN void RunAtExit(Environment* env);
#define NODE_DEFINE_CONSTANT(target, constant) \
do { \
v8::Isolate* isolate = target->GetIsolate(); \
v8::Local<v8::Context> context = isolate->GetCurrentContext(); \
v8::Local<v8::String> constant_name = \
v8::String::NewFromUtf8(isolate, #constant); \
v8::Local<v8::Number> constant_value = \
v8::Number::New(isolate, static_cast<double>(constant)); \
v8::PropertyAttribute constant_attributes = \
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); \
(target)->ForceSet(constant_name, constant_value, constant_attributes); \
(target)->DefineOwnProperty(context, \
constant_name, \
constant_value, \
constant_attributes).FromJust(); \
} \
while (0)

Expand Down
22 changes: 11 additions & 11 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class ContextifyContext {
int length = names->Length();
for (int i = 0; i < length; i++) {
Local<String> 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:
//
Expand All @@ -167,9 +167,8 @@ class ContextifyContext {
" }\n"
"})");

Local<String> fname = FIXED_ONE_BYTE_STRING(env()->isolate(),
"binding:script");
Local<Script> script = Script::Compile(code, fname);
Local<Script> script =
Script::Compile(context, code).ToLocalChecked();
clone_property_method = Local<Function>::Cast(script->Run());
CHECK(clone_property_method->IsFunction());
}
Expand Down Expand Up @@ -245,12 +244,12 @@ class ContextifyContext {
Local<String> script_source(args[0]->ToString(args.GetIsolate()));
if (script_source.IsEmpty())
return; // Exception pending.
Local<Context> debug_context = Debug::GetDebugContext();
Local<Context> debug_context = Debug::GetDebugContext(args.GetIsolate());
Environment* env = Environment::GetCurrent(args);
if (debug_context.IsEmpty()) {
// Force-load the debug context.
Debug::GetMirror(args.GetIsolate()->GetCurrentContext(), args[0]);
debug_context = Debug::GetDebugContext();
debug_context = Debug::GetDebugContext(args.GetIsolate());
CHECK(!debug_context.IsEmpty());
// Ensure that the debug context has an Environment assigned in case
// a fatal error is raised. The fatal exception handler in node.cc
Expand All @@ -263,10 +262,10 @@ class ContextifyContext {
}

Context::Scope context_scope(debug_context);
Local<Script> script = Script::Compile(script_source);
MaybeLocal<Script> script = Script::Compile(debug_context, script_source);
if (script.IsEmpty())
return; // Exception pending.
args.GetReturnValue().Set(script->Run());
args.GetReturnValue().Set(script.ToLocalChecked()->Run());
}


Expand Down Expand Up @@ -526,7 +525,7 @@ class ContextifyScript : public BaseObject {
else if (produce_cached_data)
compile_options = ScriptCompiler::kProduceCodeCache;

Local<UnboundScript> v8_script = ScriptCompiler::CompileUnbound(
MaybeLocal<UnboundScript> v8_script = ScriptCompiler::CompileUnboundScript(
env->isolate(),
&source,
compile_options);
Expand All @@ -538,7 +537,8 @@ class ContextifyScript : public BaseObject {
try_catch.ReThrow();
return;
}
contextify_script->script_.Reset(env->isolate(), v8_script);
contextify_script->script_.Reset(env->isolate(),
v8_script.ToLocalChecked());

if (compile_options == ScriptCompiler::kConsumeCodeCache) {
args.This()->Set(
Expand Down Expand Up @@ -832,7 +832,7 @@ class ContextifyScript : public BaseObject {
}

if (try_catch.HasCaught() && try_catch.HasTerminated()) {
V8::CancelTerminateExecution(env->isolate());
env->isolate()->CancelTerminateExecution();
env->ThrowError("Script execution timed out.");
try_catch.ReThrow();
return false;
Expand Down
8 changes: 4 additions & 4 deletions src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ struct sockaddr;
v8::String::NewFromUtf8(isolate, constant); \
v8::PropertyAttribute constant_attributes = \
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); \
target->ForceSet(isolate->GetCurrentContext(), \
constant_name, \
constant_value, \
constant_attributes); \
target->DefineOwnProperty(isolate->GetCurrentContext(), \
constant_name, \
constant_value, \
constant_attributes).FromJust(); \
} while (0)

namespace node {
Expand Down
2 changes: 1 addition & 1 deletion src/node_os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
name = OneByteString(env->isolate(), raw_name);
#endif

if (ret->Has(name)) {
if (ret->Has(env->context(), name).FromJust()) {
ifarr = Local<Array>::Cast(ret->Get(name));
} else {
ifarr = Array::New(env->isolate());
Expand Down
2 changes: 1 addition & 1 deletion src/node_watchdog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void Watchdog::Async(uv_async_t* async) {
void Watchdog::Timer(uv_timer_t* timer) {
Watchdog* w = ContainerOf(&Watchdog::timer_, timer);
uv_stop(w->loop_);
V8::TerminateExecution(w->isolate());
w->isolate()->TerminateExecution();
}


Expand Down
10 changes: 7 additions & 3 deletions src/stream_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ void StreamBase::AfterShutdown(ShutdownWrap* req_wrap, int status) {
req_wrap_obj
};

if (req_wrap->object()->Has(env->oncomplete_string()))
if (req_wrap->object()->Has(env->context(),
env->oncomplete_string()).FromJust()) {
req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv);
}

delete req_wrap;
}
Expand Down Expand Up @@ -371,7 +373,7 @@ void StreamBase::AfterWrite(WriteWrap* req_wrap, int status) {

// Unref handle property
Local<Object> req_wrap_obj = req_wrap->object();
req_wrap_obj->Delete(env->handle_string());
req_wrap_obj->Delete(env->context(), env->handle_string()).FromJust();
wrap->OnAfterWrite(req_wrap);

Local<Value> argv[] = {
Expand All @@ -387,8 +389,10 @@ void StreamBase::AfterWrite(WriteWrap* req_wrap, int status) {
wrap->ClearError();
}

if (req_wrap->object()->Has(env->oncomplete_string()))
if (req_wrap->object()->Has(env->context(),
env->oncomplete_string()).FromJust()) {
req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv);
}

req_wrap->Dispose();
}
Expand Down