Skip to content

Implement Node-API runtime functions ☂️ #56

Description

@kraenhansen

While the current Node-API engine functions are implemented by Hermes, this issues is tracking the implementation of the remaining runtime specific functions. Each will be tracked as a sub-issue of this "umbrella" issue.

Activity

  1. 8 remaining items

  2. shirakaba commented on May 25, 2025

    @shirakaba
    Collaborator

    Reference implementations for the Node-API runtime functions (linking to napi_create_async_work in each case):

  3. shirakaba commented on May 25, 2025

    @shirakaba
    Collaborator

    Where in the codebase are these to be implemented?

  4. kraenhansen commented on May 29, 2025

    @kraenhansen
    CollaboratorAuthor

    That's a great question - somewhere in the host package for sure: packages/react-native-node-api-modules/cpp their implementation likely needs to reach in to React Native APIs - perhaps even JSI? 🤔 (If the latter is the case, we might need a weak map to lookup the jsi::Runtime based on napi_env too).

    I imagine we'll be implementing these functions, grouped by their Node-API version levels - we could

    • start with Node-API v1 (either in order of ease of implementation or importance)
    • figure out what we other (React Native) APIs we'd need access to
    • figure out how we'd get to them from a function taking just the napi_env
  5. kraenhansen commented on Aug 12, 2026

    @kraenhansen
    CollaboratorAuthor

    Status sweep against next

    Adopting Hermes' first-party Node-API (#372) and implementing hermes_napi_host (#398) covered most of what this umbrella was tracking: the runtime-specific functions are now provided by Hermes' API/napi, with React Native supplying the pieces Hermes delegates to its embedder — a worker pool behind post_work/cancel_work, the runtime's CallInvoker behind post_task and work completions, and fatal_exception. The buffer functions and napi_fatal_error remain host implementations in packages/host/cpp/RuntimeNodeApi.cpp.

    Closed as completed (28) — each sub-issue has a comment pointing at what implements it:

    Area Issues Where it lives
    Async work #59, #60, #64, #71 hermes_napi_async_work.cpp + post_work/cancel_work (HermesNapiHost.cpp)
    Async context & callback scopes #57, #58, #69, #74, #76 hermes_napi_async_context.cpp
    Thread-safe functions #78, #79, #80, #81, #82, #83, #84 hermes_napi_tsfn.cpp + post_task (HermesNapiHost.cpp)
    Cleanup hooks #73, #77, #85, #86 hermes_napi.cpp
    Buffers #61, #62, #63, #66, #68 RuntimeNodeApi.cpp (Buffer as Uint8Array)
    Fatal error / exception #65, #75 RuntimeNodeApi.cpp / fatal_exception (HermesNapiHost.cpp)
    uv event loop #72 hermes_napi.cpp — returns napi_generic_failure, no libuv loop by design

    Test coverage for the new surface: packages/node-addon-examples/tests/async, .../tests/threadsafe-function (a port of Node's test_threadsafe_function), .../tests/buffers (a port of test_buffer), and the Catch2 suite in packages/host/tests exercising the host contract on plain Linux.

    Still open (2):

    • Implement napi_get_node_version #67 napi_get_node_version — the host shim returns napi_generic_failure and shadows Hermes' working implementation in the generated injector. Policy call: drop the shim or keep the failure. Details in the issue.
    • Implement napi_module_register #70 napi_module_register — Hermes records the module, but our loader never reads it back, so the deprecated registration path still fails to load an addon. Details in the issue.

    Two caveats recorded on the closed issues rather than left implicit: Buffer fidelity versus a real Buffer is still #171 (the host's napi_is_buffer is also looser than Node's), and tsfn ref/unref are tracked but inert since React Native has no loop lifetime to model (#82, #84).


    Generated by Claude Code

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C++Host 🏡Our `react-native-node-api-modules` packagehelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions