src: split property helpers from node::Environment
To disentangle native bindings from the main context, methods like property helpers that are heavily used in native binding initialization need to be moved off node::Environment
for:
- Dynamic scopes of
v8::Context
withIsolate::GetCurrentContext
in methods likeSetMethod
need to be prevented. They need to explicitly call into JavaScript with their specified contexts. - Native modules like
url
that have no dependencies on the event-loop don't need to accessnode::Environment
. -
FunctionTemplate
is per isolate primitives, they don't need to be created with anode::Environment
. This change enables a new initialization phase for native binding to create per-isolate primitives withoutnode::Environment
in the near future, to reduce the memory consumption when sharing function templates across realms.
These property helpers can be categorized as:
- Template property helpers: their operations require an explicit
v8::Isolate
.NewFunctionTemplate
SetInstanceMethod
SetProtoMethod
SetProtoMethodNoSideEffect
- Object property helpers: their operations require an explicit
v8::Context
.SetMethod
SetFastMethod
SetMethodNoSideEffect
SetConstructorFunction
The core change of this PR is moving these methods to src/util.h
and src/util.cc
.