Skip to content

fix(ext/node): add node_api_create_property_key_(latin1/utf8)#32559

Merged
bartlomieju merged 9 commits intomainfrom
copilot/support-node-api-create-property-key
Mar 10, 2026
Merged

fix(ext/node): add node_api_create_property_key_(latin1/utf8)#32559
bartlomieju merged 9 commits intomainfrom
copilot/support-node-api-create-property-key

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 7, 2026

Implements node_api_create_property_key_latin1 and
node_api_create_property_key_utf8 to complement the existing
node_api_create_property_key_utf16. These create internalized V8
strings for use as object property keys, enabling deduplication and
faster property lookups compared to napi_create_string_* (which use
v8::NewStringType::Normal).

  • ext/napi/js_native_api.rs — Added node_api_create_property_key_latin1
    (new_from_one_byte + Internalized) and node_api_create_property_key_utf8
    (new_from_utf8 + Internalized), following the same pattern as the existing
    _utf16 variant
  • Symbol exports — Registered both symbols in symbol_exports.json and all
    three platform .def files (Linux, macOS, Windows)
  • Tests — Added native test functions and JS integration tests that create
    property keys in each encoding, set them on objects, and verify retrieval via
    standard string keys

Fixes #31434

Adds implementations for node_api_create_property_key_latin1 and
node_api_create_property_key_utf8 to complement the existing
node_api_create_property_key_utf16 function. These functions create
internalized V8 strings optimized for use as object property keys.

Co-authored-by: bartlomieju <13602871+bartlomieju@users.noreply.github.com>
Copilot AI changed the title [WIP] Support node api create property key optimizations feat: support node_api_create_property_key_(latin1/utf8) Mar 7, 2026
@bartlomieju bartlomieju marked this pull request as ready for review March 8, 2026 08:12
@bartlomieju
Copy link
Copy Markdown
Member

CI Status Summary

Two issues remain:

1. Formatting

ext/napi/js_native_api.rs and tests/napi/src/strings.rs need to be run through tools/format.js.

2. Windows linker failure — unresolved externals

The test_napi cdylib fails to link on Windows with:

fatal error LNK1120: 3 unresolved externals
  - node_api_create_property_key_utf8
  - node_api_create_property_key_utf16
  - node_api_create_property_key_latin1

Root cause: On Windows, tests/napi links against a pre-built node-{arch}.lib import library bundled with the napi-build crate (v1). This .lib doesn't include the newer node_api_create_property_key_* symbols. The symbols are correctly added to the Deno binary's export .def files, but the test cdylib can't resolve them at link time because it uses napi_build::setup() which only knows about standard Node.js symbols.

Likely fix: Update tests/napi/build.rs to generate a supplementary Windows import library (or .def file) for the new symbols, so the linker can resolve them via delayed loading alongside the standard ones.


There's also a local fix for tests/integration/lsp_tests.rs (line number shift from the merge with main) that needs to be committed.

@bartlomieju bartlomieju force-pushed the copilot/support-node-api-create-property-key branch from 86847c3 to f645b32 Compare March 8, 2026 11:27
bartlomieju added a commit that referenced this pull request Mar 8, 2026
…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:
- #32559 (node_api_create_property_key_latin1/utf8)
- #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 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 2 commits March 9, 2026 18:14
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bartlomieju bartlomieju changed the title feat: support node_api_create_property_key_(latin1/utf8) feat(napi): support node_api_create_property_key_(latin1/utf8) Mar 9, 2026
bartlomieju and others added 2 commits March 9, 2026 19:00
…1,utf8}

Restores the napi_sys function definitions that match the implementations
added in this PR. Removes unimplemented symbols (node_api_create_object_with_*)
to avoid GetProcAddress failures on Windows debug builds.

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 — follows the same pattern as existing node_api_create_property_key_utf16

  • latin1 uses new_from_one_byte + Internalized
  • utf8 uses new_from_utf8 + Internalized
  • both handle NAPI_AUTO_LENGTH correctly
  • tests verify interoperability: property set with internalized key, retrieved with normal string key

Copy link
Copy Markdown
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Member

@crowlKats crowlKats left a comment

Choose a reason for hiding this comment

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

RSLGTM

Remove redundant `unsafe extern "C"` declarations for
node_api_create_property_key_{latin1,utf8,utf16} in the test NAPI
module. These symbols are already exported by the napi_sys crate via
the `generate!` macro. The raw extern declarations caused LNK2019
unresolved symbol errors on Windows, where napi_sys uses runtime
loading (libloading/GetProcAddress) rather than static linking.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bartlomieju bartlomieju changed the title feat(napi): support node_api_create_property_key_(latin1/utf8) fix(ext/node): support node_api_create_property_key_(latin1/utf8) Mar 10, 2026
@bartlomieju bartlomieju changed the title fix(ext/node): support node_api_create_property_key_(latin1/utf8) fix(ext/node): add node_api_create_property_key_(latin1/utf8) Mar 10, 2026
@bartlomieju bartlomieju merged commit 042a768 into main Mar 10, 2026
222 of 224 checks passed
@bartlomieju bartlomieju deleted the copilot/support-node-api-create-property-key branch March 10, 2026 16:23
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_property_key_(latin1/utf8/utf16)

4 participants