Skip to content

Commit 1742953

Browse files
doc: add napi_create_object_with_properties API
1 parent cdf5313 commit 1742953

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

doc/api/n-api.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2637,6 +2637,41 @@ It is the equivalent of doing `new Object()` in JavaScript.
26372637
The JavaScript `Object` type is described in [Section object type][] of the
26382638
ECMAScript Language Specification.
26392639

2640+
#### `napi_create_object_with_properties`
2641+
2642+
<!-- YAML
2643+
added: REPLACEME
2644+
napiVersion: 8
2645+
-->
2646+
2647+
```c
2648+
napi_status napi_create_object_with_properties(napi_env env,
2649+
napi_value prototype_or_null,
2650+
const napi_value* property_names,
2651+
const napi_value* property_values,
2652+
size_t property_count,
2653+
napi_value* result)
2654+
```
2655+
2656+
* `[in] env`: The environment that the API is invoked under.
2657+
* `[in] prototype_or_null`: The prototype object for the new object, or `null`
2658+
for no prototype.
2659+
* `[in] property_names`: Array of `napi_value` representing the property names.
2660+
* `[in] property_values`: Array of `napi_value` representing the property values.
2661+
* `[in] property_count`: Number of properties in the arrays.
2662+
* `[out] result`: A `napi_value` representing a JavaScript `Object`.
2663+
2664+
Returns `napi_ok` if the API succeeded.
2665+
2666+
This API creates a JavaScript `Object` with the specified prototype and
2667+
properties. This is more efficient than calling `napi_create_object` followed
2668+
by multiple `napi_set_property` calls, as it can create the object with all
2669+
properties atomically, avoiding potential V8 map transitions.
2670+
2671+
The arrays `property_names` and `property_values` must have the same length
2672+
specified by `property_count`. The properties are added to the object in the
2673+
order they appear in the arrays.
2674+
26402675
#### `napi_create_symbol`
26412676

26422677
<!-- YAML

0 commit comments

Comments
 (0)