Skip to content

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:

  1. Dynamic scopes of v8::Context with Isolate::GetCurrentContext in methods like SetMethod need to be prevented. They need to explicitly call into JavaScript with their specified contexts.
  2. Native modules like url that have no dependencies on the event-loop don't need to access node::Environment.
  3. FunctionTemplate is per isolate primitives, they don't need to be created with a node::Environment. This change enables a new initialization phase for native binding to create per-isolate primitives without node::Environment in the near future, to reduce the memory consumption when sharing function templates across realms.

These property helpers can be categorized as:

  1. Template property helpers: their operations require an explicit v8::Isolate.
    • NewFunctionTemplate
    • SetInstanceMethod
    • SetProtoMethod
    • SetProtoMethodNoSideEffect
  2. 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.

Refs: https://github.com/nodejs/node/issues/42528

Merge request reports

Loading