@@ -9,6 +9,7 @@ MyObject::~MyObject() {
99}
1010
1111void MyObject::Init (v8::Local<v8::Object> exports) {
12+ v8::Local<v8::Context> context = exports->CreationContext ();
1213 Nan::HandleScope scope;
1314
1415 // Prepare constructor template
@@ -21,14 +22,16 @@ void MyObject::Init(v8::Local<v8::Object> exports) {
2122 Nan::SetPrototypeMethod (tpl, " plusOne" , PlusOne);
2223 Nan::SetPrototypeMethod (tpl, " multiply" , Multiply);
2324
24- constructor.Reset (tpl->GetFunction ());
25- exports->Set (Nan::New (" MyObject" ).ToLocalChecked (), tpl->GetFunction ());
25+ constructor.Reset (tpl->GetFunction (context).ToLocalChecked ());
26+ exports->Set (Nan::New (" MyObject" ).ToLocalChecked (),
27+ tpl->GetFunction (context).ToLocalChecked ());
2628}
2729
2830void MyObject::New (const Nan::FunctionCallbackInfo<v8::Value>& info) {
31+ v8::Local<v8::Context> context = info.GetIsolate ()->GetCurrentContext ();
2932 if (info.IsConstructCall ()) {
3033 // Invoked as constructor: `new MyObject(...)`
31- double value = info[0 ]->IsUndefined () ? 0 : info[0 ]->NumberValue ();
34+ double value = info[0 ]->IsUndefined () ? 0 : info[0 ]->NumberValue (context). FromJust ( );
3235 MyObject* obj = new MyObject (value);
3336 obj->Wrap (info.This ());
3437 info.GetReturnValue ().Set (info.This ());
@@ -37,7 +40,6 @@ void MyObject::New(const Nan::FunctionCallbackInfo<v8::Value>& info) {
3740 const int argc = 1 ;
3841 v8::Local<v8::Value> argv[argc] = { info[0 ] };
3942 v8::Local<v8::Function> cons = Nan::New<v8::Function>(constructor);
40- v8::Local<v8::Context> context = info.GetIsolate ()->GetCurrentContext ();
4143 info.GetReturnValue ().Set (
4244 cons->NewInstance (context, argc, argv).ToLocalChecked ());
4345 }
@@ -55,15 +57,15 @@ void MyObject::PlusOne(const Nan::FunctionCallbackInfo<v8::Value>& info) {
5557}
5658
5759void MyObject::Multiply (const Nan::FunctionCallbackInfo<v8::Value>& info) {
60+ v8::Local<v8::Context> context = info.GetIsolate ()->GetCurrentContext ();
5861 MyObject* obj = ObjectWrap::Unwrap<MyObject>(info.Holder ());
59- double multiple = info[0 ]->IsUndefined () ? 1 : info[0 ]->NumberValue ();
62+ double multiple = info[0 ]->IsUndefined () ? 1 : info[0 ]->NumberValue (context). FromJust ( );
6063
6164 v8::Local<v8::Function> cons = Nan::New<v8::Function>(constructor);
6265
6366 const int argc = 1 ;
6467 v8::Local<v8::Value> argv[argc] = { Nan::New (obj->value_ * multiple) };
6568
66- v8::Local<v8::Context> context = info.GetIsolate ()->GetCurrentContext ();
6769 info.GetReturnValue ().Set (
6870 cons->NewInstance (context, argc, argv).ToLocalChecked ());
6971}
0 commit comments