-
Notifications
You must be signed in to change notification settings - Fork 462
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
InstanceMember creates read only, not enumerable and not configurable properties on default #811
Comments
Hi @Flarna, 'use strict'
class Class {
method() {}
}
console.log(Object.getOwnPropertyDescriptors(Class.prototype))
I did the same experiment for native add-on and I obtained the following result:
I want to discuss about this in tomorrow meeting. Thanks for reporting. |
We discussed in the N-API team meeting and its a result of history and trying to match the JavaScript spec but seems like we did not end up with the default (in both the C and C++ wrapper) we might have chosen thinking about it now. At this point though we don't want to change the default as that will affect existing addons. One idea is to introduce a new enum value |
For the C-API I think there should be two new members: For C++: To my understanding this module is not bound to the C release cycle. Therefore I think changing the defaults in the various Maybe some background how I found this: I work on an APM tool and we monkey patch sqlite3. sqlite3 re-exports native classes (e.g. I guess that a lot addons use a JS wrapper class to do at least some type checking/data preparation on JS side before calling to native. Therefore issues like I saw it with sqlite3 are most likely not that frequent. |
Add a default value for class method and js like property in enum napi_property_attributes. n-api currently offers only one default which is non configurable, non writable, non enumerable - like Object.defineProperty(). While this is formal correct the usual way to create properties in JS is either by defining a class or use obj.prop = value. The defaults from these variants are now backed into enum values. PR-URL: #35214 Refs: nodejs/node-addon-api#811 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gabriel Schulhof <[email protected]>
It is easier, but we are still concerned about changing the behaviour of existing code. If the author meant for more restricted access then we'd be breaking that. From that perspective I still see it as SemVer major and even though we have more flexibility in node-addon-api we try to minimize/avlid any SemVer majors. I do think some shortcuts like you PR'd into core make sense though. |
Add a default value for class method and js like property in enum napi_property_attributes. n-api currently offers only one default which is non configurable, non writable, non enumerable - like Object.defineProperty(). While this is formal correct the usual way to create properties in JS is either by defining a class or use obj.prop = value. The defaults from these variants are now backed into enum values. PR-URL: #35214 Refs: nodejs/node-addon-api#811 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gabriel Schulhof <[email protected]>
Add a default value for class method and js like property in enum napi_property_attributes. n-api currently offers only one default which is non configurable, non writable, non enumerable - like Object.defineProperty(). While this is formal correct the usual way to create properties in JS is either by defining a class or use obj.prop = value. The defaults from these variants are now backed into enum values. PR-URL: #35214 Refs: nodejs/node-addon-api#811 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gabriel Schulhof <[email protected]>
Add a default value for class method and js like property in enum napi_property_attributes. n-api currently offers only one default which is non configurable, non writable, non enumerable - like Object.defineProperty(). While this is formal correct the usual way to create properties in JS is either by defining a class or use obj.prop = value. The defaults from these variants are now backed into enum values. PR-URL: #35214 Refs: nodejs/node-addon-api#811 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gabriel Schulhof <[email protected]>
This has now landed in core at nodejs/node@c9506a8. |
Add a default value for class method and js like property in enum napi_property_attributes. n-api currently offers only one default which is non configurable, non writable, non enumerable - like Object.defineProperty(). While this is formal correct the usual way to create properties in JS is either by defining a class or use obj.prop = value. The defaults from these variants are now backed into enum values. PR-URL: nodejs#35214 Refs: nodejs/node-addon-api#811 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gabriel Schulhof <[email protected]>
Add the default attributes for methods to the example to make them writeable by default. See nodejs#811 for discussion.
* Update object_wrap.md Add the default attributes for methods to the example to make them writeable by default. See #811 for discussion.
* Update object_wrap.md Add the default attributes for methods to the example to make them writeable by default. See nodejs/node-addon-api#811 for discussion.
* Update object_wrap.md Add the default attributes for methods to the example to make them writeable by default. See nodejs/node-addon-api#811 for discussion.
* Update object_wrap.md Add the default attributes for methods to the example to make them writeable by default. See nodejs/node-addon-api#811 for discussion.
* Update object_wrap.md Add the default attributes for methods to the example to make them writeable by default. See nodejs/node-addon-api#811 for discussion.
InstanceMember
usesnapi_default
forattributes
if nothing else is specified.napi_default
means read only, not enumerable and not configurable.The corresponding NAN API
SetPrototypeMethod
callsPrototypeTemplate()->Set()
and to my understanding of the v8 API they usePropertyAttribute::None
which is defined inverted:Is this difference intended? In general non configurable properties are quite uncommon in JS world.
FWIW: If I define a
class
in javascript members are configureable, writable and not enumerable.The text was updated successfully, but these errors were encountered: