Skip to content

doc: add porting plan with difficulty ratings#23

Merged
legendecas merged 3 commits intonodejs:mainfrom
kraenhansen:doc/porting-plan
Mar 4, 2026
Merged

doc: add porting plan with difficulty ratings#23
legendecas merged 3 commits intonodejs:mainfrom
kraenhansen:doc/porting-plan

Conversation

@kraenhansen
Copy link
Contributor

Summary

  • Adds PORTING.md enumerating all 58 test directories from Node.js's test/js-native-api and test/node-api that are candidates for porting into the CTS
  • Rates each directory Easy / Medium / Hard based on source size and depth of Node.js runtime dependencies (libuv, worker threads, SEA, etc.)
  • Adds a Special Considerations section documenting nine porting challenges that will need harness work or Node-only scoping before the affected tests can be ported

Special considerations covered

  • node_api_post_finalizer — needs a platform-agnostic post-finalizer primitive
  • node_api_set_prototype / node_api_get_prototype — Node.js-only extensions mixed into the js-native-api general test
  • SharedArrayBuffer backing-store creation via Node-specific helper
  • Direct libuv dependency across many node-api tests (event loop access, threads, mutexes)
  • Threadsafe functions and their libuv threading primitives
  • Node.js worker threads (no equivalent in most other runtimes)
  • SEA (Single Executable Applications) — inherently Node.js-specific
  • napi_get_node_version — no equivalent in other runtimes
  • Legacy module registration via NAPI_MODULE + NULL init

🤖 Generated with Claude Code

PORTING.md Outdated
### `node_api_post_finalizer` (`6_object_wrap`, `test_finalizer`)

Both tests call `node_api_post_finalizer` to defer JS-touching work out of the GC finalizer and
onto the main thread. This is a Node.js extension not guaranteed to be present on other engines.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GC finalizers are on the main thread too.

This is a new node-api. It is not accurate to say "This is a Node.js extension".

PORTING.md Outdated
to their own deferred-callback mechanism, or the tests need to isolate the post-finalizer cases
into a Node-specific subtest.

### `node_api_set_prototype` / `node_api_get_prototype` (`test_general`, js-native-api)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only node_api_set_prototype is an API with the new name convention.

Suggested change
### `node_api_set_prototype` / `node_api_get_prototype` (`test_general`, js-native-api)
### `node_api_set_prototype` / `napi_get_prototype` (`test_general`, js-native-api)

PORTING.md Outdated
### SharedArrayBuffer backing-store creation (`test_sharedarraybuffer`)

While `napi_is_sharedarraybuffer` and `napi_get_typedarray_info` are part of `js_native_api.h`,
the test creates its SharedArrayBuffer via a Node-specific helper. The CTS version will need a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by this. What Node-specific helper is used in the tests?

### libuv dependency (multiple `node-api` tests)

The following tests call into libuv directly — `napi_get_uv_event_loop`, `uv_thread_t`,
`uv_mutex_t`, `uv_async_t`, `uv_check_t`, `uv_idle_t`, `uv_queue_work`, and related APIs:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think uv_mutex_t and uv_thread_t can be replaced with std APIs.

@kraenhansen
Copy link
Contributor Author

kraenhansen commented Mar 3, 2026

Added a commit that addresses two things:

API Naming Convention section — adds an explanation near the top of the document clarifying that the napi_ vs node_api_ prefix difference is purely historical (the project was renamed from "napi" to "Node API"), not an indicator of whether a function is Node.js-specific or runtime-agnostic. The actual distinction is which header declares the function: js_native_api.h (engine-agnostic) vs node_api.h (runtime-specific).

Function name and description corrections — verified all named functions against the actual Node.js source and fixed errors:

  • node_api_get_prototypenapi_get_prototype (mixed-prefix pair with node_api_set_prototype)
  • napi_is_sharedarraybuffernode_api_is_sharedarraybuffer (correct prefix)
  • napi_get_typedarray_infonode_api_create_sharedarraybuffer (was referencing the wrong function entirely)
  • Removed "Node.js extension" language from node_api_post_finalizer and node_api_set_prototype / napi_get_prototype — all three are declared in js_native_api.h. The real nuance is that node_api_post_finalizer and node_api_set_prototype are gated behind NAPI_EXPERIMENTAL, while napi_get_prototype is a standard API.

kraenhansen and others added 3 commits March 3, 2026 20:00
Enumerates all 58 test directories from Node.js's test/js-native-api
and test/node-api, rates each by porting difficulty (Easy/Medium/Hard),
and documents special considerations for tests with deep runtime
dependencies (libuv, worker threads, SEA, node_api_post_finalizer, etc.).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add an "API Naming Convention" section explaining that the napi_/node_api_
prefix difference is historical (rename from "napi" to "Node API"), not an
indicator of Node.js-specificity. What matters is the declaring header:
js_native_api.h (engine-agnostic) vs node_api.h (runtime-specific).

Also fix two function name errors in the Special Considerations section:
- node_api_get_prototype → napi_get_prototype (actual name in source)
- napi_is_sharedarraybuffer → node_api_is_sharedarraybuffer (correct prefix)
- napi_get_typedarray_info → node_api_create_sharedarraybuffer (wrong function
  referenced; the real concern is backing-store allocation)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
@legendecas legendecas merged commit ebd91a5 into nodejs:main Mar 4, 2026
13 checks passed
@github-project-automation github-project-automation bot moved this from Has PR to Done in Node-API Team Project Mar 4, 2026
@kraenhansen kraenhansen deleted the doc/porting-plan branch March 7, 2026 14:28
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.

2 participants