You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Migrate nan to node-addon-api for implementing the C++ addon (#1090)
The day when `rclnodejs` was initialized, [nan](https://github.com/nodejs/nan) was the only library designed to simplify the development of native addons, providing a consistent interface for interacting with the V8 JavaScript engine and Node.js APIs across different Node.js versions.
[N-API](https://nodejs.org/api/n-api.html#node-api) was introduced in Node.js v8.0.0 as an experimental feature to provide a stable Node API for native modules, it's officially supported by Node and allows developing native addons that are independent of the underlying JavaScript engine, and ensures Application Binary Interface (ABI) stability across different Node.js versions and compiler levels. so it is recommended to migrate to N-API for existing projects.
This patch leverages [node-addon-api](https://github.com/nodejs/node-addon-api) based on [Node-API](https://nodejs.org/api/n-api.html), which provides a C++ object model and exception handling semantics with low overhead, to rewrite the existing C++ bindings, including:
1. Add `node-addon-api` into dependencies.
2. Replace the `Nan` headers with `node-addon-api` headers.
3. Replace `nan` APIs with `node-addon-api` equivalents.
4. Use `Napi::Env` for environment handling.
5. Replace `Nan::ObjectWrap` with `Napi::ObjectWrap`.
6. Replace `Nan::Persistent` with `Napi::FunctionReference`.
7. Update error handling and buffer management.
After this patch, we will remove the explicit usage of classes from `v8::`.
Fix: #1036
0 commit comments