@emnapi/runtime 0.31.0
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 +1 -0
- package/dist/emnapi.cjs.js +1133 -0
- package/dist/emnapi.cjs.min.js +1 -0
- package/dist/emnapi.d.ts +557 -0
- package/dist/emnapi.esm-bundler.js +1167 -0
- package/dist/emnapi.iife.d.ts +325 -0
- package/dist/emnapi.iife.js +1230 -0
- package/dist/emnapi.js +1231 -0
- package/dist/emnapi.min.js +1 -0
- package/dist/emnapi.min.mjs +1 -0
- package/dist/emnapi.mjs +1105 -0
- package/index.js +5 -0
- package/package.json +52 -0
|
@@ -0,0 +1,1230 @@
|
|
|
1
|
+
var emnapi = (function (exports) {
|
|
2
|
+
|
|
3
|
+
var CallbackInfo = /*#__PURE__*/ (function () {
|
|
4
|
+
function CallbackInfo(parent, thiz, data, args, fn) {
|
|
5
|
+
this.parent = parent;
|
|
6
|
+
this.thiz = thiz;
|
|
7
|
+
this.data = data;
|
|
8
|
+
this.args = args;
|
|
9
|
+
this.fn = fn;
|
|
10
|
+
}
|
|
11
|
+
CallbackInfo.prototype.getNewTarget = function (envObject) {
|
|
12
|
+
var thiz = this.thiz;
|
|
13
|
+
if (thiz == null || thiz.constructor == null)
|
|
14
|
+
return 0;
|
|
15
|
+
return thiz instanceof this.fn ? envObject.ensureHandleId(thiz.constructor) : 0;
|
|
16
|
+
};
|
|
17
|
+
return CallbackInfo;
|
|
18
|
+
}());
|
|
19
|
+
var CallbackInfoStack = /*#__PURE__*/ (function () {
|
|
20
|
+
function CallbackInfoStack() {
|
|
21
|
+
this.current = null;
|
|
22
|
+
}
|
|
23
|
+
CallbackInfoStack.prototype.pop = function () {
|
|
24
|
+
var current = this.current;
|
|
25
|
+
if (current === null)
|
|
26
|
+
return;
|
|
27
|
+
this.current = current.parent;
|
|
28
|
+
};
|
|
29
|
+
CallbackInfoStack.prototype.push = function (thiz, data, args, fn) {
|
|
30
|
+
var info = new CallbackInfo(this.current, thiz, data, args, fn);
|
|
31
|
+
this.current = info;
|
|
32
|
+
return info;
|
|
33
|
+
};
|
|
34
|
+
CallbackInfoStack.prototype.dispose = function () {
|
|
35
|
+
this.current = null;
|
|
36
|
+
};
|
|
37
|
+
return CallbackInfoStack;
|
|
38
|
+
}());
|
|
39
|
+
|
|
40
|
+
/******************************************************************************
|
|
41
|
+
Copyright (c) Microsoft Corporation.
|
|
42
|
+
|
|
43
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
44
|
+
purpose with or without fee is hereby granted.
|
|
45
|
+
|
|
46
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
47
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
48
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
49
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
50
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
51
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
52
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
53
|
+
***************************************************************************** */
|
|
54
|
+
/* global Reflect, Promise */
|
|
55
|
+
|
|
56
|
+
var extendStatics = function(d, b) {
|
|
57
|
+
extendStatics = Object.setPrototypeOf ||
|
|
58
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
59
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
60
|
+
return extendStatics(d, b);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
function __extends(d, b) {
|
|
64
|
+
if (typeof b !== "function" && b !== null)
|
|
65
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
66
|
+
extendStatics(d, b);
|
|
67
|
+
function __() { this.constructor = d; }
|
|
68
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
var Store = /*#__PURE__*/ (function () {
|
|
72
|
+
function Store(capacity) {
|
|
73
|
+
this._values = [undefined];
|
|
74
|
+
this._values.length = capacity;
|
|
75
|
+
this._size = 1;
|
|
76
|
+
this._freeList = [];
|
|
77
|
+
}
|
|
78
|
+
Store.prototype.add = function (value) {
|
|
79
|
+
var id;
|
|
80
|
+
if (this._freeList.length) {
|
|
81
|
+
id = this._freeList.shift();
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
id = this._size;
|
|
85
|
+
this._size++;
|
|
86
|
+
var capacity = this._values.length;
|
|
87
|
+
if (id >= capacity) {
|
|
88
|
+
this._values.length = Math.ceil(capacity * 1.5);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
value.id = id;
|
|
92
|
+
this._values[id] = value;
|
|
93
|
+
};
|
|
94
|
+
Store.prototype.get = function (id) {
|
|
95
|
+
return this._values[id];
|
|
96
|
+
};
|
|
97
|
+
Store.prototype.has = function (id) {
|
|
98
|
+
return this._values[id] !== undefined;
|
|
99
|
+
};
|
|
100
|
+
Store.prototype.remove = function (id) {
|
|
101
|
+
var value = this._values[id];
|
|
102
|
+
if (value) {
|
|
103
|
+
value.id = 0;
|
|
104
|
+
this._values[id] = undefined;
|
|
105
|
+
this._freeList.push(Number(id));
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
Store.prototype.dispose = function () {
|
|
109
|
+
for (var i = 1; i < this._size; ++i) {
|
|
110
|
+
var value = this._values[i];
|
|
111
|
+
value === null || value === void 0 ? void 0 : value.dispose();
|
|
112
|
+
}
|
|
113
|
+
this._values = [undefined];
|
|
114
|
+
this._size = 1;
|
|
115
|
+
this._freeList = [];
|
|
116
|
+
};
|
|
117
|
+
return Store;
|
|
118
|
+
}());
|
|
119
|
+
|
|
120
|
+
var EnvStore = /*#__PURE__*/ (function (_super) {
|
|
121
|
+
__extends(EnvStore, _super);
|
|
122
|
+
function EnvStore() {
|
|
123
|
+
return _super.call(this, 2) || this;
|
|
124
|
+
}
|
|
125
|
+
return EnvStore;
|
|
126
|
+
}(Store));
|
|
127
|
+
|
|
128
|
+
var supportNewFunction = /*#__PURE__*/ (function () {
|
|
129
|
+
var f;
|
|
130
|
+
try {
|
|
131
|
+
f = new Function();
|
|
132
|
+
}
|
|
133
|
+
catch (_) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
return typeof f === 'function';
|
|
137
|
+
})();
|
|
138
|
+
var _global = /*#__PURE__*/ (function () {
|
|
139
|
+
if (typeof globalThis !== 'undefined')
|
|
140
|
+
return globalThis;
|
|
141
|
+
var g = (function () { return this; })();
|
|
142
|
+
if (!g && supportNewFunction) {
|
|
143
|
+
try {
|
|
144
|
+
g = new Function('return this')();
|
|
145
|
+
}
|
|
146
|
+
catch (_) { }
|
|
147
|
+
}
|
|
148
|
+
if (!g) {
|
|
149
|
+
if (typeof __webpack_public_path__ === 'undefined') {
|
|
150
|
+
if (typeof global !== 'undefined')
|
|
151
|
+
return global;
|
|
152
|
+
}
|
|
153
|
+
if (typeof window !== 'undefined')
|
|
154
|
+
return window;
|
|
155
|
+
if (typeof self !== 'undefined')
|
|
156
|
+
return self;
|
|
157
|
+
}
|
|
158
|
+
return g;
|
|
159
|
+
})();
|
|
160
|
+
var emptyException = new Error();
|
|
161
|
+
var TryCatch = /*#__PURE__*/ (function () {
|
|
162
|
+
function TryCatch() {
|
|
163
|
+
this._exception = emptyException;
|
|
164
|
+
}
|
|
165
|
+
TryCatch.prototype.hasCaught = function () {
|
|
166
|
+
return this._exception !== emptyException;
|
|
167
|
+
};
|
|
168
|
+
TryCatch.prototype.exception = function () {
|
|
169
|
+
return this._exception;
|
|
170
|
+
};
|
|
171
|
+
TryCatch.prototype.setError = function (err) {
|
|
172
|
+
this._exception = err;
|
|
173
|
+
};
|
|
174
|
+
TryCatch.prototype.reset = function () {
|
|
175
|
+
this._exception = emptyException;
|
|
176
|
+
};
|
|
177
|
+
TryCatch.prototype.extractException = function () {
|
|
178
|
+
var e = this._exception;
|
|
179
|
+
this.reset();
|
|
180
|
+
return e;
|
|
181
|
+
};
|
|
182
|
+
return TryCatch;
|
|
183
|
+
}());
|
|
184
|
+
var canSetFunctionName = /*#__PURE__*/ (function () {
|
|
185
|
+
var _a;
|
|
186
|
+
try {
|
|
187
|
+
return Boolean((_a = Object.getOwnPropertyDescriptor(Function.prototype, 'name')) === null || _a === void 0 ? void 0 : _a.configurable);
|
|
188
|
+
}
|
|
189
|
+
catch (_) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
})();
|
|
193
|
+
var supportReflect = typeof Reflect === 'object';
|
|
194
|
+
var supportFinalizer = (typeof FinalizationRegistry !== 'undefined') && (typeof WeakRef !== 'undefined');
|
|
195
|
+
var supportBigInt = typeof BigInt !== 'undefined';
|
|
196
|
+
function isReferenceType(v) {
|
|
197
|
+
return (typeof v === 'object' && v !== null) || typeof v === 'function';
|
|
198
|
+
}
|
|
199
|
+
var _setImmediate = typeof setImmediate === 'function'
|
|
200
|
+
? setImmediate
|
|
201
|
+
: function (f) {
|
|
202
|
+
if (typeof f !== 'function')
|
|
203
|
+
return;
|
|
204
|
+
var channel = new MessageChannel();
|
|
205
|
+
channel.port1.onmessage = function () {
|
|
206
|
+
channel.port1.onmessage = null;
|
|
207
|
+
channel = undefined;
|
|
208
|
+
f();
|
|
209
|
+
};
|
|
210
|
+
channel.port2.postMessage(null);
|
|
211
|
+
};
|
|
212
|
+
var _require = /*#__PURE__*/ (function () {
|
|
213
|
+
var nativeRequire;
|
|
214
|
+
if (typeof __webpack_public_path__ !== 'undefined') {
|
|
215
|
+
nativeRequire = (function () {
|
|
216
|
+
return typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined;
|
|
217
|
+
})();
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
nativeRequire = (function () {
|
|
221
|
+
return typeof __webpack_public_path__ !== 'undefined' ? (typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined) : (typeof require !== 'undefined' ? require : undefined);
|
|
222
|
+
})();
|
|
223
|
+
}
|
|
224
|
+
return nativeRequire;
|
|
225
|
+
})();
|
|
226
|
+
var Buffer = /*#__PURE__*/ (function () {
|
|
227
|
+
if (typeof _global.Buffer === 'function')
|
|
228
|
+
return _global.Buffer;
|
|
229
|
+
try {
|
|
230
|
+
return _require('buffer').Buffer;
|
|
231
|
+
}
|
|
232
|
+
catch (_) { }
|
|
233
|
+
return undefined;
|
|
234
|
+
})();
|
|
235
|
+
|
|
236
|
+
var Handle = /*#__PURE__*/ (function () {
|
|
237
|
+
function Handle(id, value) {
|
|
238
|
+
this.id = id;
|
|
239
|
+
this.value = value;
|
|
240
|
+
}
|
|
241
|
+
Handle.prototype.init = function (id, value) {
|
|
242
|
+
this.id = id;
|
|
243
|
+
this.value = value;
|
|
244
|
+
};
|
|
245
|
+
Handle.prototype.data = function (envObject) {
|
|
246
|
+
return envObject.getObjectBinding(this.value).data;
|
|
247
|
+
};
|
|
248
|
+
Handle.prototype.isEmpty = function () {
|
|
249
|
+
return this.id === 0;
|
|
250
|
+
};
|
|
251
|
+
Handle.prototype.isNumber = function () {
|
|
252
|
+
return !this.isEmpty() && typeof this.value === 'number';
|
|
253
|
+
};
|
|
254
|
+
Handle.prototype.isBigInt = function () {
|
|
255
|
+
return !this.isEmpty() && typeof this.value === 'bigint';
|
|
256
|
+
};
|
|
257
|
+
Handle.prototype.isString = function () {
|
|
258
|
+
return !this.isEmpty() && typeof this.value === 'string';
|
|
259
|
+
};
|
|
260
|
+
Handle.prototype.isFunction = function () {
|
|
261
|
+
return !this.isEmpty() && typeof this.value === 'function';
|
|
262
|
+
};
|
|
263
|
+
Handle.prototype.isExternal = function () {
|
|
264
|
+
return !this.isEmpty() && (isReferenceType(this.value) && Object.getPrototypeOf(this.value) === null);
|
|
265
|
+
};
|
|
266
|
+
Handle.prototype.isObject = function () {
|
|
267
|
+
return !this.isEmpty() && typeof this.value === 'object' && this.value !== null;
|
|
268
|
+
};
|
|
269
|
+
Handle.prototype.isArray = function () {
|
|
270
|
+
return !this.isEmpty() && Array.isArray(this.value);
|
|
271
|
+
};
|
|
272
|
+
Handle.prototype.isArrayBuffer = function () {
|
|
273
|
+
return !this.isEmpty() && (this.value instanceof ArrayBuffer);
|
|
274
|
+
};
|
|
275
|
+
Handle.prototype.isTypedArray = function () {
|
|
276
|
+
return !this.isEmpty() && (ArrayBuffer.isView(this.value)) && !(this.value instanceof DataView);
|
|
277
|
+
};
|
|
278
|
+
Handle.prototype.isBuffer = function () {
|
|
279
|
+
return !this.isEmpty() && typeof Buffer === 'function' && Buffer.isBuffer(this.value);
|
|
280
|
+
};
|
|
281
|
+
Handle.prototype.isDataView = function () {
|
|
282
|
+
return !this.isEmpty() && (this.value instanceof DataView);
|
|
283
|
+
};
|
|
284
|
+
Handle.prototype.isDate = function () {
|
|
285
|
+
return !this.isEmpty() && (this.value instanceof Date);
|
|
286
|
+
};
|
|
287
|
+
Handle.prototype.isPromise = function () {
|
|
288
|
+
return !this.isEmpty() && (this.value instanceof Promise);
|
|
289
|
+
};
|
|
290
|
+
Handle.prototype.isBoolean = function () {
|
|
291
|
+
return !this.isEmpty() && typeof this.value === 'boolean';
|
|
292
|
+
};
|
|
293
|
+
Handle.prototype.isUndefined = function () {
|
|
294
|
+
return !this.isEmpty() && this.value === undefined;
|
|
295
|
+
};
|
|
296
|
+
Handle.prototype.isSymbol = function () {
|
|
297
|
+
return !this.isEmpty() && typeof this.value === 'symbol';
|
|
298
|
+
};
|
|
299
|
+
Handle.prototype.isNull = function () {
|
|
300
|
+
return !this.isEmpty() && this.value === null;
|
|
301
|
+
};
|
|
302
|
+
Handle.prototype.dispose = function () {
|
|
303
|
+
if (this.id === 0)
|
|
304
|
+
return;
|
|
305
|
+
this.id = 0;
|
|
306
|
+
this.value = undefined;
|
|
307
|
+
};
|
|
308
|
+
return Handle;
|
|
309
|
+
}());
|
|
310
|
+
var ConstHandle = /*#__PURE__*/ (function (_super) {
|
|
311
|
+
__extends(ConstHandle, _super);
|
|
312
|
+
function ConstHandle(id, value) {
|
|
313
|
+
return _super.call(this, id, value) || this;
|
|
314
|
+
}
|
|
315
|
+
ConstHandle.prototype.dispose = function () { };
|
|
316
|
+
return ConstHandle;
|
|
317
|
+
}(Handle));
|
|
318
|
+
function External() {
|
|
319
|
+
Object.setPrototypeOf(this, null);
|
|
320
|
+
}
|
|
321
|
+
External.prototype = null;
|
|
322
|
+
var HandleStore = /*#__PURE__*/ (function () {
|
|
323
|
+
function HandleStore() {
|
|
324
|
+
this._values = [
|
|
325
|
+
undefined,
|
|
326
|
+
HandleStore.UNDEFINED,
|
|
327
|
+
HandleStore.NULL,
|
|
328
|
+
HandleStore.FALSE,
|
|
329
|
+
HandleStore.TRUE,
|
|
330
|
+
HandleStore.GLOBAL
|
|
331
|
+
];
|
|
332
|
+
this._next = HandleStore.MIN_ID;
|
|
333
|
+
}
|
|
334
|
+
HandleStore.prototype.push = function (value) {
|
|
335
|
+
var h;
|
|
336
|
+
var next = this._next;
|
|
337
|
+
var values = this._values;
|
|
338
|
+
if (next < values.length) {
|
|
339
|
+
h = values[next];
|
|
340
|
+
h.init(next, value);
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
h = new Handle(next, value);
|
|
344
|
+
values[next] = h;
|
|
345
|
+
}
|
|
346
|
+
this._next++;
|
|
347
|
+
return h;
|
|
348
|
+
};
|
|
349
|
+
HandleStore.prototype.erase = function (start, end) {
|
|
350
|
+
this._next = start;
|
|
351
|
+
var values = this._values;
|
|
352
|
+
for (var i = start; i < end; ++i) {
|
|
353
|
+
values[i].dispose();
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
HandleStore.prototype.get = function (id) {
|
|
357
|
+
return this._values[id];
|
|
358
|
+
};
|
|
359
|
+
HandleStore.prototype.swap = function (a, b) {
|
|
360
|
+
var values = this._values;
|
|
361
|
+
var h = values[a];
|
|
362
|
+
values[a] = values[b];
|
|
363
|
+
values[a].id = Number(a);
|
|
364
|
+
values[b] = h;
|
|
365
|
+
h.id = Number(b);
|
|
366
|
+
};
|
|
367
|
+
HandleStore.prototype.dispose = function () {
|
|
368
|
+
this._values.length = HandleStore.MIN_ID;
|
|
369
|
+
this._next = HandleStore.MIN_ID;
|
|
370
|
+
};
|
|
371
|
+
HandleStore.UNDEFINED = new ConstHandle(1 /* GlobalHandle.UNDEFINED */, undefined);
|
|
372
|
+
HandleStore.NULL = new ConstHandle(2 /* GlobalHandle.NULL */, null);
|
|
373
|
+
HandleStore.FALSE = new ConstHandle(3 /* GlobalHandle.FALSE */, false);
|
|
374
|
+
HandleStore.TRUE = new ConstHandle(4 /* GlobalHandle.TRUE */, true);
|
|
375
|
+
HandleStore.GLOBAL = new ConstHandle(5 /* GlobalHandle.GLOBAL */, _global);
|
|
376
|
+
HandleStore.MIN_ID = 6;
|
|
377
|
+
return HandleStore;
|
|
378
|
+
}());
|
|
379
|
+
|
|
380
|
+
var HandleScope = /*#__PURE__*/ (function () {
|
|
381
|
+
function HandleScope(handleStore, id, parentScope, start, end) {
|
|
382
|
+
if (end === void 0) { end = start; }
|
|
383
|
+
this.handleStore = handleStore;
|
|
384
|
+
this.id = id;
|
|
385
|
+
this.parent = parentScope;
|
|
386
|
+
this.child = null;
|
|
387
|
+
if (parentScope !== null)
|
|
388
|
+
parentScope.child = this;
|
|
389
|
+
this.start = start;
|
|
390
|
+
this.end = end;
|
|
391
|
+
this._escapeCalled = false;
|
|
392
|
+
}
|
|
393
|
+
HandleScope.prototype.add = function (value) {
|
|
394
|
+
var h = this.handleStore.push(value);
|
|
395
|
+
this.end++;
|
|
396
|
+
return h;
|
|
397
|
+
};
|
|
398
|
+
HandleScope.prototype.addExternal = function (envObject, data) {
|
|
399
|
+
var value = new External();
|
|
400
|
+
var h = envObject.ctx.handleStore.push(value);
|
|
401
|
+
var binding = envObject.initObjectBinding(value);
|
|
402
|
+
binding.data = data;
|
|
403
|
+
this.end++;
|
|
404
|
+
return h;
|
|
405
|
+
};
|
|
406
|
+
HandleScope.prototype.dispose = function () {
|
|
407
|
+
if (this.start === this.end)
|
|
408
|
+
return;
|
|
409
|
+
this.handleStore.erase(this.start, this.end);
|
|
410
|
+
};
|
|
411
|
+
HandleScope.prototype.escape = function (handle) {
|
|
412
|
+
if (this._escapeCalled)
|
|
413
|
+
return null;
|
|
414
|
+
this._escapeCalled = true;
|
|
415
|
+
if (handle < this.start || handle >= this.end) {
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
this.handleStore.swap(handle, this.start);
|
|
419
|
+
var h = this.handleStore.get(this.start);
|
|
420
|
+
this.start++;
|
|
421
|
+
this.parent.end++;
|
|
422
|
+
return h;
|
|
423
|
+
};
|
|
424
|
+
HandleScope.prototype.escapeCalled = function () {
|
|
425
|
+
return this._escapeCalled;
|
|
426
|
+
};
|
|
427
|
+
return HandleScope;
|
|
428
|
+
}());
|
|
429
|
+
|
|
430
|
+
var ScopeStore = /*#__PURE__*/ (function () {
|
|
431
|
+
function ScopeStore() {
|
|
432
|
+
this._rootScope = new HandleScope(null, 0, null, 1, HandleStore.MIN_ID);
|
|
433
|
+
this.currentScope = this._rootScope;
|
|
434
|
+
}
|
|
435
|
+
ScopeStore.prototype.get = function (id) {
|
|
436
|
+
id = Number(id);
|
|
437
|
+
var scope = this.currentScope;
|
|
438
|
+
while (scope !== this._rootScope) {
|
|
439
|
+
if (scope.id === id) {
|
|
440
|
+
return scope;
|
|
441
|
+
}
|
|
442
|
+
scope = scope.parent;
|
|
443
|
+
}
|
|
444
|
+
return undefined;
|
|
445
|
+
};
|
|
446
|
+
ScopeStore.prototype.openScope = function (envObject) {
|
|
447
|
+
var currentScope = this.currentScope;
|
|
448
|
+
var scope = currentScope.child;
|
|
449
|
+
if (scope !== null) {
|
|
450
|
+
scope.start = scope.end = currentScope.end;
|
|
451
|
+
scope._escapeCalled = false;
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
scope = new HandleScope(envObject.ctx.handleStore, currentScope.id + 1, currentScope, currentScope.end);
|
|
455
|
+
}
|
|
456
|
+
this.currentScope = scope;
|
|
457
|
+
envObject.openHandleScopes++;
|
|
458
|
+
return scope;
|
|
459
|
+
};
|
|
460
|
+
ScopeStore.prototype.closeScope = function (envObject) {
|
|
461
|
+
if (envObject.openHandleScopes === 0)
|
|
462
|
+
return;
|
|
463
|
+
var scope = this.currentScope;
|
|
464
|
+
this.currentScope = scope.parent;
|
|
465
|
+
scope.dispose();
|
|
466
|
+
envObject.openHandleScopes--;
|
|
467
|
+
};
|
|
468
|
+
ScopeStore.prototype.dispose = function () {
|
|
469
|
+
var scope = this.currentScope;
|
|
470
|
+
while (scope !== null) {
|
|
471
|
+
scope.handleStore = null;
|
|
472
|
+
scope.id = 0;
|
|
473
|
+
scope.parent = null;
|
|
474
|
+
scope.start = HandleStore.MIN_ID;
|
|
475
|
+
scope.end = HandleStore.MIN_ID;
|
|
476
|
+
scope._escapeCalled = false;
|
|
477
|
+
var child = scope.child;
|
|
478
|
+
scope.child = null;
|
|
479
|
+
scope = child;
|
|
480
|
+
}
|
|
481
|
+
this.currentScope = null;
|
|
482
|
+
};
|
|
483
|
+
return ScopeStore;
|
|
484
|
+
}());
|
|
485
|
+
|
|
486
|
+
var RefStore = /*#__PURE__*/ (function (_super) {
|
|
487
|
+
__extends(RefStore, _super);
|
|
488
|
+
function RefStore() {
|
|
489
|
+
return _super.call(this, 8) || this;
|
|
490
|
+
}
|
|
491
|
+
return RefStore;
|
|
492
|
+
}(Store));
|
|
493
|
+
|
|
494
|
+
var DeferredStore = /*#__PURE__*/ (function (_super) {
|
|
495
|
+
__extends(DeferredStore, _super);
|
|
496
|
+
function DeferredStore() {
|
|
497
|
+
return _super.call(this, 8) || this;
|
|
498
|
+
}
|
|
499
|
+
return DeferredStore;
|
|
500
|
+
}(Store));
|
|
501
|
+
|
|
502
|
+
var RefTracker = /*#__PURE__*/ (function () {
|
|
503
|
+
function RefTracker() {
|
|
504
|
+
this._next = null;
|
|
505
|
+
this._prev = null;
|
|
506
|
+
}
|
|
507
|
+
/** @virtual */
|
|
508
|
+
RefTracker.prototype.finalize = function () { };
|
|
509
|
+
RefTracker.prototype.link = function (list) {
|
|
510
|
+
this._prev = list;
|
|
511
|
+
this._next = list._next;
|
|
512
|
+
if (this._next !== null) {
|
|
513
|
+
this._next._prev = this;
|
|
514
|
+
}
|
|
515
|
+
list._next = this;
|
|
516
|
+
};
|
|
517
|
+
RefTracker.prototype.unlink = function () {
|
|
518
|
+
if (this._prev !== null) {
|
|
519
|
+
this._prev._next = this._next;
|
|
520
|
+
}
|
|
521
|
+
if (this._next !== null) {
|
|
522
|
+
this._next._prev = this._prev;
|
|
523
|
+
}
|
|
524
|
+
this._prev = null;
|
|
525
|
+
this._next = null;
|
|
526
|
+
};
|
|
527
|
+
RefTracker.finalizeAll = function (list) {
|
|
528
|
+
while (list._next !== null) {
|
|
529
|
+
list._next.finalize();
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
return RefTracker;
|
|
533
|
+
}());
|
|
534
|
+
|
|
535
|
+
var Finalizer = /*#__PURE__*/ (function () {
|
|
536
|
+
function Finalizer(envObject, _finalizeCallback, _finalizeData, _finalizeHint) {
|
|
537
|
+
if (_finalizeCallback === void 0) { _finalizeCallback = 0; }
|
|
538
|
+
if (_finalizeData === void 0) { _finalizeData = 0; }
|
|
539
|
+
if (_finalizeHint === void 0) { _finalizeHint = 0; }
|
|
540
|
+
this.envObject = envObject;
|
|
541
|
+
this._finalizeCallback = _finalizeCallback;
|
|
542
|
+
this._finalizeData = _finalizeData;
|
|
543
|
+
this._finalizeHint = _finalizeHint;
|
|
544
|
+
}
|
|
545
|
+
Finalizer.prototype.callback = function () { return this._finalizeCallback; };
|
|
546
|
+
Finalizer.prototype.data = function () { return this._finalizeData; };
|
|
547
|
+
Finalizer.prototype.hint = function () { return this._finalizeHint; };
|
|
548
|
+
Finalizer.prototype.resetFinalizer = function () {
|
|
549
|
+
this._finalizeCallback = 0;
|
|
550
|
+
this._finalizeData = 0;
|
|
551
|
+
this._finalizeHint = 0;
|
|
552
|
+
};
|
|
553
|
+
Finalizer.prototype.dispose = function () {
|
|
554
|
+
this.envObject = undefined;
|
|
555
|
+
};
|
|
556
|
+
return Finalizer;
|
|
557
|
+
}());
|
|
558
|
+
|
|
559
|
+
var RefBase = /*#__PURE__*/ (function (_super) {
|
|
560
|
+
__extends(RefBase, _super);
|
|
561
|
+
function RefBase(envObject, initial_refcount, ownership, finalize_callback, finalize_data, finalize_hint) {
|
|
562
|
+
var _this = _super.call(this, envObject, finalize_callback, finalize_data, finalize_hint) || this;
|
|
563
|
+
_this._next = null;
|
|
564
|
+
_this._prev = null;
|
|
565
|
+
_this._refcount = initial_refcount;
|
|
566
|
+
_this._ownership = ownership;
|
|
567
|
+
_this.link(!finalize_callback ? envObject.reflist : envObject.finalizing_reflist);
|
|
568
|
+
return _this;
|
|
569
|
+
}
|
|
570
|
+
RefBase.finalizeAll = function (list) {
|
|
571
|
+
RefTracker.finalizeAll(list);
|
|
572
|
+
};
|
|
573
|
+
RefBase.prototype.link = function (list) {
|
|
574
|
+
RefTracker.prototype.link.call(this, list);
|
|
575
|
+
};
|
|
576
|
+
RefBase.prototype.unlink = function () {
|
|
577
|
+
RefTracker.prototype.unlink.call(this);
|
|
578
|
+
};
|
|
579
|
+
RefBase.prototype.dispose = function () {
|
|
580
|
+
this.unlink();
|
|
581
|
+
this.envObject.dequeueFinalizer(this);
|
|
582
|
+
_super.prototype.dispose.call(this);
|
|
583
|
+
};
|
|
584
|
+
RefBase.prototype.data = function () {
|
|
585
|
+
return this._finalizeData;
|
|
586
|
+
};
|
|
587
|
+
RefBase.prototype.ref = function () {
|
|
588
|
+
return ++this._refcount;
|
|
589
|
+
};
|
|
590
|
+
RefBase.prototype.unref = function () {
|
|
591
|
+
if (this._refcount === 0) {
|
|
592
|
+
return 0;
|
|
593
|
+
}
|
|
594
|
+
return --this._refcount;
|
|
595
|
+
};
|
|
596
|
+
RefBase.prototype.refCount = function () {
|
|
597
|
+
return this._refcount;
|
|
598
|
+
};
|
|
599
|
+
RefBase.prototype.ownership = function () {
|
|
600
|
+
return this._ownership;
|
|
601
|
+
};
|
|
602
|
+
RefBase.prototype.finalize = function () {
|
|
603
|
+
var ownership = this._ownership;
|
|
604
|
+
// Swap out the field finalize_callback so that it can not be accidentally
|
|
605
|
+
// called more than once.
|
|
606
|
+
var finalize_callback = this._finalizeCallback;
|
|
607
|
+
var finalize_data = this._finalizeData;
|
|
608
|
+
var finalize_hint = this._finalizeHint;
|
|
609
|
+
this.resetFinalizer();
|
|
610
|
+
this.unlink();
|
|
611
|
+
var error;
|
|
612
|
+
var caught = false;
|
|
613
|
+
if (finalize_callback) {
|
|
614
|
+
var fini = Number(finalize_callback);
|
|
615
|
+
try {
|
|
616
|
+
this.envObject.callFinalizer(fini, finalize_data, finalize_hint);
|
|
617
|
+
}
|
|
618
|
+
catch (err) {
|
|
619
|
+
caught = true;
|
|
620
|
+
error = err;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
if (ownership === 0 /* Ownership.kRuntime */) {
|
|
624
|
+
this.dispose();
|
|
625
|
+
}
|
|
626
|
+
if (caught) {
|
|
627
|
+
throw error;
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
return RefBase;
|
|
631
|
+
}(Finalizer));
|
|
632
|
+
|
|
633
|
+
var Env = /*#__PURE__*/ (function () {
|
|
634
|
+
function Env(ctx, makeDynCall_vppp, makeDynCall_vp) {
|
|
635
|
+
this.ctx = ctx;
|
|
636
|
+
this.makeDynCall_vppp = makeDynCall_vppp;
|
|
637
|
+
this.makeDynCall_vp = makeDynCall_vp;
|
|
638
|
+
this.openHandleScopes = 0;
|
|
639
|
+
this.instanceData = null;
|
|
640
|
+
this.tryCatch = new TryCatch();
|
|
641
|
+
this.refs = 1;
|
|
642
|
+
this.reflist = new RefTracker();
|
|
643
|
+
this.finalizing_reflist = new RefTracker();
|
|
644
|
+
this.destructing = false;
|
|
645
|
+
this.finalizationScheduled = false;
|
|
646
|
+
this.pendingFinalizers = [];
|
|
647
|
+
this.lastError = {
|
|
648
|
+
errorCode: 0 /* napi_status.napi_ok */,
|
|
649
|
+
engineErrorCode: 0,
|
|
650
|
+
engineReserved: 0
|
|
651
|
+
};
|
|
652
|
+
this._bindingMap = new WeakMap();
|
|
653
|
+
this.id = 0;
|
|
654
|
+
}
|
|
655
|
+
Env.create = function (ctx, makeDynCall_vppp, makeDynCall_vp) {
|
|
656
|
+
var env = new Env(ctx, makeDynCall_vppp, makeDynCall_vp);
|
|
657
|
+
ctx.envStore.add(env);
|
|
658
|
+
ctx.addCleanupHook(env, function () { env.unref(); }, 0);
|
|
659
|
+
return env;
|
|
660
|
+
};
|
|
661
|
+
Env.prototype.ref = function () {
|
|
662
|
+
this.refs++;
|
|
663
|
+
};
|
|
664
|
+
Env.prototype.unref = function () {
|
|
665
|
+
this.refs--;
|
|
666
|
+
if (this.refs === 0) {
|
|
667
|
+
this.dispose();
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
Env.prototype.ensureHandle = function (value) {
|
|
671
|
+
return this.ctx.ensureHandle(value);
|
|
672
|
+
};
|
|
673
|
+
Env.prototype.ensureHandleId = function (value) {
|
|
674
|
+
return this.ensureHandle(value).id;
|
|
675
|
+
};
|
|
676
|
+
Env.prototype.clearLastError = function () {
|
|
677
|
+
var lastError = this.lastError;
|
|
678
|
+
lastError.errorCode = 0 /* napi_status.napi_ok */;
|
|
679
|
+
lastError.engineErrorCode = 0;
|
|
680
|
+
lastError.engineReserved = 0;
|
|
681
|
+
return 0 /* napi_status.napi_ok */;
|
|
682
|
+
};
|
|
683
|
+
Env.prototype.setLastError = function (error_code, engine_error_code, engine_reserved) {
|
|
684
|
+
if (engine_error_code === void 0) { engine_error_code = 0; }
|
|
685
|
+
if (engine_reserved === void 0) { engine_reserved = 0; }
|
|
686
|
+
var lastError = this.lastError;
|
|
687
|
+
lastError.errorCode = error_code;
|
|
688
|
+
lastError.engineErrorCode = engine_error_code;
|
|
689
|
+
lastError.engineReserved = engine_reserved;
|
|
690
|
+
return error_code;
|
|
691
|
+
};
|
|
692
|
+
Env.prototype.getReturnStatus = function () {
|
|
693
|
+
return !this.tryCatch.hasCaught() ? 0 /* napi_status.napi_ok */ : this.setLastError(10 /* napi_status.napi_pending_exception */);
|
|
694
|
+
};
|
|
695
|
+
Env.prototype.callIntoModule = function (fn) {
|
|
696
|
+
this.clearLastError();
|
|
697
|
+
var r = fn(this);
|
|
698
|
+
if (this.tryCatch.hasCaught()) {
|
|
699
|
+
var err = this.tryCatch.extractException();
|
|
700
|
+
throw err;
|
|
701
|
+
}
|
|
702
|
+
return r;
|
|
703
|
+
};
|
|
704
|
+
Env.prototype.callFinalizer = function (cb, data, hint) {
|
|
705
|
+
var f = this.makeDynCall_vppp(cb);
|
|
706
|
+
var env = this.id;
|
|
707
|
+
var scope = this.ctx.openScope(this);
|
|
708
|
+
try {
|
|
709
|
+
this.callIntoModule(function () { f(env, data, hint); });
|
|
710
|
+
}
|
|
711
|
+
finally {
|
|
712
|
+
this.ctx.closeScope(this, scope);
|
|
713
|
+
}
|
|
714
|
+
};
|
|
715
|
+
Env.prototype.enqueueFinalizer = function (finalizer) {
|
|
716
|
+
var _this = this;
|
|
717
|
+
if (this.pendingFinalizers.indexOf(finalizer) === -1) {
|
|
718
|
+
this.pendingFinalizers.push(finalizer);
|
|
719
|
+
}
|
|
720
|
+
if (!this.finalizationScheduled && !this.destructing) {
|
|
721
|
+
this.finalizationScheduled = true;
|
|
722
|
+
this.ref();
|
|
723
|
+
_setImmediate(function () {
|
|
724
|
+
_this.finalizationScheduled = false;
|
|
725
|
+
_this.unref();
|
|
726
|
+
_this.drainFinalizerQueue();
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
Env.prototype.dequeueFinalizer = function (finalizer) {
|
|
731
|
+
var index = this.pendingFinalizers.indexOf(finalizer);
|
|
732
|
+
if (index !== -1) {
|
|
733
|
+
this.pendingFinalizers.splice(index, 1);
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
Env.prototype.drainFinalizerQueue = function () {
|
|
737
|
+
while (this.pendingFinalizers.length > 0) {
|
|
738
|
+
var refTracker = this.pendingFinalizers.shift();
|
|
739
|
+
refTracker.finalize();
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
Env.prototype.dispose = function () {
|
|
743
|
+
if (this.id === 0)
|
|
744
|
+
return;
|
|
745
|
+
this.destructing = true;
|
|
746
|
+
this.drainFinalizerQueue();
|
|
747
|
+
RefBase.finalizeAll(this.finalizing_reflist);
|
|
748
|
+
RefBase.finalizeAll(this.reflist);
|
|
749
|
+
this.tryCatch.extractException();
|
|
750
|
+
this.ctx.envStore.remove(this.id);
|
|
751
|
+
this.id = 0;
|
|
752
|
+
};
|
|
753
|
+
Env.prototype.initObjectBinding = function (value) {
|
|
754
|
+
var binding = {
|
|
755
|
+
wrapped: 0,
|
|
756
|
+
tag: null,
|
|
757
|
+
data: 0
|
|
758
|
+
};
|
|
759
|
+
this._bindingMap.set(value, binding);
|
|
760
|
+
return binding;
|
|
761
|
+
};
|
|
762
|
+
Env.prototype.getObjectBinding = function (value) {
|
|
763
|
+
if (this._bindingMap.has(value)) {
|
|
764
|
+
return this._bindingMap.get(value);
|
|
765
|
+
}
|
|
766
|
+
return this.initObjectBinding(value);
|
|
767
|
+
};
|
|
768
|
+
Env.prototype.setInstanceData = function (data, finalize_cb, finalize_hint) {
|
|
769
|
+
if (this.instanceData) {
|
|
770
|
+
this.instanceData.dispose();
|
|
771
|
+
}
|
|
772
|
+
this.instanceData = new RefBase(this, 0, 0 /* Ownership.kRuntime */, finalize_cb, data, finalize_hint);
|
|
773
|
+
};
|
|
774
|
+
Env.prototype.getInstanceData = function () {
|
|
775
|
+
return this.instanceData ? this.instanceData.data() : 0;
|
|
776
|
+
};
|
|
777
|
+
return Env;
|
|
778
|
+
}());
|
|
779
|
+
|
|
780
|
+
var EmnapiError = /*#__PURE__*/ (function (_super) {
|
|
781
|
+
__extends(EmnapiError, _super);
|
|
782
|
+
function EmnapiError(message) {
|
|
783
|
+
var _newTarget = this.constructor;
|
|
784
|
+
var _this = _super.call(this, message) || this;
|
|
785
|
+
var ErrorConstructor = _newTarget;
|
|
786
|
+
var proto = ErrorConstructor.prototype;
|
|
787
|
+
if (!(_this instanceof EmnapiError)) {
|
|
788
|
+
var setPrototypeOf = Object.setPrototypeOf;
|
|
789
|
+
if (typeof setPrototypeOf === 'function') {
|
|
790
|
+
setPrototypeOf.call(Object, _this, proto);
|
|
791
|
+
}
|
|
792
|
+
else {
|
|
793
|
+
// eslint-disable-next-line no-proto
|
|
794
|
+
_this.__proto__ = proto;
|
|
795
|
+
}
|
|
796
|
+
if (typeof Error.captureStackTrace === 'function') {
|
|
797
|
+
Error.captureStackTrace(_this, ErrorConstructor);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
return _this;
|
|
801
|
+
}
|
|
802
|
+
return EmnapiError;
|
|
803
|
+
}(Error));
|
|
804
|
+
Object.defineProperty(EmnapiError.prototype, 'name', {
|
|
805
|
+
configurable: true,
|
|
806
|
+
writable: true,
|
|
807
|
+
value: 'EmnapiError'
|
|
808
|
+
});
|
|
809
|
+
var NotSupportWeakRefError = /*#__PURE__*/ (function (_super) {
|
|
810
|
+
__extends(NotSupportWeakRefError, _super);
|
|
811
|
+
function NotSupportWeakRefError(api, message) {
|
|
812
|
+
return _super.call(this, "".concat(api, ": The current runtime does not support \"FinalizationRegistry\" and \"WeakRef\".").concat(message ? " ".concat(message) : '')) || this;
|
|
813
|
+
}
|
|
814
|
+
return NotSupportWeakRefError;
|
|
815
|
+
}(EmnapiError));
|
|
816
|
+
Object.defineProperty(NotSupportWeakRefError.prototype, 'name', {
|
|
817
|
+
configurable: true,
|
|
818
|
+
writable: true,
|
|
819
|
+
value: 'NotSupportWeakRefError'
|
|
820
|
+
});
|
|
821
|
+
var NotSupportBigIntError = /*#__PURE__*/ (function (_super) {
|
|
822
|
+
__extends(NotSupportBigIntError, _super);
|
|
823
|
+
function NotSupportBigIntError(api, message) {
|
|
824
|
+
return _super.call(this, "".concat(api, ": The current runtime does not support \"BigInt\".").concat(message ? " ".concat(message) : '')) || this;
|
|
825
|
+
}
|
|
826
|
+
return NotSupportBigIntError;
|
|
827
|
+
}(EmnapiError));
|
|
828
|
+
Object.defineProperty(NotSupportBigIntError.prototype, 'name', {
|
|
829
|
+
configurable: true,
|
|
830
|
+
writable: true,
|
|
831
|
+
value: 'NotSupportBigIntError'
|
|
832
|
+
});
|
|
833
|
+
|
|
834
|
+
var Persistent = /*#__PURE__*/ (function () {
|
|
835
|
+
function Persistent(value) {
|
|
836
|
+
this._ref = value;
|
|
837
|
+
}
|
|
838
|
+
Persistent.prototype.setWeak = function (param, callback) {
|
|
839
|
+
if (this._ref === null)
|
|
840
|
+
return;
|
|
841
|
+
if (!supportFinalizer)
|
|
842
|
+
return;
|
|
843
|
+
if (this._ref instanceof WeakRef)
|
|
844
|
+
return;
|
|
845
|
+
this._param = param;
|
|
846
|
+
this._callback = callback;
|
|
847
|
+
Persistent._registry.register(this._ref, this, this);
|
|
848
|
+
this._ref = new WeakRef(this._ref);
|
|
849
|
+
};
|
|
850
|
+
Persistent.prototype.clearWeak = function () {
|
|
851
|
+
if (this._ref === null)
|
|
852
|
+
return;
|
|
853
|
+
if (!supportFinalizer)
|
|
854
|
+
return;
|
|
855
|
+
if (this._ref instanceof WeakRef) {
|
|
856
|
+
try {
|
|
857
|
+
Persistent._registry.unregister(this);
|
|
858
|
+
}
|
|
859
|
+
catch (_) { }
|
|
860
|
+
this._param = undefined;
|
|
861
|
+
this._callback = undefined;
|
|
862
|
+
this._ref = this._ref.deref();
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
Persistent.prototype.reset = function (other) {
|
|
866
|
+
if (supportFinalizer) {
|
|
867
|
+
try {
|
|
868
|
+
Persistent._registry.unregister(this);
|
|
869
|
+
}
|
|
870
|
+
catch (_) { }
|
|
871
|
+
}
|
|
872
|
+
this._param = undefined;
|
|
873
|
+
this._callback = undefined;
|
|
874
|
+
if (other) {
|
|
875
|
+
this._ref = other;
|
|
876
|
+
}
|
|
877
|
+
else {
|
|
878
|
+
this._ref = null;
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
Persistent.prototype.isEmpty = function () {
|
|
882
|
+
return this._ref === null;
|
|
883
|
+
};
|
|
884
|
+
Persistent.prototype.deref = function () {
|
|
885
|
+
var _a;
|
|
886
|
+
if (!supportFinalizer) {
|
|
887
|
+
return (_a = this._ref) !== null && _a !== void 0 ? _a : undefined;
|
|
888
|
+
}
|
|
889
|
+
if (this._ref === null)
|
|
890
|
+
return undefined;
|
|
891
|
+
if (this._ref instanceof WeakRef) {
|
|
892
|
+
return this._ref.deref();
|
|
893
|
+
}
|
|
894
|
+
return this._ref;
|
|
895
|
+
};
|
|
896
|
+
Persistent._registry = supportFinalizer
|
|
897
|
+
? new FinalizationRegistry(function (value) {
|
|
898
|
+
value._ref = null;
|
|
899
|
+
var callback = value._callback;
|
|
900
|
+
var param = value._param;
|
|
901
|
+
value._callback = undefined;
|
|
902
|
+
value._param = undefined;
|
|
903
|
+
if (typeof callback === 'function') {
|
|
904
|
+
callback(param);
|
|
905
|
+
}
|
|
906
|
+
})
|
|
907
|
+
: undefined;
|
|
908
|
+
return Persistent;
|
|
909
|
+
}());
|
|
910
|
+
|
|
911
|
+
function weakCallback(ref) {
|
|
912
|
+
ref.persistent.reset();
|
|
913
|
+
ref.envObject.enqueueFinalizer(ref);
|
|
914
|
+
}
|
|
915
|
+
var Reference = /*#__PURE__*/ (function (_super) {
|
|
916
|
+
__extends(Reference, _super);
|
|
917
|
+
function Reference(envObject, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
|
|
918
|
+
if (finalize_callback === void 0) { finalize_callback = 0; }
|
|
919
|
+
if (finalize_data === void 0) { finalize_data = 0; }
|
|
920
|
+
if (finalize_hint === void 0) { finalize_hint = 0; }
|
|
921
|
+
var _this = _super.call(this, envObject, initialRefcount >>> 0, ownership, finalize_callback, finalize_data, finalize_hint) || this;
|
|
922
|
+
_this.id = 0;
|
|
923
|
+
return _this;
|
|
924
|
+
}
|
|
925
|
+
Reference.create = function (envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
|
|
926
|
+
if (finalize_callback === void 0) { finalize_callback = 0; }
|
|
927
|
+
if (finalize_data === void 0) { finalize_data = 0; }
|
|
928
|
+
if (finalize_hint === void 0) { finalize_hint = 0; }
|
|
929
|
+
var handle = envObject.ctx.handleStore.get(handle_id);
|
|
930
|
+
if (!isReferenceType(handle.value)) {
|
|
931
|
+
throw new TypeError('Invalid reference value');
|
|
932
|
+
}
|
|
933
|
+
var ref = new Reference(envObject, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
|
|
934
|
+
envObject.ctx.refStore.add(ref);
|
|
935
|
+
ref.persistent = new Persistent(handle.value);
|
|
936
|
+
if (initialRefcount === 0) {
|
|
937
|
+
ref._setWeak();
|
|
938
|
+
}
|
|
939
|
+
return ref;
|
|
940
|
+
};
|
|
941
|
+
Reference.prototype.ref = function () {
|
|
942
|
+
if (this.persistent.isEmpty()) {
|
|
943
|
+
return 0;
|
|
944
|
+
}
|
|
945
|
+
var count = _super.prototype.ref.call(this);
|
|
946
|
+
if (count === 1) {
|
|
947
|
+
var obj = this.persistent.deref();
|
|
948
|
+
if (obj) {
|
|
949
|
+
this.persistent.clearWeak();
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
return count;
|
|
953
|
+
};
|
|
954
|
+
Reference.prototype.unref = function () {
|
|
955
|
+
if (this.persistent.isEmpty()) {
|
|
956
|
+
return 0;
|
|
957
|
+
}
|
|
958
|
+
var oldRefcount = this.refCount();
|
|
959
|
+
var refcount = _super.prototype.unref.call(this);
|
|
960
|
+
if (oldRefcount === 1 && refcount === 0) {
|
|
961
|
+
var obj = this.persistent.deref();
|
|
962
|
+
if (obj) {
|
|
963
|
+
this._setWeak();
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
return refcount;
|
|
967
|
+
};
|
|
968
|
+
Reference.prototype.get = function () {
|
|
969
|
+
var obj = this.persistent.deref();
|
|
970
|
+
if (obj) {
|
|
971
|
+
var handle = this.envObject.ensureHandle(obj);
|
|
972
|
+
return handle.id;
|
|
973
|
+
}
|
|
974
|
+
return 0;
|
|
975
|
+
};
|
|
976
|
+
Reference.prototype._setWeak = function () {
|
|
977
|
+
this.persistent.setWeak(this, weakCallback);
|
|
978
|
+
};
|
|
979
|
+
Reference.prototype.finalize = function () {
|
|
980
|
+
this.persistent.reset();
|
|
981
|
+
_super.prototype.finalize.call(this);
|
|
982
|
+
};
|
|
983
|
+
Reference.prototype.dispose = function () {
|
|
984
|
+
if (this.id === 0)
|
|
985
|
+
return;
|
|
986
|
+
this.persistent.reset();
|
|
987
|
+
this.envObject.ctx.refStore.remove(this.id);
|
|
988
|
+
_super.prototype.dispose.call(this);
|
|
989
|
+
this.id = 0;
|
|
990
|
+
};
|
|
991
|
+
return Reference;
|
|
992
|
+
}(RefBase));
|
|
993
|
+
|
|
994
|
+
var Deferred = /*#__PURE__*/ (function () {
|
|
995
|
+
function Deferred(ctx, value) {
|
|
996
|
+
this.id = 0;
|
|
997
|
+
this.ctx = ctx;
|
|
998
|
+
this.value = value;
|
|
999
|
+
}
|
|
1000
|
+
Deferred.create = function (ctx, value) {
|
|
1001
|
+
var deferred = new Deferred(ctx, value);
|
|
1002
|
+
ctx.deferredStore.add(deferred);
|
|
1003
|
+
return deferred;
|
|
1004
|
+
};
|
|
1005
|
+
Deferred.prototype.resolve = function (value) {
|
|
1006
|
+
this.value.resolve(value);
|
|
1007
|
+
this.dispose();
|
|
1008
|
+
};
|
|
1009
|
+
Deferred.prototype.reject = function (reason) {
|
|
1010
|
+
this.value.reject(reason);
|
|
1011
|
+
this.dispose();
|
|
1012
|
+
};
|
|
1013
|
+
Deferred.prototype.dispose = function () {
|
|
1014
|
+
this.ctx.deferredStore.remove(this.id);
|
|
1015
|
+
this.id = 0;
|
|
1016
|
+
this.value = null;
|
|
1017
|
+
this.ctx = null;
|
|
1018
|
+
};
|
|
1019
|
+
return Deferred;
|
|
1020
|
+
}());
|
|
1021
|
+
|
|
1022
|
+
var CleanupHookCallback = /*#__PURE__*/ (function () {
|
|
1023
|
+
function CleanupHookCallback(envObject, fn, arg, order) {
|
|
1024
|
+
this.envObject = envObject;
|
|
1025
|
+
this.fn = fn;
|
|
1026
|
+
this.arg = arg;
|
|
1027
|
+
this.order = order;
|
|
1028
|
+
}
|
|
1029
|
+
return CleanupHookCallback;
|
|
1030
|
+
}());
|
|
1031
|
+
var CleanupQueue = /*#__PURE__*/ (function () {
|
|
1032
|
+
function CleanupQueue() {
|
|
1033
|
+
this._cleanupHooks = [];
|
|
1034
|
+
this._cleanupHookCounter = 0;
|
|
1035
|
+
}
|
|
1036
|
+
CleanupQueue.prototype.empty = function () {
|
|
1037
|
+
return this._cleanupHooks.length === 0;
|
|
1038
|
+
};
|
|
1039
|
+
CleanupQueue.prototype.add = function (envObject, fn, arg) {
|
|
1040
|
+
if (this._cleanupHooks.filter(function (hook) { return (hook.envObject === envObject && hook.fn === fn && hook.arg === arg); }).length > 0) {
|
|
1041
|
+
throw new Error('Can not add same fn and arg twice');
|
|
1042
|
+
}
|
|
1043
|
+
this._cleanupHooks.push(new CleanupHookCallback(envObject, fn, arg, this._cleanupHookCounter++));
|
|
1044
|
+
};
|
|
1045
|
+
CleanupQueue.prototype.remove = function (envObject, fn, arg) {
|
|
1046
|
+
for (var i = 0; i < this._cleanupHooks.length; ++i) {
|
|
1047
|
+
var hook = this._cleanupHooks[i];
|
|
1048
|
+
if (hook.envObject === envObject && hook.fn === fn && hook.arg === arg) {
|
|
1049
|
+
this._cleanupHooks.splice(i, 1);
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
};
|
|
1054
|
+
CleanupQueue.prototype.drain = function () {
|
|
1055
|
+
var hooks = this._cleanupHooks.slice();
|
|
1056
|
+
hooks.sort(function (a, b) { return (b.order - a.order); });
|
|
1057
|
+
for (var i = 0; i < hooks.length; ++i) {
|
|
1058
|
+
var cb = hooks[i];
|
|
1059
|
+
if (typeof cb.fn === 'number') {
|
|
1060
|
+
cb.envObject.makeDynCall_vp(cb.fn)(cb.arg);
|
|
1061
|
+
}
|
|
1062
|
+
else {
|
|
1063
|
+
cb.fn(cb.arg);
|
|
1064
|
+
}
|
|
1065
|
+
this._cleanupHooks.splice(this._cleanupHooks.indexOf(cb), 1);
|
|
1066
|
+
}
|
|
1067
|
+
};
|
|
1068
|
+
CleanupQueue.prototype.dispose = function () {
|
|
1069
|
+
this._cleanupHooks.length = 0;
|
|
1070
|
+
this._cleanupHookCounter = 0;
|
|
1071
|
+
};
|
|
1072
|
+
return CleanupQueue;
|
|
1073
|
+
}());
|
|
1074
|
+
var NodejsWaitingRequestCounter = /*#__PURE__*/ (function () {
|
|
1075
|
+
function NodejsWaitingRequestCounter() {
|
|
1076
|
+
this.refHandle = new MessageChannel().port1;
|
|
1077
|
+
this.count = 0;
|
|
1078
|
+
}
|
|
1079
|
+
NodejsWaitingRequestCounter.prototype.increase = function () {
|
|
1080
|
+
if (this.count === 0) {
|
|
1081
|
+
this.refHandle.ref();
|
|
1082
|
+
}
|
|
1083
|
+
this.count++;
|
|
1084
|
+
};
|
|
1085
|
+
NodejsWaitingRequestCounter.prototype.decrease = function () {
|
|
1086
|
+
if (this.count === 0)
|
|
1087
|
+
return;
|
|
1088
|
+
if (this.count === 1) {
|
|
1089
|
+
this.refHandle.unref();
|
|
1090
|
+
}
|
|
1091
|
+
this.count--;
|
|
1092
|
+
};
|
|
1093
|
+
return NodejsWaitingRequestCounter;
|
|
1094
|
+
}());
|
|
1095
|
+
var Context = /*#__PURE__*/ (function () {
|
|
1096
|
+
function Context() {
|
|
1097
|
+
var _this = this;
|
|
1098
|
+
this.envStore = new EnvStore();
|
|
1099
|
+
this.scopeStore = new ScopeStore();
|
|
1100
|
+
this.refStore = new RefStore();
|
|
1101
|
+
this.deferredStore = new DeferredStore();
|
|
1102
|
+
this.handleStore = new HandleStore();
|
|
1103
|
+
this.cbinfoStack = new CallbackInfoStack();
|
|
1104
|
+
this.feature = {
|
|
1105
|
+
supportReflect: supportReflect,
|
|
1106
|
+
supportFinalizer: supportFinalizer,
|
|
1107
|
+
supportBigInt: supportBigInt,
|
|
1108
|
+
supportNewFunction: supportNewFunction,
|
|
1109
|
+
canSetFunctionName: canSetFunctionName,
|
|
1110
|
+
setImmediate: _setImmediate,
|
|
1111
|
+
Buffer: Buffer
|
|
1112
|
+
};
|
|
1113
|
+
this.cleanupQueue = new CleanupQueue();
|
|
1114
|
+
if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
|
|
1115
|
+
this.refCounter = new NodejsWaitingRequestCounter();
|
|
1116
|
+
process.once('beforeExit', function () {
|
|
1117
|
+
_this.runCleanup();
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
Context.prototype.createNotSupportWeakRefError = function (api, message) {
|
|
1122
|
+
return new NotSupportWeakRefError(api, message);
|
|
1123
|
+
};
|
|
1124
|
+
Context.prototype.createNotSupportBigIntError = function (api, message) {
|
|
1125
|
+
return new NotSupportBigIntError(api, message);
|
|
1126
|
+
};
|
|
1127
|
+
Context.prototype.createReference = function (envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint) {
|
|
1128
|
+
if (finalize_callback === void 0) { finalize_callback = 0; }
|
|
1129
|
+
if (finalize_data === void 0) { finalize_data = 0; }
|
|
1130
|
+
if (finalize_hint === void 0) { finalize_hint = 0; }
|
|
1131
|
+
return Reference.create(envObject, handle_id, initialRefcount, ownership, finalize_callback, finalize_data, finalize_hint);
|
|
1132
|
+
};
|
|
1133
|
+
Context.prototype.createDeferred = function (value) {
|
|
1134
|
+
return Deferred.create(this, value);
|
|
1135
|
+
};
|
|
1136
|
+
Context.prototype.createEnv = function (makeDynCall_vppp, makeDynCall_vp) {
|
|
1137
|
+
return Env.create(this, makeDynCall_vppp, makeDynCall_vp);
|
|
1138
|
+
};
|
|
1139
|
+
Context.prototype.getCurrentScope = function () {
|
|
1140
|
+
return this.scopeStore.currentScope;
|
|
1141
|
+
};
|
|
1142
|
+
Context.prototype.addToCurrentScope = function (value) {
|
|
1143
|
+
return this.scopeStore.currentScope.add(value);
|
|
1144
|
+
};
|
|
1145
|
+
Context.prototype.openScope = function (envObject) {
|
|
1146
|
+
return this.scopeStore.openScope(envObject);
|
|
1147
|
+
};
|
|
1148
|
+
Context.prototype.closeScope = function (envObject, _scope) {
|
|
1149
|
+
return this.scopeStore.closeScope(envObject);
|
|
1150
|
+
};
|
|
1151
|
+
Context.prototype.ensureHandle = function (value) {
|
|
1152
|
+
switch (value) {
|
|
1153
|
+
case undefined: return HandleStore.UNDEFINED;
|
|
1154
|
+
case null: return HandleStore.NULL;
|
|
1155
|
+
case true: return HandleStore.TRUE;
|
|
1156
|
+
case false: return HandleStore.FALSE;
|
|
1157
|
+
case _global: return HandleStore.GLOBAL;
|
|
1158
|
+
}
|
|
1159
|
+
return this.addToCurrentScope(value);
|
|
1160
|
+
};
|
|
1161
|
+
Context.prototype.addCleanupHook = function (envObject, fn, arg) {
|
|
1162
|
+
this.cleanupQueue.add(envObject, fn, arg);
|
|
1163
|
+
};
|
|
1164
|
+
Context.prototype.removeCleanupHook = function (envObject, fn, arg) {
|
|
1165
|
+
this.cleanupQueue.remove(envObject, fn, arg);
|
|
1166
|
+
};
|
|
1167
|
+
Context.prototype.runCleanup = function () {
|
|
1168
|
+
while (!this.cleanupQueue.empty()) {
|
|
1169
|
+
this.cleanupQueue.drain();
|
|
1170
|
+
}
|
|
1171
|
+
};
|
|
1172
|
+
Context.prototype.increaseWaitingRequestCounter = function () {
|
|
1173
|
+
var _a;
|
|
1174
|
+
(_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.increase();
|
|
1175
|
+
};
|
|
1176
|
+
Context.prototype.decreaseWaitingRequestCounter = function () {
|
|
1177
|
+
var _a;
|
|
1178
|
+
(_a = this.refCounter) === null || _a === void 0 ? void 0 : _a.decrease();
|
|
1179
|
+
};
|
|
1180
|
+
Context.prototype.dispose = function () {
|
|
1181
|
+
this.runCleanup();
|
|
1182
|
+
};
|
|
1183
|
+
return Context;
|
|
1184
|
+
}());
|
|
1185
|
+
var defaultContext;
|
|
1186
|
+
function createContext() {
|
|
1187
|
+
return new Context();
|
|
1188
|
+
}
|
|
1189
|
+
function getDefaultContext() {
|
|
1190
|
+
if (!defaultContext) {
|
|
1191
|
+
defaultContext = createContext();
|
|
1192
|
+
}
|
|
1193
|
+
return defaultContext;
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
var version = "0.31.0";
|
|
1197
|
+
|
|
1198
|
+
exports.CallbackInfo = CallbackInfo;
|
|
1199
|
+
exports.CallbackInfoStack = CallbackInfoStack;
|
|
1200
|
+
exports.ConstHandle = ConstHandle;
|
|
1201
|
+
exports.Context = Context;
|
|
1202
|
+
exports.Deferred = Deferred;
|
|
1203
|
+
exports.DeferredStore = DeferredStore;
|
|
1204
|
+
exports.EmnapiError = EmnapiError;
|
|
1205
|
+
exports.Env = Env;
|
|
1206
|
+
exports.EnvStore = EnvStore;
|
|
1207
|
+
exports.Finalizer = Finalizer;
|
|
1208
|
+
exports.Handle = Handle;
|
|
1209
|
+
exports.HandleScope = HandleScope;
|
|
1210
|
+
exports.HandleStore = HandleStore;
|
|
1211
|
+
exports.NotSupportBigIntError = NotSupportBigIntError;
|
|
1212
|
+
exports.NotSupportWeakRefError = NotSupportWeakRefError;
|
|
1213
|
+
exports.Persistent = Persistent;
|
|
1214
|
+
exports.RefBase = RefBase;
|
|
1215
|
+
exports.RefStore = RefStore;
|
|
1216
|
+
exports.RefTracker = RefTracker;
|
|
1217
|
+
exports.Reference = Reference;
|
|
1218
|
+
exports.ScopeStore = ScopeStore;
|
|
1219
|
+
exports.Store = Store;
|
|
1220
|
+
exports.TryCatch = TryCatch;
|
|
1221
|
+
exports.createContext = createContext;
|
|
1222
|
+
exports.getDefaultContext = getDefaultContext;
|
|
1223
|
+
exports.isReferenceType = isReferenceType;
|
|
1224
|
+
exports.version = version;
|
|
1225
|
+
|
|
1226
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1227
|
+
|
|
1228
|
+
return exports;
|
|
1229
|
+
|
|
1230
|
+
})({});
|