diff --git a/doc/api/addons.md b/doc/api/addons.md index 9ea0a6b6446ce4..13f59c958373f6 100644 --- a/doc/api/addons.md +++ b/doc/api/addons.md @@ -487,7 +487,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 @@ -593,7 +594,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); } @@ -779,10 +780,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()); @@ -790,7 +793,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(); @@ -961,10 +963,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()); @@ -973,7 +977,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); @@ -1076,9 +1079,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)); @@ -1168,10 +1171,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()); @@ -1179,7 +1184,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();