@pwaos.net/runtime-client-api 0.0.0-stage → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +137 -2
- package/binding.gyp +83 -0
- package/package.json +74 -4
- package/runtime.cjs +69 -0
- package/runtime.js +17 -0
- package/scripts/resolve-sdk.cjs +129 -0
- package/scripts/runtime-resolver.cjs +135 -0
- package/scripts/sdk-dir.cjs +37 -0
- package/scripts/setup-sdk.js +161 -0
- package/src/addon_main.cc +370 -0
- package/src/app_obj.cc +832 -0
- package/src/common.h +291 -0
- package/src/instance_obj.cc +734 -0
- package/src/instance_obj.h +10 -0
- package/src/interface_obj.cc +374 -0
- package/test/test.cjs +747 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#ifndef CHROMIUM_PWAOS_THIRD_PARTY_NODEJS_ADDON_INSTANCE_OBJ_H_
|
|
2
|
+
#define CHROMIUM_PWAOS_THIRD_PARTY_NODEJS_ADDON_INSTANCE_OBJ_H_
|
|
3
|
+
|
|
4
|
+
extern napi_value InitInstanceClass(napi_env env, napi_value exports);
|
|
5
|
+
extern napi_value InitAppClass(napi_env env, napi_value exports);
|
|
6
|
+
extern void ReleaseAllInstances(napi_env env);
|
|
7
|
+
extern void ReleaseAllApps(napi_env env);
|
|
8
|
+
extern void ReleaseAllInterfaces(napi_env env);
|
|
9
|
+
|
|
10
|
+
#endif // CHROMIUM_PWAOS_THIRD_PARTY_NODEJS_ADDON_INSTANCE_OBJ_H_
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
#include <node_api.h>
|
|
2
|
+
#include <string.h>
|
|
3
|
+
#include <stdio.h>
|
|
4
|
+
|
|
5
|
+
#include "common.h"
|
|
6
|
+
|
|
7
|
+
struct InterfaceCallbackContext {
|
|
8
|
+
napi_threadsafe_function tsfn = nullptr;
|
|
9
|
+
napi_ref user_data_ref = nullptr;
|
|
10
|
+
|
|
11
|
+
void release(napi_env env) {
|
|
12
|
+
if (tsfn)
|
|
13
|
+
napi_release_threadsafe_function(tsfn, napi_tsfn_abort);
|
|
14
|
+
if (user_data_ref)
|
|
15
|
+
napi_delete_reference(env, user_data_ref);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
static std::unordered_map<PWAOS_OBJECT_INTERFACE_HANDLE, napi_ref> g_interfaces;
|
|
20
|
+
|
|
21
|
+
static void interface_obj_finalizer(napi_env env,
|
|
22
|
+
void* finalize_data,
|
|
23
|
+
void* finalize_hint) {
|
|
24
|
+
PWAOS_OBJECT_INTERFACE_HANDLE interface_handle = (PWAOS_OBJECT_INTERFACE_HANDLE)finalize_data;
|
|
25
|
+
if (!interface_handle)
|
|
26
|
+
return;
|
|
27
|
+
pwaosInstance_destroyObjectInterface(interface_handle);
|
|
28
|
+
const auto& it = g_interfaces.find(interface_handle);
|
|
29
|
+
if (it != g_interfaces.end()) {
|
|
30
|
+
napi_delete_reference(env, it->second);
|
|
31
|
+
g_interfaces.erase(it);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static bool ObjectInterfaceMethodCallback(
|
|
36
|
+
int argc,
|
|
37
|
+
const char* argvJsonStr,
|
|
38
|
+
char* resultJsonStr,
|
|
39
|
+
int maxResultJsonStrLength,
|
|
40
|
+
void* userData) {
|
|
41
|
+
// Method-level callbacks are not wired to JS yet - keep the SDK contract
|
|
42
|
+
// (return false = no result produced) and ignore the context for now.
|
|
43
|
+
(void)argc; (void)argvJsonStr; (void)resultJsonStr;
|
|
44
|
+
(void)maxResultJsonStrLength; (void)userData;
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
static void ObjectInterfaceMethodCallback(napi_env env, napi_value js_cb, void* context, void* data) {
|
|
48
|
+
napi_value recv;
|
|
49
|
+
if (napi_get_undefined(env, &recv) != napi_ok) {
|
|
50
|
+
napi_throw_error(env,
|
|
51
|
+
"ERR_NAPI_TSFN_GET_UNDEFINED",
|
|
52
|
+
"Failed to retrieve undefined value");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 如果有 userData,还需要取出
|
|
57
|
+
napi_value user_data;
|
|
58
|
+
auto* ctx = (InterfaceCallbackContext*)context;
|
|
59
|
+
napi_value args[1];
|
|
60
|
+
size_t argc = 0;
|
|
61
|
+
if (napi_ok == napi_get_reference_value(env, ctx->user_data_ref, &user_data)) {
|
|
62
|
+
args[0] = user_data;
|
|
63
|
+
argc = 1;
|
|
64
|
+
}
|
|
65
|
+
napi_call_function(env, recv, js_cb, argc, args, nullptr);
|
|
66
|
+
}
|
|
67
|
+
static napi_value ObjectInterfaceDefineMethod(napi_env env, napi_callback_info info) {
|
|
68
|
+
size_t argc = 3;
|
|
69
|
+
napi_value argv[3];
|
|
70
|
+
napi_value this_arg;
|
|
71
|
+
NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, argv, &this_arg, nullptr));
|
|
72
|
+
|
|
73
|
+
if (argc < 3) {
|
|
74
|
+
napi_throw_type_error(env, nullptr, "Expected 3 arguments: name, methodCallback, userData");
|
|
75
|
+
return nullptr;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 从 this 对象中取出 interface 句柄
|
|
79
|
+
PWAOS_OBJECT_INTERFACE_HANDLE interface_handle;
|
|
80
|
+
napi_unwrap(env, this_arg, (void**)&interface_handle);
|
|
81
|
+
if (!interface_handle) {
|
|
82
|
+
napi_throw_error(env, nullptr, "Invalid interface handle");
|
|
83
|
+
return nullptr;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// 获取方法名
|
|
87
|
+
napi_valuetype name_type;
|
|
88
|
+
NODE_API_CALL(env, napi_typeof(env, argv[0], &name_type));
|
|
89
|
+
if (name_type != napi_string) {
|
|
90
|
+
napi_throw_type_error(env, nullptr, "Second argument must be a string");
|
|
91
|
+
return nullptr;
|
|
92
|
+
}
|
|
93
|
+
size_t name_len;
|
|
94
|
+
NODE_API_CALL(env, napi_get_value_string_utf8(env, argv[0], nullptr, 0, &name_len));
|
|
95
|
+
char name[256];
|
|
96
|
+
if (name_len >= sizeof(name)) {
|
|
97
|
+
napi_throw_error(env, nullptr, "Method name too long");
|
|
98
|
+
return nullptr;
|
|
99
|
+
}
|
|
100
|
+
NODE_API_CALL(env, napi_get_value_string_utf8(env, argv[0], name, sizeof(name), &name_len));
|
|
101
|
+
|
|
102
|
+
napi_valuetype callback_type;
|
|
103
|
+
NODE_API_CALL(env, napi_typeof(env, argv[1], &callback_type));
|
|
104
|
+
if (callback_type != napi_function) {
|
|
105
|
+
napi_throw_type_error(env, nullptr, "Third argument must be an function");
|
|
106
|
+
return nullptr;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
auto interface_method_ctx = std::make_unique<InterfaceCallbackContext>();
|
|
110
|
+
if (!interface_method_ctx) {
|
|
111
|
+
napi_throw_error(env, nullptr, "Out of memory!");
|
|
112
|
+
return nullptr;
|
|
113
|
+
}
|
|
114
|
+
auto* raw_interface_method_ctx = interface_method_ctx.get();
|
|
115
|
+
|
|
116
|
+
napi_value async_name;
|
|
117
|
+
NODE_API_CALL(env, napi_create_string_utf8(env, "ObjectInterfaceMethodCallback", NAPI_AUTO_LENGTH, &async_name));
|
|
118
|
+
NODE_API_CALL(env, napi_create_threadsafe_function(env, argv[1], nullptr, async_name, 0, 1, nullptr,
|
|
119
|
+
nullptr, raw_interface_method_ctx, ObjectInterfaceMethodCallback, &raw_interface_method_ctx->tsfn));
|
|
120
|
+
|
|
121
|
+
napi_create_reference(env, argv[2], 1, &raw_interface_method_ctx->user_data_ref);
|
|
122
|
+
|
|
123
|
+
interface_method_ctx.release();
|
|
124
|
+
PWAOS_API_CALL_AND_RETURN(env,
|
|
125
|
+
pwaosObjectInterface_defineMethod(interface_handle, name, ObjectInterfaceMethodCallback, raw_interface_method_ctx));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
static napi_value ObjectInterfaceRemoveMethod(napi_env env, napi_callback_info info) {
|
|
129
|
+
size_t argc = 1;
|
|
130
|
+
napi_value argv[1];
|
|
131
|
+
napi_value this_arg;
|
|
132
|
+
NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, argv, &this_arg, nullptr));
|
|
133
|
+
|
|
134
|
+
if (argc < 1) {
|
|
135
|
+
napi_throw_type_error(env, nullptr, "Expected 1 arguments: name");
|
|
136
|
+
return nullptr;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// 从 this 对象中取出 interface 句柄
|
|
140
|
+
PWAOS_OBJECT_INTERFACE_HANDLE interface_handle;
|
|
141
|
+
napi_unwrap(env, this_arg, (void**)&interface_handle);
|
|
142
|
+
if (!interface_handle) {
|
|
143
|
+
napi_throw_error(env, nullptr, "Invalid interface handle");
|
|
144
|
+
return nullptr;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// 获取方法名
|
|
148
|
+
napi_valuetype name_type;
|
|
149
|
+
NODE_API_CALL(env, napi_typeof(env, argv[0], &name_type));
|
|
150
|
+
if (name_type != napi_string) {
|
|
151
|
+
napi_throw_type_error(env, nullptr, "Second argument must be a string");
|
|
152
|
+
return nullptr;
|
|
153
|
+
}
|
|
154
|
+
size_t name_len;
|
|
155
|
+
NODE_API_CALL(env, napi_get_value_string_utf8(env, argv[0], nullptr, 0, &name_len));
|
|
156
|
+
char name[256];
|
|
157
|
+
if (name_len >= sizeof(name)) {
|
|
158
|
+
napi_throw_error(env, nullptr, "Method name too long");
|
|
159
|
+
return nullptr;
|
|
160
|
+
}
|
|
161
|
+
NODE_API_CALL(env, napi_get_value_string_utf8(env, argv[0], name, sizeof(name), &name_len));
|
|
162
|
+
|
|
163
|
+
PWAOS_API_CALL_AND_RETURN(env, pwaosObjectInterface_removeMethod(interface_handle, name));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
struct PropertyCallbackContext {
|
|
167
|
+
napi_threadsafe_function tsfn_getter = nullptr;
|
|
168
|
+
napi_threadsafe_function tsfn_setter = nullptr;
|
|
169
|
+
napi_ref user_data_ref = nullptr;
|
|
170
|
+
|
|
171
|
+
void release(napi_env env) {
|
|
172
|
+
if (tsfn_getter)
|
|
173
|
+
napi_release_threadsafe_function(tsfn_getter, napi_tsfn_abort);
|
|
174
|
+
if (tsfn_setter)
|
|
175
|
+
napi_release_threadsafe_function(tsfn_setter, napi_tsfn_abort);
|
|
176
|
+
if (user_data_ref)
|
|
177
|
+
napi_delete_reference(env, user_data_ref);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
static bool ObjectInterfaceSetPropertyCallback(
|
|
181
|
+
const char* propJsonStr,
|
|
182
|
+
void* userData) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
static bool ObjectInterfaceGetPropertyCallback(
|
|
186
|
+
char* out_propJsonStr,
|
|
187
|
+
int maxPropJsonStrLength,
|
|
188
|
+
void* userData) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
static void ObjectInterfacePropertyCallback(napi_env env, napi_value js_cb, void* context, void* data) {
|
|
192
|
+
napi_value recv;
|
|
193
|
+
if (napi_get_undefined(env, &recv) != napi_ok) {
|
|
194
|
+
napi_throw_error(env,
|
|
195
|
+
"ERR_NAPI_TSFN_GET_UNDEFINED",
|
|
196
|
+
"Failed to retrieve undefined value");
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// 如果有 userData,还需要取出
|
|
201
|
+
napi_value user_data;
|
|
202
|
+
auto* ctx = (InterfaceCallbackContext*)context;
|
|
203
|
+
napi_value args[1];
|
|
204
|
+
size_t argc = 0;
|
|
205
|
+
if (napi_ok == napi_get_reference_value(env, ctx->user_data_ref, &user_data)) {
|
|
206
|
+
args[0] = user_data;
|
|
207
|
+
argc = 1;
|
|
208
|
+
}
|
|
209
|
+
napi_call_function(env, recv, js_cb, argc, args, nullptr);
|
|
210
|
+
}
|
|
211
|
+
static napi_value ObjectInterfaceDefineProperty(napi_env env, napi_callback_info info) {
|
|
212
|
+
size_t argc = 4;
|
|
213
|
+
napi_value argv[4];
|
|
214
|
+
napi_value this_arg;
|
|
215
|
+
NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, argv, &this_arg, nullptr));
|
|
216
|
+
|
|
217
|
+
if (argc < 4) {
|
|
218
|
+
napi_throw_type_error(env, nullptr, "Expected 4 arguments: name, setterCallback, getterCallback, userData");
|
|
219
|
+
return nullptr;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// 从 this 对象中取出 interface 句柄
|
|
223
|
+
PWAOS_OBJECT_INTERFACE_HANDLE interface_handle;
|
|
224
|
+
napi_unwrap(env, this_arg, (void**)&interface_handle);
|
|
225
|
+
if (!interface_handle) {
|
|
226
|
+
napi_throw_error(env, nullptr, "Invalid interface handle");
|
|
227
|
+
return nullptr;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// 获取属性名
|
|
231
|
+
napi_valuetype name_type;
|
|
232
|
+
NODE_API_CALL(env, napi_typeof(env, argv[0], &name_type));
|
|
233
|
+
if (name_type != napi_string) {
|
|
234
|
+
napi_throw_type_error(env, nullptr, "Second argument must be a string");
|
|
235
|
+
return nullptr;
|
|
236
|
+
}
|
|
237
|
+
size_t name_len;
|
|
238
|
+
NODE_API_CALL(env, napi_get_value_string_utf8(env, argv[0], nullptr, 0, &name_len));
|
|
239
|
+
char name[256];
|
|
240
|
+
if (name_len >= sizeof(name)) {
|
|
241
|
+
napi_throw_error(env, nullptr, "Property name too long");
|
|
242
|
+
return nullptr;
|
|
243
|
+
}
|
|
244
|
+
NODE_API_CALL(env, napi_get_value_string_utf8(env, argv[0], name, sizeof(name), &name_len));
|
|
245
|
+
|
|
246
|
+
napi_valuetype callback_type;
|
|
247
|
+
NODE_API_CALL(env, napi_typeof(env, argv[1], &callback_type));
|
|
248
|
+
if (callback_type != napi_function) {
|
|
249
|
+
napi_throw_type_error(env, nullptr, "Second argument must be an function");
|
|
250
|
+
return nullptr;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
NODE_API_CALL(env, napi_typeof(env, argv[2], &callback_type));
|
|
254
|
+
if (callback_type != napi_function) {
|
|
255
|
+
napi_throw_type_error(env, nullptr, "Third argument must be an function");
|
|
256
|
+
return nullptr;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
auto interface_property_ctx = std::make_unique<PropertyCallbackContext>();
|
|
260
|
+
if (!interface_property_ctx) {
|
|
261
|
+
napi_throw_error(env, nullptr, "Out of memory!");
|
|
262
|
+
return nullptr;
|
|
263
|
+
}
|
|
264
|
+
auto* raw_interface_property_ctx = interface_property_ctx.get();
|
|
265
|
+
|
|
266
|
+
napi_value async_name_getter;
|
|
267
|
+
NODE_API_CALL(env, napi_create_string_utf8(env, "ObjectInterfacePropertyGetterCallback", NAPI_AUTO_LENGTH, &async_name_getter));
|
|
268
|
+
NODE_API_CALL(env, napi_create_threadsafe_function(env, argv[1], nullptr, async_name_getter, 0, 1, nullptr,
|
|
269
|
+
nullptr, raw_interface_property_ctx, ObjectInterfacePropertyCallback, &raw_interface_property_ctx->tsfn_getter));
|
|
270
|
+
|
|
271
|
+
napi_value async_name_setter;
|
|
272
|
+
NODE_API_CALL(env, napi_create_string_utf8(env, "ObjectInterfacePropertySetterCallback", NAPI_AUTO_LENGTH, &async_name_setter));
|
|
273
|
+
NODE_API_CALL(env, napi_create_threadsafe_function(env, argv[2], nullptr, async_name_setter, 0, 1, nullptr,
|
|
274
|
+
nullptr, raw_interface_property_ctx, ObjectInterfacePropertyCallback, &raw_interface_property_ctx->tsfn_setter));
|
|
275
|
+
|
|
276
|
+
napi_create_reference(env, argv[3], 1, &raw_interface_property_ctx->user_data_ref);
|
|
277
|
+
|
|
278
|
+
interface_property_ctx.release();
|
|
279
|
+
PWAOS_API_CALL_AND_RETURN(env, pwaosObjectInterface_defineProperty(interface_handle, name, ObjectInterfaceSetPropertyCallback, ObjectInterfaceGetPropertyCallback, raw_interface_property_ctx));
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
static napi_value ObjectInterfaceRemoveProperty(napi_env env, napi_callback_info info) {
|
|
283
|
+
size_t argc = 1;
|
|
284
|
+
napi_value argv[1];
|
|
285
|
+
napi_value this_arg;
|
|
286
|
+
NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, argv, &this_arg, nullptr));
|
|
287
|
+
|
|
288
|
+
if (argc < 1) {
|
|
289
|
+
napi_throw_type_error(env, nullptr, "Expected 1 arguments: name");
|
|
290
|
+
return nullptr;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// 从 this 对象中取出 interface 句柄
|
|
294
|
+
PWAOS_OBJECT_INTERFACE_HANDLE interface_handle;
|
|
295
|
+
napi_unwrap(env, this_arg, (void**)&interface_handle);
|
|
296
|
+
if (!interface_handle) {
|
|
297
|
+
napi_throw_error(env, nullptr, "Invalid interface handle");
|
|
298
|
+
return nullptr;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// 获取属性名
|
|
302
|
+
napi_valuetype name_type;
|
|
303
|
+
NODE_API_CALL(env, napi_typeof(env, argv[0], &name_type));
|
|
304
|
+
if (name_type != napi_string) {
|
|
305
|
+
napi_throw_type_error(env, nullptr, "Second argument must be a string");
|
|
306
|
+
return nullptr;
|
|
307
|
+
}
|
|
308
|
+
size_t name_len;
|
|
309
|
+
NODE_API_CALL(env, napi_get_value_string_utf8(env, argv[0], nullptr, 0, &name_len));
|
|
310
|
+
char name[256];
|
|
311
|
+
if (name_len >= sizeof(name)) {
|
|
312
|
+
napi_throw_error(env, nullptr, "Property name too long");
|
|
313
|
+
return nullptr;
|
|
314
|
+
}
|
|
315
|
+
NODE_API_CALL(env, napi_get_value_string_utf8(env, argv[0], name, sizeof(name), &name_len));
|
|
316
|
+
|
|
317
|
+
PWAOS_API_CALL_AND_RETURN(env, pwaosObjectInterface_removeProperty(interface_handle, name));
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
static napi_value InterfaceConstructor(napi_env env, napi_callback_info info) {
|
|
321
|
+
return nullptr;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
static napi_ref g_interface_class_ref = nullptr;
|
|
325
|
+
static void Init(napi_env env) {
|
|
326
|
+
napi_property_descriptor methods[] = {
|
|
327
|
+
DECLARE_NODE_API_PROPERTY("defineMethod", ObjectInterfaceDefineMethod),
|
|
328
|
+
DECLARE_NODE_API_PROPERTY("removeMethod", ObjectInterfaceRemoveMethod),
|
|
329
|
+
DECLARE_NODE_API_PROPERTY("defineProperty", ObjectInterfaceDefineProperty),
|
|
330
|
+
DECLARE_NODE_API_PROPERTY("removeProperty", ObjectInterfaceRemoveProperty),
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
napi_value interface_class;
|
|
334
|
+
NODE_API_CALL_RETURN_VOID(
|
|
335
|
+
env,
|
|
336
|
+
napi_define_class(env, "pwaosObjectInterface", NAPI_AUTO_LENGTH,
|
|
337
|
+
InterfaceConstructor, nullptr,
|
|
338
|
+
sizeof(methods) / sizeof(methods[0]),
|
|
339
|
+
methods, &interface_class));
|
|
340
|
+
|
|
341
|
+
NODE_API_CALL_RETURN_VOID(env, napi_create_reference(env, interface_class, 1, &g_interface_class_ref));
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
napi_value GetOrCreateInterfaceObj(napi_env env, PWAOS_OBJECT_INTERFACE_HANDLE interface_handle) {
|
|
345
|
+
if (!g_interface_class_ref)
|
|
346
|
+
Init(env);
|
|
347
|
+
|
|
348
|
+
const auto& iter = g_interfaces.find(interface_handle);
|
|
349
|
+
if (iter != g_interfaces.end()) {
|
|
350
|
+
napi_value obj;
|
|
351
|
+
NODE_API_CALL(env, napi_get_reference_value(env, iter->second, &obj));
|
|
352
|
+
return obj;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
napi_value interface_class;
|
|
356
|
+
NODE_API_CALL(env, napi_get_reference_value(env, g_interface_class_ref, &interface_class));
|
|
357
|
+
|
|
358
|
+
napi_value interface_obj;
|
|
359
|
+
NODE_API_CALL(env, napi_new_instance(env, interface_class, 0, 0, &interface_obj));
|
|
360
|
+
napi_wrap(env, interface_obj, interface_handle, interface_obj_finalizer, nullptr, nullptr);
|
|
361
|
+
|
|
362
|
+
napi_ref ref;
|
|
363
|
+
NODE_API_CALL(env, napi_create_reference(env, interface_obj, 0, &ref));
|
|
364
|
+
|
|
365
|
+
g_interfaces.emplace(interface_handle, ref);
|
|
366
|
+
|
|
367
|
+
return interface_obj;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
void ReleaseAllInterfaces(napi_env env) {
|
|
371
|
+
for (auto& [iface, ref] : g_interfaces)
|
|
372
|
+
napi_delete_reference(env, ref);
|
|
373
|
+
g_interfaces.clear();
|
|
374
|
+
}
|