@@ -195,10 +195,12 @@ function postInstantiate(extendedExports, instance) {
195
195
}
196
196
197
197
/** Allocates a new array in the module's memory and returns its pointer. */
198
- function __newArray ( id , values ) {
198
+ function __newArray ( id , valuesOrCapacity = 0 ) {
199
+ const input = valuesOrCapacity ;
199
200
const info = getArrayInfo ( id ) ;
200
201
const align = getValueAlign ( info ) ;
201
- const length = values . length ;
202
+ const isArrayLike = typeof input !== "number" ;
203
+ const length = isArrayLike ? input . length : input ;
202
204
const buf = __new ( length << align , info & STATICARRAY ? id : ARRAYBUFFER_ID ) ;
203
205
let result ;
204
206
if ( info & STATICARRAY ) {
@@ -214,14 +216,16 @@ function postInstantiate(extendedExports, instance) {
214
216
if ( info & ARRAY ) U32 [ arr + ARRAY_LENGTH_OFFSET >>> 2 ] = length ;
215
217
result = arr ;
216
218
}
217
- const view = getView ( align , info & VAL_SIGNED , info & VAL_FLOAT ) ;
218
- if ( info & VAL_MANAGED ) {
219
- for ( let i = 0 ; i < length ; ++ i ) {
220
- const value = values [ i ] ;
221
- view [ ( buf >>> align ) + i ] = value ;
219
+ if ( isArrayLike ) {
220
+ const view = getView ( align , info & VAL_SIGNED , info & VAL_FLOAT ) ;
221
+ const start = buf >>> align ;
222
+ if ( info & VAL_MANAGED ) {
223
+ for ( let i = 0 ; i < length ; ++ i ) {
224
+ view [ start + i ] = input [ i ] ;
225
+ }
226
+ } else {
227
+ view . set ( input , start ) ;
222
228
}
223
- } else {
224
- view . set ( values , buf >>> align ) ;
225
229
}
226
230
return result ;
227
231
}
0 commit comments