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

n-api: add more property defaults #35214

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions doc/api/n-api.md
Expand Up @@ -3731,6 +3731,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 {
Expand All @@ -3742,6 +3748,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,
Flarna marked this conversation as resolved.
Show resolved Hide resolved
} napi_property_attributes;
```

Expand All @@ -3760,6 +3774,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

Expand Down
10 changes: 10 additions & 0 deletions src/js_native_api_types.h
Expand Up @@ -30,6 +30,16 @@ typedef enum {
// Used with napi_define_class to distinguish static properties
// from instance properties. Ignored by napi_define_properties.
napi_static = 1 << 10,

#ifdef NAPI_EXPERIMENTAL
// Default for class methods.
napi_default_method = napi_writable | napi_configurable,

// Default for object properties, like in JS obj[prop].
napi_default_jsproperty = napi_writable |
napi_enumerable |
napi_configurable,
Flarna marked this conversation as resolved.
Show resolved Hide resolved
#endif // NAPI_EXPERIMENTAL
} napi_property_attributes;

typedef enum {
Expand Down