diff --git a/doc/api/addons.md b/doc/api/addons.md index bba4820ca9c084..483f2ad27d7feb 100644 --- a/doc/api/addons.md +++ b/doc/api/addons.md @@ -491,7 +491,8 @@ void Add(const FunctionCallbackInfo& args) { } // Perform the operation - double value = args[0]->NumberValue() + args[1]->NumberValue(); + double value = + args[0].As()->Value() + args[1].As()->Value(); Local num = Number::New(isolate, value); // Set the return value (using the passed in @@ -597,7 +598,7 @@ void CreateObject(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); Local obj = Object::New(isolate); - obj->Set(String::NewFromUtf8(isolate, "msg"), args[0]->ToString()); + obj->Set(String::NewFromUtf8(isolate, "msg"), args[0]->ToString(isolate)); args.GetReturnValue().Set(obj); } @@ -783,10 +784,12 @@ void MyObject::Init(Local exports) { void MyObject::New(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); + Local context = isolate->GetCurrentContext(); if (args.IsConstructCall()) { // Invoked as constructor: `new MyObject(...)` - double value = args[0]->IsUndefined() ? 0 : args[0]->NumberValue(); + double value = args[0]->IsUndefined() ? + 0 : args[0]->NumberValue(context).FromMaybe(0); MyObject* obj = new MyObject(value); obj->Wrap(args.This()); args.GetReturnValue().Set(args.This()); @@ -794,7 +797,6 @@ 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); Local result = cons->NewInstance(context, argc, argv).ToLocalChecked(); @@ -965,10 +967,12 @@ void MyObject::Init(Isolate* isolate) { void MyObject::New(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); + Local context = isolate->GetCurrentContext(); if (args.IsConstructCall()) { // Invoked as constructor: `new MyObject(...)` - double value = args[0]->IsUndefined() ? 0 : args[0]->NumberValue(); + double value = args[0]->IsUndefined() ? + 0 : args[0]->NumberValue(context).FromMaybe(0); MyObject* obj = new MyObject(value); obj->Wrap(args.This()); args.GetReturnValue().Set(args.This()); @@ -977,7 +981,6 @@ void MyObject::New(const FunctionCallbackInfo& args) { const int argc = 1; Local argv[argc] = { args[0] }; Local cons = Local::New(isolate, constructor); - Local context = isolate->GetCurrentContext(); Local instance = cons->NewInstance(context, argc, argv).ToLocalChecked(); args.GetReturnValue().Set(instance); @@ -1080,9 +1083,9 @@ void Add(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); MyObject* obj1 = node::ObjectWrap::Unwrap( - args[0]->ToObject()); + args[0]->ToObject(isolate)); MyObject* obj2 = node::ObjectWrap::Unwrap( - args[1]->ToObject()); + args[1]->ToObject(isolate)); double sum = obj1->value() + obj2->value(); args.GetReturnValue().Set(Number::New(isolate, sum)); @@ -1172,10 +1175,12 @@ void MyObject::Init(Isolate* isolate) { void MyObject::New(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); + Local context = isolate->GetCurrentContext(); if (args.IsConstructCall()) { // Invoked as constructor: `new MyObject(...)` - double value = args[0]->IsUndefined() ? 0 : args[0]->NumberValue(); + double value = args[0]->IsUndefined() ? + 0 : args[0]->NumberValue(context).FromMaybe(0); MyObject* obj = new MyObject(value); obj->Wrap(args.This()); args.GetReturnValue().Set(args.This()); @@ -1183,7 +1188,6 @@ 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); Local instance = cons->NewInstance(context, argc, argv).ToLocalChecked();