Skip to content

Commit 79ecc2c

Browse files
mhdawsonMylesBorins
authored andcommitted
doc: updates examples to use NULL
Examples in the N-API doc used a mix of nullptr and NULL. We should be consistent and because N-API is a 'C' API I believe using NULL is better. This will avoid any potential confusion as to whether N-API can be used with plain C. Backport-PR-URL: #19265 PR-URL: #18008 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
1 parent ad8c079 commit 79ecc2c

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

doc/api/n-api.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -905,9 +905,9 @@ napi_value Init(napi_env env, napi_value exports) {
905905
napi_status status;
906906
napi_property_descriptor desc =
907907
{"hello", Method, 0, 0, 0, napi_default, 0};
908-
if (status != napi_ok) return nullptr;
908+
if (status != napi_ok) return NULL;
909909
status = napi_define_properties(env, exports, 1, &desc);
910-
if (status != napi_ok) return nullptr;
910+
if (status != napi_ok) return NULL;
911911
return exports;
912912
}
913913
```
@@ -919,7 +919,7 @@ napi_value Init(napi_env env, napi_value exports) {
919919
napi_value method;
920920
napi_status status;
921921
status = napi_create_function(env, "exports", Method, NULL, &method));
922-
if (status != napi_ok) return nullptr;
922+
if (status != napi_ok) return NULL;
923923
return method;
924924
}
925925
```
@@ -932,21 +932,21 @@ For example, to define a class so that new instances can be created
932932
napi_value Init(napi_env env, napi_value exports) {
933933
napi_status status;
934934
napi_property_descriptor properties[] = {
935-
{ "value", nullptr, GetValue, SetValue, 0, napi_default, 0 },
935+
{ "value", NULL, GetValue, SetValue, 0, napi_default, 0 },
936936
DECLARE_NAPI_METHOD("plusOne", PlusOne),
937937
DECLARE_NAPI_METHOD("multiply", Multiply),
938938
};
939939

940940
napi_value cons;
941941
status =
942-
napi_define_class(env, "MyObject", New, nullptr, 3, properties, &cons);
943-
if (status != napi_ok) return nullptr;
942+
napi_define_class(env, "MyObject", New, NULL, 3, properties, &cons);
943+
if (status != napi_ok) return NULL;
944944

945945
status = napi_create_reference(env, cons, 1, &constructor);
946-
if (status != napi_ok) return nullptr;
946+
if (status != napi_ok) return NULL;
947947

948948
status = napi_set_named_property(env, exports, "MyObject", cons);
949-
if (status != napi_ok) return nullptr;
949+
if (status != napi_ok) return NULL;
950950

951951
return exports;
952952
}
@@ -2364,8 +2364,8 @@ if (status != napi_ok) return status;
23642364

23652365
// Set the properties
23662366
napi_property_descriptor descriptors[] = {
2367-
{ "foo", nullptr, 0, 0, 0, fooValue, napi_default, 0 },
2368-
{ "bar", nullptr, 0, 0, 0, barValue, napi_default, 0 }
2367+
{ "foo", NULL, 0, 0, 0, fooValue, napi_default, 0 },
2368+
{ "bar", NULL, 0, 0, 0, barValue, napi_default, 0 }
23692369
}
23702370
status = napi_define_properties(env,
23712371
obj,
@@ -2876,18 +2876,18 @@ object. A sample module might look as follows:
28762876
```C
28772877
napi_value SayHello(napi_env env, napi_callback_info info) {
28782878
printf("Hello\n");
2879-
return nullptr;
2879+
return NULL;
28802880
}
28812881

28822882
napi_value Init(napi_env env, napi_value exports) {
28832883
napi_status status;
28842884

28852885
napi_value fn;
2886-
status = napi_create_function(env, nullptr, 0, SayHello, nullptr, &fn);
2887-
if (status != napi_ok) return nullptr;
2886+
status = napi_create_function(env, NULL, 0, SayHello, nullptr, &fn);
2887+
if (status != napi_ok) return NULL;
28882888

28892889
status = napi_set_named_property(env, exports, "sayHello", fn);
2890-
if (status != napi_ok) return nullptr;
2890+
if (status != napi_ok) return NULL;
28912891

28922892
return exports;
28932893
}
@@ -2952,7 +2952,7 @@ napi_status napi_get_new_target(napi_env env,
29522952
Returns `napi_ok` if the API succeeded.
29532953

29542954
This API returns the `new.target` of the constructor call. If the current
2955-
callback is not a constructor call, the result is `nullptr`.
2955+
callback is not a constructor call, the result is `NULL`.
29562956

29572957
### *napi_new_instance*
29582958
<!-- YAML
@@ -3034,7 +3034,7 @@ reference to the class constructor for later `instanceof` checks.
30343034
As an example:
30353035

30363036
```C
3037-
napi_value MyClass_constructor = nullptr;
3037+
napi_value MyClass_constructor = NULL;
30383038
status = napi_get_reference_value(env, MyClass::es_constructor, &MyClass_constructor);
30393039
assert(napi_ok == status);
30403040
bool is_instance = false;

0 commit comments

Comments
 (0)