Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d938e85

Browse filesBrowse files
FlarnaMylesBorins
authored andcommitted
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: #35214 Refs: nodejs/node-addon-api#811 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
1 parent c3e1bf7 commit d938e85
Copy full SHA for d938e85

File tree

Expand file treeCollapse file tree

2 files changed

+28
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+28
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/n-api.md‎

Copy file name to clipboardExpand all lines: doc/api/n-api.md
+18Lines changed: 18 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -3643,6 +3643,12 @@ if (status != napi_ok) return status;
36433643

36443644
### Structures
36453645
#### napi_property_attributes
3646+
<!-- YAML
3647+
changes:
3648+
- version: REPLACEME
3649+
pr-url: https://github.com/nodejs/node/pull/35214
3650+
description: added `napi_default_method` and `napi_default_property`
3651+
-->
36463652

36473653
```c
36483654
typedef enum {
@@ -3654,6 +3660,14 @@ typedef enum {
36543660
// Used with napi_define_class to distinguish static properties
36553661
// from instance properties. Ignored by napi_define_properties.
36563662
napi_static = 1 << 10,
3663+
3664+
// Default for class methods.
3665+
napi_default_method = napi_writable | napi_configurable,
3666+
3667+
// Default for object properties, like in JS obj[prop].
3668+
napi_default_property = napi_writable |
3669+
napi_enumerable |
3670+
napi_configurable,
36573671
} napi_property_attributes;
36583672
```
36593673

@@ -3672,6 +3686,10 @@ They can be one or more of the following bitflags:
36723686
* `napi_static`: The property will be defined as a static property on a class as
36733687
opposed to an instance property, which is the default. This is used only by
36743688
[`napi_define_class`][]. It is ignored by `napi_define_properties`.
3689+
* `napi_default_method`: The property is configureable, writeable but not
3690+
enumerable like a method in a JS class.
3691+
* `napi_default_property`: The property is writable, enumerable and configurable
3692+
like a property set via JS code `obj.key = value`.
36753693

36763694
#### napi_property_descriptor
36773695

Collapse file

‎src/js_native_api_types.h‎

Copy file name to clipboardExpand all lines: src/js_native_api_types.h
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ typedef enum {
3030
// Used with napi_define_class to distinguish static properties
3131
// from instance properties. Ignored by napi_define_properties.
3232
napi_static = 1 << 10,
33+
34+
#ifdef NAPI_EXPERIMENTAL
35+
// Default for class methods.
36+
napi_default_method = napi_writable | napi_configurable,
37+
38+
// Default for object properties, like in JS obj[prop].
39+
napi_default_jsproperty = napi_writable |
40+
napi_enumerable |
41+
napi_configurable,
42+
#endif // NAPI_EXPERIMENTAL
3343
} napi_property_attributes;
3444

3545
typedef enum {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.