emnapi 1.9.2 → 2.0.0-alpha.1
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/CMakeLists.txt +127 -57
- package/README.md +164 -776
- package/cmake/wasm32.cmake +0 -3
- package/common.gypi +16 -14
- package/dist/library_async_work.js +390 -0
- package/dist/library_napi.js +1743 -2759
- package/dist/library_threadsafe_function.js +1178 -0
- package/dist/library_v8.js +1594 -0
- package/emnapi.gyp +37 -0
- package/include/node/emnapi.h +39 -3
- package/include/node/js_native_api.h +10 -0
- package/include/node/js_native_api_types.h +26 -0
- package/include/node/node.h +198 -0
- package/include/node/node_api.h +0 -10
- package/include/node/node_buffer.h +92 -0
- package/include/node/node_object_wrap.h +132 -0
- package/include/node/node_version.h +110 -0
- package/include/node/uv/unix.h +1 -0
- package/include/node/uv/version.h +43 -0
- package/include/node/uv.h +6 -0
- package/index.js +15 -7
- package/lib/wasm32-emscripten/libemnapi-mt.a +0 -0
- package/lib/wasm32-emscripten/libemnapi.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-mt.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-napi-rs-mt.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi.a +0 -0
- package/lib/wasm64-emscripten/libemnapi-mt.a +0 -0
- package/lib/wasm64-emscripten/libemnapi.a +0 -0
- package/package.json +1 -1
- package/src/async_cleanup_hook.c +6 -6
- package/src/emnapi_internal.h +5 -10
- package/src/js_native_api.c +37 -21
- package/src/js_native_api_internal.h +66 -0
- package/src/node_api.c +1 -1
- package/src/threadsafe_function.c +2 -2
- package/src/uv/unix/thread.c +21 -0
- package/src/v8/array.cc +19 -0
- package/src/v8/boolean.cc +26 -0
- package/src/v8/date.cc +15 -0
- package/src/v8/exception.cc +48 -0
- package/src/v8/external.cc +23 -0
- package/src/v8/function.cc +35 -0
- package/src/v8/handle_scope.cc +46 -0
- package/src/v8/internal.cc +126 -0
- package/src/v8/internal.h +41 -0
- package/src/v8/isolate.cc +35 -0
- package/src/v8/json.cc +25 -0
- package/src/v8/node.cc +24 -0
- package/src/v8/number.cc +62 -0
- package/src/v8/object.cc +106 -0
- package/src/v8/script.cc +75 -0
- package/src/v8/string.cc +104 -0
- package/src/v8/template.cc +234 -0
- package/src/v8/try_catch.cc +50 -0
- package/src/v8/v8_impl.h +42 -0
- package/src/v8/value.cc +138 -0
- package/lib/wasm32/libdlmalloc-mt.a +0 -0
- package/lib/wasm32/libdlmalloc.a +0 -0
- package/lib/wasm32/libemmalloc-mt.a +0 -0
- package/lib/wasm32/libemmalloc.a +0 -0
- package/lib/wasm32/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32/libemnapi-basic.a +0 -0
- package/lib/wasm32/libemnapi.a +0 -0
- package/lib/wasm32-emscripten/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasi/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasi/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasi/libemnapi.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-basic-napi-rs-mt.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-mt.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-napi-rs-mt.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi.a +0 -0
- package/lib/wasm32-wasip1/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasip1/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasip1/libemnapi.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-basic-napi-rs-mt.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-basic.a +0 -0
- package/lib/wasm64-emscripten/libemnapi-basic.a +0 -0
package/cmake/wasm32.cmake
CHANGED
package/common.gypi
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
'max_memory%': 2147483648,
|
|
12
12
|
# must be an absolute path
|
|
13
13
|
'emnapi_js_library%': '<!(node -p "path.resolve(process.argv[1],\'dist/library_napi.js\').replace(process.argv[2],\'/\')" "<(node_root_dir)" "\\\\")',
|
|
14
|
+
'v8_js_library%': '<!(node -p "path.resolve(process.argv[1],\'dist/library_v8.js\').replace(process.argv[2],\'/\')" "<(node_root_dir)" "\\\\")',
|
|
14
15
|
'emnapi_manual_linking%': 0,
|
|
15
16
|
},
|
|
16
17
|
|
|
@@ -20,6 +21,7 @@
|
|
|
20
21
|
'defines': [
|
|
21
22
|
'BUILDING_NODE_EXTENSION',
|
|
22
23
|
'__STDC_FORMAT_MACROS',
|
|
24
|
+
'V8_ENABLE_DIRECT_LOCAL',
|
|
23
25
|
],
|
|
24
26
|
|
|
25
27
|
'cflags': [
|
|
@@ -81,7 +83,7 @@
|
|
|
81
83
|
],
|
|
82
84
|
'ldflags': [
|
|
83
85
|
"-sALLOW_MEMORY_GROWTH=1",
|
|
84
|
-
"-sEXPORTED_FUNCTIONS=['_malloc','_free'
|
|
86
|
+
"-sEXPORTED_FUNCTIONS=['_malloc','_free']",
|
|
85
87
|
'-sNODEJS_CATCH_EXIT=0',
|
|
86
88
|
'-sNODEJS_CATCH_REJECTION=0',
|
|
87
89
|
'-sWASM_BIGINT=1',
|
|
@@ -98,7 +100,7 @@
|
|
|
98
100
|
],
|
|
99
101
|
'OTHER_LDFLAGS': [
|
|
100
102
|
"-sALLOW_MEMORY_GROWTH=1",
|
|
101
|
-
"-sEXPORTED_FUNCTIONS=['_malloc','_free'
|
|
103
|
+
"-sEXPORTED_FUNCTIONS=['_malloc','_free']",
|
|
102
104
|
'-sNODEJS_CATCH_EXIT=0',
|
|
103
105
|
'-sNODEJS_CATCH_REJECTION=0',
|
|
104
106
|
'-sWASM_BIGINT=1',
|
|
@@ -176,11 +178,11 @@
|
|
|
176
178
|
'conditions': [
|
|
177
179
|
['wasm_threads != 0', {
|
|
178
180
|
# wasi-threads
|
|
179
|
-
'cflags': [ '--target=wasm64-
|
|
180
|
-
'ldflags': [ '--target=wasm64-
|
|
181
|
+
'cflags': [ '--target=wasm64-wasip1-threads', '-pthread' ],
|
|
182
|
+
'ldflags': [ '--target=wasm64-wasip1-threads', '-pthread' ],
|
|
181
183
|
'xcode_settings': {
|
|
182
|
-
'WARNING_CFLAGS': [ '--target=wasm64-
|
|
183
|
-
'OTHER_LDFLAGS': [ '--target=wasm64-
|
|
184
|
+
'WARNING_CFLAGS': [ '--target=wasm64-wasip1-threads', '-pthread' ],
|
|
185
|
+
'OTHER_LDFLAGS': [ '--target=wasm64-wasip1-threads', '-pthread' ],
|
|
184
186
|
},
|
|
185
187
|
}, {
|
|
186
188
|
# wasi
|
|
@@ -196,11 +198,11 @@
|
|
|
196
198
|
'conditions': [
|
|
197
199
|
['wasm_threads != 0', {
|
|
198
200
|
# wasi-threads
|
|
199
|
-
'cflags': [ '--target=wasm32-
|
|
200
|
-
'ldflags': [ '--target=wasm32-
|
|
201
|
+
'cflags': [ '--target=wasm32-wasip1-threads', '-pthread' ],
|
|
202
|
+
'ldflags': [ '--target=wasm32-wasip1-threads', '-pthread' ],
|
|
201
203
|
'xcode_settings': {
|
|
202
|
-
'WARNING_CFLAGS': [ '--target=wasm32-
|
|
203
|
-
'OTHER_LDFLAGS': [ '--target=wasm32-
|
|
204
|
+
'WARNING_CFLAGS': [ '--target=wasm32-wasip1-threads', '-pthread' ],
|
|
205
|
+
'OTHER_LDFLAGS': [ '--target=wasm32-wasip1-threads', '-pthread' ],
|
|
204
206
|
},
|
|
205
207
|
}, {
|
|
206
208
|
# wasi
|
|
@@ -246,7 +248,7 @@
|
|
|
246
248
|
'-Wl,--export-dynamic',
|
|
247
249
|
'-Wl,--export=malloc',
|
|
248
250
|
'-Wl,--export=free',
|
|
249
|
-
'-Wl,--export=napi_register_wasm_v1',
|
|
251
|
+
'-Wl,--export-if-defined=napi_register_wasm_v1',
|
|
250
252
|
'-Wl,--export-if-defined=node_api_module_get_api_version_v1',
|
|
251
253
|
'-Wl,--import-undefined',
|
|
252
254
|
'-Wl,--export-table',
|
|
@@ -259,7 +261,7 @@
|
|
|
259
261
|
'-Wl,--export-dynamic',
|
|
260
262
|
'-Wl,--export=malloc',
|
|
261
263
|
'-Wl,--export=free',
|
|
262
|
-
'-Wl,--export=napi_register_wasm_v1',
|
|
264
|
+
'-Wl,--export-if-defined=napi_register_wasm_v1',
|
|
263
265
|
'-Wl,--export-if-defined=node_api_module_get_api_version_v1',
|
|
264
266
|
'-Wl,--import-undefined',
|
|
265
267
|
'-Wl,--export-table',
|
|
@@ -335,7 +337,7 @@
|
|
|
335
337
|
'-Wl,--export-dynamic',
|
|
336
338
|
'-Wl,--export=malloc',
|
|
337
339
|
'-Wl,--export=free',
|
|
338
|
-
'-Wl,--export=napi_register_wasm_v1',
|
|
340
|
+
'-Wl,--export-if-defined=napi_register_wasm_v1',
|
|
339
341
|
'-Wl,--export-if-defined=node_api_module_get_api_version_v1',
|
|
340
342
|
'-Wl,--import-undefined',
|
|
341
343
|
'-Wl,--export-table',
|
|
@@ -348,7 +350,7 @@
|
|
|
348
350
|
'-Wl,--export-dynamic',
|
|
349
351
|
'-Wl,--export=malloc',
|
|
350
352
|
'-Wl,--export=free',
|
|
351
|
-
'-Wl,--export=napi_register_wasm_v1',
|
|
353
|
+
'-Wl,--export-if-defined=napi_register_wasm_v1',
|
|
352
354
|
'-Wl,--export-if-defined=node_api_module_get_api_version_v1',
|
|
353
355
|
'-Wl,--import-undefined',
|
|
354
356
|
'-Wl,--export-table',
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
//#region src/emscripten/init.ts
|
|
2
|
+
/* eslint-disable @stylistic/indent */
|
|
3
|
+
var emnapiCtx$1 = undefined;
|
|
4
|
+
var emnapiEnv$1 = undefined;
|
|
5
|
+
// export var emnapiRuntimeModuleExports: any = undefined!
|
|
6
|
+
var emnapiNodeBinding$1 = undefined;
|
|
7
|
+
var emnapiAsyncWorkPoolSize$1 = 0;
|
|
8
|
+
const emnapiModule = {
|
|
9
|
+
exports: {},
|
|
10
|
+
loaded: false,
|
|
11
|
+
filename: ''
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @__deps emnapi_create_env
|
|
15
|
+
* @__deps emnapi_delete_env
|
|
16
|
+
*/
|
|
17
|
+
function emnapiInit(options) {
|
|
18
|
+
if (emnapiModule.loaded)
|
|
19
|
+
return emnapiModule.exports;
|
|
20
|
+
if (typeof options !== 'object' || options === null) {
|
|
21
|
+
throw new TypeError('Invalid emnapi init option');
|
|
22
|
+
}
|
|
23
|
+
const context = options.context;
|
|
24
|
+
if (typeof context !== 'object' || context === null) {
|
|
25
|
+
throw new TypeError("Invalid `options.context`. Use `import { getDefaultContext } from '@emnapi/runtime'`");
|
|
26
|
+
}
|
|
27
|
+
emnapiCtx$1 = context;
|
|
28
|
+
const filename = typeof options.filename === 'string' ? options.filename : '';
|
|
29
|
+
emnapiModule.filename = filename;
|
|
30
|
+
if ('nodeBinding' in options) {
|
|
31
|
+
const nodeBinding = options.nodeBinding;
|
|
32
|
+
if (typeof nodeBinding !== 'object' || nodeBinding === null) {
|
|
33
|
+
throw new TypeError('Invalid `options.nodeBinding`. Use @emnapi/node-binding package');
|
|
34
|
+
}
|
|
35
|
+
emnapiNodeBinding$1 = nodeBinding;
|
|
36
|
+
}
|
|
37
|
+
if ('asyncWorkPoolSize' in options) {
|
|
38
|
+
if (typeof options.asyncWorkPoolSize !== 'number') {
|
|
39
|
+
throw new TypeError('options.asyncWorkPoolSize must be a integer');
|
|
40
|
+
}
|
|
41
|
+
emnapiAsyncWorkPoolSize$1 = options.asyncWorkPoolSize >> 0;
|
|
42
|
+
if (emnapiAsyncWorkPoolSize$1 > 1024) {
|
|
43
|
+
emnapiAsyncWorkPoolSize$1 = 1024;
|
|
44
|
+
}
|
|
45
|
+
else if (emnapiAsyncWorkPoolSize$1 < -1024) {
|
|
46
|
+
emnapiAsyncWorkPoolSize$1 = -1024;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const NODE_MODULE_VERSION = 127 /* Version.NODE_MODULE_VERSION */;
|
|
50
|
+
const nodeRegisterModuleSymbol = `node_register_module_v${NODE_MODULE_VERSION}`;
|
|
51
|
+
const emscriptenExportedSymbol = `_${nodeRegisterModuleSymbol}`;
|
|
52
|
+
if (typeof Module[emscriptenExportedSymbol] === 'function') {
|
|
53
|
+
const scope = emnapiCtx$1.isolate.openScope();
|
|
54
|
+
try {
|
|
55
|
+
const exports = emnapiModule.exports;
|
|
56
|
+
const exportsHandle = scope.add(exports);
|
|
57
|
+
const moduleHandle = scope.add(emnapiModule);
|
|
58
|
+
Module[emscriptenExportedSymbol]({{{ to64('exportsHandle') }}}, {{{ to64('moduleHandle') }}}, {{{ to64('5') }}});
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
if (err !== 'unwind') {
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
emnapiCtx$1.isolate.closeScope(scope);
|
|
67
|
+
}
|
|
68
|
+
emnapiModule.loaded = true;
|
|
69
|
+
delete emnapiModule.envObject;
|
|
70
|
+
return emnapiModule.exports;
|
|
71
|
+
}
|
|
72
|
+
const find = Object.keys(Module).filter(k => k.startsWith('_node_register_module_v'));
|
|
73
|
+
if (find.length > 0) {
|
|
74
|
+
throw new Error(`The module${emnapiModule.filename ? ` '${emnapiModule.filename}'` : ''}
|
|
75
|
+
was compiled against a different Node.js version using
|
|
76
|
+
NODE_MODULE_VERSION ${find[0].slice(23)}. This version of Node.js requires
|
|
77
|
+
NODE_MODULE_VERSION ${NODE_MODULE_VERSION}.`);
|
|
78
|
+
}
|
|
79
|
+
const moduleApiVersion = Module._node_api_module_get_api_version_v1();
|
|
80
|
+
const envObject = emnapiModule.envObject || (() => {
|
|
81
|
+
let address = _emnapi_create_env();
|
|
82
|
+
{{{ from64('address') }}};
|
|
83
|
+
address += 8;
|
|
84
|
+
const envObject = emnapiModule.envObject = emnapiEnv$1 = emnapiCtx$1.createEnv(filename, moduleApiVersion, {
|
|
85
|
+
address,
|
|
86
|
+
deleteEnv: (ptr) => {
|
|
87
|
+
_emnapi_delete_env({{{ to64('ptr') }}} - {{{ to64('8') }}});
|
|
88
|
+
},
|
|
89
|
+
setLastError(env, error_code, engine_error_code, engine_reserved) {
|
|
90
|
+
{{{ from64('env') }}};
|
|
91
|
+
env -= 8;
|
|
92
|
+
{{{ from64('engine_reserved') }}};
|
|
93
|
+
#if MEMORY64
|
|
94
|
+
{{{ makeSetValue('env', 60 /* NapiEnvOffset64.last_error_error_code */, 'error_code', 'i32') }}};
|
|
95
|
+
{{{ makeSetValue('env', 56 /* NapiEnvOffset64.last_error_engine_error_code */, 'engine_error_code', 'u32') }}};
|
|
96
|
+
{{{ makeSetValue('env', 48 /* NapiEnvOffset64.last_error_engine_reserved */, 'engine_reserved', '*') }}};
|
|
97
|
+
#else
|
|
98
|
+
{{{ makeSetValue('env', 40 /* NapiEnvOffset32.last_error_error_code */, 'error_code', 'i32') }}};
|
|
99
|
+
{{{ makeSetValue('env', 36 /* NapiEnvOffset32.last_error_engine_error_code */, 'engine_error_code', 'u32') }}};
|
|
100
|
+
{{{ makeSetValue('env', 32 /* NapiEnvOffset32.last_error_engine_reserved */, 'engine_reserved', '*') }}};
|
|
101
|
+
#endif
|
|
102
|
+
return error_code;
|
|
103
|
+
},
|
|
104
|
+
makeDynCall_vppp: (cb) => {{{ makeDynCall('vppp', 'cb') }}},
|
|
105
|
+
makeDynCall_vp: (cb) => {{{ makeDynCall('vp', 'cb') }}},
|
|
106
|
+
abort
|
|
107
|
+
}, emnapiNodeBinding$1);
|
|
108
|
+
#if MEMORY64
|
|
109
|
+
{{{ makeSetValue('address - 8', 32 /* NapiEnvOffset64.id */, 'envObject.id', 'u32') }}};
|
|
110
|
+
#else
|
|
111
|
+
{{{ makeSetValue('address - 8', 24 /* NapiEnvOffset32.id */, 'envObject.id', 'u32') }}};
|
|
112
|
+
#endif
|
|
113
|
+
return envObject;
|
|
114
|
+
})();
|
|
115
|
+
const scope = emnapiCtx$1.openScope(envObject);
|
|
116
|
+
try {
|
|
117
|
+
envObject.callIntoModule((envObject) => {
|
|
118
|
+
const exports = emnapiModule.exports;
|
|
119
|
+
const env = envObject.bridge.address;
|
|
120
|
+
const exportsHandle = scope.add(exports);
|
|
121
|
+
const napiValue = Module._napi_register_wasm_v1({{{ to64('env') }}}, {{{ to64('exportsHandle') }}});
|
|
122
|
+
emnapiModule.exports = (!napiValue) ? exports : emnapiCtx$1.jsValueFromNapiValue(napiValue);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
if (err !== 'unwind') {
|
|
127
|
+
throw err;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
finally {
|
|
131
|
+
emnapiCtx$1.closeScope(envObject, scope);
|
|
132
|
+
}
|
|
133
|
+
emnapiModule.loaded = true;
|
|
134
|
+
delete emnapiModule.envObject;
|
|
135
|
+
return emnapiModule.exports;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* @__sig i
|
|
139
|
+
*/
|
|
140
|
+
function _emnapi_async_work_pool_size() {
|
|
141
|
+
return Math.abs(emnapiAsyncWorkPoolSize$1);
|
|
142
|
+
}
|
|
143
|
+
//#endregion src/emscripten/init.ts
|
|
144
|
+
//#region src/async-work.ts
|
|
145
|
+
/**
|
|
146
|
+
* @__deps $emnapiCtx
|
|
147
|
+
* @__deps $emnapiEnv
|
|
148
|
+
* @__deps $emnapiNodeBinding
|
|
149
|
+
* @__deps $emnapiAsyncWorkPoolSize
|
|
150
|
+
* @__postset
|
|
151
|
+
* ```
|
|
152
|
+
* emnapiAWST.init();
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
var emnapiAWST = {
|
|
156
|
+
idGen: {},
|
|
157
|
+
values: [undefined],
|
|
158
|
+
queued: new Set(),
|
|
159
|
+
pending: [],
|
|
160
|
+
init: function () {
|
|
161
|
+
const idGen = {
|
|
162
|
+
nextId: 1,
|
|
163
|
+
list: [],
|
|
164
|
+
generate: function () {
|
|
165
|
+
let id;
|
|
166
|
+
if (idGen.list.length) {
|
|
167
|
+
id = idGen.list.shift();
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
id = idGen.nextId;
|
|
171
|
+
idGen.nextId++;
|
|
172
|
+
}
|
|
173
|
+
return id;
|
|
174
|
+
},
|
|
175
|
+
reuse: function (id) {
|
|
176
|
+
idGen.list.push(id);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
emnapiAWST.idGen = idGen;
|
|
180
|
+
emnapiAWST.values = [undefined];
|
|
181
|
+
emnapiAWST.queued = new Set();
|
|
182
|
+
emnapiAWST.pending = [];
|
|
183
|
+
},
|
|
184
|
+
create: function (env, resource, resourceName, execute, complete, data) {
|
|
185
|
+
let asyncId = 0;
|
|
186
|
+
let triggerAsyncId = 0;
|
|
187
|
+
if (emnapiNodeBinding) {
|
|
188
|
+
const asyncContext = emnapiNodeBinding.node.emitAsyncInit(resource, resourceName, -1);
|
|
189
|
+
asyncId = asyncContext.asyncId;
|
|
190
|
+
triggerAsyncId = asyncContext.triggerAsyncId;
|
|
191
|
+
}
|
|
192
|
+
const id = emnapiAWST.idGen.generate();
|
|
193
|
+
emnapiAWST.values[id] = {
|
|
194
|
+
env,
|
|
195
|
+
id,
|
|
196
|
+
resource,
|
|
197
|
+
asyncId,
|
|
198
|
+
triggerAsyncId,
|
|
199
|
+
status: 0,
|
|
200
|
+
execute,
|
|
201
|
+
complete,
|
|
202
|
+
data
|
|
203
|
+
};
|
|
204
|
+
return id;
|
|
205
|
+
},
|
|
206
|
+
callComplete: function (work, status) {
|
|
207
|
+
const complete = work.complete;
|
|
208
|
+
const env = work.env;
|
|
209
|
+
const data = work.data;
|
|
210
|
+
const callback = () => {
|
|
211
|
+
if (!complete)
|
|
212
|
+
return;
|
|
213
|
+
const envObject = emnapiEnv$1;
|
|
214
|
+
const scope = emnapiCtx.openScope(envObject);
|
|
215
|
+
try {
|
|
216
|
+
envObject.callbackIntoModule(true, () => {
|
|
217
|
+
{{{ makeDynCall('vpip', 'complete') }}}(env, status, data);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
finally {
|
|
221
|
+
emnapiCtx.closeScope(envObject, scope);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
if (emnapiNodeBinding) {
|
|
225
|
+
emnapiNodeBinding.node.makeCallback(work.resource, callback, [], {
|
|
226
|
+
asyncId: work.asyncId,
|
|
227
|
+
triggerAsyncId: work.triggerAsyncId
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
callback();
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
queue: function (id) {
|
|
235
|
+
const work = emnapiAWST.values[id];
|
|
236
|
+
if (!work)
|
|
237
|
+
return;
|
|
238
|
+
if (work.status === 0) {
|
|
239
|
+
work.status = 1;
|
|
240
|
+
if (emnapiAWST.queued.size >= (Math.abs(emnapiAsyncWorkPoolSize) || 4)) {
|
|
241
|
+
emnapiAWST.pending.push(id);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
emnapiAWST.queued.add(id);
|
|
245
|
+
const env = work.env;
|
|
246
|
+
const data = work.data;
|
|
247
|
+
const execute = work.execute;
|
|
248
|
+
work.status = 2;
|
|
249
|
+
emnapiCtx.features.setImmediate(() => {
|
|
250
|
+
{{{ makeDynCall('vpp', 'execute') }}}(env, data);
|
|
251
|
+
emnapiAWST.queued.delete(id);
|
|
252
|
+
work.status = 3;
|
|
253
|
+
emnapiCtx.features.setImmediate(() => {
|
|
254
|
+
emnapiAWST.callComplete(work, 0 /* napi_status.napi_ok */);
|
|
255
|
+
});
|
|
256
|
+
if (emnapiAWST.pending.length > 0) {
|
|
257
|
+
const nextWorkId = emnapiAWST.pending.shift();
|
|
258
|
+
emnapiAWST.values[nextWorkId].status = 0;
|
|
259
|
+
emnapiAWST.queue(nextWorkId);
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
cancel: function (id) {
|
|
265
|
+
const index = emnapiAWST.pending.indexOf(id);
|
|
266
|
+
if (index !== -1) {
|
|
267
|
+
const work = emnapiAWST.values[id];
|
|
268
|
+
if (work && (work.status === 1)) {
|
|
269
|
+
work.status = 4;
|
|
270
|
+
emnapiAWST.pending.splice(index, 1);
|
|
271
|
+
emnapiCtx.features.setImmediate(() => {
|
|
272
|
+
emnapiAWST.callComplete(work, 11 /* napi_status.napi_cancelled */);
|
|
273
|
+
});
|
|
274
|
+
return 0 /* napi_status.napi_ok */;
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
return 9 /* napi_status.napi_generic_failure */;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return 9 /* napi_status.napi_generic_failure */;
|
|
281
|
+
},
|
|
282
|
+
remove: function (id) {
|
|
283
|
+
const work = emnapiAWST.values[id];
|
|
284
|
+
if (!work)
|
|
285
|
+
return;
|
|
286
|
+
if (emnapiNodeBinding) {
|
|
287
|
+
emnapiNodeBinding.node.emitAsyncDestroy({
|
|
288
|
+
asyncId: work.asyncId,
|
|
289
|
+
triggerAsyncId: work.triggerAsyncId
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
emnapiAWST.values[id] = undefined;
|
|
293
|
+
emnapiAWST.idGen.reuse(id);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
//#endregion src/async-work.ts
|
|
297
|
+
//#region src/macro.ts
|
|
298
|
+
//#endregion src/macro.ts
|
|
299
|
+
//#region src/emscripten/async-work.ts
|
|
300
|
+
/**
|
|
301
|
+
* @__deps $emnapiCtx
|
|
302
|
+
* @__deps $emnapiEnv
|
|
303
|
+
* @__sig ippppppp
|
|
304
|
+
*/
|
|
305
|
+
function _napi_create_async_work(env, resource, resource_name, execute, complete, data, result) {
|
|
306
|
+
if (!env)
|
|
307
|
+
return 1 /* napi_status.napi_invalid_arg */;
|
|
308
|
+
// @ts-expect-error
|
|
309
|
+
const envObject = emnapiEnv;
|
|
310
|
+
envObject.checkGCAccess();
|
|
311
|
+
if (!execute)
|
|
312
|
+
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
313
|
+
if (!result)
|
|
314
|
+
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
315
|
+
let resourceObject;
|
|
316
|
+
if (resource) {
|
|
317
|
+
resourceObject = Object(emnapiCtx.jsValueFromNapiValue(resource));
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
resourceObject = {};
|
|
321
|
+
}
|
|
322
|
+
if (!resource_name)
|
|
323
|
+
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
324
|
+
const resourceName = String(emnapiCtx.jsValueFromNapiValue(resource_name));
|
|
325
|
+
const id = emnapiAWST.create(env, resourceObject, resourceName, execute, complete, data);
|
|
326
|
+
{{{ from64('result') }}};
|
|
327
|
+
{{{ makeSetValue('result', 0, 'id', '*') }}};
|
|
328
|
+
return envObject.clearLastError();
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* @__deps $emnapiCtx
|
|
332
|
+
* @__sig ipp
|
|
333
|
+
*/
|
|
334
|
+
function _napi_delete_async_work(env, work) {
|
|
335
|
+
if (!env)
|
|
336
|
+
return 1 /* napi_status.napi_invalid_arg */;
|
|
337
|
+
// @ts-expect-error
|
|
338
|
+
const envObject = emnapiEnv;
|
|
339
|
+
envObject.checkGCAccess();
|
|
340
|
+
if (!work)
|
|
341
|
+
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
342
|
+
emnapiAWST.remove(work);
|
|
343
|
+
return envObject.clearLastError();
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* @__deps $emnapiCtx
|
|
347
|
+
* @__sig ipp
|
|
348
|
+
*/
|
|
349
|
+
function _napi_queue_async_work(env, work) {
|
|
350
|
+
if (!env)
|
|
351
|
+
return 1 /* napi_status.napi_invalid_arg */;
|
|
352
|
+
const envObject = emnapiEnv;
|
|
353
|
+
if (!work)
|
|
354
|
+
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
355
|
+
emnapiAWST.queue(work);
|
|
356
|
+
return envObject.clearLastError();
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* @__deps $emnapiCtx
|
|
360
|
+
* @__sig ipp
|
|
361
|
+
*/
|
|
362
|
+
function _napi_cancel_async_work(env, work) {
|
|
363
|
+
if (!env)
|
|
364
|
+
return 1 /* napi_status.napi_invalid_arg */;
|
|
365
|
+
const envObject = emnapiEnv;
|
|
366
|
+
if (!work)
|
|
367
|
+
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
368
|
+
const status = emnapiAWST.cancel(work);
|
|
369
|
+
if (status === 0 /* napi_status.napi_ok */)
|
|
370
|
+
return envObject.clearLastError();
|
|
371
|
+
return envObject.setLastError(status);
|
|
372
|
+
}
|
|
373
|
+
(typeof addToLibrary === "function" ? addToLibrary : (...args) => mergeInto(LibraryManager.library, ...args))({
|
|
374
|
+
$emnapiEnv$1: "undefined",
|
|
375
|
+
$emnapiAWST: emnapiAWST,
|
|
376
|
+
$emnapiAWST__deps: ["$emnapiEnv$1", "$emnapiCtx", "$emnapiEnv", "$emnapiNodeBinding", "$emnapiAsyncWorkPoolSize"],
|
|
377
|
+
$emnapiAWST__postset: "emnapiAWST.init();",
|
|
378
|
+
napi_cancel_async_work: _napi_cancel_async_work,
|
|
379
|
+
napi_cancel_async_work__deps: ["$emnapiAWST", "$emnapiCtx"],
|
|
380
|
+
napi_cancel_async_work__sig: "ipp",
|
|
381
|
+
napi_create_async_work: _napi_create_async_work,
|
|
382
|
+
napi_create_async_work__deps: ["$emnapiAWST", "$emnapiCtx", "$emnapiEnv"],
|
|
383
|
+
napi_create_async_work__sig: "ippppppp",
|
|
384
|
+
napi_delete_async_work: _napi_delete_async_work,
|
|
385
|
+
napi_delete_async_work__deps: ["$emnapiAWST", "$emnapiCtx"],
|
|
386
|
+
napi_delete_async_work__sig: "ipp",
|
|
387
|
+
napi_queue_async_work: _napi_queue_async_work,
|
|
388
|
+
napi_queue_async_work__deps: ["$emnapiAWST", "$emnapiCtx"],
|
|
389
|
+
napi_queue_async_work__sig: "ipp"
|
|
390
|
+
});
|