ABI 稳定性中的枚举值
¥Enum values in ABI stability
Node-API 中定义的所有枚举数据类型都应视为固定大小的 int32_t
值。位标志枚举类型应明确记录,并且它们可以与位运算符(例如位或 (|
))一起使用,作为位值。除非另有说明,否则枚举类型应被视为可扩展的。
¥All enum data types defined in Node-API should be considered as a fixed size
int32_t
value. Bit flag enum types should be explicitly documented, and they
work with bit operators like bit-OR (|
) as a bit value. Unless otherwise
documented, an enum type should be considered to be extensible.
将在枚举定义的末尾添加一个新的枚举值。枚举值不会被删除或重命名。
¥A new enum value will be added at the end of the enum definition. An enum value will not be removed or renamed.
对于从 Node-API 函数返回的枚举类型,或作为 Node-API 函数的输出参数提供的枚举类型,其值为整数值,并且插件应该处理未知值。允许引入新值,无需版本保护。例如,在 switch 语句中检查 napi_status
时,插件应该包含一个默认分支,因为较新的 Node.js 版本可能会引入新的状态代码。
¥For an enum type returned from a Node-API function, or provided as an out
parameter of a Node-API function, the value is an integer value and an addon
should handle unknown values. New values are allowed to be introduced without
a version guard. For example, when checking napi_status
in switch statements,
an addon should include a default branch, as new status codes may be introduced
in newer Node.js versions.
对于在输入参数中使用的枚举类型,除非另有说明,否则将未知整数值传递给 Node-API 函数的结果是未定义的。将添加一个带有版本保护的新值,以指示引入该值的 Node-API 版本。例如,可以使用新的枚举值 napi_key_filter
来扩展 napi_get_all_property_names
。
¥For an enum type used in an in-parameter, the result of passing an unknown
integer value to Node-API functions is undefined unless otherwise documented.
A new value is added with a version guard to indicate the Node-API version in
which it was introduced. For example, napi_get_all_property_names
can be
extended with new enum value of napi_key_filter
.
对于同时在输入参数和输出参数中使用的枚举类型,允许引入新值,而无需版本保护。
¥For an enum type used in both in-parameters and out-parameters, new values are allowed to be introduced without a version guard.