Implications of ABI stability
Source: Node.js documentationAlthough Node-API provides an ABI stability guarantee, other parts of Node.js do not, and any external libraries used from the addon may not. In particular, none of the following APIs provide an ABI stability guarantee across major versions:
-
the Node.js C++ APIs available via any of
#include <node.h> #include <node_buffer.h> #include <node_version.h> #include <node_object_wrap.h> -
the libuv APIs which are also included with Node.js and available via
#include <uv.h> -
the V8 API available via
#include <v8.h>
Thus, for an addon to remain ABI-compatible across Node.js major versions, it must use Node-API exclusively by restricting itself to using
#include <node_api.h>
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
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.
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.
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.