-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
node-api: clarify enum value ABI stability #59085
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -121,6 +121,24 @@ must use Node-API exclusively by restricting itself to using | |||||||||
and by checking, for all external libraries that it uses, that the external | ||||||||||
library makes ABI stability guarantees similar to Node-API. | ||||||||||
|
||||||||||
### Enum values in ABI stability | ||||||||||
|
||||||||||
All enum data types defined in Node-API should be considered as a fixed size | ||||||||||
integer value. Bit flag enum types should be explicitly documented, and they | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we be more specific and say that we expect enums to be
Suggested change
|
||||||||||
work with bit operators like bit-OR (`|`) as a bit value. Unless otherwise | ||||||||||
documented, an enum type should be considered to be extensible. | ||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we mention that we must never remove or reuse previous enum values. Instead, we must always only add new enum values with the new integer values. |
||||||||||
For an enum type returned from an Node-API function, or as an out parameter of | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a Node There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or provided as an out ... |
||||||||||
an Node-API function, the value is an integer value and an addon should | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a Node-API |
||||||||||
handle unknown values. For example, an addon should have a `default` branch | ||||||||||
when checking `napi_status` in switch statements as new status codes can be | ||||||||||
introduced in newer Node.js versions. | ||||||||||
Comment on lines
+133
to
+135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example, when checking |
||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While I see the justification for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is rare because usually kernel APIs do not return a value like It is more like a design choice that the kernel does not return types/flags information after the user code handed over them, avoiding compatibility issue. However, Node-API needs to incorporate new ECMAScript features, and we must expose new (rare) JavaScript types (symbol as an example, retrospectively). Even |
||||||||||
For an enum type used in an in-parameter, extended values are guarded with | ||||||||||
Node-API version of which version they are introduced. The result of passing | ||||||||||
an unknown integer value to Node-API functions is undefined unless otherwise | ||||||||||
documented. | ||||||||||
Comment on lines
+137
to
+140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For an enum type used in an in-parameter, extended values are version-guarded based on the Node-API version in which they were introduced. The result of passing an unknown integer value to Node-API functions is undefined unless otherwise documented.
Comment on lines
+139
to
+140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we avoid the undefined bahaviour and rather say that it is an error.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a side note: these constraints generally look good to me but they could likely benefit from some concrete examples illustrating the correct structure. |
||||||||||
|
||||||||||
vmoroz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
## Building | ||||||||||
|
||||||||||
Unlike modules written in JavaScript, developing and deploying Node.js | ||||||||||
|
@@ -2203,7 +2221,7 @@ typedef enum { | |||||||||
} napi_key_filter; | ||||||||||
``` | ||||||||||
|
||||||||||
Property filter bits. They can be or'ed to build a composite filter. | ||||||||||
Property filter bit flag. This works with bit operators to build a composite filter. | ||||||||||
|
||||||||||
#### `napi_key_conversion` | ||||||||||
|
||||||||||
|
@@ -4419,11 +4437,11 @@ typedef enum { | |||||||||
} napi_property_attributes; | ||||||||||
``` | ||||||||||
|
||||||||||
`napi_property_attributes` are flags used to control the behavior of properties | ||||||||||
set on a JavaScript object. Other than `napi_static` they correspond to the | ||||||||||
attributes listed in [Section 6.1.7.1][] | ||||||||||
of the [ECMAScript Language Specification][]. | ||||||||||
They can be one or more of the following bitflags: | ||||||||||
`napi_property_attributes` are bit flags used to control the behavior of | ||||||||||
properties set on a JavaScript object. This works with bit operators. Other | ||||||||||
than `napi_static` they correspond to the attributes listed in | ||||||||||
[Section 6.1.7.1][] of the [ECMAScript Language Specification][]. | ||||||||||
They can be one or more of the following bit flags: | ||||||||||
|
||||||||||
* `napi_default`: No explicit attributes are set on the property. By default, a | ||||||||||
property is read only, not enumerable and not configurable. | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also augment the https://github.com/nodejs/node/blob/main/doc/contributing/adding-new-napi-api.md document along with it?