1 /*
2 * Copyright (c) 2022 Huawei Device 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 "napi/native_api.h"
17 #include "napi/native_node_api.h"
18 #include "tools/log.h"
19
20 extern const char _binary_js_hashmap_js_start[];
21 extern const char _binary_js_hashmap_js_end[];
22 extern const char _binary_hashmap_abc_start[];
23 extern const char _binary_hashmap_abc_end[];
24
25 namespace OHOS::Util {
HashMapInit(napi_env env,napi_value exports)26 static napi_value HashMapInit(napi_env env, napi_value exports)
27 {
28 return exports;
29 }
30
31 extern "C"
NAPI_util_HashMap_GetJSCode(const char ** buf,int * bufLen)32 __attribute__((visibility("default"))) void NAPI_util_HashMap_GetJSCode(const char **buf, int *bufLen)
33 {
34 if (buf != nullptr) {
35 *buf = _binary_js_hashmap_js_start;
36 }
37
38 if (bufLen != nullptr) {
39 *bufLen = _binary_js_hashmap_js_end - _binary_js_hashmap_js_start;
40 }
41 }
42 extern "C"
NAPI_util_HashMap_GetABCCode(const char ** buf,int * buflen)43 __attribute__((visibility("default"))) void NAPI_util_HashMap_GetABCCode(const char** buf, int* buflen)
44 {
45 if (buf != nullptr) {
46 *buf = _binary_hashmap_abc_start;
47 }
48 if (buflen != nullptr) {
49 *buflen = _binary_hashmap_abc_end - _binary_hashmap_abc_start;
50 }
51 }
52
53 static napi_module_with_js hashMapModule = {
54 .nm_version = 1,
55 .nm_flags = 0,
56 .nm_filename = nullptr,
57 .nm_register_func = HashMapInit,
58 .nm_modname = "util.HashMap",
59 .nm_priv = ((void*)0),
60 .nm_get_abc_code = NAPI_util_HashMap_GetABCCode,
61 .nm_get_js_code = NAPI_util_HashMap_GetJSCode,
62 };
63
HashMapRegisterModule()64 extern "C" __attribute__ ((constructor)) void HashMapRegisterModule()
65 {
66 napi_module_with_js_register(&hashMapModule);
67 }
68 } // namespace OHOS::Util
69