Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Node 23 #979

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions nan_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ template<typename T> class FunctionCallbackInfo;
template<typename T> class PropertyCallbackInfo;
template<typename T> class Global;

#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \
(V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4))
namespace Intercepted {
constexpr v8::Intercepted No() { return v8::Intercepted::kNo; }
constexpr v8::Intercepted Yes() { return v8::Intercepted::kYes; }
};
#else
namespace Intercepted {
inline void No() {}
inline void Yes() {}
};
#endif

typedef void(*FunctionCallback)(const FunctionCallbackInfo<v8::Value>&);
typedef void(*GetterCallback)
(v8::Local<v8::String>, const PropertyCallbackInfo<v8::Value>&);
Expand Down
18 changes: 16 additions & 2 deletions nan_callbacks_12_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,24 @@ class FunctionCallbackInfo {
}

#if NODE_MAJOR_VERSION < 10
inline v8::Local<v8::Function> Callee() const { return info_.Callee(); }
NAN_DEPRECATED inline v8::Local<v8::Function> Callee() const {
return info_.Callee();
}
#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
8 changes: 6 additions & 2 deletions nan_callbacks_pre_12_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,13 @@ class FunctionCallbackInfo {
return ReturnValue<T>(return_value_);
}

inline v8::Local<v8::Function> Callee() const { return args_.Callee(); }
NAN_DEPRECATED inline v8::Local<v8::Function> Callee() const {
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
18 changes: 11 additions & 7 deletions nan_scriptorigin.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,28 @@

class ScriptOrigin : public v8::ScriptOrigin {
public:

#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 11 \
&& defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 7)
#if defined(V8_MAJOR_VERSION) && \
(V8_MAJOR_VERSION > 12 || \
(V8_MAJOR_VERSION == 12 && \
(defined(V8_MINOR_VERSION) && \
(V8_MINOR_VERSION > 6 || \
(V8_MINOR_VERSION == 6 && defined(V8_BUILD_NUMBER) && \
V8_BUILD_NUMBER >= 175)))))
explicit ScriptOrigin(v8::Local<v8::Value> name) :
v8::ScriptOrigin(name) {}

ScriptOrigin(v8::Local<v8::Value> name
, v8::Local<v8::Integer> line) :
v8::ScriptOrigin(name
, To<int32_t>(line).FromMaybe(0)) {}
, To<int32_t>(line).FromMaybe(0)) {}

ScriptOrigin(v8::Local<v8::Value> name
, v8::Local<v8::Integer> line
, v8::Local<v8::Integer> column) :
v8::ScriptOrigin(name
, To<int32_t>(line).FromMaybe(0)
, To<int32_t>(column).FromMaybe(0)) {}
#elif defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 9 || \
, To<int32_t>(line).FromMaybe(0)
, To<int32_t>(column).FromMaybe(0)) {}
#elif defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 9 || \
(V8_MAJOR_VERSION == 9 && (defined(V8_MINOR_VERSION) && (V8_MINOR_VERSION > 0\
|| (V8_MINOR_VERSION == 0 && defined(V8_BUILD_NUMBER) \
&& V8_BUILD_NUMBER >= 1)))))
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
7 changes: 7 additions & 0 deletions test/cpp/indexedinterceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ NAN_INDEX_GETTER(IndexedInterceptor::PropertyGetter) {
} else {
info.GetReturnValue().Set(Nan::New("bar").ToLocalChecked());
}
return Intercepted::Yes();
}

NAN_INDEX_SETTER(IndexedInterceptor::PropertySetter) {
Expand All @@ -94,28 +95,34 @@ NAN_INDEX_SETTER(IndexedInterceptor::PropertySetter) {
} else {
info.GetReturnValue().Set(info.This());
}
return Intercepted::Yes();
}

NAN_INDEX_ENUMERATOR(IndexedInterceptor::PropertyEnumerator) {
v8::Local<v8::Array> arr = Nan::New<v8::Array>();
Set(arr, 0, Nan::New(42));
info.GetReturnValue().Set(arr);
return Intercepted::Yes();
}

NAN_INDEX_DELETER(IndexedInterceptor::PropertyDeleter) {
IndexedInterceptor* interceptor =
ObjectWrap::Unwrap<IndexedInterceptor>(info.Holder());
std::strncpy(interceptor->buf, "goober", sizeof (interceptor->buf));
info.GetReturnValue().Set(True());
return Intercepted::Yes();
}

NAN_INDEX_QUERY(IndexedInterceptor::PropertyQuery) {
if (index == 1) {
info.GetReturnValue().Set(Nan::New<v8::Integer>(v8::DontEnum));
return Intercepted::Yes();
}
if (index == 42) {
info.GetReturnValue().Set(Nan::New(0));
return Intercepted::Yes();
}
return Intercepted::No();
}

NODE_MODULE(indexedinterceptors, IndexedInterceptor::Init)
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
10 changes: 8 additions & 2 deletions test/cpp/namedinterceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ NAN_PROPERTY_GETTER(NamedInterceptor::PropertyGetter) {
} else {
info.GetReturnValue().Set(Nan::New("bar").ToLocalChecked());
}
return Intercepted::Yes();
}

NAN_PROPERTY_SETTER(NamedInterceptor::PropertySetter) {
Expand All @@ -94,6 +95,7 @@ NAN_PROPERTY_SETTER(NamedInterceptor::PropertySetter) {
} else {
info.GetReturnValue().Set(info.This());
}
return Intercepted::Yes();
}

NAN_PROPERTY_ENUMERATOR(NamedInterceptor::PropertyEnumerator) {
Expand All @@ -107,16 +109,20 @@ NAN_PROPERTY_DELETER(NamedInterceptor::PropertyDeleter) {
ObjectWrap::Unwrap<NamedInterceptor>(info.Holder());
std::strncpy(interceptor->buf, "goober", sizeof (interceptor->buf));
info.GetReturnValue().Set(True());
return Intercepted::Yes();
}

NAN_PROPERTY_QUERY(NamedInterceptor::PropertyQuery) {
Nan::Utf8String s(property);
if (!std::strcmp(*s, "thing")) {
return info.GetReturnValue().Set(Nan::New<v8::Integer>(v8::DontEnum));
info.GetReturnValue().Set(Nan::New<v8::Integer>(v8::DontEnum));
return Intercepted::Yes();
}
if (!std::strcmp(*s, "value")) {
return info.GetReturnValue().Set(Nan::New(0));
info.GetReturnValue().Set(Nan::New(0));
return Intercepted::Yes();
}
return Intercepted::No();
}

NODE_MODULE(namedinterceptors, NamedInterceptor::Init)
10 changes: 2 additions & 8 deletions test/cpp/news.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ NAN_METHOD(NewScript) {
}

NAN_METHOD(NewScript2) {
v8::ScriptOrigin origin(
#if NODE_MODULE_VERSION >= NODE_18_0_MODULE_VERSION
info.GetIsolate(),
#endif
ScriptOrigin origin(
New<v8::String>("x").ToLocalChecked());
v8::Local<UnboundScript> script =
New<UnboundScript>(
Expand All @@ -135,10 +132,7 @@ NAN_METHOD(CompileScript) {
}

NAN_METHOD(CompileScript2) {
v8::ScriptOrigin origin(
#if NODE_MODULE_VERSION >= NODE_18_0_MODULE_VERSION
info.GetIsolate(),
#endif
ScriptOrigin origin(
New<v8::String>("x").ToLocalChecked());
v8::Local<BoundScript> script =
CompileScript(New("2+4").ToLocalChecked(), origin).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')
})
Loading