Skip to content

Commit

Permalink
[cleanup][v8] Replace uses of deprecated API
Browse files Browse the repository at this point in the history
  • Loading branch information
gahaas authored and hashseed committed Sep 21, 2018
1 parent c17d90b commit 70d60c4
Show file tree
Hide file tree
Showing 38 changed files with 148 additions and 80 deletions.
12 changes: 8 additions & 4 deletions doc/api/addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ functions and returning those back to JavaScript:

namespace demo {

using v8::Context;
using v8::Function;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand All @@ -649,8 +650,9 @@ void MyFunction(const FunctionCallbackInfo<Value>& args) {
void CreateFunction(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();

Local<Context> context = isolate->GetCurrentContext();
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, MyFunction);
Local<Function> fn = tpl->GetFunction();
Local<Function> fn = tpl->GetFunction(context).ToLocalChecked();

// omit this to make it anonymous
fn->SetName(String::NewFromUtf8(isolate, "theFunction"));
Expand Down Expand Up @@ -774,9 +776,10 @@ void MyObject::Init(Local<Object> exports) {
// Prototype
NODE_SET_PROTOTYPE_METHOD(tpl, "plusOne", PlusOne);

constructor.Reset(isolate, tpl->GetFunction());
Local<Context> context = isolate->GetCurrentContext();
constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked());
exports->Set(String::NewFromUtf8(isolate, "MyObject"),
tpl->GetFunction());
tpl->GetFunction(context).ToLocalChecked());
}

void MyObject::New(const FunctionCallbackInfo<Value>& args) {
Expand Down Expand Up @@ -958,7 +961,8 @@ void MyObject::Init(Isolate* isolate) {
// Prototype
NODE_SET_PROTOTYPE_METHOD(tpl, "plusOne", PlusOne);

constructor.Reset(isolate, tpl->GetFunction());
Local<Context> context = isolate->GetCurrentContext();
constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked());
}

void MyObject::New(const FunctionCallbackInfo<Value>& args) {
Expand Down
9 changes: 5 additions & 4 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2129,23 +2129,23 @@ void Initialize(Local<Object> target,
Local<String> addrInfoWrapString =
FIXED_ONE_BYTE_STRING(env->isolate(), "GetAddrInfoReqWrap");
aiw->SetClassName(addrInfoWrapString);
target->Set(addrInfoWrapString, aiw->GetFunction());
target->Set(addrInfoWrapString, aiw->GetFunction(context).ToLocalChecked());

Local<FunctionTemplate> niw =
BaseObject::MakeLazilyInitializedJSTemplate(env);
AsyncWrap::AddWrapMethods(env, niw);
Local<String> nameInfoWrapString =
FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap");
niw->SetClassName(nameInfoWrapString);
target->Set(nameInfoWrapString, niw->GetFunction());
target->Set(nameInfoWrapString, niw->GetFunction(context).ToLocalChecked());

Local<FunctionTemplate> qrw =
BaseObject::MakeLazilyInitializedJSTemplate(env);
AsyncWrap::AddWrapMethods(env, qrw);
Local<String> queryWrapString =
FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap");
qrw->SetClassName(queryWrapString);
target->Set(queryWrapString, qrw->GetFunction());
target->Set(queryWrapString, qrw->GetFunction(context).ToLocalChecked());

Local<FunctionTemplate> channel_wrap =
env->NewFunctionTemplate(ChannelWrap::New);
Expand All @@ -2172,7 +2172,8 @@ void Initialize(Local<Object> target,
Local<String> channelWrapString =
FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap");
channel_wrap->SetClassName(channelWrapString);
target->Set(channelWrapString, channel_wrap->GetFunction());
target->Set(channelWrapString,
channel_wrap->GetFunction(context).ToLocalChecked());
}

} // anonymous namespace
Expand Down
16 changes: 10 additions & 6 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -685,13 +685,15 @@ inline v8::Local<v8::FunctionTemplate>
inline void Environment::SetMethod(v8::Local<v8::Object> that,
const char* name,
v8::FunctionCallback callback) {
v8::Local<v8::Context> context = isolate()->GetCurrentContext();
v8::Local<v8::Function> function =
NewFunctionTemplate(callback,
v8::Local<v8::Signature>(),
NewFunctionTemplate(callback, v8::Local<v8::Signature>(),
// TODO(TimothyGu): Investigate if SetMethod is ever
// used for constructors.
v8::ConstructorBehavior::kAllow,
v8::SideEffectType::kHasSideEffect)->GetFunction();
v8::SideEffectType::kHasSideEffect)
->GetFunction(context)
.ToLocalChecked();
// kInternalized strings are created in the old space.
const v8::NewStringType type = v8::NewStringType::kInternalized;
v8::Local<v8::String> name_string =
Expand All @@ -703,13 +705,15 @@ inline void Environment::SetMethod(v8::Local<v8::Object> that,
inline void Environment::SetMethodNoSideEffect(v8::Local<v8::Object> that,
const char* name,
v8::FunctionCallback callback) {
v8::Local<v8::Context> context = isolate()->GetCurrentContext();
v8::Local<v8::Function> function =
NewFunctionTemplate(callback,
v8::Local<v8::Signature>(),
NewFunctionTemplate(callback, v8::Local<v8::Signature>(),
// TODO(TimothyGu): Investigate if SetMethod is ever
// used for constructors.
v8::ConstructorBehavior::kAllow,
v8::SideEffectType::kHasNoSideEffect)->GetFunction();
v8::SideEffectType::kHasNoSideEffect)
->GetFunction(context)
.ToLocalChecked();
// kInternalized strings are created in the old space.
const v8::NewStringType type = v8::NewStringType::kInternalized;
v8::Local<v8::String> name_string =
Expand Down
6 changes: 4 additions & 2 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,10 @@ void Environment::Start(int argc,
auto process_template = FunctionTemplate::New(isolate());
process_template->SetClassName(FIXED_ONE_BYTE_STRING(isolate(), "process"));

auto process_object =
process_template->GetFunction()->NewInstance(context()).ToLocalChecked();
auto process_object = process_template->GetFunction(context())
.ToLocalChecked()
->NewInstance(context())
.ToLocalChecked();
set_process_object(process_object);

SetupProcessObject(this, argc, argv, exec_argc, exec_argv);
Expand Down
2 changes: 1 addition & 1 deletion src/fs_event_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void FSEventWrap::Initialize(Local<Object> target,
Local<FunctionTemplate>(),
static_cast<PropertyAttribute>(ReadOnly | DontDelete | v8::DontEnum));

target->Set(fsevent_string, t->GetFunction());
target->Set(fsevent_string, t->GetFunction(context).ToLocalChecked());
}


Expand Down
5 changes: 4 additions & 1 deletion src/inspector_js_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,10 @@ void Initialize(Local<Object> target, Local<Value> unused,
AsyncWrap::AddWrapMethods(env, tmpl);
env->SetProtoMethod(tmpl, "dispatch", JSBindingsConnection::Dispatch);
env->SetProtoMethod(tmpl, "disconnect", JSBindingsConnection::Disconnect);
target->Set(env->context(), conn_str, tmpl->GetFunction()).ToChecked();
target
->Set(env->context(), conn_str,
tmpl->GetFunction(env->context()).ToLocalChecked())
.ToChecked();
}

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion src/js_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void JSStream::Initialize(Local<Object> target,
env->SetProtoMethod(t, "emitEOF", EmitEOF);

StreamBase::AddMethods<JSStream>(env, t);
target->Set(jsStreamString, t->GetFunction());
target->Set(jsStreamString, t->GetFunction(context).ToLocalChecked());
}

} // namespace node
Expand Down
3 changes: 2 additions & 1 deletion src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,8 @@ void ModuleWrap::Initialize(Local<Object> target,
env->SetProtoMethodNoSideEffect(tpl, "getStaticDependencySpecifiers",
GetStaticDependencySpecifiers);

target->Set(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"), tpl->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"),
tpl->GetFunction(context).ToLocalChecked());
env->SetMethod(target, "resolve", Resolve);
env->SetMethod(target,
"setImportModuleDynamicallyCallback",
Expand Down
3 changes: 2 additions & 1 deletion src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,10 @@ inline void NODE_SET_METHOD(v8::Local<v8::Object> recv,
v8::FunctionCallback callback) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = isolate->GetCurrentContext();
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate,
callback);
v8::Local<v8::Function> fn = t->GetFunction();
v8::Local<v8::Function> fn = t->GetFunction(context).ToLocalChecked();
v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name);
fn->SetName(fn_name);
recv->Set(fn_name, fn);
Expand Down
4 changes: 3 additions & 1 deletion src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,9 @@ napi_status napi_define_class(napi_env env,
}
}

*result = v8impl::JsValueFromV8LocalValue(scope.Escape(tpl->GetFunction()));
v8::Local<v8::Context> context = isolate->GetCurrentContext();
*result = v8impl::JsValueFromV8LocalValue(
scope.Escape(tpl->GetFunction(context).ToLocalChecked()));

if (static_property_count > 0) {
std::vector<napi_property_descriptor> static_descriptors;
Expand Down
6 changes: 4 additions & 2 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ void ContextifyContext::Init(Environment* env, Local<Object> target) {
Local<FunctionTemplate> function_template =
FunctionTemplate::New(env->isolate());
function_template->InstanceTemplate()->SetInternalFieldCount(1);
env->set_script_data_constructor_function(function_template->GetFunction());
env->set_script_data_constructor_function(
function_template->GetFunction(env->context()).ToLocalChecked());

env->SetMethod(target, "makeContext", MakeContext);
env->SetMethod(target, "isContext", IsContext);
Expand Down Expand Up @@ -601,7 +602,8 @@ class ContextifyScript : public BaseObject {
env->SetProtoMethod(script_tmpl, "runInContext", RunInContext);
env->SetProtoMethod(script_tmpl, "runInThisContext", RunInThisContext);

target->Set(class_name, script_tmpl->GetFunction());
target->Set(class_name,
script_tmpl->GetFunction(env->context()).ToLocalChecked());
env->set_script_context_constructor_template(script_tmpl);

Local<Symbol> parsing_context_symbol =
Expand Down
4 changes: 3 additions & 1 deletion src/node_counters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ void InitPerfCounters(Environment* env, Local<Object> target) {

for (size_t i = 0; i < arraysize(tab); i++) {
Local<String> key = OneByteString(env->isolate(), tab[i].name);
Local<Value> val = env->NewFunctionTemplate(tab[i].func)->GetFunction();
Local<Value> val = env->NewFunctionTemplate(tab[i].func)
->GetFunction(env->context())
.ToLocalChecked();
target->Set(key, val);
}

Expand Down
22 changes: 13 additions & 9 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ void SecureContext::Initialize(Environment* env, Local<Object> target) {
t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kTicketKeyIVIndex"),
Integer::NewFromUnsigned(env->isolate(), kTicketKeyIVIndex));

target->Set(secureContextString, t->GetFunction());
target->Set(secureContextString,
t->GetFunction(env->context()).ToLocalChecked());
env->set_secure_context_constructor_template(t);
}

Expand Down Expand Up @@ -2576,7 +2577,7 @@ void CipherBase::Initialize(Environment* env, Local<Object> target) {
env->SetProtoMethod(t, "setAAD", SetAAD);

target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "CipherBase"),
t->GetFunction());
t->GetFunction(env->context()).ToLocalChecked());
}


Expand Down Expand Up @@ -3166,7 +3167,8 @@ void Hmac::Initialize(Environment* env, v8::Local<Object> target) {
env->SetProtoMethod(t, "update", HmacUpdate);
env->SetProtoMethod(t, "digest", HmacDigest);

target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Hmac"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Hmac"),
t->GetFunction(env->context()).ToLocalChecked());
}


Expand Down Expand Up @@ -3285,7 +3287,8 @@ void Hash::Initialize(Environment* env, v8::Local<Object> target) {
env->SetProtoMethod(t, "update", HashUpdate);
env->SetProtoMethod(t, "digest", HashDigest);

target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Hash"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Hash"),
t->GetFunction(env->context()).ToLocalChecked());
}


Expand Down Expand Up @@ -3478,7 +3481,8 @@ void Sign::Initialize(Environment* env, v8::Local<Object> target) {
env->SetProtoMethod(t, "update", SignUpdate);
env->SetProtoMethod(t, "sign", SignFinal);

target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Sign"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Sign"),
t->GetFunction(env->context()).ToLocalChecked());
}


Expand Down Expand Up @@ -3645,7 +3649,7 @@ void Verify::Initialize(Environment* env, v8::Local<Object> target) {
env->SetProtoMethod(t, "verify", VerifyFinal);

target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Verify"),
t->GetFunction());
t->GetFunction(env->context()).ToLocalChecked());
}


Expand Down Expand Up @@ -3930,7 +3934,7 @@ void DiffieHellman::Initialize(Environment* env, Local<Object> target) {
attributes);

target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "DiffieHellman"),
t->GetFunction());
t->GetFunction(env->context()).ToLocalChecked());

Local<FunctionTemplate> t2 = env->NewFunctionTemplate(DiffieHellmanGroup);
t2->InstanceTemplate()->SetInternalFieldCount(1);
Expand Down Expand Up @@ -3959,7 +3963,7 @@ void DiffieHellman::Initialize(Environment* env, Local<Object> target) {
attributes);

target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "DiffieHellmanGroup"),
t2->GetFunction());
t2->GetFunction(env->context()).ToLocalChecked());
}


Expand Down Expand Up @@ -4308,7 +4312,7 @@ void ECDH::Initialize(Environment* env, Local<Object> target) {
env->SetProtoMethod(t, "setPrivateKey", SetPrivateKey);

target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ECDH"),
t->GetFunction());
t->GetFunction(env->context()).ToLocalChecked());
}


Expand Down
4 changes: 3 additions & 1 deletion src/node_dtrace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ void InitDTrace(Environment* env, Local<Object> target) {

for (size_t i = 0; i < arraysize(tab); i++) {
Local<String> key = OneByteString(env->isolate(), tab[i].name);
Local<Value> val = env->NewFunctionTemplate(tab[i].func)->GetFunction();
Local<Value> val = env->NewFunctionTemplate(tab[i].func)
->GetFunction(env->context())
.ToLocalChecked();
target->Set(key, val);
}

Expand Down
10 changes: 8 additions & 2 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,10 @@ void Initialize(Local<Object> target,
Local<String> wrapString =
FIXED_ONE_BYTE_STRING(env->isolate(), "FSReqWrap");
fst->SetClassName(wrapString);
target->Set(context, wrapString, fst->GetFunction()).FromJust();
target
->Set(context, wrapString,
fst->GetFunction(env->context()).ToLocalChecked())
.FromJust();

// Create FunctionTemplate for FileHandleReadWrap. There’s no need
// to do anything in the constructor, so we only store the instance template.
Expand Down Expand Up @@ -1998,7 +2001,10 @@ void Initialize(Local<Object> target,
FIXED_ONE_BYTE_STRING(env->isolate(), "FileHandle");
fd->SetClassName(handleString);
StreamBase::AddMethods<FileHandle>(env, fd);
target->Set(context, handleString, fd->GetFunction()).FromJust();
target
->Set(context, handleString,
fd->GetFunction(env->context()).ToLocalChecked())
.FromJust();
env->set_fd_constructor_template(fdt);

// Create FunctionTemplate for FileHandle::CloseReq
Expand Down
4 changes: 2 additions & 2 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2845,7 +2845,7 @@ void Initialize(Local<Object> target,
env->set_http2stream_constructor_template(streamt);
target->Set(context,
FIXED_ONE_BYTE_STRING(env->isolate(), "Http2Stream"),
stream->GetFunction()).FromJust();
stream->GetFunction(env->context()).ToLocalChecked()).FromJust();

Local<FunctionTemplate> session =
env->NewFunctionTemplate(Http2Session::New);
Expand All @@ -2872,7 +2872,7 @@ void Initialize(Local<Object> target,
Http2Session::RefreshSettings<nghttp2_session_get_remote_settings>);
target->Set(context,
http2SessionClassName,
session->GetFunction()).FromJust();
session->GetFunction(env->context()).ToLocalChecked()).FromJust();

Local<Object> constants = Object::New(isolate);
Local<Array> name_for_error_code = Array::New(isolate);
Expand Down
2 changes: 1 addition & 1 deletion src/node_http_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ void Initialize(Local<Object> target,
env->SetProtoMethod(t, "getCurrentBuffer", Parser::GetCurrentBuffer);

target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "HTTPParser"),
t->GetFunction());
t->GetFunction(env->context()).ToLocalChecked());
}

} // anonymous namespace
Expand Down
2 changes: 1 addition & 1 deletion src/node_perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ void Initialize(Local<Object> target,

Local<FunctionTemplate> pe = FunctionTemplate::New(isolate);
pe->SetClassName(performanceEntryString);
Local<Function> fn = pe->GetFunction();
Local<Function> fn = pe->GetFunction(context).ToLocalChecked();
target->Set(context, performanceEntryString, fn).FromJust();
env->set_performance_entry_template(fn);

Expand Down
3 changes: 2 additions & 1 deletion src/node_stat_watcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ void StatWatcher::Initialize(Environment* env, Local<Object> target) {
env->SetProtoMethod(t, "unref", HandleWrap::Unref);
env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef);

target->Set(statWatcherString, t->GetFunction());
target->Set(statWatcherString,
t->GetFunction(env->context()).ToLocalChecked());
}


Expand Down
2 changes: 1 addition & 1 deletion src/node_trace_events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void Initialize(Local<Object> target,
env->SetProtoMethod(category_set, "disable", NodeCategorySet::Disable);

target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "CategorySet"),
category_set->GetFunction());
category_set->GetFunction(env->context()).ToLocalChecked());
}

} // namespace node
Expand Down
Loading

0 comments on commit 70d60c4

Please sign in to comment.