From b869cdb876ede6350fbb8a3b071b65fefbad119d Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 9 May 2016 15:09:09 +0200 Subject: [PATCH] doc: fix deprecation warnings in addon examples Use the overload of `v8::Function::NewInstance()` that returns a `v8::MaybeLocal`. The overloads that return a simple `v8::Local` are deprecated. PR-URL: https://github.com/nodejs/node/pull/6652 Reviewed-By: Anna Henningsen --- doc/api/addons.md | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/doc/api/addons.md b/doc/api/addons.md index 9650329b0a5604..a4041637f2fcea 100644 --- a/doc/api/addons.md +++ b/doc/api/addons.md @@ -549,6 +549,7 @@ prototype: namespace demo { +using v8::Context; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; @@ -597,8 +598,11 @@ void MyObject::New(const FunctionCallbackInfo& args) { // Invoked as plain function `MyObject(...)`, turn into construct call. const int argc = 1; Local argv[argc] = { args[0] }; + Local context = isolate->GetCurrentContext(); Local cons = Local::New(isolate, constructor); - args.GetReturnValue().Set(cons->NewInstance(argc, argv)); + Local result = + cons->NewInstance(context, argc, argv).ToLocalChecked(); + args.GetReturnValue().Set(result); } } @@ -728,6 +732,7 @@ The implementation in `myobject.cc` is similar to the previous example: namespace demo { +using v8::Context; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; @@ -773,7 +778,10 @@ void MyObject::New(const FunctionCallbackInfo& args) { const int argc = 1; Local argv[argc] = { args[0] }; Local cons = Local::New(isolate, constructor); - args.GetReturnValue().Set(cons->NewInstance(argc, argv)); + Local context = isolate->GetCurrentContext(); + Local instance = + cons->NewInstance(context, argc, argv).ToLocalChecked(); + args.GetReturnValue().Set(instance); } } @@ -783,7 +791,9 @@ void MyObject::NewInstance(const FunctionCallbackInfo& args) { const unsigned argc = 1; Local argv[argc] = { args[0] }; Local cons = Local::New(isolate, constructor); - Local instance = cons->NewInstance(argc, argv); + Local context = isolate->GetCurrentContext(); + Local instance = + cons->NewInstance(context, argc, argv).ToLocalChecked(); args.GetReturnValue().Set(instance); } @@ -928,6 +938,7 @@ The implementation of `myobject.cc` is similar to before: namespace demo { +using v8::Context; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; @@ -968,8 +979,11 @@ void MyObject::New(const FunctionCallbackInfo& args) { // Invoked as plain function `MyObject(...)`, turn into construct call. const int argc = 1; Local argv[argc] = { args[0] }; + Local context = isolate->GetCurrentContext(); Local cons = Local::New(isolate, constructor); - args.GetReturnValue().Set(cons->NewInstance(argc, argv)); + Local instance = + cons->NewInstance(context, argc, argv).ToLocalChecked(); + args.GetReturnValue().Set(instance); } } @@ -979,7 +993,9 @@ void MyObject::NewInstance(const FunctionCallbackInfo& args) { const unsigned argc = 1; Local argv[argc] = { args[0] }; Local cons = Local::New(isolate, constructor); - Local instance = cons->NewInstance(argc, argv); + Local context = isolate->GetCurrentContext(); + Local instance = + cons->NewInstance(context, argc, argv).ToLocalChecked(); args.GetReturnValue().Set(instance); }