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

chore: overload deprecated AccessorSignatures #943

Merged
merged 2 commits into from
Oct 10, 2022
Merged
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
53 changes: 48 additions & 5 deletions nan.h
Original file line number Diff line number Diff line change
Expand Up @@ -2509,15 +2509,61 @@ inline void SetPrototypeMethod(

//=== Accessors and Such =======================================================

NAN_DEPRECATED inline void SetAccessor(
v8::Local<v8::ObjectTemplate> tpl
, v8::Local<v8::String> name
, GetterCallback getter
, SetterCallback setter
, v8::Local<v8::Value> data
, v8::AccessControl settings
, v8::PropertyAttribute attribute
, imp::Sig signature) {
HandleScope scope;

imp::NativeGetter getter_ =
imp::GetterCallbackWrapper;
imp::NativeSetter setter_ =
setter ? imp::SetterCallbackWrapper : 0;

v8::Local<v8::ObjectTemplate> otpl = New<v8::ObjectTemplate>();
otpl->SetInternalFieldCount(imp::kAccessorFieldCount);
v8::Local<v8::Object> obj = NewInstance(otpl).ToLocalChecked();

obj->SetInternalField(
imp::kGetterIndex
, New<v8::External>(reinterpret_cast<void *>(getter)));

if (setter != 0) {
obj->SetInternalField(
imp::kSetterIndex
, New<v8::External>(reinterpret_cast<void *>(setter)));
}

if (!data.IsEmpty()) {
obj->SetInternalField(imp::kDataIndex, data);
}

tpl->SetAccessor(
name
, getter_
, setter_
, obj
, settings
, attribute
#if (NODE_MODULE_VERSION < NODE_16_0_MODULE_VERSION)
, signature
#endif
);
}

inline void SetAccessor(
v8::Local<v8::ObjectTemplate> tpl
, v8::Local<v8::String> name
, GetterCallback getter
, SetterCallback setter = 0
, v8::Local<v8::Value> data = v8::Local<v8::Value>()
, v8::AccessControl settings = v8::DEFAULT
, v8::PropertyAttribute attribute = v8::None
, imp::Sig signature = imp::Sig()) {
, v8::PropertyAttribute attribute = v8::None) {
HandleScope scope;

imp::NativeGetter getter_ =
Expand Down Expand Up @@ -2550,9 +2596,6 @@ inline void SetAccessor(
, obj
, settings
, attribute
#if (NODE_MODULE_VERSION < NODE_18_0_MODULE_VERSION)
, signature
#endif
);
}

Expand Down
4 changes: 4 additions & 0 deletions nan_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ typedef void(*IndexQueryCallback)(
const PropertyCallbackInfo<v8::Integer>&);

namespace imp {
#if (NODE_MODULE_VERSION < NODE_16_0_MODULE_VERSION)
typedef v8::Local<v8::AccessorSignature> Sig;
#else
typedef v8::Local<v8::Data> Sig;
#endif

static const int kDataIndex = 0;

Expand Down