Skip to content

Commit

Permalink
chore: overload deprecated AccessorSignatures
Browse files Browse the repository at this point in the history
  • Loading branch information
VerteDinde authored and kkoopa committed Oct 10, 2022
1 parent 6c1574a commit 7f9ceb8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
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_18_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: 3 additions & 1 deletion nan_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ typedef void(*IndexQueryCallback)(
const PropertyCallbackInfo<v8::Integer>&);

namespace imp {
typedef v8::Local<v8::AccessorSignature> Sig;
#if (NODE_MODULE_VERSION < NODE_18_0_MODULE_VERSION)
NAN_DEPRECATED typedef v8::Local<v8::AccessorSignature> Sig;
#endif

static const int kDataIndex = 0;

Expand Down

0 comments on commit 7f9ceb8

Please sign in to comment.