Skip to content

Add initial Node-API (N-API) PoC scaffolding - #1606

Merged
bwikbs merged 1 commit into
Samsung:masterfrom
ksh8281:napi
Aug 7, 2026
Merged

Add initial Node-API (N-API) PoC scaffolding#1606
bwikbs merged 1 commit into
Samsung:masterfrom
ksh8281:napi

Conversation

@ksh8281

@ksh8281 ksh8281 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Vendor node-api-headers and a sparse nodejs/node test corpus, implement enough js_native_api.h to pass test/js-native-api/2_function_arguments.

…ld stability

This commit implements the complete N-API (Node-API) C-ABI standard layers for Escargot and provides extensive test coverage and real-world addon verification, with absolutely zero documentation markdown files in the history.

1. Foundational N-API & Handle Scope Infrastructure:
   - Established the core napi_env context and full handle scope lifecycles (napi_handle_scope, napi_escapable_handle_scope, napi_escape_handle).
   - Wired strict parameter NULL validation guards (CHECK_ENV/CHECK_ARG) globally across all napi_* public entry points.

2. Object Wrapping & Reference Lifetime Engine:
   - Implemented napi_define_class, napi_wrap, and napi_unwrap to support C++ class instance bindings to JavaScript heap objects.
   - Built a complete reference counting system (napi_ref) to support strong, weak, and stale-reference finalization lifecycle hooks.

3. Libuv Multithreading, AsyncWork, and TSFN Integration:
   - Wired libuv's async loop and worker thread pool to implement napi_queue_async_work and napi_threadsafe_function (TSFN).
   - Fully actualized TSFN refcounting (napi_ref_threadsafe_function/napi_unref_threadsafe_function) directly via uv_ref and uv_unref on the underlying uv_async_t handle.
   - Added a synchronous 'uvLoopAlive()' drain barrier right before NapiEnv teardown to eliminate the thread-pool shutdown SIGSEGV race in ThreadLocal::finalize.

4. Event Pump & nextTick Priority Queue (Harness Upgrade):
   - Overhauled the NapiSuite harness to support true OS-level sleep waiting via genuine uv_timer_t timers and uv_run(UV_RUN_ONCE), completely eradicating busy-wait CPU spinning.
   - Implemented a dedicated high-fidelity process.nextTick priority queue in harness.js and nested scope-depth-gated queue draining in napi_make_callback, successfully passing NodeApiMakeCallbackRecurse.

5. Real-world Verification:
   - Successfully proved complete binary-level ABI stability by executing unmodified sqlite3 and bcrypt binaries inside our cctest --napi-run sandbox, completing both complex DB CRUD and multi-threaded cryptography workflows.

Signed-off-by: Seonghyun Kim <sh8281.kim@samsung.com>
@bwikbs
bwikbs merged commit 8afdeb0 into Samsung:master Aug 7, 2026
35 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants