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

napi_define_properties should create ECMAScript-compliant accessors. #26551

Closed
iamstolis opened this issue Mar 9, 2019 · 0 comments
Closed

Comments

@iamstolis
Copy link

  • Version: v10.15.2
  • Platform: Linux stola-ThinkPad 3.16.0-38-generic io.js on The Changelog! #52~14.04.1-Ubuntu SMP Fri May 8 09:43:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem: napi

Append the following lines to addons-napi/test_properties test-case

console.log(Object.getOwnPropertyDescriptor(test_object, 'readwriteAccessor1'));
var anotherObject = Object.create(test_object);
anotherObject.readwriteAccessor1 = 42;
console.log(anotherObject.hasOwnProperty('readwriteAccessor1'));
console.log(test_object.readwriteAccessor1);

and execute it. You will get the following output

{ value: 2,
  writable: true,
  enumerable: false,
  configurable: false }
false
42

You can see that readwriteAccessor1 looks like a data property (according to its property descriptor) despite being created with setter and getter. On the other hand, it behaves like an accessor property because anotherObject.readwriteAccessor1 = 42 does not create a data property on anotherObject but invokes the setter in the prototype chain (as you can see from the last two lines of the output).

This strange behaviour is not possible in ECMAScript-compliant world. It is some weird legacy behaviour of v8::Object:SetAccessor (used in the implementation of napi_define_properties) and should be avoided. It would be unfortunate to promote this off-spec behaviour in newly arising N-API.

BridgeAR pushed a commit to BridgeAR/node that referenced this issue Jun 17, 2019
PR-URL: nodejs#27851
Fixes: nodejs#26551
Fixes: nodejs/node-addon-api#485
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
BridgeAR pushed a commit that referenced this issue Jun 17, 2019
PR-URL: #27851
Fixes: #26551
Fixes: nodejs/node-addon-api#485
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
BridgeAR pushed a commit that referenced this issue Jun 17, 2019
PR-URL: #27851
Fixes: #26551
Fixes: nodejs/node-addon-api#485
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
targos pushed a commit that referenced this issue Jun 18, 2019
PR-URL: #27851
Fixes: #26551
Fixes: nodejs/node-addon-api#485
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
targos pushed a commit that referenced this issue Jun 18, 2019
PR-URL: #27851
Fixes: #26551
Fixes: nodejs/node-addon-api#485
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant