@@ -549,6 +549,7 @@ prototype:
549549
550550namespace  demo  {
551551
552+ using v8::Context;
552553using v8::Function;
553554using v8::FunctionCallbackInfo;
554555using v8::FunctionTemplate;
@@ -597,8 +598,11 @@ void MyObject::New(const FunctionCallbackInfo<Value>& args) {
597598    // Invoked as plain function ` MyObject(...) ` , turn into construct call.
598599    const int argc = 1;
599600    Local<Value > argv[ argc]  = { args[ 0]  };
601+     Local<Context > context = isolate->GetCurrentContext();
600602    Local<Function > cons = Local<Function >::New(isolate, constructor);
601-     args.GetReturnValue().Set(cons->NewInstance(argc, argv));
603+     Local<Object > result =
604+         cons->NewInstance(context, argc, argv).ToLocalChecked();
605+     args.GetReturnValue().Set(result);
602606  }
603607}
604608
@@ -728,6 +732,7 @@ The implementation in `myobject.cc` is similar to the previous example:
728732
729733namespace  demo  {
730734
735+ using v8::Context;
731736using v8::Function;
732737using v8::FunctionCallbackInfo;
733738using v8::FunctionTemplate;
@@ -773,7 +778,10 @@ void MyObject::New(const FunctionCallbackInfo<Value>& args) {
773778    const int argc = 1;
774779    Local<Value > argv[ argc]  = { args[ 0]  };
775780    Local<Function > cons = Local<Function >::New(isolate, constructor);
776-     args.GetReturnValue().Set(cons->NewInstance(argc, argv));
781+     Local<Context > context = isolate->GetCurrentContext();
782+     Local<Object > instance =
783+         cons->NewInstance(context, argc, argv).ToLocalChecked();
784+     args.GetReturnValue().Set(instance);
777785  }
778786}
779787
@@ -783,7 +791,9 @@ void MyObject::NewInstance(const FunctionCallbackInfo<Value>& args) {
783791  const unsigned argc = 1;
784792  Local<Value > argv[ argc]  = { args[ 0]  };
785793  Local<Function > cons = Local<Function >::New(isolate, constructor);
786-   Local<Object > instance = cons->NewInstance(argc, argv);
794+   Local<Context > context = isolate->GetCurrentContext();
795+   Local<Object > instance =
796+       cons->NewInstance(context, argc, argv).ToLocalChecked();
787797
788798  args.GetReturnValue().Set(instance);
789799}
@@ -928,6 +938,7 @@ The implementation of `myobject.cc` is similar to before:
928938
929939namespace  demo  {
930940
941+ using v8::Context;
931942using v8::Function;
932943using v8::FunctionCallbackInfo;
933944using v8::FunctionTemplate;
@@ -968,8 +979,11 @@ void MyObject::New(const FunctionCallbackInfo<Value>& args) {
968979    // Invoked as plain function ` MyObject(...) ` , turn into construct call.
969980    const int argc = 1;
970981    Local<Value > argv[ argc]  = { args[ 0]  };
982+     Local<Context > context = isolate->GetCurrentContext();
971983    Local<Function > cons = Local<Function >::New(isolate, constructor);
972-     args.GetReturnValue().Set(cons->NewInstance(argc, argv));
984+     Local<Object > instance =
985+         cons->NewInstance(context, argc, argv).ToLocalChecked();
986+     args.GetReturnValue().Set(instance);
973987  }
974988}
975989
@@ -979,7 +993,9 @@ void MyObject::NewInstance(const FunctionCallbackInfo<Value>& args) {
979993  const unsigned argc = 1;
980994  Local<Value > argv[ argc]  = { args[ 0]  };
981995  Local<Function > cons = Local<Function >::New(isolate, constructor);
982-   Local<Object > instance = cons->NewInstance(argc, argv);
996+   Local<Context > context = isolate->GetCurrentContext();
997+   Local<Object > instance =
998+       cons->NewInstance(context, argc, argv).ToLocalChecked();
983999
9841000  args.GetReturnValue().Set(instance);
9851001}
0 commit comments