diff options
| author | Octavian Soldea <octavian.soldea@intel.com> | 2019-07-27 17:42:19 -0700 |
|---|---|---|
| committer | Rich Trott <rtrott@gmail.com> | 2019-07-31 23:19:41 -0700 |
| commit | 1ee47d550c6de132f06110aa13eceb7551d643b3 (patch) | |
| tree | 685583cdb150bc9d91bfdfe683d25c13f6e106a1 /test/js-native-api/test_function/test_function.c | |
| parent | 8492acfd572c8a5fde2ad8feffe47c98bff4f775 (diff) | |
| download | node-new-1ee47d550c6de132f06110aa13eceb7551d643b3.tar.gz | |
n-api: refactoring napi_create_function testing
This is a refactoring of https://github.com/nodejs/node/pull/26998
following https://github.com/nodejs/node/pull/28505.
The functions `add_last_status()` and `add_returned_status()` are now
reused, see also https://github.com/nodejs/node/pull/28848.
PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'test/js-native-api/test_function/test_function.c')
| -rw-r--r-- | test/js-native-api/test_function/test_function.c | 102 |
1 files changed, 37 insertions, 65 deletions
diff --git a/test/js-native-api/test_function/test_function.c b/test/js-native-api/test_function/test_function.c index 4d2b3fbe85..713e935e08 100644 --- a/test/js-native-api/test_function/test_function.c +++ b/test/js-native-api/test_function/test_function.c @@ -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; } |
