@@ -491,7 +491,8 @@ void Add(const FunctionCallbackInfo<Value>& args) {
491
491
}
492
492
493
493
// Perform the operation
494
- double value = args[ 0] ->NumberValue() + args[ 1] ->NumberValue();
494
+ double value =
495
+ args[ 0] .As<Number >()->Value() + args[ 1] .As<Number >()->Value();
495
496
Local<Number > num = Number::New(isolate, value);
496
497
497
498
// Set the return value (using the passed in
@@ -597,7 +598,7 @@ void CreateObject(const FunctionCallbackInfo<Value>& args) {
597
598
Isolate* isolate = args.GetIsolate();
598
599
599
600
Local<Object > obj = Object::New(isolate);
600
- obj->Set(String::NewFromUtf8(isolate, "msg"), args[ 0] ->ToString());
601
+ obj->Set(String::NewFromUtf8(isolate, "msg"), args[ 0] ->ToString(isolate ));
601
602
602
603
args.GetReturnValue().Set(obj);
603
604
}
@@ -783,18 +784,19 @@ void MyObject::Init(Local<Object> exports) {
783
784
784
785
void MyObject::New(const FunctionCallbackInfo<Value >& args) {
785
786
Isolate* isolate = args.GetIsolate();
787
+ Local<Context > context = isolate->GetCurrentContext();
786
788
787
789
if (args.IsConstructCall()) {
788
790
// Invoked as constructor: ` new MyObject(...) `
789
- double value = args[ 0] ->IsUndefined() ? 0 : args[ 0] ->NumberValue();
791
+ double value = args[ 0] ->IsUndefined() ?
792
+ 0 : args[ 0] ->NumberValue(context).FromMaybe(0);
790
793
MyObject* obj = new MyObject(value);
791
794
obj->Wrap(args.This());
792
795
args.GetReturnValue().Set(args.This());
793
796
} else {
794
797
// Invoked as plain function ` MyObject(...) ` , turn into construct call.
795
798
const int argc = 1;
796
799
Local<Value > argv[ argc] = { args[ 0] };
797
- Local<Context > context = isolate->GetCurrentContext();
798
800
Local<Function > cons = Local<Function >::New(isolate, constructor);
799
801
Local<Object > result =
800
802
cons->NewInstance(context, argc, argv).ToLocalChecked();
@@ -965,10 +967,12 @@ void MyObject::Init(Isolate* isolate) {
965
967
966
968
void MyObject::New(const FunctionCallbackInfo<Value >& args) {
967
969
Isolate* isolate = args.GetIsolate();
970
+ Local<Context > context = isolate->GetCurrentContext();
968
971
969
972
if (args.IsConstructCall()) {
970
973
// Invoked as constructor: ` new MyObject(...) `
971
- double value = args[ 0] ->IsUndefined() ? 0 : args[ 0] ->NumberValue();
974
+ double value = args[ 0] ->IsUndefined() ?
975
+ 0 : args[ 0] ->NumberValue(context).FromMaybe(0);
972
976
MyObject* obj = new MyObject(value);
973
977
obj->Wrap(args.This());
974
978
args.GetReturnValue().Set(args.This());
@@ -977,7 +981,6 @@ void MyObject::New(const FunctionCallbackInfo<Value>& args) {
977
981
const int argc = 1;
978
982
Local<Value > argv[ argc] = { args[ 0] };
979
983
Local<Function > cons = Local<Function >::New(isolate, constructor);
980
- Local<Context > context = isolate->GetCurrentContext();
981
984
Local<Object > instance =
982
985
cons->NewInstance(context, argc, argv).ToLocalChecked();
983
986
args.GetReturnValue().Set(instance);
@@ -1080,9 +1083,9 @@ void Add(const FunctionCallbackInfo<Value>& args) {
1080
1083
Isolate* isolate = args.GetIsolate();
1081
1084
1082
1085
MyObject* obj1 = node::ObjectWrap::Unwrap<MyObject >(
1083
- args[ 0] ->ToObject());
1086
+ args[ 0] ->ToObject(isolate ));
1084
1087
MyObject* obj2 = node::ObjectWrap::Unwrap<MyObject >(
1085
- args[ 1] ->ToObject());
1088
+ args[ 1] ->ToObject(isolate ));
1086
1089
1087
1090
double sum = obj1->value() + obj2->value();
1088
1091
args.GetReturnValue().Set(Number::New(isolate, sum));
@@ -1172,18 +1175,19 @@ void MyObject::Init(Isolate* isolate) {
1172
1175
1173
1176
void MyObject::New(const FunctionCallbackInfo<Value >& args) {
1174
1177
Isolate* isolate = args.GetIsolate();
1178
+ Local<Context > context = isolate->GetCurrentContext();
1175
1179
1176
1180
if (args.IsConstructCall()) {
1177
1181
// Invoked as constructor: ` new MyObject(...) `
1178
- double value = args[ 0] ->IsUndefined() ? 0 : args[ 0] ->NumberValue();
1182
+ double value = args[ 0] ->IsUndefined() ?
1183
+ 0 : args[ 0] ->NumberValue(context).FromMaybe(0);
1179
1184
MyObject* obj = new MyObject(value);
1180
1185
obj->Wrap(args.This());
1181
1186
args.GetReturnValue().Set(args.This());
1182
1187
} else {
1183
1188
// Invoked as plain function ` MyObject(...) ` , turn into construct call.
1184
1189
const int argc = 1;
1185
1190
Local<Value > argv[ argc] = { args[ 0] };
1186
- Local<Context > context = isolate->GetCurrentContext();
1187
1191
Local<Function > cons = Local<Function >::New(isolate, constructor);
1188
1192
Local<Object > instance =
1189
1193
cons->NewInstance(context, argc, argv).ToLocalChecked();
0 commit comments