Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions doc/object.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ Creates a new `Napi::Object` value.
Napi::Object Napi::Object::New(
napi_env env,
napi_value prototypeOrNull,
std::vector<napi_value>& propertyNames,
std::vector<napi_value>& propertyValues);
const std::vector<napi_value>& propertyNames,
const std::vector<napi_value>& propertyValues);
```
- `[in] env`: The `napi_env` environment in which to construct the `Napi::Value`
object.
Expand Down
18 changes: 9 additions & 9 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1644,22 +1644,22 @@ inline Object Object::New(napi_env env) {
#ifdef NODE_API_EXPERIMENTAL_HAS_CREATE_OBJECT_WITH_PROPERTIES
inline Object Object::New(napi_env env,
napi_value prototypeOrNull,
std::vector<napi_value>& propertyNames,
std::vector<napi_value>& propertyValues) {
const std::vector<napi_value>& propertyNames,
const std::vector<napi_value>& propertyValues) {
if (propertyNames.size() != propertyValues.size()) {
NAPI_THROW(
Napi::Error::New(env, "Mismatch in size of property names and values"),
Object());
}

napi_value value;
napi_status status =
node_api_create_object_with_properties(env,
prototypeOrNull,
propertyNames.data(),
propertyValues.data(),
propertyNames.size(),
&value);
napi_status status = node_api_create_object_with_properties(

@legendecas legendecas Aug 28, 2026

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.

Could we add a TODO to remove the const_cast when nodejs/node#65621 is fully backported?

env,
prototypeOrNull,
const_cast<napi_value*>(propertyNames.data()),
const_cast<napi_value*>(propertyValues.data()),
propertyNames.size(),
&value);

NAPI_THROW_IF_FAILED(env, status, Object());
return Object(env, value);
Expand Down
4 changes: 2 additions & 2 deletions napi.h
Original file line number Diff line number Diff line change
Expand Up @@ -955,8 +955,8 @@ class Object : public TypeTaggable {
static Object New(
napi_env env, ///< Node-API environment
napi_value prototypeOrNull, ///< Prototype (Object) or null / empty Value
std::vector<napi_value>& propertyNames, ///< Property names
std::vector<napi_value>& propertyValues ///< Property values
const std::vector<napi_value>& propertyNames, ///< Property names
const std::vector<napi_value>& propertyValues ///< Property values
);
#endif

Expand Down
Loading