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_get_all_property_names 可以通过新增 napi_key_filter 枚举值来扩展。

🌐 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.