Skip to content

Commit cefce1a

Browse files
committed
fix: allow const vectors with Object::New overload utilizing node_api_create_object_with_properties
1 parent 1c057d0 commit cefce1a

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

doc/object.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ Creates a new `Napi::Object` value.
7575
Napi::Object Napi::Object::New(
7676
napi_env env,
7777
napi_value prototypeOrNull,
78-
std::vector<napi_value>& propertyNames,
79-
std::vector<napi_value>& propertyValues);
78+
const std::vector<napi_value>& propertyNames,
79+
const std::vector<napi_value>& propertyValues);
8080
```
8181
- `[in] env`: The `napi_env` environment in which to construct the `Napi::Value`
8282
object.

napi-inl.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,22 +1644,22 @@ inline Object Object::New(napi_env env) {
16441644
#ifdef NODE_API_EXPERIMENTAL_HAS_CREATE_OBJECT_WITH_PROPERTIES
16451645
inline Object Object::New(napi_env env,
16461646
napi_value prototypeOrNull,
1647-
std::vector<napi_value>& propertyNames,
1648-
std::vector<napi_value>& propertyValues) {
1647+
const std::vector<napi_value>& propertyNames,
1648+
const std::vector<napi_value>& propertyValues) {
16491649
if (propertyNames.size() != propertyValues.size()) {
16501650
NAPI_THROW(
16511651
Napi::Error::New(env, "Mismatch in size of property names and values"),
16521652
Object());
16531653
}
16541654

16551655
napi_value value;
1656-
napi_status status =
1657-
node_api_create_object_with_properties(env,
1658-
prototypeOrNull,
1659-
propertyNames.data(),
1660-
propertyValues.data(),
1661-
propertyNames.size(),
1662-
&value);
1656+
napi_status status = node_api_create_object_with_properties(
1657+
env,
1658+
prototypeOrNull,
1659+
const_cast<napi_value*>(propertyNames.data()),
1660+
const_cast<napi_value*>(propertyValues.data()),
1661+
propertyNames.size(),
1662+
&value);
16631663

16641664
NAPI_THROW_IF_FAILED(env, status, Object());
16651665
return Object(env, value);

napi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -955,8 +955,8 @@ class Object : public TypeTaggable {
955955
static Object New(
956956
napi_env env, ///< Node-API environment
957957
napi_value prototypeOrNull, ///< Prototype (Object) or null / empty Value
958-
std::vector<napi_value>& propertyNames, ///< Property names
959-
std::vector<napi_value>& propertyValues ///< Property values
958+
const std::vector<napi_value>& propertyNames, ///< Property names
959+
const std::vector<napi_value>& propertyValues ///< Property values
960960
);
961961
#endif
962962

0 commit comments

Comments
 (0)