Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 48a634e

Browse filesBrowse files
Gabriel Schulhofdanielleadams
authored andcommitted
test: rename n-api to node-api
This renames the macros used in the tests from `NAPI_*` to `NODE_API_*`. PR-URL: #37217 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Beth Griggs <bgriggs@redhat.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 3e2746f commit 48a634e
Copy full SHA for 48a634e

File tree

Expand file treeCollapse file tree

52 files changed

+1374
-1451
lines changed
Open diff view settings
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

52 files changed

+1374
-1451
lines changed
Open diff view settings
Collapse file

‎test/js-native-api/2_function_arguments/binding.c‎

Copy file name to clipboardExpand all lines: test/js-native-api/2_function_arguments/binding.c
+10-10Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,35 @@
44
static napi_value Add(napi_env env, napi_callback_info info) {
55
size_t argc = 2;
66
napi_value args[2];
7-
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
7+
NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
88

9-
NAPI_ASSERT(env, argc >= 2, "Wrong number of arguments");
9+
NODE_API_ASSERT(env, argc >= 2, "Wrong number of arguments");
1010

1111
napi_valuetype valuetype0;
12-
NAPI_CALL(env, napi_typeof(env, args[0], &valuetype0));
12+
NODE_API_CALL(env, napi_typeof(env, args[0], &valuetype0));
1313

1414
napi_valuetype valuetype1;
15-
NAPI_CALL(env, napi_typeof(env, args[1], &valuetype1));
15+
NODE_API_CALL(env, napi_typeof(env, args[1], &valuetype1));
1616

17-
NAPI_ASSERT(env, valuetype0 == napi_number && valuetype1 == napi_number,
17+
NODE_API_ASSERT(env, valuetype0 == napi_number && valuetype1 == napi_number,
1818
"Wrong argument type. Numbers expected.");
1919

2020
double value0;
21-
NAPI_CALL(env, napi_get_value_double(env, args[0], &value0));
21+
NODE_API_CALL(env, napi_get_value_double(env, args[0], &value0));
2222

2323
double value1;
24-
NAPI_CALL(env, napi_get_value_double(env, args[1], &value1));
24+
NODE_API_CALL(env, napi_get_value_double(env, args[1], &value1));
2525

2626
napi_value sum;
27-
NAPI_CALL(env, napi_create_double(env, value0 + value1, &sum));
27+
NODE_API_CALL(env, napi_create_double(env, value0 + value1, &sum));
2828

2929
return sum;
3030
}
3131

3232
EXTERN_C_START
3333
napi_value Init(napi_env env, napi_value exports) {
34-
napi_property_descriptor desc = DECLARE_NAPI_PROPERTY("add", Add);
35-
NAPI_CALL(env, napi_define_properties(env, exports, 1, &desc));
34+
napi_property_descriptor desc = DECLARE_NODE_API_PROPERTY("add", Add);
35+
NODE_API_CALL(env, napi_define_properties(env, exports, 1, &desc));
3636
return exports;
3737
}
3838
EXTERN_C_END
Collapse file

‎test/js-native-api/3_callbacks/binding.c‎

Copy file name to clipboardExpand all lines: test/js-native-api/3_callbacks/binding.c
+14-14Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,53 @@
55
static napi_value RunCallback(napi_env env, napi_callback_info info) {
66
size_t argc = 2;
77
napi_value args[2];
8-
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
8+
NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
99

10-
NAPI_ASSERT(env, argc == 1,
10+
NODE_API_ASSERT(env, argc == 1,
1111
"Wrong number of arguments. Expects a single argument.");
1212

1313
napi_valuetype valuetype0;
14-
NAPI_CALL(env, napi_typeof(env, args[0], &valuetype0));
15-
NAPI_ASSERT(env, valuetype0 == napi_function,
14+
NODE_API_CALL(env, napi_typeof(env, args[0], &valuetype0));
15+
NODE_API_ASSERT(env, valuetype0 == napi_function,
1616
"Wrong type of arguments. Expects a function as first argument.");
1717

1818
napi_valuetype valuetype1;
19-
NAPI_CALL(env, napi_typeof(env, args[1], &valuetype1));
20-
NAPI_ASSERT(env, valuetype1 == napi_undefined,
19+
NODE_API_CALL(env, napi_typeof(env, args[1], &valuetype1));
20+
NODE_API_ASSERT(env, valuetype1 == napi_undefined,
2121
"Additional arguments should be undefined.");
2222

2323
napi_value argv[1];
2424
const char* str = "hello world";
2525
size_t str_len = strlen(str);
26-
NAPI_CALL(env, napi_create_string_utf8(env, str, str_len, argv));
26+
NODE_API_CALL(env, napi_create_string_utf8(env, str, str_len, argv));
2727

2828
napi_value global;
29-
NAPI_CALL(env, napi_get_global(env, &global));
29+
NODE_API_CALL(env, napi_get_global(env, &global));
3030

3131
napi_value cb = args[0];
32-
NAPI_CALL(env, napi_call_function(env, global, cb, 1, argv, NULL));
32+
NODE_API_CALL(env, napi_call_function(env, global, cb, 1, argv, NULL));
3333

3434
return NULL;
3535
}
3636

3737
static napi_value RunCallbackWithRecv(napi_env env, napi_callback_info info) {
3838
size_t argc = 2;
3939
napi_value args[2];
40-
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
40+
NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
4141

4242
napi_value cb = args[0];
4343
napi_value recv = args[1];
44-
NAPI_CALL(env, napi_call_function(env, recv, cb, 0, NULL, NULL));
44+
NODE_API_CALL(env, napi_call_function(env, recv, cb, 0, NULL, NULL));
4545
return NULL;
4646
}
4747

4848
EXTERN_C_START
4949
napi_value Init(napi_env env, napi_value exports) {
5050
napi_property_descriptor desc[2] = {
51-
DECLARE_NAPI_PROPERTY("RunCallback", RunCallback),
52-
DECLARE_NAPI_PROPERTY("RunCallbackWithRecv", RunCallbackWithRecv),
51+
DECLARE_NODE_API_PROPERTY("RunCallback", RunCallback),
52+
DECLARE_NODE_API_PROPERTY("RunCallbackWithRecv", RunCallbackWithRecv),
5353
};
54-
NAPI_CALL(env, napi_define_properties(env, exports, 2, desc));
54+
NODE_API_CALL(env, napi_define_properties(env, exports, 2, desc));
5555
return exports;
5656
}
5757
EXTERN_C_END
Collapse file

‎test/js-native-api/4_object_factory/binding.c‎

Copy file name to clipboardExpand all lines: test/js-native-api/4_object_factory/binding.c
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
static napi_value CreateObject(napi_env env, napi_callback_info info) {
55
size_t argc = 1;
66
napi_value args[1];
7-
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
7+
NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
88

99
napi_value obj;
10-
NAPI_CALL(env, napi_create_object(env, &obj));
10+
NODE_API_CALL(env, napi_create_object(env, &obj));
1111

12-
NAPI_CALL(env, napi_set_named_property(env, obj, "msg", args[0]));
12+
NODE_API_CALL(env, napi_set_named_property(env, obj, "msg", args[0]));
1313

1414
return obj;
1515
}
1616

1717
EXTERN_C_START
1818
napi_value Init(napi_env env, napi_value exports) {
19-
NAPI_CALL(env,
19+
NODE_API_CALL(env,
2020
napi_create_function(env, "exports", -1, CreateObject, NULL, &exports));
2121
return exports;
2222
}
Collapse file

‎test/js-native-api/5_function_factory/binding.c‎

Copy file name to clipboardExpand all lines: test/js-native-api/5_function_factory/binding.c
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33

44
static napi_value MyFunction(napi_env env, napi_callback_info info) {
55
napi_value str;
6-
NAPI_CALL(env, napi_create_string_utf8(env, "hello world", -1, &str));
6+
NODE_API_CALL(env, napi_create_string_utf8(env, "hello world", -1, &str));
77
return str;
88
}
99

1010
static napi_value CreateFunction(napi_env env, napi_callback_info info) {
1111
napi_value fn;
12-
NAPI_CALL(env,
12+
NODE_API_CALL(env,
1313
napi_create_function(env, "theFunction", -1, MyFunction, NULL, &fn));
1414
return fn;
1515
}
1616

1717
EXTERN_C_START
1818
napi_value Init(napi_env env, napi_value exports) {
19-
NAPI_CALL(env,
19+
NODE_API_CALL(env,
2020
napi_create_function(env, "exports", -1, CreateFunction, NULL, &exports));
2121
return exports;
2222
}
Collapse file

‎test/js-native-api/6_object_wrap/myobject.cc‎

Copy file name to clipboardExpand all lines: test/js-native-api/6_object_wrap/myobject.cc
+30-32Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,50 @@ void MyObject::Init(napi_env env, napi_value exports) {
1919
{ "value", nullptr, nullptr, GetValue, SetValue, 0, napi_default, 0 },
2020
{ "valueReadonly", nullptr, nullptr, GetValue, nullptr, 0, napi_default,
2121
0 },
22-
DECLARE_NAPI_PROPERTY("plusOne", PlusOne),
23-
DECLARE_NAPI_PROPERTY("multiply", Multiply),
22+
DECLARE_NODE_API_PROPERTY("plusOne", PlusOne),
23+
DECLARE_NODE_API_PROPERTY("multiply", Multiply),
2424
};
2525

2626
napi_value cons;
27-
NAPI_CALL_RETURN_VOID(env, napi_define_class(
27+
NODE_API_CALL_RETURN_VOID(env, napi_define_class(
2828
env, "MyObject", -1, New, nullptr,
2929
sizeof(properties) / sizeof(napi_property_descriptor),
3030
properties, &cons));
3131

32-
NAPI_CALL_RETURN_VOID(env, napi_create_reference(env, cons, 1, &constructor));
32+
NODE_API_CALL_RETURN_VOID(env,
33+
napi_create_reference(env, cons, 1, &constructor));
3334

34-
NAPI_CALL_RETURN_VOID(env,
35+
NODE_API_CALL_RETURN_VOID(env,
3536
napi_set_named_property(env, exports, "MyObject", cons));
3637
}
3738

3839
napi_value MyObject::New(napi_env env, napi_callback_info info) {
3940
napi_value new_target;
40-
NAPI_CALL(env, napi_get_new_target(env, info, &new_target));
41+
NODE_API_CALL(env, napi_get_new_target(env, info, &new_target));
4142
bool is_constructor = (new_target != nullptr);
4243

4344
size_t argc = 1;
4445
napi_value args[1];
4546
napi_value _this;
46-
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &_this, nullptr));
47+
NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, &_this, nullptr));
4748

4849
if (is_constructor) {
4950
// Invoked as constructor: `new MyObject(...)`
5051
double value = 0;
5152

5253
napi_valuetype valuetype;
53-
NAPI_CALL(env, napi_typeof(env, args[0], &valuetype));
54+
NODE_API_CALL(env, napi_typeof(env, args[0], &valuetype));
5455

5556
if (valuetype != napi_undefined) {
56-
NAPI_CALL(env, napi_get_value_double(env, args[0], &value));
57+
NODE_API_CALL(env, napi_get_value_double(env, args[0], &value));
5758
}
5859

5960
MyObject* obj = new MyObject(value);
6061

6162
obj->env_ = env;
62-
NAPI_CALL(env, napi_wrap(env,
63-
_this,
64-
obj,
65-
MyObject::Destructor,
66-
nullptr, // finalize_hint
67-
&obj->wrapper_));
63+
NODE_API_CALL(env,
64+
napi_wrap(env, _this, obj, MyObject::Destructor,
65+
nullptr /* finalize_hint */, &obj->wrapper_));
6866

6967
return _this;
7068
}
@@ -74,24 +72,24 @@ napi_value MyObject::New(napi_env env, napi_callback_info info) {
7472
napi_value argv[1] = {args[0]};
7573

7674
napi_value cons;
77-
NAPI_CALL(env, napi_get_reference_value(env, constructor, &cons));
75+
NODE_API_CALL(env, napi_get_reference_value(env, constructor, &cons));
7876

7977
napi_value instance;
80-
NAPI_CALL(env, napi_new_instance(env, cons, argc, argv, &instance));
78+
NODE_API_CALL(env, napi_new_instance(env, cons, argc, argv, &instance));
8179

8280
return instance;
8381
}
8482

8583
napi_value MyObject::GetValue(napi_env env, napi_callback_info info) {
8684
napi_value _this;
87-
NAPI_CALL(env,
85+
NODE_API_CALL(env,
8886
napi_get_cb_info(env, info, nullptr, nullptr, &_this, nullptr));
8987

9088
MyObject* obj;
91-
NAPI_CALL(env, napi_unwrap(env, _this, reinterpret_cast<void**>(&obj)));
89+
NODE_API_CALL(env, napi_unwrap(env, _this, reinterpret_cast<void**>(&obj)));
9290

9391
napi_value num;
94-
NAPI_CALL(env, napi_create_double(env, obj->value_, &num));
92+
NODE_API_CALL(env, napi_create_double(env, obj->value_, &num));
9593

9694
return num;
9795
}
@@ -100,28 +98,28 @@ napi_value MyObject::SetValue(napi_env env, napi_callback_info info) {
10098
size_t argc = 1;
10199
napi_value args[1];
102100
napi_value _this;
103-
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &_this, nullptr));
101+
NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, &_this, nullptr));
104102

105103
MyObject* obj;
106-
NAPI_CALL(env, napi_unwrap(env, _this, reinterpret_cast<void**>(&obj)));
104+
NODE_API_CALL(env, napi_unwrap(env, _this, reinterpret_cast<void**>(&obj)));
107105

108-
NAPI_CALL(env, napi_get_value_double(env, args[0], &obj->value_));
106+
NODE_API_CALL(env, napi_get_value_double(env, args[0], &obj->value_));
109107

110108
return nullptr;
111109
}
112110

113111
napi_value MyObject::PlusOne(napi_env env, napi_callback_info info) {
114112
napi_value _this;
115-
NAPI_CALL(env,
113+
NODE_API_CALL(env,
116114
napi_get_cb_info(env, info, nullptr, nullptr, &_this, nullptr));
117115

118116
MyObject* obj;
119-
NAPI_CALL(env, napi_unwrap(env, _this, reinterpret_cast<void**>(&obj)));
117+
NODE_API_CALL(env, napi_unwrap(env, _this, reinterpret_cast<void**>(&obj)));
120118

121119
obj->value_ += 1;
122120

123121
napi_value num;
124-
NAPI_CALL(env, napi_create_double(env, obj->value_, &num));
122+
NODE_API_CALL(env, napi_create_double(env, obj->value_, &num));
125123

126124
return num;
127125
}
@@ -130,25 +128,25 @@ napi_value MyObject::Multiply(napi_env env, napi_callback_info info) {
130128
size_t argc = 1;
131129
napi_value args[1];
132130
napi_value _this;
133-
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &_this, nullptr));
131+
NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, &_this, nullptr));
134132

135133
double multiple = 1;
136134
if (argc >= 1) {
137-
NAPI_CALL(env, napi_get_value_double(env, args[0], &multiple));
135+
NODE_API_CALL(env, napi_get_value_double(env, args[0], &multiple));
138136
}
139137

140138
MyObject* obj;
141-
NAPI_CALL(env, napi_unwrap(env, _this, reinterpret_cast<void**>(&obj)));
139+
NODE_API_CALL(env, napi_unwrap(env, _this, reinterpret_cast<void**>(&obj)));
142140

143141
napi_value cons;
144-
NAPI_CALL(env, napi_get_reference_value(env, constructor, &cons));
142+
NODE_API_CALL(env, napi_get_reference_value(env, constructor, &cons));
145143

146144
const int kArgCount = 1;
147145
napi_value argv[kArgCount];
148-
NAPI_CALL(env, napi_create_double(env, obj->value_ * multiple, argv));
146+
NODE_API_CALL(env, napi_create_double(env, obj->value_ * multiple, argv));
149147

150148
napi_value instance;
151-
NAPI_CALL(env, napi_new_instance(env, cons, kArgCount, argv, &instance));
149+
NODE_API_CALL(env, napi_new_instance(env, cons, kArgCount, argv, &instance));
152150

153151
return instance;
154152
}
Collapse file

‎test/js-native-api/7_factory_wrap/binding.cc‎

Copy file name to clipboardExpand all lines: test/js-native-api/7_factory_wrap/binding.cc
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,25 @@
55
napi_value CreateObject(napi_env env, napi_callback_info info) {
66
size_t argc = 1;
77
napi_value args[1];
8-
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr));
8+
NODE_API_CALL(env,
9+
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr));
910

1011
napi_value instance;
11-
NAPI_CALL(env, MyObject::NewInstance(env, args[0], &instance));
12+
NODE_API_CALL(env, MyObject::NewInstance(env, args[0], &instance));
1213

1314
return instance;
1415
}
1516

1617
EXTERN_C_START
1718
napi_value Init(napi_env env, napi_value exports) {
18-
NAPI_CALL(env, MyObject::Init(env));
19+
NODE_API_CALL(env, MyObject::Init(env));
1920

2021
napi_property_descriptor descriptors[] = {
21-
DECLARE_NAPI_GETTER("finalizeCount", MyObject::GetFinalizeCount),
22-
DECLARE_NAPI_PROPERTY("createObject", CreateObject),
22+
DECLARE_NODE_API_GETTER("finalizeCount", MyObject::GetFinalizeCount),
23+
DECLARE_NODE_API_PROPERTY("createObject", CreateObject),
2324
};
2425

25-
NAPI_CALL(env, napi_define_properties(
26+
NODE_API_CALL(env, napi_define_properties(
2627
env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors));
2728

2829
return exports;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.