You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NAN_GETTER and NAN_SETTER not called in Node 23+ #1006
On Fri, Jan 9, 2026, 10:47 Francisco Javier Cano Sandoval < ***@***.***> wrote:
*FranciscoCano* created an issue (nodejs/nan#1006)
<#1006>
I have a NAN_SETTER declared like:
.h
static NAN_SETTER(SessionConnectedSetter);
.cpp
NAN_SETTER(MyClass::SessionConnectedSetter) {
printf("MyClass::SessionConnectedSetter 0\n");
MyClass *obj = ObjectWrap::Unwrap<MyClass>(info.This());
printf("OTKSession::SessionConnectedSetter 1\n");
Local<Function> cb = value.As<Function>();
printf("OTKSession::SessionConnectedSetter 2\n");
obj->session_connected_callback_ = new Nan::Callback(cb);
printf("OTKSession::SessionConnectedSetter 3\n");
}
// Inside the Init function:
...
Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(MyClass::New);
ctor->SetClassName(Nan::New("MyClass").ToLocalChecked());
ctor->InstanceTemplate()->SetInternalFieldCount(1);
constructor.Reset(ctor);
printf("MyClass::Init 2\n");
// Methods
Local<ObjectTemplate> proto = ctor->PrototypeTemplate();
Nan::SetAccessor(proto, Nan::New("onConnected").ToLocalChecked(), nullptr, SessionConnectedSetter);
...
And, I call the setter from Javascript:
const myObject = new MyClass();
myObject.onConnected = () => {
console.log('onConnected Called!');
}
*Expected*
When the onConnected setter is set, I would expect:
printf("MyClass::SessionConnectedSetter 0\n");
printf("MyClass::SessionConnectedSetter 1\n");
printf("MyClass::SessionConnectedSetter 2\n");
printf("MyClass::SessionConnectedSetter 3\n");
*Actual*
The Setter is never called.
The same behaviour is seen with NAN_GETTER.
This works for node versions <= 22.
—
Reply to this email directly, view it on GitHub
<#1006>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA7JXKNLXT4TGLEK6I27YRL4F52JXAVCNFSM6AAAAACRFJB7BWVHI2DSMVQWIX3LMV43ASLTON2WKOZTG44TMMRUHEZTAMQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
The problem, though does not seem related to the c++ code, because I started seeing the issue when moving from Node 22 to Node 23, so looks to me that's an interaction with Node 23, something changed in V8, or in the way bindings work. Something I realized is that, until Node 22, when I set a property using the NAN_SETTER, I could not see it when doing a console.log of that object. Output would be something like:
MyObject {}
But, starting from Node 23, if I set a property that does NOT have a getter, even then I would see something like:
Activity
kkoopa commentedon Jan 9, 2026
FranciscoCano commentedon Jan 9, 2026
Yep, that's what I don't understand... I'm using the same code done in accessors.cpp. And it stopped working when moving to Node 23
FranciscoCano commentedon Jan 10, 2026
The problem, though does not seem related to the c++ code, because I started seeing the issue when moving from Node 22 to Node 23, so looks to me that's an interaction with Node 23, something changed in V8, or in the way bindings work. Something I realized is that, until Node 22, when I set a property using the NAN_SETTER, I could not see it when doing a
console.logof that object. Output would be something like:But, starting from Node 23, if I set a property that does NOT have a getter, even then I would see something like:
Looks like Node.js is intercepting the setter instead of forwarding it to the c++ object...