• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "javascriptapi.h"
18 
19 static const char *TAG = "[javascriptapi_property]";
20 
testNapiObjectFreeze(napi_env env,napi_callback_info info)21 napi_value testNapiObjectFreeze(napi_env env, napi_callback_info info)
22 {
23     // pages/javascript/jsproperty/napiobjectfreeze
24     // 获取参数数量
25     size_t argc = PARAM1;
26     // 准备接收参数的变量
27     napi_value argv[PARAM1];
28     napi_value obj;
29     napi_status status;
30     const napi_extended_error_info *extended_error_info;
31 
32     // 获取回调函数的参数信息
33     status = napi_get_cb_info(env, info, &argc, argv, NULL, NULL);
34     if (status != napi_ok) {
35         getErrMsg(status, env, extended_error_info, "Failed to get callback info", TAG);
36         return NULL;
37     }
38 
39     // 检查参数数量是否符合预期
40     if (argc != PARAM1) {
41         napi_throw_error(env, NULL, "Expected exactly one argument");
42         return NULL;
43     }
44 
45     // 检查传入参数是否为object
46     napi_valuetype resultType;
47     napi_typeof(env, argv[0], &resultType);
48     if (resultType != napi_object) {
49         napi_throw_error(env, NULL, "The incoming parameters are not as expected");
50         return NULL;
51     }
52     obj = argv[PARAM0];
53     status = napi_object_freeze(env, obj);
54     if (status != napi_ok) {
55         getErrMsg(status, env, extended_error_info, "object freeze", TAG);
56         return NULL;
57     }
58 
59     return obj;
60 }
61