1 /*
2 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "common.h"
17
18 static const char *TAG = "[jsapi_isarray]";
19
testNapiIsArray(napi_env env,napi_callback_info info)20 napi_value testNapiIsArray(napi_env env, napi_callback_info info)
21 {
22 // pages/javascript/jsabstractops/napiisarray
23 size_t requireArgc = PARAM1;
24 size_t argc = PARAM1;
25 napi_status status;
26 bool result;
27 napi_value bolresult;
28 napi_value argv[PARAM1];
29 const napi_extended_error_info *extended_error_info;
30
31 // Obtain the parameters of the callback function
32 status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
33 if (status != napi_ok) {
34 getErrMsg(status, env, extended_error_info, "get cb info", TAG);
35 return NULL;
36 }
37 // Check if the number of parameters meets expectations
38 if (argc != requireArgc) {
39 napi_throw_error(env, NULL, "Expected exactly one argument");
40 return NULL;
41 }
42
43 // Call napi_is_array(), any -> bool
44 status = napi_is_array(env, argv[0], &result);
45 if (status != napi_ok) {
46 napi_throw_error(env, NULL, "Unable to check if value is an array");
47 return NULL;
48 }
49
50 status = napi_get_boolean(env, result, &bolresult);
51 if (status != napi_ok) {
52 napi_throw_error(env, NULL, "Unable to convert boolean to napi_value");
53 return NULL;
54 }
55 return bolresult;
56 }
57