Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
doc: fix deprecation warnings from ToObject() in addons.md
These code snippets are also used in addon tests.
  • Loading branch information
oyyd committed Oct 10, 2018
commit 301b4a870f3daddb898ab2487683f32cd780b5ea
11 changes: 8 additions & 3 deletions doc/api/addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -589,16 +589,19 @@ namespace demo {

using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Context;
using v8::Local;
using v8::Object;
using v8::String;
using v8::Value;

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

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

args.GetReturnValue().Set(obj);
}
Expand Down Expand Up @@ -1080,6 +1083,7 @@ namespace demo {

using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Context;
using v8::Local;
using v8::Number;
using v8::Object;
Expand All @@ -1092,11 +1096,12 @@ void CreateObject(const FunctionCallbackInfo<Value>& args) {

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

MyObject* obj1 = node::ObjectWrap::Unwrap<MyObject>(
args[0]->ToObject(isolate));
args[0]->ToObject(context).ToLocalChecked());
MyObject* obj2 = node::ObjectWrap::Unwrap<MyObject>(
args[1]->ToObject(isolate));
args[1]->ToObject(context).ToLocalChecked());

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