@@ -195,10 +195,12 @@ function postInstantiate(extendedExports, instance) {
195195 }
196196
197197 /** 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 ;
199200 const info = getArrayInfo ( id ) ;
200201 const align = getValueAlign ( info ) ;
201- const length = values . length ;
202+ const isArrayLike = typeof input !== "number" ;
203+ const length = isArrayLike ? input . length : input ;
202204 const buf = __new ( length << align , info & STATICARRAY ? id : ARRAYBUFFER_ID ) ;
203205 let result ;
204206 if ( info & STATICARRAY ) {
@@ -214,14 +216,16 @@ function postInstantiate(extendedExports, instance) {
214216 if ( info & ARRAY ) U32 [ arr + ARRAY_LENGTH_OFFSET >>> 2 ] = length ;
215217 result = arr ;
216218 }
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 ) ;
222228 }
223- } else {
224- view . set ( values , buf >>> align ) ;
225229 }
226230 return result ;
227231 }
0 commit comments