Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

n-api: refactoring napi_create_function testing #28894

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/js-native-api/test_function/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{
"target_name": "test_function",
"sources": [
"../common.c",
"../entry_point.c",
"test_function.c"
]
Expand Down
8 changes: 4 additions & 4 deletions test/js-native-api/test_function/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ tracked_function = null;
global.gc();

assert.deepStrictEqual(test_function.TestCreateFunctionParameters(), {
envIsNull: 'pass',
nameIsNull: 'pass',
cbIsNull: 'pass',
resultIsNull: 'pass'
envIsNull: 'Invalid argument',
nameIsNull: 'napi_ok',
cbIsNull: 'Invalid argument',
resultIsNull: 'Invalid argument'
});
102 changes: 37 additions & 65 deletions test/js-native-api/test_function/test_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,79 +3,51 @@

static napi_value TestCreateFunctionParameters(napi_env env,
napi_callback_info info) {
napi_status ret[4];
napi_value result, return_value, prop_value;
napi_status status;
napi_value result, return_value;

NAPI_CALL(env, napi_create_object(env, &return_value));

ret[0] = napi_create_function(NULL,
status = napi_create_function(NULL,
"TrackedFunction",
NAPI_AUTO_LENGTH,
TestCreateFunctionParameters,
NULL,
&result);

ret[1] = napi_create_function(env,
NULL,
NAPI_AUTO_LENGTH,
TestCreateFunctionParameters,
NULL,
&result);

ret[2] = napi_create_function(env,
"TrackedFunction",
NAPI_AUTO_LENGTH,
NULL,
NULL,
&result);

ret[3] = napi_create_function(env,
"TrackedFunction",
NAPI_AUTO_LENGTH,
TestCreateFunctionParameters,
NULL,
NULL);

NAPI_CALL(env, napi_create_object(env, &return_value));

NAPI_CALL(env, napi_create_string_utf8(env,
(ret[0] == napi_invalid_arg ?
"pass" : "fail"),
NAPI_AUTO_LENGTH,
&prop_value));
NAPI_CALL(env, napi_set_named_property(env,
return_value,
"envIsNull",
prop_value));

NAPI_CALL(env, napi_create_string_utf8(env,
(ret[1] == napi_ok ?
"pass" : "fail"),
NAPI_AUTO_LENGTH,
&prop_value));
NAPI_CALL(env, napi_set_named_property(env,
return_value,
"nameIsNull",
prop_value));

NAPI_CALL(env, napi_create_string_utf8(env,
(ret[2] == napi_invalid_arg ?
"pass" : "fail"),
NAPI_AUTO_LENGTH,
&prop_value));
NAPI_CALL(env, napi_set_named_property(env,
return_value,
"cbIsNull",
prop_value));

NAPI_CALL(env, napi_create_string_utf8(env,
(ret[3] == napi_invalid_arg ?
"pass" : "fail"),
NAPI_AUTO_LENGTH,
&prop_value));
NAPI_CALL(env, napi_set_named_property(env,
return_value,
"resultIsNull",
prop_value));
add_returned_status(env,
"envIsNull",
return_value,
"Invalid argument",
napi_invalid_arg,
status);

napi_create_function(env,
NULL,
NAPI_AUTO_LENGTH,
TestCreateFunctionParameters,
NULL,
&result);

add_last_status(env, "nameIsNull", return_value);

napi_create_function(env,
"TrackedFunction",
NAPI_AUTO_LENGTH,
NULL,
NULL,
&result);

add_last_status(env, "cbIsNull", return_value);

napi_create_function(env,
"TrackedFunction",
NAPI_AUTO_LENGTH,
TestCreateFunctionParameters,
NULL,
NULL);

add_last_status(env, "resultIsNull", return_value);

return return_value;
}
Expand Down