Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2018-09-02 21:27:55 +0300
committerMichaël Zasso <targos@protonmail.com>2018-09-05 14:49:24 +0300
commitd9ea50ee66b93266f0c8ebe9d98502816e04acf2 (patch)
treef00317222cb3782c87db9096ee4ba749cfee3fdb /doc/api/addons.md
parentf464ac3c74ca2b2411c578b4dcb52838f569e9fa (diff)
doc: remove usage of deprecated V8 APIs in addons.md
PR-URL: https://github.com/nodejs/node/pull/22667 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'doc/api/addons.md')
-rw-r--r--doc/api/addons.md24
1 files changed, 14 insertions, 10 deletions
diff --git a/doc/api/addons.md b/doc/api/addons.md
index bba4820ca9c..483f2ad27d7 100644
--- a/doc/api/addons.md
+++ b/doc/api/addons.md
@@ -491,7 +491,8 @@ void Add(const FunctionCallbackInfo<Value>& args) {
}
// Perform the operation
- double value = args[0]->NumberValue() + args[1]->NumberValue();
+ double value =
+ args[0].As<Number>()->Value() + args[1].As<Number>()->Value();
Local<Number> num = Number::New(isolate, value);
// Set the return value (using the passed in
@@ -597,7 +598,7 @@ void CreateObject(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Local<Object> 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);
}
@@ -783,10 +784,12 @@ void MyObject::Init(Local<Object> exports) {
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
+ Local<Context> 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());
@@ -794,7 +797,6 @@ void MyObject::New(const FunctionCallbackInfo<Value>& args) {
// Invoked as plain function `MyObject(...)`, turn into construct call.
const int argc = 1;
Local<Value> argv[argc] = { args[0] };
- Local<Context> context = isolate->GetCurrentContext();
Local<Function> cons = Local<Function>::New(isolate, constructor);
Local<Object> result =
cons->NewInstance(context, argc, argv).ToLocalChecked();
@@ -965,10 +967,12 @@ void MyObject::Init(Isolate* isolate) {
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
+ Local<Context> 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());
@@ -977,7 +981,6 @@ void MyObject::New(const FunctionCallbackInfo<Value>& args) {
const int argc = 1;
Local<Value> argv[argc] = { args[0] };
Local<Function> cons = Local<Function>::New(isolate, constructor);
- Local<Context> context = isolate->GetCurrentContext();
Local<Object> instance =
cons->NewInstance(context, argc, argv).ToLocalChecked();
args.GetReturnValue().Set(instance);
@@ -1080,9 +1083,9 @@ void Add(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
MyObject* obj1 = node::ObjectWrap::Unwrap<MyObject>(
- args[0]->ToObject());
+ args[0]->ToObject(isolate));
MyObject* obj2 = node::ObjectWrap::Unwrap<MyObject>(
- args[1]->ToObject());
+ args[1]->ToObject(isolate));
double sum = obj1->value() + obj2->value();
args.GetReturnValue().Set(Number::New(isolate, sum));
@@ -1172,10 +1175,12 @@ void MyObject::Init(Isolate* isolate) {
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
+ Local<Context> 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());
@@ -1183,7 +1188,6 @@ void MyObject::New(const FunctionCallbackInfo<Value>& args) {
// Invoked as plain function `MyObject(...)`, turn into construct call.
const int argc = 1;
Local<Value> argv[argc] = { args[0] };
- Local<Context> context = isolate->GetCurrentContext();
Local<Function> cons = Local<Function>::New(isolate, constructor);
Local<Object> instance =
cons->NewInstance(context, argc, argv).ToLocalChecked();