summaryrefslogtreecommitdiff
path: root/test/js-native-api
diff options
context:
space:
mode:
authorOctavian Soldea <octavian.soldea@intel.com>2019-03-29 13:12:23 -0700
committerGabriel Schulhof <gabriel.schulhof@intel.com>2019-04-10 16:35:22 -0700
commit06c803d9b929880dc21eeb5f8eb40fe17ff2e499 (patch)
treec97362c86949770fb37328c2bc8978b5e143bc52 /test/js-native-api
parent1a67c9948c005b7d1f8a7fc128e7530078da5c2c (diff)
downloadandroid-node-v8-06c803d9b929880dc21eeb5f8eb40fe17ff2e499.tar.gz
android-node-v8-06c803d9b929880dc21eeb5f8eb40fe17ff2e499.tar.bz2
android-node-v8-06c803d9b929880dc21eeb5f8eb40fe17ff2e499.zip
test: pass null params to napi_create_function()
Each one of the following arguments is checked: napi_env env, const char* utf8name, napi_callback cb, napi_value* result. PR-URL: https://github.com/nodejs/node/pull/26998 Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
Diffstat (limited to 'test/js-native-api')
-rw-r--r--test/js-native-api/test_function/test.js7
-rw-r--r--test/js-native-api/test_function/test_function.c92
2 files changed, 99 insertions, 0 deletions
diff --git a/test/js-native-api/test_function/test.js b/test/js-native-api/test_function/test.js
index e89d64f61d..21b2ac7ff4 100644
--- a/test/js-native-api/test_function/test.js
+++ b/test/js-native-api/test_function/test.js
@@ -35,3 +35,10 @@ let tracked_function = test_function.MakeTrackedFunction(common.mustCall());
assert(!!tracked_function);
tracked_function = null;
global.gc();
+
+assert.deepStrictEqual(test_function.TestCreateFunctionParameters(), {
+ envIsNull: 'pass',
+ nameIsNull: 'pass',
+ cbIsNull: 'pass',
+ resultIsNull: 'pass'
+});
diff --git a/test/js-native-api/test_function/test_function.c b/test/js-native-api/test_function/test_function.c
index faa520b907..4d2b3fbe85 100644
--- a/test/js-native-api/test_function/test_function.c
+++ b/test/js-native-api/test_function/test_function.c
@@ -1,6 +1,85 @@
#include <js_native_api.h>
#include "../common.h"
+static napi_value TestCreateFunctionParameters(napi_env env,
+ napi_callback_info info) {
+ napi_status ret[4];
+ napi_value result, return_value, prop_value;
+
+
+ ret[0] = 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));
+
+ return return_value;
+}
+
static napi_value TestCallFunction(napi_env env, napi_callback_info info) {
size_t argc = 10;
napi_value args[10];
@@ -124,6 +203,14 @@ napi_value Init(napi_env env, napi_value exports) {
NULL,
&fn4));
+ napi_value fn5;
+ NAPI_CALL(env, napi_create_function(env,
+ "TestCreateFunctionParameters",
+ NAPI_AUTO_LENGTH,
+ TestCreateFunctionParameters,
+ NULL,
+ &fn5));
+
NAPI_CALL(env, napi_set_named_property(env, exports, "TestCall", fn1));
NAPI_CALL(env, napi_set_named_property(env, exports, "TestName", fn2));
NAPI_CALL(env, napi_set_named_property(env, exports, "TestNameShort", fn3));
@@ -132,6 +219,11 @@ napi_value Init(napi_env env, napi_value exports) {
"MakeTrackedFunction",
fn4));
+ NAPI_CALL(env, napi_set_named_property(env,
+ exports,
+ "TestCreateFunctionParameters",
+ fn5));
+
return exports;
}
EXTERN_C_END