Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 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
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
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,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
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
24 changes: 22 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,7 +155,24 @@ 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})
Expand Down
42 changes: 35 additions & 7 deletions Core/Node-API/Source/js_native_api_javascriptcore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,9 @@ struct napi_ref__ {
CHECK_NAPI(ReferenceInfo::GetObjectId(env, _value, &_objectId));
if (_objectId == 0) {
CHECK_NAPI(ReferenceInfo::Initialize(env, _value, [value = _value](ReferenceInfo* info) {
if (info->Env()->shutting_down) {
return;
}
auto entry{info->Env()->active_ref_values.find(value)};
// NOTE: The finalizer callback is actually on a "sentinel" JS object that is linked to the
// actual JS object we are trying to track. This means it is possible for the tracked object
Expand Down Expand Up @@ -841,6 +844,18 @@ void napi_env__::deinit_symbol(JSValueRef symbol) {
JSValueUnprotect(context, symbol);
}

void napi_env__::init_function_prototype_call() {
// Capture the canonical Function.prototype.call once, at env init, so napi_call_function does not
// depend on a target function's own (user-overridable) "call" property.
JSObjectRef global = JSContextGetGlobalObject(context);
JSValueRef function_ctor = JSObjectGetProperty(context, global, JSString("Function"), nullptr);
JSObjectRef function_ctor_obj = JSValueToObject(context, function_ctor, nullptr);
JSValueRef prototype = JSObjectGetProperty(context, function_ctor_obj, JSString("prototype"), nullptr);
JSObjectRef prototype_obj = JSValueToObject(context, prototype, nullptr);
function_prototype_call = JSObjectGetProperty(context, prototype_obj, JSString("call"), nullptr);
JSValueProtect(context, function_prototype_call);
}

// Warning: Keep in-sync with napi_status enum
static const char* error_messages[] = {
nullptr,
Expand Down Expand Up @@ -1642,14 +1657,27 @@ napi_status napi_call_function(napi_env env,
CHECK_ARG(env, argv);
}

JSObjectRef function_object = ToJSObject(env, func);

std::vector<JSValueRef> call_args(argc + 1);
call_args[0] = ToJSValue(recv);
for (size_t i = 0; i < argc; ++i) {
call_args[i + 1] = ToJSValue(argv[i]);
}

JSValueRef exception{};
JSValueRef return_value{JSObjectCallAsFunction(
env->context,
ToJSObject(env, func),
JSValueIsUndefined(env->context, ToJSValue(recv)) ? nullptr : ToJSObject(env, recv),
argc,
ToJSValues(argv),
&exception)};
// Invoke through the canonical Function.prototype.call (captured at env init), not the target's own
// "call" property -- user code could override func.call and change native call behavior.
JSObjectRef call_object =
JSValueToObject(env->context, env->function_prototype_call, &exception);
CHECK_JSC(env, exception);

JSValueRef return_value{JSObjectCallAsFunction(env->context,
call_object,
function_object,
call_args.size(),
call_args.data(),
&exception)};
Comment thread
matthargett marked this conversation as resolved.
CHECK_JSC(env, exception);

if (result != nullptr) {
Expand Down
6 changes: 6 additions & 0 deletions Core/Node-API/Source/js_native_api_javascriptcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ struct napi_env__ {
napi_extended_error_info last_error{nullptr, nullptr, 0, napi_ok};
std::unordered_map<napi_value, std::uintptr_t> active_ref_values{};
std::list<napi_ref> strong_refs{};
bool shutting_down{false};

JSValueRef constructor_info_symbol{};
JSValueRef function_info_symbol{};
JSValueRef reference_info_symbol{};
JSValueRef wrapper_info_symbol{};
JSValueRef function_prototype_call{};

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

Expand All @@ -29,10 +31,13 @@ struct napi_env__ {
init_symbol(function_info_symbol, "BabylonNative_FunctionInfo");
init_symbol(reference_info_symbol, "BabylonNative_ReferenceInfo");
init_symbol(wrapper_info_symbol, "BabylonNative_WrapperInfo");
init_function_prototype_call();
}

~napi_env__() {
shutting_down = true;
deinit_refs();
deinit_symbol(function_prototype_call);
deinit_symbol(wrapper_info_symbol);
deinit_symbol(reference_info_symbol);
deinit_symbol(function_info_symbol);
Expand All @@ -55,6 +60,7 @@ struct napi_env__ {

void deinit_refs();
void init_symbol(JSValueRef& symbol, const char* description);
void init_function_prototype_call();
void deinit_symbol(JSValueRef symbol);
};

Expand Down
1 change: 1 addition & 0 deletions Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_subdirectory(UnitTests)
add_subdirectory(NodeApi)
npm(install --silent)
111 changes: 111 additions & 0 deletions Tests/NodeApi/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 8
UseTab: Never
Loading