Skip to content

Commit bdee2de

Browse files
committed
node-api: clarify enum value ABI stability
1 parent 229cc3b commit bdee2de

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

doc/api/n-api.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,27 @@ must use Node-API exclusively by restricting itself to using
121121
and by checking, for all external libraries that it uses, that the external
122122
library makes ABI stability guarantees similar to Node-API.
123123

124+
### Enum values in ABI stability
125+
126+
All enum data types defined in Node-API should be considered as a fixed size
127+
`int32_t` value. Bit flag enum types should be explicitly documented, and they
128+
work with bit operators like bit-OR (`|`) as a bit value. Unless otherwise
129+
documented, an enum type should be considered to be extensible.
130+
131+
An enum value will not be removed or renamed.
132+
133+
For an enum type returned from a Node-API function, or provided as an out
134+
parameter of a Node-API function, the value is an integer value and an addon
135+
should handle unknown values. For example, when checking `napi_status` in
136+
switch statements, an addon should include a default branch, as new status
137+
codes may be introduced in newer Node.js versions
138+
139+
For an enum type used in an in-parameter, extended values are version-guarded
140+
based on the Node-API version in which they were introduced. The result of
141+
passing an unknown integer value to Node-API functions is undefined unless
142+
otherwise documented. For example, `napi_get_all_property_names` can be
143+
extended with new enum value of `napi_key_filter`.
144+
124145
## Building
125146

126147
Unlike modules written in JavaScript, developing and deploying Node.js
@@ -2203,7 +2224,7 @@ typedef enum {
22032224
} napi_key_filter;
22042225
```
22052226

2206-
Property filter bits. They can be or'ed to build a composite filter.
2227+
Property filter bit flag. This works with bit operators to build a composite filter.
22072228

22082229
#### `napi_key_conversion`
22092230

@@ -4419,11 +4440,11 @@ typedef enum {
44194440
} napi_property_attributes;
44204441
```
44214442

4422-
`napi_property_attributes` are flags used to control the behavior of properties
4423-
set on a JavaScript object. Other than `napi_static` they correspond to the
4424-
attributes listed in [Section 6.1.7.1][]
4425-
of the [ECMAScript Language Specification][].
4426-
They can be one or more of the following bitflags:
4443+
`napi_property_attributes` are bit flags used to control the behavior of
4444+
properties set on a JavaScript object. This works with bit operators. Other
4445+
than `napi_static` they correspond to the attributes listed in
4446+
[Section 6.1.7.1][] of the [ECMAScript Language Specification][].
4447+
They can be one or more of the following bit flags:
44274448

44284449
* `napi_default`: No explicit attributes are set on the property. By default, a
44294450
property is read only, not enumerable and not configurable.

0 commit comments

Comments
 (0)