-
-
Notifications
You must be signed in to change notification settings - Fork 600
Open
Description
node-addon-examples/src/1-getting-started/7_factory_wrap/node-addon-api/myobject.cc
Lines 24 to 28 in ed36ba2
| Napi::Object MyObject::NewInstance(Napi::Env env, Napi::Value arg) { | |
| Napi::EscapableHandleScope scope(env); | |
| Napi::Object obj = env.GetInstanceData<Napi::FunctionReference>()->New({arg}); | |
| return scope.Escape(napi_value(obj)).ToObject(); | |
| } |
node-addon-examples/src/1-getting-started/6_object_wrap/node-addon-api/myobject.cc
Lines 46 to 58 in ed36ba2
| Napi::Value MyObject::Multiply(const Napi::CallbackInfo& info) { | |
| Napi::Number multiple; | |
| if (info.Length() <= 0 || !info[0].IsNumber()) { | |
| multiple = Napi::Number::New(info.Env(), 1); | |
| } else { | |
| multiple = info[0].As<Napi::Number>(); | |
| } | |
| Napi::Object obj = info.Env().GetInstanceData<Napi::FunctionReference>()->New( | |
| {Napi::Number::New(info.Env(), this->value_ * multiple.DoubleValue())}); | |
| return obj; | |
| } |
I'm Newby, who just got into NAPI.
In the above two codes, methods are create and return the object.
I wonder why only the return value in NewInstance uses escape scope.
Metadata
Metadata
Assignees
Labels
No labels