Skip to content
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
doc: add napi_create_object_with_properties API
  • Loading branch information
miguelmarcondesf committed Sep 20, 2025
commit 1742953a222d2ecc0cca31cf56aa80403cb56924
35 changes: 35 additions & 0 deletions doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2637,6 +2637,41 @@ It is the equivalent of doing `new Object()` in JavaScript.
The JavaScript `Object` type is described in [Section object type][] of the
ECMAScript Language Specification.

#### `napi_create_object_with_properties`

<!-- YAML
added: REPLACEME
napiVersion: 8
-->

Comment thread
miguelmarcondesf marked this conversation as resolved.
```c
napi_status napi_create_object_with_properties(napi_env env,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@vmoroz mentioned that the new name convention is node_api_. Given that this is a new api, this should also follow the new name convention.

@vmoroz is volunteered to submit a PR to fix this.

napi_value prototype_or_null,
const napi_value* property_names,
const napi_value* property_values,
size_t property_count,
napi_value* result)
```

* `[in] env`: The environment that the API is invoked under.
* `[in] prototype_or_null`: The prototype object for the new object, or `null`
for no prototype.
Comment thread
miguelmarcondesf marked this conversation as resolved.
Outdated
* `[in] property_names`: Array of `napi_value` representing the property names.
* `[in] property_values`: Array of `napi_value` representing the property values.
* `[in] property_count`: Number of properties in the arrays.
* `[out] result`: A `napi_value` representing a JavaScript `Object`.

Returns `napi_ok` if the API succeeded.

This API creates a JavaScript `Object` with the specified prototype and
properties. This is more efficient than calling `napi_create_object` followed
by multiple `napi_set_property` calls, as it can create the object with all
properties atomically, avoiding potential V8 map transitions.

The arrays `property_names` and `property_values` must have the same length
specified by `property_count`. The properties are added to the object in the
order they appear in the arrays.

#### `napi_create_symbol`

<!-- YAML
Expand Down
Loading