NAN_GETTER and NAN_SETTER not called in Node 23+
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.4k
- Forks
- 531
- Avg merge
- 21m
- Merged PRs (30d)
- 1
Description
Hello!
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 the following output:
MyClass::SessionConnectedSetter 0
MyClass::SessionConnectedSetter 1
MyClass::SessionConnectedSetter 2
MyClass::SessionConnectedSetter 3
Actual
The Setter is never called and there are no logs in the output.
The same behaviour is seen with NAN_GETTER.
This works for node versions <= 22.
Can anyone please shed a bit of light here?
Thank you very much in advance!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The reproduction is in the issue body, centered on NAN_SETTER, NAN_GETTER, MyClass::Init, and the onConnected assignment. First compare the example on Node versions through 22 and Node 23+, then inspect why Nan::SetAccessor no longer invokes either callback. Done means both callbacks work with the shown example on Node 23+.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, node.js
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100