feat(ext/node): add node_api_create_object_with_properties API#31443
feat(ext/node): add node_api_create_object_with_properties API#31443bartlomieju merged 29 commits intodenoland:mainfrom
node_api_create_object_with_properties API#31443Conversation
WalkthroughThis PR introduces a new N-API function Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
ext/napi/generated_symbol_exports_list_linux.def(1 hunks)ext/napi/generated_symbol_exports_list_macos.def(1 hunks)ext/napi/generated_symbol_exports_list_windows.def(1 hunks)ext/napi/js_native_api.rs(1 hunks)ext/napi/sym/symbol_exports.json(1 hunks)tests/napi/object_test.js(1 hunks)tests/napi/src/object.rs(3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rs
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.rs: For debugging Rust code, set breakpoints in IDE debuggers (VS Code with rust-analyzer, IntelliJ IDEA) or uselldbdirectly
Useeprintln!()ordbg!()macros for debug prints in Rust code
Files:
ext/napi/js_native_api.rstests/napi/src/object.rs
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.{ts,tsx,js}: For JavaScript runtime debugging, enable V8 inspector with--inspect-brkflag and connect Chrome DevTools tochrome://inspect
Useconsole.log()for debug prints in JavaScript runtime code
Files:
tests/napi/object_test.js
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: test debug linux-x86_64
- GitHub Check: test debug macos-aarch64
- GitHub Check: test release linux-x86_64
- GitHub Check: test debug windows-x86_64
- GitHub Check: test debug linux-aarch64
- GitHub Check: test debug macos-x86_64
- GitHub Check: lint debug macos-x86_64
- GitHub Check: build libs
- GitHub Check: lint debug windows-x86_64
- GitHub Check: lint debug linux-x86_64
🔇 Additional comments (8)
ext/napi/generated_symbol_exports_list_windows.def (1)
96-98: Windows export entry looks correctSymbol name and ordering (between
napi_create_objectandnapi_create_promise) are consistent with the other export lists and JSON manifest.ext/napi/generated_symbol_exports_list_linux.def (1)
1-1: Linux symbol list updated consistently
"napi_create_object_with_properties"is added in the expected position alongside the other object-related symbols.ext/napi/generated_symbol_exports_list_macos.def (1)
94-96: macOS export looks alignedThe
_napi_create_object_with_propertiessymbol is correctly exported and ordered after_napi_create_object.ext/napi/sym/symbol_exports.json (1)
96-98: Symbol manifest entry is consistentThe JSON export list now includes
"napi_create_object_with_properties"in the same relative position as the platform-specific.deffiles. No issues.tests/napi/object_test.js (1)
40-65: New N-API object tests look solidThe three tests exercise non-empty, empty, and custom-prototype cases and validate both shape and prototype behavior (via the
testmethod). This provides good coverage for the new API.tests/napi/src/object.rs (3)
11-21: Extern declaration matches the intended N-API shapeThe experimental
napi_create_object_with_propertiesdeclaration lines up with the expected N-API signature and is fine as a temporary bridge until napi-sys grows this API.
81-205: Rust tests nicely cover the new API (and highlight the 0-property edge case)The three helpers exercise:
- non-empty properties with a
nullprototype,- the
property_count == 0case with null pointers for the property arrays,- and a custom prototype carrying a method plus an own data property.
Once the implementation in
napi_create_object_with_propertiesis adjusted to avoidfrom_raw_partson null pointers whenproperty_count == 0, these tests give good coverage of the new behavior.
216-230: Init wiring for new test exports looks correctThe new entries in the
propertiesarray correctly expose all three test helpers under the expected names; this integrates cleanly with the existing init pattern.
|
Any blockers for this one? |
|
Just a quick note here that we'd like to fix the name of the functions to our latest guideline: nodejs/node#61319 |
napi_create_object_with_properties APInode_api_create_object_with_properties API
Update napi-sys from 2.2.2 to 3.2.1 which includes `napi_create_object_with_properties` behind the `experimental` feature flag. Fix test_napi compile errors caused by string length parameters changing from `usize` to `isize` in napi-sys 3.x (`usize::MAX` → `-1` for NAPI_AUTO_LENGTH). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use the correct `node_api_` prefix per nodejs/node#61319. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…symbols The bundled node.lib from napi-build 1.x doesn't include the newer `node_api_create_object_with_properties` symbol, causing linker errors on Windows. Generate an extra import library from a .def file to provide the missing symbol. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…i_sys crate Fork napi-sys into libs/napi_sys to avoid build-time dependency on Node.js binaries (required by napi-sys v3.x) and allow adding new Node-API symbols directly in-tree. This unblocks PRs that need newer symbols: - denoland#32559 (node_api_create_property_key_latin1/utf8) - denoland#31443 (node_api_create_object_with_properties) All napi version feature gates have been removed — every symbol is always available. The napi-build dependency is also eliminated by inlining the macOS linker flags into tests/napi/build.rs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The in-tree napi_sys declares functions as `pub safe fn` inside
`unsafe extern "C"` blocks, so existing `unsafe { ... }` wrappers
around napi calls are now redundant. Allow them crate-wide rather
than touching every test file.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove duplicate `load()` from functions.rs (the `generate!` macro already creates one) - Add `unsafe` blocks inside the Windows `generate!` macro for Rust 2024 edition compatibility (mutable static access, unsafe fn calls) - Move host library creation into `setup()` in lib.rs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The old napi-sys had separate modules each with their own load() call, so a missing symbol only skipped that module. With everything in a single generate! block, the early return on a missing symbol (e.g. a new node_api_* function not yet exported by Deno) would abort loading ALL subsequent symbols including core ones like napi_create_object. Fix by continuing to load remaining symbols when one is missing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove redundant `unsafe extern "C"` declaration in test_napi and fix the napi_sys signature to match Deno's implementation (includes prototype_or_null parameter). Fixes Windows linker error. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The debug_assert println messages for missing NAPI symbols were going to stdout, causing the cleanup_hook test to fail on Windows debug builds by adding unexpected lines to the output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Missing symbols are expected — napi_sys declares all known NAPI symbols but Deno doesn't implement every one. The load function already handles this gracefully by keeping a panic stub. Remove the debug_assert prints that pollute stdout/stderr and break test assertions on Windows. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…#32582) ## Summary - Forks `napi-sys` (v2.2.2) into `libs/napi_sys/` to avoid build-time dependency on Node.js binaries (required by `napi-sys` v3.x) and allow adding new Node-API symbols directly in-tree - Removes all napi version feature gates — every symbol is always available - Eliminates `napi-build` dependency by inlining the macOS linker flags into `tests/napi/build.rs` - Adds new symbols that are needed by blocked PRs: - `node_api_create_property_key_latin1`, `node_api_create_property_key_utf8` (#32559) - `node_api_create_object_with_properties`, `node_api_create_object_with_named_properties` (#31443) - `node_api_symbol_for`, `node_api_create_property_key_utf16` This unblocks #32559 and #31443 which currently can't build because the symbols they need aren't available in `napi-sys` v2.2.2, and upgrading to v3.x introduces a requirement for Node.js binaries during build. --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Take upstream's parameter naming for node_api_create_object_with_properties and debug_assert error handling in lib.rs load(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Match the actual implementation signature which includes the prototype_or_null parameter and correct argument order. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Removes node_api_create_property_key_{latin1,utf8} and
node_api_create_object_with_named_properties which are not yet
implemented in ext/napi. On Windows debug builds, GetProcAddress
failure messages for these symbols pollute stdout and break tests.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
kajukitli
left a comment
There was a problem hiding this comment.
lgtm — clean implementation of node_api_create_object_with_properties
- uses
v8::Object::with_prototype_and_propertieswhich is the right API - validates property names are v8::Name types before use
- handles empty properties case
- good test coverage (with properties, empty, custom prototype)
Closes #31433
node_api_create_object_with_propertiesAPI usingv8::Object::with_prototype_and_properties()napi-sysfrom 2.2.2 to 3.2.1 which includes the functionbinding behind the
experimentalfeature flagusize→isize)for napi-sys 3.x compatibility