Skip to content

Commit 29959e7

Browse files
node-api: convert nullptr to null
1 parent 7a51c98 commit 29959e7

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

doc/api/n-api.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,7 +2644,7 @@ added: REPLACEME
26442644
napiVersion: 8
26452645
-->
26462646

2647-
```c
2647+
```cpp
26482648
napi_status napi_create_object_with_properties(napi_env env,
26492649
napi_value prototype_or_null,
26502650
const napi_value* property_names,
@@ -2654,8 +2654,9 @@ napi_status napi_create_object_with_properties(napi_env env,
26542654
```
26552655

26562656
* `[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.
2657+
* `[in] prototype_or_null`: The prototype object for the new object. Can be a
2658+
`napi_value` representing a JavaScript object to use as the prototype, a
2659+
`napi_value` representing JavaScript `null`, or a `nullptr` that will be converted to `null`.
26592660
* `[in] property_names`: Array of `napi_value` representing the property names.
26602661
* `[in] property_values`: Array of `napi_value` representing the property values.
26612662
* `[in] property_count`: Number of properties in the arrays.

src/js_native_api_v8.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,8 +1606,12 @@ napi_create_object_with_properties(napi_env env,
16061606
CHECK_ARG(env, property_values);
16071607
}
16081608

1609-
v8::Local<v8::Value> v8_prototype_or_null =
1610-
v8impl::V8LocalValueFromJsValue(prototype_or_null);
1609+
v8::Local<v8::Value> v8_prototype_or_null;
1610+
if (prototype_or_null == nullptr) {
1611+
v8_prototype_or_null = v8::Null(env->isolate);
1612+
} else {
1613+
v8_prototype_or_null = v8impl::V8LocalValueFromJsValue(prototype_or_null);
1614+
}
16111615

16121616
v8::LocalVector<v8::Name> v8_names(env->isolate, property_count);
16131617
v8::LocalVector<v8::Value> v8_values(env->isolate, property_count);

0 commit comments

Comments
 (0)