Skip to content

feat(ext/napi): add node_api_create_object_with_named_properties#32906

Merged
bartlomieju merged 1 commit intomainfrom
feat/napi-create-object-named-properties
Mar 24, 2026
Merged

feat(ext/napi): add node_api_create_object_with_named_properties#32906
bartlomieju merged 1 commit intomainfrom
feat/napi-create-object-named-properties

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

Summary

Implement node_api_create_object_with_named_properties — a convenience
function that creates a JavaScript object with properties specified by UTF-8
C string names and napi_value values.

This is the "named" counterpart to the existing
node_api_create_object_with_properties (which takes napi_value keys),
following the same pattern as napi_set_named_property vs napi_set_property.

API signature

napi_status node_api_create_object_with_named_properties(
    napi_env env,
    napi_value* result,
    size_t property_count,
    const char** property_names,   // UTF-8 C strings
    const napi_value* property_values);

Changes

  • ext/napi/js_native_api.rs — Implementation using internalized V8
    strings for property names (enables deduplication and faster lookups)
  • Symbol exports — Registered in symbol_exports.json and all three
    platform .def files
  • libs/napi_sys/src/functions.rs — FFI declaration
  • tests/napi/ — Native test functions and JS integration tests covering
    both normal and empty property cases

Closes #32595

Test plan

  • cargo test --test integration -- napi passes (both napi_tests and
    finalizer test)
  • New JS tests verify property creation and retrieval
  • Empty property count case tested

🤖 Generated with Claude Code

Implement `node_api_create_object_with_named_properties` which creates a
JavaScript object with properties specified by C string names (UTF-8)
and napi_value values. This is the "named" counterpart to the existing
`node_api_create_object_with_properties` which takes napi_value keys.

The function creates internalized V8 strings for the property names
(enabling deduplication and faster property lookups) and constructs the
object using `v8::Object::with_prototype_and_properties`.

- ext/napi/js_native_api.rs — Implementation
- Symbol exports — Registered in symbol_exports.json and all three
  platform .def files (Linux, macOS, Windows)
- libs/napi_sys/src/functions.rs — FFI declaration
- tests/napi/ — Native test functions and JS integration tests

Closes #32595

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

This comment was marked as off-topic.

@bartlomieju bartlomieju merged commit 9839137 into main Mar 24, 2026
116 checks passed
@bartlomieju bartlomieju deleted the feat/napi-create-object-named-properties branch March 24, 2026 07:29
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.

Add node_api_create_object_with_named_properties to ext/napi/

2 participants