@dacely/toilscript-loader 0.0.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/README.md +318 -0
- package/index.d.ts +124 -0
- package/index.js +453 -0
- package/package.json +53 -0
- package/umd/index.d.ts +1 -0
- package/umd/index.js +477 -0
- package/umd/package.json +4 -0
package/umd/index.js
ADDED
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
// GENERATED FILE. DO NOT EDIT.
|
|
2
|
+
(function (global, factory) {
|
|
3
|
+
function preferDefault(exports) {
|
|
4
|
+
return exports.default || exports;
|
|
5
|
+
}
|
|
6
|
+
if (typeof define === "function" && define.amd) {
|
|
7
|
+
define([], function () {
|
|
8
|
+
var exports = {};
|
|
9
|
+
factory(exports);
|
|
10
|
+
return preferDefault(exports);
|
|
11
|
+
});
|
|
12
|
+
} else if (typeof exports === "object") {
|
|
13
|
+
factory(exports);
|
|
14
|
+
if (typeof module === "object") module.exports = preferDefault(exports);
|
|
15
|
+
} else {
|
|
16
|
+
(function () {
|
|
17
|
+
var exports = {};
|
|
18
|
+
factory(exports);
|
|
19
|
+
global.loader = preferDefault(exports);
|
|
20
|
+
})();
|
|
21
|
+
}
|
|
22
|
+
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports) {
|
|
23
|
+
"use strict";
|
|
24
|
+
|
|
25
|
+
Object.defineProperty(_exports, "__esModule", {
|
|
26
|
+
value: true
|
|
27
|
+
});
|
|
28
|
+
_exports.default = void 0;
|
|
29
|
+
_exports.demangle = demangle;
|
|
30
|
+
_exports.instantiate = instantiate;
|
|
31
|
+
_exports.instantiateStreaming = instantiateStreaming;
|
|
32
|
+
_exports.instantiateSync = instantiateSync;
|
|
33
|
+
// Runtime header offsets
|
|
34
|
+
const ID_OFFSET = -8;
|
|
35
|
+
const SIZE_OFFSET = -4;
|
|
36
|
+
|
|
37
|
+
// Runtime ids
|
|
38
|
+
// const OBJECT_ID = 0;
|
|
39
|
+
const ARRAYBUFFER_ID = 1;
|
|
40
|
+
const STRING_ID = 2;
|
|
41
|
+
|
|
42
|
+
// Runtime type information
|
|
43
|
+
const ARRAYBUFFERVIEW = 1 << 0;
|
|
44
|
+
const ARRAY = 1 << 1;
|
|
45
|
+
const STATICARRAY = 1 << 2;
|
|
46
|
+
// const SET = 1 << 3;
|
|
47
|
+
// const MAP = 1 << 4;
|
|
48
|
+
const VAL_ALIGN_OFFSET = 6;
|
|
49
|
+
// const VAL_ALIGN = 1 << VAL_ALIGN_OFFSET;
|
|
50
|
+
const VAL_SIGNED = 1 << 11;
|
|
51
|
+
const VAL_FLOAT = 1 << 12;
|
|
52
|
+
// const VAL_NULLABLE = 1 << 13;
|
|
53
|
+
const VAL_MANAGED = 1 << 14;
|
|
54
|
+
// const KEY_ALIGN_OFFSET = 15;
|
|
55
|
+
// const KEY_ALIGN = 1 << KEY_ALIGN_OFFSET;
|
|
56
|
+
// const KEY_SIGNED = 1 << 20;
|
|
57
|
+
// const KEY_FLOAT = 1 << 21;
|
|
58
|
+
// const KEY_NULLABLE = 1 << 22;
|
|
59
|
+
// const KEY_MANAGED = 1 << 23;
|
|
60
|
+
|
|
61
|
+
// Array(BufferView) layout
|
|
62
|
+
const ARRAYBUFFERVIEW_BUFFER_OFFSET = 0;
|
|
63
|
+
const ARRAYBUFFERVIEW_DATASTART_OFFSET = 4;
|
|
64
|
+
const ARRAYBUFFERVIEW_BYTELENGTH_OFFSET = 8;
|
|
65
|
+
const ARRAYBUFFERVIEW_SIZE = 12;
|
|
66
|
+
const ARRAY_LENGTH_OFFSET = 12;
|
|
67
|
+
const ARRAY_SIZE = 16;
|
|
68
|
+
const E_NO_EXPORT_TABLE = "Operation requires compiling with --exportTable";
|
|
69
|
+
const E_NO_EXPORT_RUNTIME = "Operation requires compiling with --exportRuntime";
|
|
70
|
+
const F_NO_EXPORT_RUNTIME = () => {
|
|
71
|
+
throw Error(E_NO_EXPORT_RUNTIME);
|
|
72
|
+
};
|
|
73
|
+
const BIGINT = typeof BigUint64Array !== "undefined";
|
|
74
|
+
const THIS = Symbol();
|
|
75
|
+
const STRING_SMALLSIZE = 192; // break-even point in V8
|
|
76
|
+
const STRING_CHUNKSIZE = 1024; // mitigate stack overflow
|
|
77
|
+
const utf16 = new TextDecoder("utf-16le", {
|
|
78
|
+
fatal: true
|
|
79
|
+
}); // != wtf16
|
|
80
|
+
|
|
81
|
+
/** polyfill for Object.hasOwn */
|
|
82
|
+
Object.hasOwn = Object.hasOwn || function (obj, prop) {
|
|
83
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/** Gets a string from memory. */
|
|
87
|
+
function getStringImpl(buffer, ptr) {
|
|
88
|
+
let len = new Uint32Array(buffer)[ptr + SIZE_OFFSET >>> 2] >>> 1;
|
|
89
|
+
const wtf16 = new Uint16Array(buffer, ptr, len);
|
|
90
|
+
if (len <= STRING_SMALLSIZE) return String.fromCharCode(...wtf16);
|
|
91
|
+
try {
|
|
92
|
+
return utf16.decode(wtf16);
|
|
93
|
+
} catch {
|
|
94
|
+
let str = "",
|
|
95
|
+
off = 0;
|
|
96
|
+
while (len - off > STRING_CHUNKSIZE) {
|
|
97
|
+
str += String.fromCharCode(...wtf16.subarray(off, off += STRING_CHUNKSIZE));
|
|
98
|
+
}
|
|
99
|
+
return str + String.fromCharCode(...wtf16.subarray(off));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Prepares the base module prior to instantiation. */
|
|
104
|
+
function preInstantiate(imports) {
|
|
105
|
+
const extendedExports = {};
|
|
106
|
+
function getString(memory, ptr) {
|
|
107
|
+
if (!memory) return "<yet unknown>";
|
|
108
|
+
return getStringImpl(memory.buffer, ptr);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// add common imports used by stdlib for convenience
|
|
112
|
+
const env = imports.env = imports.env || {};
|
|
113
|
+
env.abort = env.abort || function abort(msg, file, line, colm) {
|
|
114
|
+
const memory = extendedExports.memory || env.memory; // prefer exported, otherwise try imported
|
|
115
|
+
throw Error(`abort: ${getString(memory, msg)} at ${getString(memory, file)}:${line}:${colm}`);
|
|
116
|
+
};
|
|
117
|
+
env.trace = env.trace || function trace(msg, n, ...args) {
|
|
118
|
+
const memory = extendedExports.memory || env.memory;
|
|
119
|
+
console.log(`trace: ${getString(memory, msg)}${n ? " " : ""}${args.slice(0, n).join(", ")}`);
|
|
120
|
+
};
|
|
121
|
+
env.seed = env.seed || Date.now;
|
|
122
|
+
imports.Math = imports.Math || Math;
|
|
123
|
+
imports.Date = imports.Date || Date;
|
|
124
|
+
return extendedExports;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Prepares the final module once instantiation is complete. */
|
|
128
|
+
function postInstantiate(extendedExports, instance) {
|
|
129
|
+
const exports = instance.exports;
|
|
130
|
+
const memory = exports.memory;
|
|
131
|
+
const table = exports.table;
|
|
132
|
+
const __new = exports.__new || F_NO_EXPORT_RUNTIME;
|
|
133
|
+
const __pin = exports.__pin || F_NO_EXPORT_RUNTIME;
|
|
134
|
+
const __unpin = exports.__unpin || F_NO_EXPORT_RUNTIME;
|
|
135
|
+
const __collect = exports.__collect || F_NO_EXPORT_RUNTIME;
|
|
136
|
+
const __rtti_base = exports.__rtti_base;
|
|
137
|
+
const getTypeinfoCount = __rtti_base ? arr => arr[__rtti_base >>> 2] : F_NO_EXPORT_RUNTIME;
|
|
138
|
+
extendedExports.__new = __new;
|
|
139
|
+
extendedExports.__pin = __pin;
|
|
140
|
+
extendedExports.__unpin = __unpin;
|
|
141
|
+
extendedExports.__collect = __collect;
|
|
142
|
+
|
|
143
|
+
/** Gets the runtime type info for the given id. */
|
|
144
|
+
function getTypeinfo(id) {
|
|
145
|
+
const U32 = new Uint32Array(memory.buffer);
|
|
146
|
+
if ((id >>>= 0) >= getTypeinfoCount(U32)) throw Error(`invalid id: ${id}`);
|
|
147
|
+
return U32[(__rtti_base + 4 >>> 2) + id];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Gets and validates runtime type info for the given id for array like objects */
|
|
151
|
+
function getArrayInfo(id) {
|
|
152
|
+
const info = getTypeinfo(id);
|
|
153
|
+
if (!(info & (ARRAYBUFFERVIEW | ARRAY | STATICARRAY))) throw Error(`not an array: ${id}, flags=${info}`);
|
|
154
|
+
return info;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Gets the runtime alignment of a collection's values. */
|
|
158
|
+
function getValueAlign(info) {
|
|
159
|
+
return 31 - Math.clz32(info >>> VAL_ALIGN_OFFSET & 31); // -1 if none
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Gets the runtime alignment of a collection's keys. */
|
|
163
|
+
// function getKeyAlign(info) {
|
|
164
|
+
// return 31 - Math.clz32((info >>> KEY_ALIGN_OFFSET) & 31); // -1 if none
|
|
165
|
+
// }
|
|
166
|
+
|
|
167
|
+
/** Allocates a new string in the module's memory and returns its pointer. */
|
|
168
|
+
function __newString(str) {
|
|
169
|
+
if (str == null) return 0;
|
|
170
|
+
const length = str.length;
|
|
171
|
+
const ptr = __new(length << 1, STRING_ID);
|
|
172
|
+
const U16 = new Uint16Array(memory.buffer);
|
|
173
|
+
for (let i = 0, p = ptr >>> 1; i < length; ++i) U16[p + i] = str.charCodeAt(i);
|
|
174
|
+
return ptr;
|
|
175
|
+
}
|
|
176
|
+
extendedExports.__newString = __newString;
|
|
177
|
+
|
|
178
|
+
/** Allocates a new ArrayBuffer in the module's memory and returns its pointer. */
|
|
179
|
+
function __newArrayBuffer(buf) {
|
|
180
|
+
if (buf == null) return 0;
|
|
181
|
+
const bufview = new Uint8Array(buf);
|
|
182
|
+
const ptr = __new(bufview.length, ARRAYBUFFER_ID);
|
|
183
|
+
const U8 = new Uint8Array(memory.buffer);
|
|
184
|
+
U8.set(bufview, ptr);
|
|
185
|
+
return ptr;
|
|
186
|
+
}
|
|
187
|
+
extendedExports.__newArrayBuffer = __newArrayBuffer;
|
|
188
|
+
|
|
189
|
+
/** Reads a string from the module's memory by its pointer. */
|
|
190
|
+
function __getString(ptr) {
|
|
191
|
+
if (!ptr) return null;
|
|
192
|
+
const buffer = memory.buffer;
|
|
193
|
+
const id = new Uint32Array(buffer)[ptr + ID_OFFSET >>> 2];
|
|
194
|
+
if (id !== STRING_ID) throw Error(`not a string: ${ptr}`);
|
|
195
|
+
return getStringImpl(buffer, ptr);
|
|
196
|
+
}
|
|
197
|
+
extendedExports.__getString = __getString;
|
|
198
|
+
|
|
199
|
+
/** Gets the view matching the specified alignment, signedness and floatness. */
|
|
200
|
+
function getView(alignLog2, signed, float) {
|
|
201
|
+
const buffer = memory.buffer;
|
|
202
|
+
if (float) {
|
|
203
|
+
switch (alignLog2) {
|
|
204
|
+
case 2:
|
|
205
|
+
return new Float32Array(buffer);
|
|
206
|
+
case 3:
|
|
207
|
+
return new Float64Array(buffer);
|
|
208
|
+
}
|
|
209
|
+
} else {
|
|
210
|
+
switch (alignLog2) {
|
|
211
|
+
case 0:
|
|
212
|
+
return new (signed ? Int8Array : Uint8Array)(buffer);
|
|
213
|
+
case 1:
|
|
214
|
+
return new (signed ? Int16Array : Uint16Array)(buffer);
|
|
215
|
+
case 2:
|
|
216
|
+
return new (signed ? Int32Array : Uint32Array)(buffer);
|
|
217
|
+
case 3:
|
|
218
|
+
return new (signed ? BigInt64Array : BigUint64Array)(buffer);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
throw Error(`unsupported align: ${alignLog2}`);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** Allocates a new array in the module's memory and returns its pointer. */
|
|
225
|
+
function __newArray(id, valuesOrCapacity = 0) {
|
|
226
|
+
const input = valuesOrCapacity;
|
|
227
|
+
const info = getArrayInfo(id);
|
|
228
|
+
const align = getValueAlign(info);
|
|
229
|
+
const isArrayLike = typeof input !== "number";
|
|
230
|
+
const length = isArrayLike ? input.length : input;
|
|
231
|
+
const buf = __new(length << align, info & STATICARRAY ? id : ARRAYBUFFER_ID);
|
|
232
|
+
let result;
|
|
233
|
+
if (info & STATICARRAY) {
|
|
234
|
+
result = buf;
|
|
235
|
+
} else {
|
|
236
|
+
__pin(buf);
|
|
237
|
+
const arr = __new(info & ARRAY ? ARRAY_SIZE : ARRAYBUFFERVIEW_SIZE, id);
|
|
238
|
+
__unpin(buf);
|
|
239
|
+
const U32 = new Uint32Array(memory.buffer);
|
|
240
|
+
U32[arr + ARRAYBUFFERVIEW_BUFFER_OFFSET >>> 2] = buf;
|
|
241
|
+
U32[arr + ARRAYBUFFERVIEW_DATASTART_OFFSET >>> 2] = buf;
|
|
242
|
+
U32[arr + ARRAYBUFFERVIEW_BYTELENGTH_OFFSET >>> 2] = length << align;
|
|
243
|
+
if (info & ARRAY) U32[arr + ARRAY_LENGTH_OFFSET >>> 2] = length;
|
|
244
|
+
result = arr;
|
|
245
|
+
}
|
|
246
|
+
if (isArrayLike) {
|
|
247
|
+
const view = getView(align, info & VAL_SIGNED, info & VAL_FLOAT);
|
|
248
|
+
const start = buf >>> align;
|
|
249
|
+
if (info & VAL_MANAGED) {
|
|
250
|
+
for (let i = 0; i < length; ++i) {
|
|
251
|
+
view[start + i] = input[i];
|
|
252
|
+
}
|
|
253
|
+
} else {
|
|
254
|
+
view.set(input, start);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return result;
|
|
258
|
+
}
|
|
259
|
+
extendedExports.__newArray = __newArray;
|
|
260
|
+
|
|
261
|
+
/** Gets a live view on an array's values in the module's memory. Infers the array type from RTTI. */
|
|
262
|
+
function __getArrayView(arr) {
|
|
263
|
+
const U32 = new Uint32Array(memory.buffer);
|
|
264
|
+
const id = U32[arr + ID_OFFSET >>> 2];
|
|
265
|
+
const info = getArrayInfo(id);
|
|
266
|
+
const align = getValueAlign(info);
|
|
267
|
+
let buf = info & STATICARRAY ? arr : U32[arr + ARRAYBUFFERVIEW_DATASTART_OFFSET >>> 2];
|
|
268
|
+
const length = info & ARRAY ? U32[arr + ARRAY_LENGTH_OFFSET >>> 2] : U32[buf + SIZE_OFFSET >>> 2] >>> align;
|
|
269
|
+
return getView(align, info & VAL_SIGNED, info & VAL_FLOAT).subarray(buf >>>= align, buf + length);
|
|
270
|
+
}
|
|
271
|
+
extendedExports.__getArrayView = __getArrayView;
|
|
272
|
+
|
|
273
|
+
/** Copies an array's values from the module's memory. Infers the array type from RTTI. */
|
|
274
|
+
function __getArray(arr) {
|
|
275
|
+
const input = __getArrayView(arr);
|
|
276
|
+
const len = input.length;
|
|
277
|
+
const out = new Array(len);
|
|
278
|
+
for (let i = 0; i < len; i++) out[i] = input[i];
|
|
279
|
+
return out;
|
|
280
|
+
}
|
|
281
|
+
extendedExports.__getArray = __getArray;
|
|
282
|
+
|
|
283
|
+
/** Copies an ArrayBuffer's value from the module's memory. */
|
|
284
|
+
function __getArrayBuffer(ptr) {
|
|
285
|
+
const buffer = memory.buffer;
|
|
286
|
+
const length = new Uint32Array(buffer)[ptr + SIZE_OFFSET >>> 2];
|
|
287
|
+
return buffer.slice(ptr, ptr + length);
|
|
288
|
+
}
|
|
289
|
+
extendedExports.__getArrayBuffer = __getArrayBuffer;
|
|
290
|
+
|
|
291
|
+
/** Gets a function from poiner which contain table's index. */
|
|
292
|
+
function __getFunction(ptr) {
|
|
293
|
+
if (!table) throw Error(E_NO_EXPORT_TABLE);
|
|
294
|
+
const index = new Uint32Array(memory.buffer)[ptr >>> 2];
|
|
295
|
+
return table.get(index);
|
|
296
|
+
}
|
|
297
|
+
extendedExports.__getFunction = __getFunction;
|
|
298
|
+
|
|
299
|
+
/** Copies a typed array's values from the module's memory. */
|
|
300
|
+
function getTypedArray(Type, alignLog2, ptr) {
|
|
301
|
+
return new Type(getTypedArrayView(Type, alignLog2, ptr));
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** Gets a live view on a typed array's values in the module's memory. */
|
|
305
|
+
function getTypedArrayView(Type, alignLog2, ptr) {
|
|
306
|
+
const buffer = memory.buffer;
|
|
307
|
+
const U32 = new Uint32Array(buffer);
|
|
308
|
+
return new Type(buffer, U32[ptr + ARRAYBUFFERVIEW_DATASTART_OFFSET >>> 2], U32[ptr + ARRAYBUFFERVIEW_BYTELENGTH_OFFSET >>> 2] >>> alignLog2);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** Attach a set of get TypedArray and View functions to the exports. */
|
|
312
|
+
function attachTypedArrayFunctions(ctor, name, align) {
|
|
313
|
+
extendedExports[`__get${name}`] = getTypedArray.bind(null, ctor, align);
|
|
314
|
+
extendedExports[`__get${name}View`] = getTypedArrayView.bind(null, ctor, align);
|
|
315
|
+
}
|
|
316
|
+
[Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array].forEach(ctor => {
|
|
317
|
+
attachTypedArrayFunctions(ctor, ctor.name, 31 - Math.clz32(ctor.BYTES_PER_ELEMENT));
|
|
318
|
+
});
|
|
319
|
+
if (BIGINT) {
|
|
320
|
+
[BigUint64Array, BigInt64Array].forEach(ctor => {
|
|
321
|
+
attachTypedArrayFunctions(ctor, ctor.name.slice(3), 3);
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Pull basic exports to extendedExports so code in preInstantiate can use them
|
|
326
|
+
extendedExports.memory = extendedExports.memory || memory;
|
|
327
|
+
extendedExports.table = extendedExports.table || table;
|
|
328
|
+
|
|
329
|
+
// Demangle exports and provide the usual utility on the prototype
|
|
330
|
+
return demangle(exports, extendedExports);
|
|
331
|
+
}
|
|
332
|
+
function isResponse(src) {
|
|
333
|
+
return typeof Response !== "undefined" && src instanceof Response;
|
|
334
|
+
}
|
|
335
|
+
function isModule(src) {
|
|
336
|
+
return src instanceof WebAssembly.Module;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** Asynchronously instantiates an AssemblyScript module from anything that can be instantiated. */
|
|
340
|
+
async function instantiate(source, imports = {}) {
|
|
341
|
+
if (isResponse(source = await source)) return instantiateStreaming(source, imports);
|
|
342
|
+
const module = isModule(source) ? source : await WebAssembly.compile(source);
|
|
343
|
+
const extended = preInstantiate(imports);
|
|
344
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
345
|
+
const exports = postInstantiate(extended, instance);
|
|
346
|
+
return {
|
|
347
|
+
module,
|
|
348
|
+
instance,
|
|
349
|
+
exports
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/** Synchronously instantiates an AssemblyScript module from a WebAssembly.Module or binary buffer. */
|
|
354
|
+
function instantiateSync(source, imports = {}) {
|
|
355
|
+
const module = isModule(source) ? source : new WebAssembly.Module(source);
|
|
356
|
+
const extended = preInstantiate(imports);
|
|
357
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
358
|
+
const exports = postInstantiate(extended, instance);
|
|
359
|
+
return {
|
|
360
|
+
module,
|
|
361
|
+
instance,
|
|
362
|
+
exports
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** Asynchronously instantiates an AssemblyScript module from a response, i.e. as obtained by `fetch`. */
|
|
367
|
+
async function instantiateStreaming(source, imports = {}) {
|
|
368
|
+
if (!WebAssembly.instantiateStreaming) {
|
|
369
|
+
return instantiate(isResponse(source = await source) ? source.arrayBuffer() : source, imports);
|
|
370
|
+
}
|
|
371
|
+
const extended = preInstantiate(imports);
|
|
372
|
+
const result = await WebAssembly.instantiateStreaming(source, imports);
|
|
373
|
+
const exports = postInstantiate(extended, result.instance);
|
|
374
|
+
return {
|
|
375
|
+
...result,
|
|
376
|
+
exports
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** Demangles an AssemblyScript module's exports to a friendly object structure. */
|
|
381
|
+
function demangle(exports, extendedExports = {}) {
|
|
382
|
+
const setArgumentsLength = exports["__argumentsLength"] ? length => {
|
|
383
|
+
exports["__argumentsLength"].value = length;
|
|
384
|
+
} : exports["__setArgumentsLength"] || exports["__setargc"] || (() => {/* nop */});
|
|
385
|
+
for (let internalName of Object.keys(exports)) {
|
|
386
|
+
const elem = exports[internalName];
|
|
387
|
+
let parts = internalName.split(".");
|
|
388
|
+
let curr = extendedExports;
|
|
389
|
+
while (parts.length > 1) {
|
|
390
|
+
let part = parts.shift();
|
|
391
|
+
if (!Object.hasOwn(curr, part)) curr[part] = {};
|
|
392
|
+
curr = curr[part];
|
|
393
|
+
}
|
|
394
|
+
let name = parts[0];
|
|
395
|
+
let hash = name.indexOf("#");
|
|
396
|
+
if (hash >= 0) {
|
|
397
|
+
const className = name.substring(0, hash);
|
|
398
|
+
const classElem = curr[className];
|
|
399
|
+
if (typeof classElem === "undefined" || !classElem.prototype) {
|
|
400
|
+
const ctor = function (...args) {
|
|
401
|
+
return ctor.wrap(ctor.prototype.constructor(0, ...args));
|
|
402
|
+
};
|
|
403
|
+
ctor.prototype = {
|
|
404
|
+
valueOf() {
|
|
405
|
+
return this[THIS];
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
ctor.wrap = function (thisValue) {
|
|
409
|
+
return Object.create(ctor.prototype, {
|
|
410
|
+
[THIS]: {
|
|
411
|
+
value: thisValue,
|
|
412
|
+
writable: false
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
};
|
|
416
|
+
if (classElem) Object.getOwnPropertyNames(classElem).forEach(name => Object.defineProperty(ctor, name, Object.getOwnPropertyDescriptor(classElem, name)));
|
|
417
|
+
curr[className] = ctor;
|
|
418
|
+
}
|
|
419
|
+
name = name.substring(hash + 1);
|
|
420
|
+
curr = curr[className].prototype;
|
|
421
|
+
if (/^(get|set):/.test(name)) {
|
|
422
|
+
if (!Object.hasOwn(curr, name = name.substring(4))) {
|
|
423
|
+
let getter = exports[internalName.replace("set:", "get:")];
|
|
424
|
+
let setter = exports[internalName.replace("get:", "set:")];
|
|
425
|
+
Object.defineProperty(curr, name, {
|
|
426
|
+
get() {
|
|
427
|
+
return getter(this[THIS]);
|
|
428
|
+
},
|
|
429
|
+
set(value) {
|
|
430
|
+
setter(this[THIS], value);
|
|
431
|
+
},
|
|
432
|
+
enumerable: true
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
} else {
|
|
436
|
+
if (name === 'constructor') {
|
|
437
|
+
(curr[name] = function (...args) {
|
|
438
|
+
setArgumentsLength(args.length);
|
|
439
|
+
return elem(...args);
|
|
440
|
+
}).original = elem;
|
|
441
|
+
} else {
|
|
442
|
+
// instance method
|
|
443
|
+
(curr[name] = function (...args) {
|
|
444
|
+
// !
|
|
445
|
+
setArgumentsLength(args.length);
|
|
446
|
+
return elem(this[THIS], ...args);
|
|
447
|
+
}).original = elem;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
} else {
|
|
451
|
+
if (/^(get|set):/.test(name)) {
|
|
452
|
+
if (!Object.hasOwn(curr, name = name.substring(4))) {
|
|
453
|
+
Object.defineProperty(curr, name, {
|
|
454
|
+
get: exports[internalName.replace("set:", "get:")],
|
|
455
|
+
set: exports[internalName.replace("get:", "set:")],
|
|
456
|
+
enumerable: true
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
} else if (typeof elem === "function" && elem !== setArgumentsLength) {
|
|
460
|
+
(curr[name] = (...args) => {
|
|
461
|
+
setArgumentsLength(args.length);
|
|
462
|
+
return elem(...args);
|
|
463
|
+
}).original = elem;
|
|
464
|
+
} else {
|
|
465
|
+
curr[name] = elem;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return extendedExports;
|
|
470
|
+
}
|
|
471
|
+
_exports.default = {
|
|
472
|
+
instantiate,
|
|
473
|
+
instantiateSync,
|
|
474
|
+
instantiateStreaming,
|
|
475
|
+
demangle
|
|
476
|
+
};
|
|
477
|
+
});
|
package/umd/package.json
ADDED