diff options
author | Gerhard Stoebich <18708370+Flarna@users.noreply.github.com> | 2020-09-15 23:04:48 +0200 |
---|---|---|
committer | Myles Borins <mylesborins@github.com> | 2020-11-16 11:57:54 -0500 |
commit | d938e8508ba86ad40183366d4e600feee9c584f9 (patch) | |
tree | 32161485dca2c070af55db60b31305c4614606bc /doc | |
parent | c3e1bf78c430d3a716ba5c90b422653abe2d1d51 (diff) | |
download | node-new-d938e8508ba86ad40183366d4e600feee9c584f9.tar.gz |
n-api: add more property defaults
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: https://github.com/nodejs/node/pull/35214
Refs: https://github.com/nodejs/node-addon-api/issues/811
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/api/n-api.md | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/doc/api/n-api.md b/doc/api/n-api.md index 38f5983868..a8620c209c 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -3643,6 +3643,12 @@ if (status != napi_ok) return status; ### Structures #### napi_property_attributes +<!-- YAML +changes: + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/35214 + description: added `napi_default_method` and `napi_default_property` +--> ```c typedef enum { @@ -3654,6 +3660,14 @@ typedef enum { // Used with napi_define_class to distinguish static properties // from instance properties. Ignored by napi_define_properties. napi_static = 1 << 10, + + // Default for class methods. + napi_default_method = napi_writable | napi_configurable, + + // Default for object properties, like in JS obj[prop]. + napi_default_property = napi_writable | + napi_enumerable | + napi_configurable, } napi_property_attributes; ``` @@ -3672,6 +3686,10 @@ They can be one or more of the following bitflags: * `napi_static`: The property will be defined as a static property on a class as opposed to an instance property, which is the default. This is used only by [`napi_define_class`][]. It is ignored by `napi_define_properties`. +* `napi_default_method`: The property is configureable, writeable but not + enumerable like a method in a JS class. +* `napi_default_property`: The property is writable, enumerable and configurable + like a property set via JS code `obj.key = value`. #### napi_property_descriptor |