Skip to content

Commit 301b4a8

Browse files
committed
doc: fix deprecation warnings from ToObject() in addons.md
These code snippets are also used in addon tests.
1 parent eb9748d commit 301b4a8

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

doc/api/addons.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,16 +589,19 @@ namespace demo {
589589

590590
using v8::FunctionCallbackInfo;
591591
using v8::Isolate;
592+
using v8::Context;
592593
using v8::Local;
593594
using v8::Object;
594595
using v8::String;
595596
using v8::Value;
596597

597598
void CreateObject(const FunctionCallbackInfo<Value>& args) {
598599
Isolate* isolate = args.GetIsolate();
600+
Local<Context> context = isolate->GetCurrentContext();
599601

600602
Local<Object> obj = Object::New(isolate);
601-
obj->Set(String::NewFromUtf8(isolate, "msg"), args[0]->ToString(isolate));
603+
obj->Set(String::NewFromUtf8(isolate, "msg"),
604+
args[0]->ToString(context).ToLocalChecked());
602605

603606
args.GetReturnValue().Set(obj);
604607
}
@@ -1080,6 +1083,7 @@ namespace demo {
10801083

10811084
using v8::FunctionCallbackInfo;
10821085
using v8::Isolate;
1086+
using v8::Context;
10831087
using v8::Local;
10841088
using v8::Number;
10851089
using v8::Object;
@@ -1092,11 +1096,12 @@ void CreateObject(const FunctionCallbackInfo<Value>& args) {
10921096

10931097
void Add(const FunctionCallbackInfo<Value>& args) {
10941098
Isolate* isolate = args.GetIsolate();
1099+
Local<Context> context = isolate->GetCurrentContext();
10951100

10961101
MyObject* obj1 = node::ObjectWrap::Unwrap<MyObject>(
1097-
args[0]->ToObject(isolate));
1102+
args[0]->ToObject(context).ToLocalChecked());
10981103
MyObject* obj2 = node::ObjectWrap::Unwrap<MyObject>(
1099-
args[1]->ToObject(isolate));
1104+
args[1]->ToObject(context).ToLocalChecked());
11001105

11011106
double sum = obj1->value() + obj2->value();
11021107
args.GetReturnValue().Set(Number::New(isolate, sum));

0 commit comments

Comments
 (0)