I have difficulties to understand how to correctly use HandleScope and EscapableHandleScope. For example, from this Node example:
MyObject::MyObject(const Napi::CallbackInfo& info) : Napi::ObjectWrap<MyObject>(info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->val_ = info[0].As<Napi::Number>().DoubleValue();
};
Why do we need to create a new HandleScope in this case? And from this other example:
Napi::Object CreateObject(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::Object obj = Napi::Object::New(env);
obj.Set(Napi::String::New(env, "msg"), info[0].ToString());
return obj;
}
Why is it not needed here?
Also, I didn't find any example using EscapableHandleScope, when is this needed?