node-addon-examples icon indicating copy to clipboard operation
node-addon-examples copied to clipboard

Why do these two examples need a static FunctionReference?

Open seishun opened this issue 4 years ago • 0 comments

https://github.com/nodejs/node-addon-examples/blob/c1bdff050f8c7dc250f7779283fbab664bfb5bcd/function-reference-demo/node-addon-api/src/native-addon.cc#L4 https://github.com/nodejs/node-addon-examples/blob/c1bdff050f8c7dc250f7779283fbab664bfb5bcd/inherits_from_event_emitter/node-addon-api/src/native-emitter.cc#L7

It's not referred anywhere other than the Init function and having an "immortal" Napi::FunctionReference seems unnecessary since the constructor isn't invoked from native code.

Curiously, these two examples were untouched by dc86a662c27c5732e069e1c19d3b7a8e74e86d29, which replaced the usage of a static FunctionReference with instance data in examples that do need to keep the constructor alive.

seishun avatar Dec 18 '20 11:12 seishun