Skip to content

Commit 54608d8

Browse files
legendecasrichardlau
authored andcommittedNov 24, 2022
src: split property helpers from node::Environment
PR-URL: #44056 Backport-PR-URL: #44542 Refs: #42528 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Feng Yu <F3n67u@outlook.com>
1 parent e972ff7 commit 54608d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1484
-1271
lines changed
 

‎src/README.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -390,32 +390,33 @@ void Initialize(Local<Object> target,
390390
void* priv) {
391391
Environment* env = Environment::GetCurrent(context);
392392

393-
env->SetMethod(target, "getaddrinfo", GetAddrInfo);
394-
env->SetMethod(target, "getnameinfo", GetNameInfo);
393+
SetMethod(context, target, "getaddrinfo", GetAddrInfo);
394+
SetMethod(context, target, "getnameinfo", GetNameInfo);
395395

396396
// 'SetMethodNoSideEffect' means that debuggers can safely execute this
397397
// function for e.g. previews.
398-
env->SetMethodNoSideEffect(target, "canonicalizeIP", CanonicalizeIP);
398+
SetMethodNoSideEffect(context, target, "canonicalizeIP", CanonicalizeIP);
399399

400400
// ... more code ...
401401

402+
Isolate* isolate = env->isolate();
402403
// Building the `ChannelWrap` class for JS:
403404
Local<FunctionTemplate> channel_wrap =
404-
env->NewFunctionTemplate(ChannelWrap::New);
405+
NewFunctionTemplate(isolate, ChannelWrap::New);
405406
// Allow for 1 internal field, see `BaseObject` for details on this:
406407
channel_wrap->InstanceTemplate()->SetInternalFieldCount(1);
407408
channel_wrap->Inherit(AsyncWrap::GetConstructorTemplate(env));
408409

409410
// Set various methods on the class (i.e. on the prototype):
410-
env->SetProtoMethod(channel_wrap, "queryAny", Query<QueryAnyWrap>);
411-
env->SetProtoMethod(channel_wrap, "queryA", Query<QueryAWrap>);
411+
SetProtoMethod(isolate, channel_wrap, "queryAny", Query<QueryAnyWrap>);
412+
SetProtoMethod(isolate, channel_wrap, "queryA", Query<QueryAWrap>);
412413
// ...
413-
env->SetProtoMethod(channel_wrap, "querySoa", Query<QuerySoaWrap>);
414-
env->SetProtoMethod(channel_wrap, "getHostByAddr", Query<GetHostByAddrWrap>);
414+
SetProtoMethod(isolate, channel_wrap, "querySoa", Query<QuerySoaWrap>);
415+
SetProtoMethod(isolate, channel_wrap, "getHostByAddr", Query<GetHostByAddrWrap>);
415416

416-
env->SetProtoMethodNoSideEffect(channel_wrap, "getServers", GetServers);
417+
SetProtoMethodNoSideEffect(isolate, channel_wrap, "getServers", GetServers);
417418

418-
env->SetConstructorFunction(target, "ChannelWrap", channel_wrap);
419+
SetConstructorFunction(context, target, "ChannelWrap", channel_wrap);
419420
}
420421

421422
// Run the `Initialize` function when loading this module through

‎src/async_wrap.cc

+15-13
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,14 @@ void AsyncWrap::SetCallbackTrampoline(const FunctionCallbackInfo<Value>& args) {
340340
Local<FunctionTemplate> AsyncWrap::GetConstructorTemplate(Environment* env) {
341341
Local<FunctionTemplate> tmpl = env->async_wrap_ctor_template();
342342
if (tmpl.IsEmpty()) {
343-
tmpl = env->NewFunctionTemplate(nullptr);
343+
Isolate* isolate = env->isolate();
344+
tmpl = NewFunctionTemplate(isolate, nullptr);
344345
tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "AsyncWrap"));
345346
tmpl->Inherit(BaseObject::GetConstructorTemplate(env));
346-
env->SetProtoMethod(tmpl, "getAsyncId", AsyncWrap::GetAsyncId);
347-
env->SetProtoMethod(tmpl, "asyncReset", AsyncWrap::AsyncReset);
348-
env->SetProtoMethod(tmpl, "getProviderType", AsyncWrap::GetProviderType);
347+
SetProtoMethod(isolate, tmpl, "getAsyncId", AsyncWrap::GetAsyncId);
348+
SetProtoMethod(isolate, tmpl, "asyncReset", AsyncWrap::AsyncReset);
349+
SetProtoMethod(
350+
isolate, tmpl, "getProviderType", AsyncWrap::GetProviderType);
349351
env->set_async_wrap_ctor_template(tmpl);
350352
}
351353
return tmpl;
@@ -359,15 +361,15 @@ void AsyncWrap::Initialize(Local<Object> target,
359361
Isolate* isolate = env->isolate();
360362
HandleScope scope(isolate);
361363

362-
env->SetMethod(target, "setupHooks", SetupHooks);
363-
env->SetMethod(target, "setCallbackTrampoline", SetCallbackTrampoline);
364-
env->SetMethod(target, "pushAsyncContext", PushAsyncContext);
365-
env->SetMethod(target, "popAsyncContext", PopAsyncContext);
366-
env->SetMethod(target, "executionAsyncResource", ExecutionAsyncResource);
367-
env->SetMethod(target, "clearAsyncIdStack", ClearAsyncIdStack);
368-
env->SetMethod(target, "queueDestroyAsyncId", QueueDestroyAsyncId);
369-
env->SetMethod(target, "setPromiseHooks", SetPromiseHooks);
370-
env->SetMethod(target, "registerDestroyHook", RegisterDestroyHook);
364+
SetMethod(context, target, "setupHooks", SetupHooks);
365+
SetMethod(context, target, "setCallbackTrampoline", SetCallbackTrampoline);
366+
SetMethod(context, target, "pushAsyncContext", PushAsyncContext);
367+
SetMethod(context, target, "popAsyncContext", PopAsyncContext);
368+
SetMethod(context, target, "executionAsyncResource", ExecutionAsyncResource);
369+
SetMethod(context, target, "clearAsyncIdStack", ClearAsyncIdStack);
370+
SetMethod(context, target, "queueDestroyAsyncId", QueueDestroyAsyncId);
371+
SetMethod(context, target, "setPromiseHooks", SetPromiseHooks);
372+
SetMethod(context, target, "registerDestroyHook", RegisterDestroyHook);
371373

372374
PropertyAttribute ReadOnlyDontDelete =
373375
static_cast<PropertyAttribute>(ReadOnly | DontDelete);

0 commit comments

Comments
 (0)
Please sign in to comment.