diff options
Diffstat (limited to 'doc/api/addons.md')
-rw-r--r-- | doc/api/addons.md | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/doc/api/addons.md b/doc/api/addons.md index 5e06336a85a..b2c52d5128b 100644 --- a/doc/api/addons.md +++ b/doc/api/addons.md @@ -635,6 +635,7 @@ functions and returning those back to JavaScript: namespace demo { +using v8::Context; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; @@ -652,8 +653,9 @@ void MyFunction(const FunctionCallbackInfo<Value>& args) { void CreateFunction(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); + Local<Context> context = isolate->GetCurrentContext(); Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, MyFunction); - Local<Function> fn = tpl->GetFunction(); + Local<Function> fn = tpl->GetFunction(context).ToLocalChecked(); // omit this to make it anonymous fn->SetName(String::NewFromUtf8(isolate, "theFunction")); @@ -777,9 +779,10 @@ void MyObject::Init(Local<Object> exports) { // Prototype NODE_SET_PROTOTYPE_METHOD(tpl, "plusOne", PlusOne); - constructor.Reset(isolate, tpl->GetFunction()); + Local<Context> context = isolate->GetCurrentContext(); + constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked()); exports->Set(String::NewFromUtf8(isolate, "MyObject"), - tpl->GetFunction()); + tpl->GetFunction(context).ToLocalChecked()); } void MyObject::New(const FunctionCallbackInfo<Value>& args) { @@ -969,7 +972,8 @@ void MyObject::Init(Isolate* isolate) { // Prototype NODE_SET_PROTOTYPE_METHOD(tpl, "plusOne", PlusOne); - constructor.Reset(isolate, tpl->GetFunction()); + Local<Context> context = isolate->GetCurrentContext(); + constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked()); } void MyObject::New(const FunctionCallbackInfo<Value>& args) { @@ -1177,7 +1181,8 @@ void MyObject::Init(Isolate* isolate) { tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject")); tpl->InstanceTemplate()->SetInternalFieldCount(1); - constructor.Reset(isolate, tpl->GetFunction()); + Local<Context> context = isolate->GetCurrentContext(); + constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked()); } void MyObject::New(const FunctionCallbackInfo<Value>& args) { |