Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b869cdb

Browse filesBrowse files
bnoordhuisMyles Borins
authored andcommitted
doc: fix deprecation warnings in addon examples
Use the overload of `v8::Function::NewInstance()` that returns a `v8::MaybeLocal<v8::Object>`. The overloads that return a simple `v8::Local<v8::Object>` are deprecated. PR-URL: #6652 Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 686d7b3 commit b869cdb
Copy full SHA for b869cdb

File tree

Expand file treeCollapse file tree

1 file changed

+21
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+21
-5
lines changed
Open diff view settings
Collapse file

‎doc/api/addons.md‎

Copy file name to clipboardExpand all lines: doc/api/addons.md
+21-5Lines changed: 21 additions & 5 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ prototype:
549549

550550
namespace demo {
551551

552+
using v8::Context;
552553
using v8::Function;
553554
using v8::FunctionCallbackInfo;
554555
using 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

729733
namespace demo {
730734

735+
using v8::Context;
731736
using v8::Function;
732737
using v8::FunctionCallbackInfo;
733738
using 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

929939
namespace demo {
930940

941+
using v8::Context;
931942
using v8::Function;
932943
using v8::FunctionCallbackInfo;
933944
using 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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.