@@ -38,10 +38,17 @@ var loader = (function(exports) {
38
38
39
39
const ARRAYBUFFERVIEW_BUFFER_OFFSET = 0 ;
40
40
const ARRAYBUFFERVIEW_DATASTART_OFFSET = 4 ;
41
- const ARRAYBUFFERVIEW_DATALENGTH_OFFSET = 8 ;
41
+ const ARRAYBUFFERVIEW_BYTELENGTH_OFFSET = 8 ;
42
42
const ARRAYBUFFERVIEW_SIZE = 12 ;
43
43
const ARRAY_LENGTH_OFFSET = 12 ;
44
44
const ARRAY_SIZE = 16 ;
45
+ const E_NO_EXPORT_TABLE = "Operation requires compiling with --exportTable" ;
46
+ const E_NO_EXPORT_RUNTIME = "Operation requires compiling with --exportRuntime" ;
47
+
48
+ const F_NO_EXPORT_RUNTIME = ( ) => {
49
+ throw Error ( E_NO_EXPORT_RUNTIME ) ;
50
+ } ;
51
+
45
52
const BIGINT = typeof BigUint64Array !== "undefined" ;
46
53
const THIS = Symbol ( ) ;
47
54
const STRING_SMALLSIZE = 192 ; // break-even point in V8
@@ -52,8 +59,14 @@ var loader = (function(exports) {
52
59
fatal : true
53
60
} ) ; // != wtf16
54
61
62
+ /** polyfill for Object.hasOwn */
63
+
64
+ Object . hasOwn = Object . hasOwn || function ( obj , prop ) {
65
+ return Object . prototype . hasOwnProperty . call ( obj , prop ) ;
66
+ } ;
55
67
/** Gets a string from memory. */
56
68
69
+
57
70
function getStringImpl ( buffer , ptr ) {
58
71
let len = new Uint32Array ( buffer ) [ ptr + SIZE_OFFSET >>> 2 ] >>> 1 ;
59
72
const wtf16 = new Uint16Array ( buffer , ptr , len ) ;
@@ -102,12 +115,6 @@ var loader = (function(exports) {
102
115
imports . Date = imports . Date || Date ;
103
116
return extendedExports ;
104
117
}
105
-
106
- const E_NOEXPORTRUNTIME = "Operation requires compiling with --exportRuntime" ;
107
-
108
- const F_NOEXPORTRUNTIME = function ( ) {
109
- throw Error ( E_NOEXPORTRUNTIME ) ;
110
- } ;
111
118
/** Prepares the final module once instantiation is complete. */
112
119
113
120
@@ -116,47 +123,43 @@ var loader = (function(exports) {
116
123
const memory = exports . memory ;
117
124
const table = exports . table ;
118
125
119
- const __new = exports . __new || F_NOEXPORTRUNTIME ;
126
+ const __new = exports . __new || F_NO_EXPORT_RUNTIME ;
120
127
121
- const __pin = exports . __pin || F_NOEXPORTRUNTIME ;
128
+ const __pin = exports . __pin || F_NO_EXPORT_RUNTIME ;
122
129
123
- const __unpin = exports . __unpin || F_NOEXPORTRUNTIME ;
130
+ const __unpin = exports . __unpin || F_NO_EXPORT_RUNTIME ;
124
131
125
- const __collect = exports . __collect || F_NOEXPORTRUNTIME ;
132
+ const __collect = exports . __collect || F_NO_EXPORT_RUNTIME ;
126
133
127
134
const __rtti_base = exports . __rtti_base ;
128
- const getRttiCount = __rtti_base ? function ( arr ) {
129
- return arr [ __rtti_base >>> 2 ] ;
130
- } : F_NOEXPORTRUNTIME ;
135
+ const getRttiCount = __rtti_base ? arr => arr [ __rtti_base >>> 2 ] : F_NO_EXPORT_RUNTIME ;
131
136
extendedExports . __new = __new ;
132
137
extendedExports . __pin = __pin ;
133
138
extendedExports . __unpin = __unpin ;
134
139
extendedExports . __collect = __collect ;
135
140
/** Gets the runtime type info for the given id. */
136
141
137
- function getInfo ( id ) {
142
+ function getRttInfo ( id ) {
143
+ const U32 = new Uint32Array ( memory . buffer ) ;
144
+ if ( ( id >>>= 0 ) >= getRttiCount ( U32 ) ) throw Error ( `invalid id: ${ id } ` ) ;
145
+ return U32 [ ( __rtti_base + 4 >>> 2 ) + ( id << 1 ) ] ;
146
+ }
147
+ /** Gets the runtime base id for the given id. */
148
+
149
+
150
+ function getRttBase ( id ) {
138
151
const U32 = new Uint32Array ( memory . buffer ) ;
139
- const count = getRttiCount ( U32 ) ;
140
- if ( ( id >>>= 0 ) >= count ) throw Error ( `invalid id: ${ id } ` ) ;
141
- return U32 [ ( __rtti_base + 4 >>> 2 ) + id * 2 ] ;
152
+ if ( ( id >>>= 0 ) >= getRttiCount ( U32 ) ) throw Error ( `invalid id: ${ id } ` ) ;
153
+ return U32 [ ( __rtti_base + 4 >>> 2 ) + ( id << 1 ) + 1 ] ;
142
154
}
143
155
/** Gets and validate runtime type info for the given id for array like objects */
144
156
145
157
146
158
function getArrayInfo ( id ) {
147
- const info = getInfo ( id ) ;
159
+ const info = getRttInfo ( id ) ;
148
160
if ( ! ( info & ( ARRAYBUFFERVIEW | ARRAY | STATICARRAY ) ) ) throw Error ( `not an array: ${ id } , flags=${ info } ` ) ;
149
161
return info ;
150
162
}
151
- /** Gets the runtime base id for the given id. */
152
-
153
-
154
- function getBase ( id ) {
155
- const U32 = new Uint32Array ( memory . buffer ) ;
156
- const count = getRttiCount ( U32 ) ;
157
- if ( ( id >>>= 0 ) >= count ) throw Error ( `invalid id: ${ id } ` ) ;
158
- return U32 [ ( __rtti_base + 4 >>> 2 ) + id * 2 + 1 ] ;
159
- }
160
163
/** Gets the runtime alignment of a collection's values. */
161
164
162
165
@@ -185,6 +188,20 @@ var loader = (function(exports) {
185
188
}
186
189
187
190
extendedExports . __newString = __newString ;
191
+ /** Allocates a new ArrayBuffer in the module's memory and returns its pointer. */
192
+
193
+ function __newArrayBuffer ( buf ) {
194
+ if ( buf == null ) return 0 ;
195
+ const bufview = new Uint8Array ( buf ) ;
196
+
197
+ const ptr = __new ( bufview . length , ARRAYBUFFER_ID ) ;
198
+
199
+ const U8 = new Uint8Array ( memory . buffer ) ;
200
+ U8 . set ( bufview , ptr ) ;
201
+ return ptr ;
202
+ }
203
+
204
+ extendedExports . __newArrayBuffer = __newArrayBuffer ;
188
205
/** Reads a string from the module's memory by its pointer. */
189
206
190
207
function __getString ( ptr ) {
@@ -230,10 +247,12 @@ var loader = (function(exports) {
230
247
/** Allocates a new array in the module's memory and returns its pointer. */
231
248
232
249
233
- function __newArray ( id , values ) {
250
+ function __newArray ( id , valuesOrCapacity = 0 ) {
251
+ const input = valuesOrCapacity ;
234
252
const info = getArrayInfo ( id ) ;
235
253
const align = getValueAlign ( info ) ;
236
- const length = values . length ;
254
+ const isArrayLike = typeof input !== "number" ;
255
+ const length = isArrayLike ? input . length : input ;
237
256
238
257
const buf = __new ( length << align , info & STATICARRAY ? id : ARRAYBUFFER_ID ) ;
239
258
@@ -251,20 +270,22 @@ var loader = (function(exports) {
251
270
const U32 = new Uint32Array ( memory . buffer ) ;
252
271
U32 [ arr + ARRAYBUFFERVIEW_BUFFER_OFFSET >>> 2 ] = buf ;
253
272
U32 [ arr + ARRAYBUFFERVIEW_DATASTART_OFFSET >>> 2 ] = buf ;
254
- U32 [ arr + ARRAYBUFFERVIEW_DATALENGTH_OFFSET >>> 2 ] = length << align ;
273
+ U32 [ arr + ARRAYBUFFERVIEW_BYTELENGTH_OFFSET >>> 2 ] = length << align ;
255
274
if ( info & ARRAY ) U32 [ arr + ARRAY_LENGTH_OFFSET >>> 2 ] = length ;
256
275
result = arr ;
257
276
}
258
277
259
- const view = getView ( align , info & VAL_SIGNED , info & VAL_FLOAT ) ;
278
+ if ( isArrayLike ) {
279
+ const view = getView ( align , info & VAL_SIGNED , info & VAL_FLOAT ) ;
280
+ const start = buf >>> align ;
260
281
261
- if ( info & VAL_MANAGED ) {
262
- for ( let i = 0 ; i < length ; ++ i ) {
263
- const value = values [ i ] ;
264
- view [ ( buf >>> align ) + i ] = value ;
282
+ if ( info & VAL_MANAGED ) {
283
+ for ( let i = 0 ; i < length ; ++ i ) {
284
+ view [ start + i ] = input [ i ] ;
285
+ }
286
+ } else {
287
+ view . set ( input , start ) ;
265
288
}
266
- } else {
267
- view . set ( values , buf >>> align ) ;
268
289
}
269
290
270
291
return result ;
@@ -307,6 +328,15 @@ var loader = (function(exports) {
307
328
}
308
329
309
330
extendedExports . __getArrayBuffer = __getArrayBuffer ;
331
+ /** Gets a function from poiner which contain table's index. */
332
+
333
+ function __getFunction ( ptr ) {
334
+ if ( ! table ) throw Error ( E_NO_EXPORT_TABLE ) ;
335
+ const index = new Uint32Array ( memory . buffer ) [ ptr >>> 2 ] ;
336
+ return table . get ( index ) ;
337
+ }
338
+
339
+ extendedExports . __getFunction = __getFunction ;
310
340
/** Copies a typed array's values from the module's memory. */
311
341
312
342
function getTypedArray ( Type , alignLog2 , ptr ) {
@@ -318,8 +348,7 @@ var loader = (function(exports) {
318
348
function getTypedArrayView ( Type , alignLog2 , ptr ) {
319
349
const buffer = memory . buffer ;
320
350
const U32 = new Uint32Array ( buffer ) ;
321
- const bufPtr = U32 [ ptr + ARRAYBUFFERVIEW_DATASTART_OFFSET >>> 2 ] ;
322
- return new Type ( buffer , bufPtr , U32 [ bufPtr + SIZE_OFFSET >>> 2 ] >>> alignLog2 ) ;
351
+ return new Type ( buffer , U32 [ ptr + ARRAYBUFFERVIEW_DATASTART_OFFSET >>> 2 ] , U32 [ ptr + ARRAYBUFFERVIEW_BYTELENGTH_OFFSET >>> 2 ] >>> alignLog2 ) ;
323
352
}
324
353
/** Attach a set of get TypedArray and View functions to the exports. */
325
354
@@ -348,7 +377,7 @@ var loader = (function(exports) {
348
377
if ( id <= getRttiCount ( U32 ) ) {
349
378
do {
350
379
if ( id == baseId ) return true ;
351
- id = getBase ( id ) ;
380
+ id = getRttBase ( id ) ;
352
381
} while ( id ) ;
353
382
}
354
383
@@ -424,15 +453,14 @@ var loader = (function(exports) {
424
453
/* nop */
425
454
} ) ;
426
455
427
- for ( let internalName in exports ) {
428
- if ( ! Object . prototype . hasOwnProperty . call ( exports , internalName ) ) continue ;
456
+ for ( let internalName of Object . keys ( exports ) ) {
429
457
const elem = exports [ internalName ] ;
430
458
let parts = internalName . split ( "." ) ;
431
459
let curr = extendedExports ;
432
460
433
461
while ( parts . length > 1 ) {
434
462
let part = parts . shift ( ) ;
435
- if ( ! Object . prototype . hasOwnProperty . call ( curr , part ) ) curr [ part ] = { } ;
463
+ if ( ! Object . hasOwn ( curr , part ) ) curr [ part ] = { } ;
436
464
curr = curr [ part ] ;
437
465
}
438
466
@@ -472,7 +500,7 @@ var loader = (function(exports) {
472
500
curr = curr [ className ] . prototype ;
473
501
474
502
if ( / ^ ( g e t | s e t ) : / . test ( name ) ) {
475
- if ( ! Object . prototype . hasOwnProperty . call ( curr , name = name . substring ( 4 ) ) ) {
503
+ if ( ! Object . hasOwn ( curr , name = name . substring ( 4 ) ) ) {
476
504
let getter = exports [ internalName . replace ( "set:" , "get:" ) ] ;
477
505
let setter = exports [ internalName . replace ( "get:" , "set:" ) ] ;
478
506
Object . defineProperty ( curr , name , {
@@ -489,7 +517,7 @@ var loader = (function(exports) {
489
517
}
490
518
} else {
491
519
if ( name === 'constructor' ) {
492
- ( curr [ name ] = ( ...args ) => {
520
+ ( curr [ name ] = function ( ...args ) {
493
521
setArgumentsLength ( args . length ) ;
494
522
return elem ( ...args ) ;
495
523
} ) . original = elem ;
@@ -504,7 +532,7 @@ var loader = (function(exports) {
504
532
}
505
533
} else {
506
534
if ( / ^ ( g e t | s e t ) : / . test ( name ) ) {
507
- if ( ! Object . prototype . hasOwnProperty . call ( curr , name = name . substring ( 4 ) ) ) {
535
+ if ( ! Object . hasOwn ( curr , name = name . substring ( 4 ) ) ) {
508
536
Object . defineProperty ( curr , name , {
509
537
get : exports [ internalName . replace ( "set:" , "get:" ) ] ,
510
538
set : exports [ internalName . replace ( "get:" , "set:" ) ] ,
0 commit comments