豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

feat(ext/node): add node_api_create_object_with_properties API#31443

Merged
bartlomieju merged 29 commits intodenoland:mainfrom
littledivy:napi_create_object_with_properties
Mar 10, 2026
Merged

feat(ext/node): add node_api_create_object_with_properties API#31443
bartlomieju merged 29 commits intodenoland:mainfrom
littledivy:napi_create_object_with_properties

Conversation

@littledivy
Copy link
Copy Markdown
Member

@littledivy littledivy commented Nov 28, 2025

Closes #31433

  • Implements node_api_create_object_with_properties API using
    v8::Object::with_prototype_and_properties()
  • Updates napi-sys from 2.2.2 to 3.2.1 which includes the function
    binding behind the experimental feature flag
  • Fixes test_napi string length parameter types (usizeisize)
    for napi-sys 3.x compatibility

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 28, 2025

Walkthrough

This PR introduces a new N-API function napi_create_object_with_properties that creates JavaScript objects with specified properties and prototypes. The function is added to the Rust N-API bindings and exported in symbol lists for Linux, macOS, and Windows. The implementation validates arguments, converts property names to v8::Name objects, and constructs objects with both a custom prototype and properties. Comprehensive tests are included covering standard property creation, empty objects, and objects with custom prototypes.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a new NAPI API function for creating objects with properties.
Description check ✅ Passed The description references the closed issue #31433, which relates to implementing the napi_create_object_with_properties API.
Linked Issues check ✅ Passed The PR implements napi_create_object_with_properties across all platforms (Linux, macOS, Windows) with supporting tests, meeting the objective to support faster object creation in Deno's Node API compatibility layer.
Out of Scope Changes check ✅ Passed All changes are in-scope: new API implementation, platform-specific symbol exports, and comprehensive tests for the new functionality. No unrelated modifications detected.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef3192d and 440eead.

📒 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 use lldb directly
Use eprintln!() or dbg!() macros for debug prints in Rust code

Files:

  • ext/napi/js_native_api.rs
  • tests/napi/src/object.rs
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,js}: For JavaScript runtime debugging, enable V8 inspector with --inspect-brk flag and connect Chrome DevTools to chrome://inspect
Use console.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 correct

Symbol name and ordering (between napi_create_object and napi_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 aligned

The _napi_create_object_with_properties symbol is correctly exported and ordered after _napi_create_object.

ext/napi/sym/symbol_exports.json (1)

96-98: Symbol manifest entry is consistent

The JSON export list now includes "napi_create_object_with_properties" in the same relative position as the platform-specific .def files. No issues.

tests/napi/object_test.js (1)

40-65: New N-API object tests look solid

The three tests exercise non-empty, empty, and custom-prototype cases and validate both shape and prototype behavior (via the test method). This provides good coverage for the new API.

tests/napi/src/object.rs (3)

11-21: Extern declaration matches the intended N-API shape

The experimental napi_create_object_with_properties declaration 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 null prototype,
  • the property_count == 0 case 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_properties is adjusted to avoid from_raw_parts on null pointers when property_count == 0, these tests give good coverage of the new behavior.


216-230: Init wiring for new test exports looks correct

The new entries in the properties array correctly expose all three test helpers under the expected names; this integrates cleanly with the existing init pattern.

Comment thread ext/napi/js_native_api.rs
@rracariu
Copy link
Copy Markdown

Any blockers for this one?

@legendecas
Copy link
Copy Markdown
Contributor

Just a quick note here that we'd like to fix the name of the functions to our latest guideline: nodejs/node#61319

@littledivy littledivy changed the title feat(ext/node): add napi_create_object_with_properties API feat(ext/node): add node_api_create_object_with_properties API Feb 11, 2026
bartlomieju and others added 7 commits February 26, 2026 22:12
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>
bartlomieju and others added 12 commits March 8, 2026 17:23
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>
bartlomieju added a commit that referenced this pull request Mar 9, 2026
…#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>
bartlomieju and others added 5 commits March 9, 2026 18:11
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>
Copy link
Copy Markdown
Contributor

@kajukitli kajukitli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm — clean implementation of node_api_create_object_with_properties

  • uses v8::Object::with_prototype_and_properties which 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)

@bartlomieju bartlomieju merged commit 9c73df3 into denoland:main Mar 10, 2026
112 checks passed
@bartlomieju bartlomieju deleted the napi_create_object_with_properties branch March 10, 2026 15:11
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.

Support node_api_create_object_with_properties

5 participants