Skip to content

Commit 3d8e1aa

Browse files
mhdawsonMylesBorins
authored andcommittedApr 16, 2018
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: #19447 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 a6c277e commit 3d8e1aa

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
@@ -903,9 +903,9 @@ napi_value Init(napi_env env, napi_value exports) {
903903
napi_status status;
904904
napi_property_descriptor desc =
905905
{"hello", Method, 0, 0, 0, napi_default, 0};
906-
if (status != napi_ok) return nullptr;
906+
if (status != napi_ok) return NULL;
907907
status = napi_define_properties(env, exports, 1, &desc);
908-
if (status != napi_ok) return nullptr;
908+
if (status != napi_ok) return NULL;
909909
return exports;
910910
}
911911
```
@@ -917,7 +917,7 @@ napi_value Init(napi_env env, napi_value exports) {
917917
napi_value method;
918918
napi_status status;
919919
status = napi_create_function(env, "exports", Method, NULL, &method));
920-
if (status != napi_ok) return nullptr;
920+
if (status != napi_ok) return NULL;
921921
return method;
922922
}
923923
```
@@ -930,21 +930,21 @@ For example, to define a class so that new instances can be created
930930
napi_value Init(napi_env env, napi_value exports) {
931931
napi_status status;
932932
napi_property_descriptor properties[] = {
933-
{ "value", nullptr, GetValue, SetValue, 0, napi_default, 0 },
933+
{ "value", NULL, GetValue, SetValue, 0, napi_default, 0 },
934934
DECLARE_NAPI_METHOD("plusOne", PlusOne),
935935
DECLARE_NAPI_METHOD("multiply", Multiply),
936936
};
937937

938938
napi_value cons;
939939
status =
940-
napi_define_class(env, "MyObject", New, nullptr, 3, properties, &cons);
941-
if (status != napi_ok) return nullptr;
940+
napi_define_class(env, "MyObject", New, NULL, 3, properties, &cons);
941+
if (status != napi_ok) return NULL;
942942

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

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

949949
return exports;
950950
}
@@ -2362,8 +2362,8 @@ if (status != napi_ok) return status;
23622362

23632363
// Set the properties
23642364
napi_property_descriptor descriptors[] = {
2365-
{ "foo", nullptr, 0, 0, 0, fooValue, napi_default, 0 },
2366-
{ "bar", nullptr, 0, 0, 0, barValue, napi_default, 0 }
2365+
{ "foo", NULL, 0, 0, 0, fooValue, napi_default, 0 },
2366+
{ "bar", NULL, 0, 0, 0, barValue, napi_default, 0 }
23672367
}
23682368
status = napi_define_properties(env,
23692369
obj,
@@ -2874,18 +2874,18 @@ object. A sample module might look as follows:
28742874
```C
28752875
napi_value SayHello(napi_env env, napi_callback_info info) {
28762876
printf("Hello\n");
2877-
return nullptr;
2877+
return NULL;
28782878
}
28792879

28802880
napi_value Init(napi_env env, napi_value exports) {
28812881
napi_status status;
28822882

28832883
napi_value fn;
2884-
status = napi_create_function(env, nullptr, 0, SayHello, nullptr, &fn);
2885-
if (status != napi_ok) return nullptr;
2884+
status = napi_create_function(env, NULL, 0, SayHello, NULL, &fn);
2885+
if (status != napi_ok) return NULL;
28862886

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

28902890
return exports;
28912891
}
@@ -2950,7 +2950,7 @@ napi_status napi_get_new_target(napi_env env,
29502950
Returns `napi_ok` if the API succeeded.
29512951

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

29552955
### *napi_new_instance*
29562956
<!-- YAML
@@ -3032,7 +3032,7 @@ reference to the class constructor for later `instanceof` checks.
30323032
As an example:
30333033

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

0 commit comments

Comments
 (0)
Please sign in to comment.