Skip to content

src: add context-aware helpers and init macro

Introduces macro NODE_MODULE_INIT() which creates the boilerplate for a context-aware module which can be loaded multiple times via the special symbol mechanism.

Also introduces class node::WeakData with which one can weakly associate a native class instance with a JavaScript object, and convenience methods node::SetMethodWithData() and node::SetPrototypeMethodWithData() which pass a native pointer through to bindings.

Together, these APIs allow one to avoid using global static data in an addon.

Re: https://github.com/nodejs/node/issues/21291#issuecomment-396729727

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Merge request reports

Loading