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 c93df0c

Browse filesBrowse files
Octavian Soldeatargos
authored andcommitted
n-api: refactoring napi_create_function testing
This is a refactoring of #26998 following #28505. The functions `add_last_status()` and `add_returned_status()` are now reused, see also #28848. PR-URL: #28894 Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 7c80963 commit c93df0c
Copy full SHA for c93df0c

File tree

Expand file treeCollapse file tree

3 files changed

+42
-69
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+42
-69
lines changed
Open diff view settings
Collapse file

‎test/js-native-api/test_function/binding.gyp‎

Copy file name to clipboardExpand all lines: test/js-native-api/test_function/binding.gyp
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{
44
"target_name": "test_function",
55
"sources": [
6+
"../common.c",
67
"../entry_point.c",
78
"test_function.c"
89
]
Collapse file

‎test/js-native-api/test_function/test.js‎

Copy file name to clipboardExpand all lines: test/js-native-api/test_function/test.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ tracked_function = null;
3737
global.gc();
3838

3939
assert.deepStrictEqual(test_function.TestCreateFunctionParameters(), {
40-
envIsNull: 'pass',
41-
nameIsNull: 'pass',
42-
cbIsNull: 'pass',
43-
resultIsNull: 'pass'
40+
envIsNull: 'Invalid argument',
41+
nameIsNull: 'napi_ok',
42+
cbIsNull: 'Invalid argument',
43+
resultIsNull: 'Invalid argument'
4444
});
Collapse file

‎test/js-native-api/test_function/test_function.c‎

Copy file name to clipboardExpand all lines: test/js-native-api/test_function/test_function.c
+37-65Lines changed: 37 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,79 +3,51 @@
33

44
static napi_value TestCreateFunctionParameters(napi_env env,
55
napi_callback_info info) {
6-
napi_status ret[4];
7-
napi_value result, return_value, prop_value;
6+
napi_status status;
7+
napi_value result, return_value;
88

9+
NAPI_CALL(env, napi_create_object(env, &return_value));
910

10-
ret[0] = napi_create_function(NULL,
11+
status = napi_create_function(NULL,
1112
"TrackedFunction",
1213
NAPI_AUTO_LENGTH,
1314
TestCreateFunctionParameters,
1415
NULL,
1516
&result);
1617

17-
ret[1] = napi_create_function(env,
18-
NULL,
19-
NAPI_AUTO_LENGTH,
20-
TestCreateFunctionParameters,
21-
NULL,
22-
&result);
23-
24-
ret[2] = napi_create_function(env,
25-
"TrackedFunction",
26-
NAPI_AUTO_LENGTH,
27-
NULL,
28-
NULL,
29-
&result);
30-
31-
ret[3] = napi_create_function(env,
32-
"TrackedFunction",
33-
NAPI_AUTO_LENGTH,
34-
TestCreateFunctionParameters,
35-
NULL,
36-
NULL);
37-
38-
NAPI_CALL(env, napi_create_object(env, &return_value));
39-
40-
NAPI_CALL(env, napi_create_string_utf8(env,
41-
(ret[0] == napi_invalid_arg ?
42-
"pass" : "fail"),
43-
NAPI_AUTO_LENGTH,
44-
&prop_value));
45-
NAPI_CALL(env, napi_set_named_property(env,
46-
return_value,
47-
"envIsNull",
48-
prop_value));
49-
50-
NAPI_CALL(env, napi_create_string_utf8(env,
51-
(ret[1] == napi_ok ?
52-
"pass" : "fail"),
53-
NAPI_AUTO_LENGTH,
54-
&prop_value));
55-
NAPI_CALL(env, napi_set_named_property(env,
56-
return_value,
57-
"nameIsNull",
58-
prop_value));
59-
60-
NAPI_CALL(env, napi_create_string_utf8(env,
61-
(ret[2] == napi_invalid_arg ?
62-
"pass" : "fail"),
63-
NAPI_AUTO_LENGTH,
64-
&prop_value));
65-
NAPI_CALL(env, napi_set_named_property(env,
66-
return_value,
67-
"cbIsNull",
68-
prop_value));
69-
70-
NAPI_CALL(env, napi_create_string_utf8(env,
71-
(ret[3] == napi_invalid_arg ?
72-
"pass" : "fail"),
73-
NAPI_AUTO_LENGTH,
74-
&prop_value));
75-
NAPI_CALL(env, napi_set_named_property(env,
76-
return_value,
77-
"resultIsNull",
78-
prop_value));
18+
add_returned_status(env,
19+
"envIsNull",
20+
return_value,
21+
"Invalid argument",
22+
napi_invalid_arg,
23+
status);
24+
25+
napi_create_function(env,
26+
NULL,
27+
NAPI_AUTO_LENGTH,
28+
TestCreateFunctionParameters,
29+
NULL,
30+
&result);
31+
32+
add_last_status(env, "nameIsNull", return_value);
33+
34+
napi_create_function(env,
35+
"TrackedFunction",
36+
NAPI_AUTO_LENGTH,
37+
NULL,
38+
NULL,
39+
&result);
40+
41+
add_last_status(env, "cbIsNull", return_value);
42+
43+
napi_create_function(env,
44+
"TrackedFunction",
45+
NAPI_AUTO_LENGTH,
46+
TestCreateFunctionParameters,
47+
NULL,
48+
NULL);
49+
50+
add_last_status(env, "resultIsNull", return_value);
7951

8052
return return_value;
8153
}

0 commit comments

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