1 /*
2 * Copyright (c) 2023 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 = "[nodeapi_instancedata]";
19
20 // 设置要关联的自定义数据
21 // warning: 'napi_set_instance_data' is deprecated [-Wdeprecated-declarations]
22 // ld.lld: error: undefined symbol: napi_set_instance_data
23 #define TEST_INT32 315
setInstancedata(napi_env env,napi_value exports)24 napi_value setInstancedata(napi_env env, napi_value exports)
25 {
26 // pages/nodeapi/envlifecycleapis/napisetinstancedata
27 napi_value instance;
28 napi_create_object(env, &instance);
29 napi_value testint32 = nullptr;
30 napi_create_int32(env, TEST_INT32, &testint32);
31 napi_set_named_property(env, instance, "testint32", testint32);
32
33 // 导出 N-API 实例对象
34 napi_set_named_property(env, exports, "instance", instance);
35 return instance;
36 }
37