Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ba33209
JavaScriptCore wrapper previously passed nullptr to JSObjectCallAsFun…
matthargett Oct 12, 2025
e1fce6b
Add the node-lite test suite Vlad added into hermes-windows. The JSC …
matthargett Oct 12, 2025
e9aa436
Android tests now pass. StdoutLogger was holding on to destroyed mute…
matthargett Oct 12, 2025
9ebd4ce
Run the macOS NodeApiTests under sanitizers, which found another bug …
matthargett Oct 13, 2025
eb2eae4
Fix build errors. This deduplicates struct definitions that were inli…
matthargett Oct 15, 2025
a18d1cc
always build the napi tests
matthargett Oct 16, 2025
2eabe90
try and get address sanitizer and thread sanitizer to run on Android,…
matthargett Oct 16, 2025
8362442
Add N-API version/conformance roadmap (folds in engine-compat baseline)
matthargett Jun 4, 2026
1180892
Restore NodeApi tests build on current macOS toolchain
matthargett Jun 4, 2026
900b8eb
Restore Android NodeApi test build (compiles/links/installs/runs on e…
matthargett Jun 4, 2026
7714d9f
Fix Android NodeApi harness JNI crash; wire up SetNodeApiTestEnvironment
matthargett Jun 4, 2026
1cedda1
Android: make the NodeApi conformance tests actually execute on-device
matthargett Jun 4, 2026
33412f5
Android: enter the V8 context in jsr_open_napi_env_scope (fix napi_cr…
matthargett Jun 4, 2026
b15d528
Android/in-process node_lite: let ExitOnException propagate the fatal…
matthargett Jun 4, 2026
b35d519
Android/in-process: make node_lite teardown destructors exception-safe
matthargett Jun 4, 2026
f4e170b
Android/in-process: guard the fatal handler against throwing while un…
matthargett Jun 4, 2026
38864e4
Android/in-process: drop noexcept from throwing error-exit functions …
matthargett Jun 4, 2026
39a87ea
Android: skip in-process js-native-api addon tests pending shared-lib…
matthargett Jun 4, 2026
b559f69
docs(roadmap): document Android in-process addon-load constraint + sh…
matthargett Jun 4, 2026
f32130e
Android: statically link conformance addons into the test binary (run…
matthargett Jun 5, 2026
f0d1c2e
Android tests: pump native stdout/stderr to logcat
matthargett Jun 5, 2026
1938ff0
docs(roadmap): Android v5 js-native-api now green via static linking …
matthargett Jun 5, 2026
d4231ee
Android: drop the now-dead dynamic-.node build machinery (superseded …
matthargett Jun 5, 2026
04e3158
Android: remove vestigial V8Platform scaffolding from the env holder
matthargett Jun 5, 2026
b51d1a7
docs(roadmap): record node-api-cts FetchContent evaluation (task 6) —…
matthargett Jun 5, 2026
58223c0
Android: dlopen conformance addons as dynamic .node backed by a share…
matthargett Jun 5, 2026
538fe04
docs(roadmap): Android uses dynamic .node + shared libnapi.so (aligns…
matthargett Jun 5, 2026
44d903e
Android tests: use AndroidExtensions StdoutLogger for stdout->logcat
matthargett Jun 5, 2026
d225e74
docs(roadmap): stdout->logcat is via AndroidExtensions StdoutLogger, …
matthargett Jun 5, 2026
e94c72e
Sync napi shared-lib change with PR #183 (gate behind JSR_NAPI_SHARED…
matthargett Jun 5, 2026
17316b7
Tests: enable the v5-clean reference double-free conformance test
matthargett Jun 5, 2026
ed74d61
docs(roadmap): reference-test staging + GC-safety review (re hermes-w…
matthargett Jun 5, 2026
3f63934
Node-API: address #116 review (JSC call dispatch, status type, Window…
matthargett Jun 5, 2026
eee2960
Node-API: raise default NAPI_VERSION 5 -> 7
matthargett Jun 5, 2026
30a1dff
JSC: implement napi_set/get_instance_data (N-API v6)
matthargett Jun 5, 2026
d728c4f
JSC: implement N-API v6 BigInt + v7 ArrayBuffer detach
matthargett Jun 5, 2026
8a56437
tests: note detach/property_names conformance tests are v9-gated (nod…
matthargett Jun 5, 2026
84ede39
JSC: detect BigInt in napi_typeof on jsc-android (cached typeof predi…
matthargett Jun 5, 2026
d69bade
Chakra/JSI: N-API v6/v7 surface for the cross-engine version bump
matthargett Jun 5, 2026
98bca40
Tests/NodeApi: add missing <cstdint> in child_process.h (fixes Linux …
matthargett Jun 5, 2026
2e70227
Tests/node_lite: select the napi engine by compile-define, not platform
matthargett Jun 5, 2026
9e6c171
Tests/NodeApi: link napi into addons on Windows/UWP so napi_* resolve…
matthargett Jun 5, 2026
522f310
Tests/Android: run test_bigint on V8 only (jsc-android ~2020 BigInt s…
matthargett Jun 5, 2026
f21ccc0
build: suppress MSVC C4875 from vendored GSL to unblock the Windows b…
matthargett Jun 5, 2026
e55e6bc
Core/Node-API-JSI: add the shared napi include path (fixes pre-existi…
matthargett Jun 5, 2026
172a990
JSC: feature-detect BigInt; throw ENOTSUP where the engine lacks it (…
matthargett Jun 5, 2026
32d37fa
Tests/NodeApi: add literal-free test_bigint_unsupported fallback; gat…
matthargett Jun 5, 2026
8e6a62a
Tests/Android: surface in-process node_lite failure detail to logcat
matthargett Jun 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# A newer MSVC (windows-latest) emits C4875 ("a non-string literal argument to [[gsl::suppress]] is
# deprecated") from the vendored GSL headers, which several targets compile with warnings-as-error.
# Suppress this dependency-side deprecation so the Windows build isn't broken by toolchain drift. Must
# be set before arcana.cpp / Core / Polyfills are added below so they inherit it.
if(MSVC)
add_compile_options(/wd4875)
endif()

# --------------------------------------------------
# Options
# --------------------------------------------------
Expand Down Expand Up @@ -135,6 +143,17 @@ endif()
FetchContent_MakeAvailable_With_Message(arcana.cpp)
set_property(TARGET arcana PROPERTY FOLDER Dependencies)

if(ANDROID)
FetchContent_GetProperties(AndroidExtensions)
if(NOT AndroidExtensions_POPULATED)
FetchContent_Populate(AndroidExtensions)
FetchContent_GetProperties(AndroidExtensions)
add_subdirectory(${androidextensions_SOURCE_DIR} ${androidextensions_BINARY_DIR})
else()
add_subdirectory(${androidextensions_SOURCE_DIR} ${androidextensions_BINARY_DIR})
endif()
endif()

if(JSRUNTIMEHOST_POLYFILL_XMLHTTPREQUEST)
FetchContent_MakeAvailable_With_Message(UrlLib)
set_property(TARGET UrlLib PROPERTY FOLDER Dependencies)
Expand Down
7 changes: 6 additions & 1 deletion Core/Node-API-JSI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ if(NOT TARGET jsi)
endif()

target_include_directories(napi
PUBLIC "include")
PUBLIC "include"
# napi.h pulls in the shared <napi/js_native_api_types.h>, which lives in
# Core/Node-API/Include/Shared. That sibling isn't built when the engine is JSI
# (Core/CMakeLists.txt selects Node-API-JSI instead of Node-API), so reference the shared
# headers directly here -- otherwise the JSI napi fails to compile with C1083.
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../Node-API/Include/Shared")

target_link_libraries(napi
PUBLIC jsi)
Expand Down
37 changes: 1 addition & 36 deletions Core/Node-API-JSI/Include/napi/napi.h
Original file line number Diff line number Diff line change
@@ -1,49 +1,14 @@
#pragma once

#include <jsi/jsi.h>
#include <napi/js_native_api_types.h>
#include <functional>
#include <initializer_list>
#include <memory>
#include <string>
#include <vector>
#include <optional>

// Copied from js_native_api_types.h (https://git.io/J8aI5)
typedef enum {
napi_default = 0,
napi_writable = 1 << 0,
napi_enumerable = 1 << 1,
napi_configurable = 1 << 2,
} napi_property_attributes;

typedef enum {
// ES6 types (corresponds to typeof)
napi_undefined,
napi_null,
napi_boolean,
napi_number,
napi_string,
napi_symbol,
napi_object,
napi_function,
napi_external,
} napi_valuetype;

typedef enum {
napi_int8_array,
napi_uint8_array,
napi_uint8_clamped_array,
napi_int16_array,
napi_uint16_array,
napi_int32_array,
napi_uint32_array,
napi_float32_array,
napi_float64_array,
// JSI doesn't support bigint.
// napi_bigint64_array,
// napi_biguint64_array,
} napi_typedarray_type;

struct napi_env__ {
napi_env__(facebook::jsi::Runtime& rt)
: rt{rt}
Expand Down
30 changes: 28 additions & 2 deletions Core/Node-API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ elseif(ANDROID)
set(NAPI_JAVASCRIPT_ENGINE "V8" CACHE STRING "JavaScript engine for Node-API")
elseif(UNIX)
set(NAPI_JAVASCRIPT_ENGINE "JavaScriptCore" CACHE STRING "JavaScript engine for Node-API")
set(JAVASCRIPTCORE_LIBRARY "/usr/lib/x86_64-linux-gnu/libjavascriptcoregtk-4.1.so" CACHE STRING "Path to the JavaScriptCore shared library")
find_library(JAVASCRIPTCORE_LIBRARY javascriptcoregtk-4.1)
if(NOT JAVASCRIPTCORE_LIBRARY)
message(FATAL_ERROR "JavaScriptCore library not found. Please install libwebkit2gtk-4.1-dev")
endif()
else()
message(FATAL_ERROR "Unable to select Node-API JavaScript engine for platform")
endif()
Expand Down Expand Up @@ -152,10 +155,33 @@ if(NAPI_BUILD_ABI)
message(STATUS "Selected ${NAPI_JAVASCRIPT_ENGINE}")
endif()

add_library(napi ${SOURCES})
# On Android, native addons are dlopen'd as standalone .node modules and resolve their napi_* imports
# from a shared napi at load time -- bionic will not surface a statically-linked host's napi to a
# dlopen'd module, so the host and every addon must share a single libnapi.so. Default napi to a
# shared library on Android so that model works out of the box; an integrator who wants a static napi
# (e.g. for size/packaging) can override with -DJSR_NAPI_SHARED=OFF. The option defaults OFF on other
# platforms, where napi keeps following the project's default library type (i.e. honors
# BUILD_SHARED_LIBS).
set(JSR_NAPI_SHARED_DEFAULT OFF)
if(ANDROID)
set(JSR_NAPI_SHARED_DEFAULT ON)
endif()
option(JSR_NAPI_SHARED "Build napi as a shared library (libnapi.so)" ${JSR_NAPI_SHARED_DEFAULT})

if(JSR_NAPI_SHARED)
add_library(napi SHARED ${SOURCES})
else()
add_library(napi ${SOURCES})
endif()

target_include_directories(napi ${INCLUDE_DIRECTORIES})
target_link_libraries(napi ${LINK_LIBRARIES})

# Expose the selected engine as a compile definition so engine-agnostic consumers (the node_lite test
# harness) can branch on engine capability instead of guessing from the platform
# (__APPLE__ == JSC / __ANDROID__ == V8 breaks Android-JSC, Linux-V8, Windows-Chakra, ...).
string(TOUPPER "${NAPI_JAVASCRIPT_ENGINE}" NAPI_ENGINE_UPPER)
target_compile_definitions(napi PUBLIC JSR_NAPI_ENGINE_${NAPI_ENGINE_UPPER})

set_property(TARGET napi PROPERTY FOLDER Dependencies)
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES})
2 changes: 1 addition & 1 deletion Core/Node-API/Include/Shared/napi/js_native_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// [BABYLON-NATIVE-ADDITION]
#ifndef NAPI_VERSION
#define NAPI_VERSION 5
#define NAPI_VERSION 7
#endif

// This file needs to be compatible with C compilers.
Expand Down
2 changes: 1 addition & 1 deletion Core/Node-API/Include/Shared/napi/js_native_api_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// [BABYLON-NATIVE-ADDITION]
#ifndef NAPI_VERSION
#define NAPI_VERSION 5
#define NAPI_VERSION 7
#endif

// This file needs to be compatible with C compilers.
Expand Down
73 changes: 73 additions & 0 deletions Core/Node-API/Source/js_native_api_chakra.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2419,6 +2419,79 @@ napi_status napi_run_script(napi_env env,
return napi_ok;
}

// === N-API v6 / v7 ===
//
// napi_set_instance_data / napi_get_instance_data (v6): per-env data slot, finalized at env teardown
// by ~napi_env__ (see js_native_api_chakra.h).
napi_status napi_set_instance_data(napi_env env,
void* data,
napi_finalize finalize_cb,
void* finalize_hint) {
CHECK_ENV(env);
env->instance_data = data;
env->instance_data_finalize_cb = finalize_cb;
env->instance_data_finalize_hint = finalize_hint;
return napi_ok;
}

napi_status napi_get_instance_data(napi_env env, void** data) {
CHECK_ENV(env);
CHECK_ARG(env, data);
*data = env->instance_data;
return napi_ok;
}

// BigInt (v6): the Win10 OS edge-mode Chakra (jsrt) predates BigInt and exposes no JsBigInt* API, so
// there is no value-preserving fallback. Per the Node-API feature-detection-by-exception pattern, throw
// a JS-catchable error tagged "ENOTSUP" (so JS land can detect + polyfill) and return a pending
// exception rather than silently failing. (ChakraCore added BigInt behind a flag, but the OS Chakra
// this backend targets did not ship it.)
static napi_status napi_bigint_not_supported(napi_env env) {
CHECK_ENV(env);
CHECK_NAPI(napi_throw_error(
env, "ENOTSUP",
"BigInt is not supported by the underlying JavaScript engine (Chakra)."));
return napi_set_last_error(env, napi_pending_exception);
}

napi_status napi_create_bigint_int64(napi_env env, int64_t value, napi_value* result) {
return napi_bigint_not_supported(env);
}

napi_status napi_create_bigint_uint64(napi_env env, uint64_t value, napi_value* result) {
return napi_bigint_not_supported(env);
}

napi_status napi_create_bigint_words(napi_env env,
int sign_bit,
size_t word_count,
const uint64_t* words,
napi_value* result) {
return napi_bigint_not_supported(env);
}

napi_status napi_get_value_bigint_int64(napi_env env,
napi_value value,
int64_t* result,
bool* lossless) {
return napi_bigint_not_supported(env);
}

napi_status napi_get_value_bigint_uint64(napi_env env,
napi_value value,
uint64_t* result,
bool* lossless) {
return napi_bigint_not_supported(env);
}

napi_status napi_get_value_bigint_words(napi_env env,
napi_value value,
int* sign_bit,
size_t* word_count,
uint64_t* words) {
return napi_bigint_not_supported(env);
}

napi_status napi_add_finalizer(napi_env env,
napi_value js_object,
void* native_object,
Expand Down
12 changes: 12 additions & 0 deletions Core/Node-API/Source/js_native_api_chakra.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ struct napi_env__ {

JsPropertyIdRef wrap_property_id = JS_INVALID_REFERENCE;

// napi_set_instance_data / napi_get_instance_data (N-API v6).
void* instance_data = nullptr;
napi_finalize instance_data_finalize_cb = nullptr;
void* instance_data_finalize_hint = nullptr;

const std::thread::id thread_id{std::this_thread::get_id()};

~napi_env__() {
// Run the instance-data finalizer at env teardown (env_chakra.cc deletes the env), matching V8/JSC.
if (instance_data_finalize_cb != nullptr) {
instance_data_finalize_cb(this, instance_data, instance_data_finalize_hint);
}
}
};

#define RETURN_STATUS_IF_FALSE(env, condition, status) \
Expand Down
Loading