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

src: remove const qualifier on Object::GetPropertyNames and Object::InstanceOf #992

Closed
wants to merge 1 commit into from

Conversation

legendecas
Copy link
Member

@legendecas legendecas commented May 5, 2021

These operations can call into JavaScript and result in arbitrary
side effects, hence shall not be considered as const member functions.

E.g. the following examples intercepts the operations by Proxy handlers:

const obj = new Proxy({
  foo: 0,
}, {
  ownKeys(target) {
    target.foo++;
    return [ 'foo' ];
  },
  getPrototypeOf(target) {
    target.foo++;
    return Object.prototype;
  },
});

Object.getOwnPropertyNames(obj);
obj.foo // => 1
obj instanceof Object;
obj.foo // => 2

…nstanceOf

These operations can calling into JavaScript and result in arbitrary
side effects, hence shall not be considered as `const` member functions.
@mhdawson
Copy link
Member

mhdawson commented May 6, 2021

@legendecas we might need to consider this breaking, as code may no longer compile...

@mhdawson
Copy link
Member

mhdawson commented May 6, 2021

There has been some discussion as to what const means. Maybe we should discuss in the next team meeting.

@legendecas
Copy link
Member Author

@mhdawson Yes, this is a breaking change. Apart from the const semantics, do we have any policies on node-addon-api like semver-major changes or breaking changes?

@legendecas
Copy link
Member Author

Labeled as "do not land" until we concluded with a policy regarding the breaking changes and find a consensus on const qualifier semantics on node-addon-api.

@legendecas
Copy link
Member Author

Discussed at today's node-api meeting. This is quite similar to const pointers and pointer to const objects. These functions did not change the Napi::* c++ objects so it seems reasonable to keep them const.

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

Successfully merging this pull request may close these issues.

2 participants