• 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_function]";
20 
SayHello(napi_env env,napi_callback_info info)21 napi_value SayHello(napi_env env, napi_callback_info info)
22 {
23     printf("Hello\n");
24     return NULL;
25 }
26 
testNapiCreateFunction(napi_env env,napi_callback_info info)27 napi_value testNapiCreateFunction(napi_env env, napi_callback_info info)
28 {
29     // pages/javascript/jsfunctions/napicreatefunction
30     napi_value func;
31     napi_status status;
32     napi_value obj;
33     const napi_extended_error_info *extended_error_info;
34 
35     status = napi_create_object(env, &obj);
36     if (status != napi_ok) {
37         // 错误处理
38         return NULL;
39     }
40 
41     status = napi_create_function(env, NULL, 0, SayHello, NULL, &func);
42     if (status != napi_ok) {
43         getErrMsg(status, env, extended_error_info, "create function", TAG);
44         return NULL;
45     }
46 
47     return func;
48 }
49