Skip to content

NAN_GETTER and NAN_SETTER not called in Node 23+ #1006

Open

Description

@FranciscoCano

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!

Activity

  1. kkoopa commented on Jan 9, 2026

    @kkoopa
    Collaborator
  2. FranciscoCano commented on Jan 9, 2026

    @FranciscoCano
    Author

    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

  3. FranciscoCano commented on Jan 10, 2026

    @FranciscoCano
    Author

    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:

    MyObject { logLevel: 3, onConnected: [Function (anonymous)] }
    

    Looks like Node.js is intercepting the setter instead of forwarding it to the c++ object...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions