Skip to content

feat: add experimental Node-API feature infrastructure#31

Open
kraenhansen wants to merge 1 commit intonodejs:mainfrom
kraenhansen:feat/experimental-infrastructure
Open

feat: add experimental Node-API feature infrastructure#31
kraenhansen wants to merge 1 commit intonodejs:mainfrom
kraenhansen:feat/experimental-infrastructure

Conversation

@kraenhansen
Copy link
Contributor

Summary

Adds infrastructure to support experimental Node-API features in the CTS, enabling future test ports for the six test suites that depend on experimental APIs (test_dataview, test_sharedarraybuffer, test_object, test_general, test_finalizer, 6_object_wrap). Closes #26.

  • Vendor Node-API headers from the Node.js repository (replacing the node-api-headers npm package), giving access to experimental API declarations behind #ifdef NAPI_EXPERIMENTAL
  • Add scripts/update-headers.mjs to download latest headers and generate layered Windows .def files via clang AST dump
  • Add add_node_api_cts_experimental_addon() CMake function that compiles addons with NAPI_EXPERIMENTAL defined
  • Add implementor feature declaration (features.js harness module) so runtimes declare which experimental features they support via globalThis.experimentalFeatures
  • Add harness validation test (tests/harness/features.js) that ensures all expected feature flags are declared as booleans

Design decisions

  1. Vendored headers — Uses actual Node.js headers verbatim. NAPI_EXPERIMENTAL works exactly as upstream. Removable if node-api-headers ever adds experimental support.
  2. NAPI_EXPERIMENTAL at C level, per-feature guards at JS level — The vendored headers auto-define all NODE_API_EXPERIMENTAL_HAS_* macros when NAPI_EXPERIMENTAL is set. Per-feature granularity is only needed in JS (experimentalFeatures.*).
  3. Silent skip — When a runtime doesn't support a feature, guarded code simply doesn't execute; the test passes with zero experimental assertions.
  4. Layered .def files — Four deduplicated .def files (js_native_api.def, node_api.def, js_native_api_experimental.def, node_api_experimental.def) combined at CMake configure time for Windows import libraries.

Test plan

  • npm run addons:configure && npm run addons:build — addons compile with vendored headers
  • npm run node:test — all 26 tests pass, including new harness/features.js
  • npm run update-headers — headers download and .def files regenerate via clang
  • Windows CI — MSVC builds with layered .def import libraries

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

Vendor Node-API headers from the Node.js repository (replacing the
node-api-headers npm package) and introduce infrastructure for
experimental feature support.

- Vendor headers from Node.js src/ into include/, including experimental
  API declarations behind #ifdef NAPI_EXPERIMENTAL
- Add scripts/update-headers.mjs to download headers and generate
  layered .def files via clang AST dump
- Add add_node_api_cts_experimental_addon() CMake function that defines
  NAPI_EXPERIMENTAL for addons using experimental APIs
- Add implementor feature declaration (features.js) with
  globalThis.experimentalFeatures for conditional test execution
- Add harness test validating the experimentalFeatures global, ensuring
  every expected feature is declared as a boolean

The .def files are deduplicated layers: js_native_api.def contains
stable engine-agnostic symbols, node_api.def adds stable runtime
symbols, and the _experimental variants add only experimental symbols.
CMake combines the layers when generating MSVC import libraries.

Closes nodejs#26
@KevinEady
Copy link

Should the GitHub Actions workflow be extended to include experimental builds/tests?

@kraenhansen
Copy link
Contributor Author

Should the GitHub Actions workflow be extended to include experimental builds/tests?

Not really as I see it. Running / skipping tests based on the availability of experimental features is controlled by the harness. I expect a future PR to update the value of the feature flags based on the Node.js version executing the harness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

Support experimental Node-API features in the CTS

3 participants