Skip to content

Commit

Permalink
Deprecate FunctionCallbackInfo::Holder
Browse files Browse the repository at this point in the history
Use FunctionCallbackInfo::This instead.

See http://crbug.com/333672197.
  • Loading branch information
kkoopa committed Oct 19, 2024
1 parent bf14d52 commit 4a8af32
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 43 deletions.
14 changes: 13 additions & 1 deletion nan_callbacks_12_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,19 @@ class FunctionCallbackInfo {
}
#endif
inline v8::Local<v8::Value> Data() const { return data_; }
inline v8::Local<v8::Object> Holder() const { return info_.Holder(); }
NAN_DEPRECATED inline v8::Local<v8::Object> Holder() const {
#if defined(V8_MAJOR_VERSION) && \
(V8_MAJOR_VERSION > 12 || \
(V8_MAJOR_VERSION == 12 && \
(defined(V8_MINOR_VERSION) && \
(V8_MINOR_VERSION > 5 || \
(V8_MINOR_VERSION == 5 && defined(V8_BUILD_NUMBER) && \
V8_BUILD_NUMBER >= 214)))))
return info_.This();
#else
return info_.Holder();
#endif
}
inline bool IsConstructCall() const { return info_.IsConstructCall(); }
inline int Length() const { return info_.Length(); }
inline v8::Local<v8::Value> operator[](int i) const { return info_[i]; }
Expand Down
4 changes: 3 additions & 1 deletion nan_callbacks_pre_12_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ class FunctionCallbackInfo {
return args_.Callee();
}
inline v8::Local<v8::Value> Data() const { return data_; }
inline v8::Local<v8::Object> Holder() const { return args_.Holder(); }
NAN_DEPRECATED inline v8::Local<v8::Object> Holder() const {
return args_.Holder();
}
inline bool IsConstructCall() const { return args_.IsConstructCall(); }
inline int Length() const { return args_.Length(); }
inline v8::Local<v8::Value> operator[](int i) const { return args_[i]; }
Expand Down
8 changes: 4 additions & 4 deletions test/cpp/accessors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ NAN_METHOD(SetterGetter::New) {

NAN_GETTER(SetterGetter::GetProp1) {
SetterGetter* settergetter =
ObjectWrap::Unwrap<SetterGetter>(info.Holder());
ObjectWrap::Unwrap<SetterGetter>(info.This());
assert(strlen(settergetter->log) < sizeof (settergetter->log));
strncat(
settergetter->log
Expand All @@ -112,7 +112,7 @@ NAN_GETTER(SetterGetter::GetProp1) {

NAN_GETTER(SetterGetter::GetProp2) {
SetterGetter* settergetter =
ObjectWrap::Unwrap<SetterGetter>(info.Holder());
ObjectWrap::Unwrap<SetterGetter>(info.This());
assert(strlen(settergetter->log) < sizeof (settergetter->log));
strncat(
settergetter->log
Expand All @@ -134,7 +134,7 @@ NAN_GETTER(SetterGetter::GetProp2) {

NAN_SETTER(SetterGetter::SetProp2) {
SetterGetter* settergetter =
ObjectWrap::Unwrap<SetterGetter>(info.Holder());
ObjectWrap::Unwrap<SetterGetter>(info.This());
strncpy(
settergetter->prop2
, *Utf8String(value)
Expand All @@ -159,7 +159,7 @@ NAN_SETTER(SetterGetter::SetProp2) {

NAN_METHOD(SetterGetter::Log) {
SetterGetter* settergetter =
ObjectWrap::Unwrap<SetterGetter>(info.Holder());
ObjectWrap::Unwrap<SetterGetter>(info.This());

info.GetReturnValue().Set(Nan::New(settergetter->log).ToLocalChecked());
}
Expand Down
8 changes: 4 additions & 4 deletions test/cpp/accessors2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ NAN_METHOD(SetterGetter::New) {

NAN_GETTER(SetterGetter::GetProp1) {
SetterGetter* settergetter =
ObjectWrap::Unwrap<SetterGetter>(info.Holder());
ObjectWrap::Unwrap<SetterGetter>(info.This());
assert(strlen(settergetter->log) < sizeof (settergetter->log));
strncat(
settergetter->log
Expand All @@ -110,7 +110,7 @@ NAN_GETTER(SetterGetter::GetProp1) {

NAN_GETTER(SetterGetter::GetProp2) {
SetterGetter* settergetter =
ObjectWrap::Unwrap<SetterGetter>(info.Holder());
ObjectWrap::Unwrap<SetterGetter>(info.This());
assert(strlen(settergetter->log) < sizeof (settergetter->log));
strncat(
settergetter->log
Expand All @@ -132,7 +132,7 @@ NAN_GETTER(SetterGetter::GetProp2) {

NAN_SETTER(SetterGetter::SetProp2) {
SetterGetter* settergetter =
ObjectWrap::Unwrap<SetterGetter>(info.Holder());
ObjectWrap::Unwrap<SetterGetter>(info.This());
strncpy(
settergetter->prop2
, *Nan::Utf8String(value)
Expand All @@ -157,7 +157,7 @@ NAN_SETTER(SetterGetter::SetProp2) {

NAN_METHOD(SetterGetter::Log) {
SetterGetter* settergetter =
ObjectWrap::Unwrap<SetterGetter>(info.Holder());
ObjectWrap::Unwrap<SetterGetter>(info.This());

info.GetReturnValue().Set(Nan::New(settergetter->log).ToLocalChecked());
}
Expand Down
8 changes: 4 additions & 4 deletions test/cpp/methodswithdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ NAN_GETTER(SetterGetter::GetProp1) {
std::string datavalue = *Nan::Utf8String(info.Data());
assert(datavalue == "prop1-data");
SetterGetter* settergetter =
ObjectWrap::Unwrap<SetterGetter>(info.Holder());
ObjectWrap::Unwrap<SetterGetter>(info.This());
assert(strlen(settergetter->log) < sizeof (settergetter->log));
strncat(
settergetter->log
Expand All @@ -99,7 +99,7 @@ NAN_GETTER(SetterGetter::GetProp2) {
assert(datavalue == "prop2-data");

SetterGetter* settergetter =
ObjectWrap::Unwrap<SetterGetter>(info.Holder());
ObjectWrap::Unwrap<SetterGetter>(info.This());
assert(strlen(settergetter->log) < sizeof (settergetter->log));
strncat(
settergetter->log
Expand All @@ -124,7 +124,7 @@ NAN_SETTER(SetterGetter::SetProp2) {
assert(datavalue == "prop2-data");

SetterGetter* settergetter =
ObjectWrap::Unwrap<SetterGetter>(info.Holder());
ObjectWrap::Unwrap<SetterGetter>(info.This());
strncpy(
settergetter->prop2
, *Utf8String(value)
Expand All @@ -149,7 +149,7 @@ NAN_SETTER(SetterGetter::SetProp2) {

NAN_METHOD(SetterGetter::Log) {
SetterGetter* settergetter =
ObjectWrap::Unwrap<SetterGetter>(info.Holder());
ObjectWrap::Unwrap<SetterGetter>(info.This());

info.GetReturnValue().Set(Nan::New(settergetter->log).ToLocalChecked());
}
Expand Down
6 changes: 3 additions & 3 deletions test/cpp/objectwraphandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ class MyObject : public ObjectWrap {
}

static NAN_METHOD(GetHandle) {
MyObject* obj = ObjectWrap::Unwrap<MyObject>(info.Holder());
MyObject* obj = ObjectWrap::Unwrap<MyObject>(info.This());
info.GetReturnValue().Set(obj->handle());
}

static NAN_METHOD(GetHandleConst) {
MyObject const *obj = ObjectWrap::Unwrap<MyObject>(info.Holder());
MyObject const *obj = ObjectWrap::Unwrap<MyObject>(info.This());
info.GetReturnValue().Set(obj->handle());
}

static NAN_METHOD(GetValue) {
MyObject* obj = ObjectWrap::Unwrap<MyObject>(info.Holder());
MyObject* obj = ObjectWrap::Unwrap<MyObject>(info.This());
info.GetReturnValue().Set(obj->value_);
}

Expand Down
4 changes: 2 additions & 2 deletions test/cpp/wrappedobjectfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class InnerObject : public ObjectWrap {
}

static NAN_METHOD(GetValue) {
InnerObject* obj = ObjectWrap::Unwrap<InnerObject>(info.Holder());
InnerObject* obj = ObjectWrap::Unwrap<InnerObject>(info.This());
info.GetReturnValue().Set(obj->value_);
}

Expand Down Expand Up @@ -102,7 +102,7 @@ class MyObject : public ObjectWrap {
}

static NAN_METHOD(GetValue) {
MyObject* obj = ObjectWrap::Unwrap<MyObject>(info.Holder());
MyObject* obj = ObjectWrap::Unwrap<MyObject>(info.This());
info.GetReturnValue().Set(obj->value_);
}

Expand Down
7 changes: 5 additions & 2 deletions test/js/accessors-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const test = require('tap').test
, bindings = require('bindings')({ module_root: testRoot, bindings: 'accessors' });

test('accessors', function (t) {
t.plan(7)
t.plan(9)
var settergetter = bindings.create()
t.equal(settergetter.prop1, 'this is property 1')
t.ok(settergetter.prop2 === '')
Expand All @@ -28,5 +28,8 @@ test('accessors', function (t) {
t.equal(derived.prop1, 'this is property 1')
derived.prop2 = 'setting a new value'
t.equal(derived.prop2, 'setting a new value')
t.equal(settergetter.prop2, 'setting a new value')
t.equal(settergetter.prop2, 'setting a value')
settergetter.prop2 = 'setting another value'
t.equal(settergetter.prop2, 'setting another value')
t.equal(derived.prop2, 'setting a new value')
})
46 changes: 24 additions & 22 deletions test/js/methodswithdata-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,30 @@ const test = require('tap').test
, bindings = require('bindings')({ module_root: testRoot, bindings: 'methodswithdata' })

test('SetMethod with data', function (t) {
t.plan(1);
t.ok(bindings.testWithData());
t.plan(1);
t.ok(bindings.testWithData());
});

test('accessors with data', function (t) {
t.plan(7)
var settergetter = bindings.create()
t.equal(settergetter.prop1, 'this is property 1')
t.ok(settergetter.prop2 === '')
settergetter.prop2 = 'setting a value'
t.equal(settergetter.prop2, 'setting a value')
t.equal(settergetter.log(),
'New()\n' +
'Prop1:GETTER(this is property 1)\n' +
'Prop2:GETTER()\n' +
'Prop2:SETTER(setting a value)\n' +
'Prop2:GETTER(setting a value)\n'
)
var derived = Object.create(settergetter)
t.equal(derived.prop1, 'this is property 1')
derived.prop2 = 'setting a new value'
t.equal(derived.prop2, 'setting a new value')
t.equal(settergetter.prop2, 'setting a new value')
})

t.plan(9)
var settergetter = bindings.create()
t.equal(settergetter.prop1, 'this is property 1')
t.ok(settergetter.prop2 === '')
settergetter.prop2 = 'setting a value'
t.equal(settergetter.prop2, 'setting a value')
t.equal(settergetter.log(),
'New()\n' +
'Prop1:GETTER(this is property 1)\n' +
'Prop2:GETTER()\n' +
'Prop2:SETTER(setting a value)\n' +
'Prop2:GETTER(setting a value)\n'
)
var derived = Object.create(settergetter)
t.equal(derived.prop1, 'this is property 1')
derived.prop2 = 'setting a new value'
t.equal(derived.prop2, 'setting a new value')
t.equal(settergetter.prop2, 'setting a value')
settergetter.prop2 = 'setting another value'
t.equal(settergetter.prop2, 'setting another value')
t.equal(derived.prop2, 'setting a new value')
})

0 comments on commit 4a8af32

Please sign in to comment.