@@ -277,9 +277,9 @@ function postInstantiate(baseModule, instance) {
277
277
}
278
278
279
279
/** Wraps a WebAssembly function while also taking care of variable arguments. */
280
- function wrapFunction ( fn , argumentsLength ) {
280
+ function wrapFunction ( fn , setArgumentsLength ) {
281
281
var wrap = ( ...args ) => {
282
- if ( argumentsLength ) argumentsLength . value = args . length ;
282
+ setArgumentsLength ( args . length ) ;
283
283
return fn ( ...args ) ;
284
284
}
285
285
wrap . original = fn ;
@@ -342,7 +342,10 @@ exports.instantiateStreaming = instantiateStreaming;
342
342
/** Demangles an AssemblyScript module's exports to a friendly object structure. */
343
343
function demangle ( exports , baseModule ) {
344
344
var module = baseModule ? Object . create ( baseModule ) : { } ;
345
- var argumentsLength = exports [ "__argumentsLength" ] ;
345
+ function setArgumentsLength ( length ) {
346
+ if ( exports [ "__argumentsLength" ] ) exports [ "__argumentsLength" ] . value = length ;
347
+ else if ( exports [ "set:__argumentsLength" ] ) exports [ "set:__argumentsLength" ] ( length ) ;
348
+ }
346
349
function hasOwnProperty ( elem , prop ) {
347
350
return Object . prototype . hasOwnProperty . call ( elem , prop ) ;
348
351
}
@@ -392,11 +395,11 @@ function demangle(exports, baseModule) {
392
395
}
393
396
} else {
394
397
if ( name === 'constructor' ) {
395
- curr [ name ] = wrapFunction ( elem , argumentsLength ) ;
398
+ curr [ name ] = wrapFunction ( elem , setArgumentsLength ) ;
396
399
} else { // for methods
397
400
Object . defineProperty ( curr , name , {
398
401
value : function ( ...args ) {
399
- if ( argumentsLength ) argumentsLength . value = args . length ;
402
+ setArgumentsLength ( args . length ) ;
400
403
return elem ( this [ THIS ] , ...args ) ;
401
404
}
402
405
} ) ;
@@ -412,7 +415,7 @@ function demangle(exports, baseModule) {
412
415
} ) ;
413
416
}
414
417
} else if ( typeof elem === "function" ) {
415
- curr [ name ] = wrapFunction ( elem , argumentsLength ) ;
418
+ curr [ name ] = wrapFunction ( elem , setArgumentsLength ) ;
416
419
} else {
417
420
curr [ name ] = elem ;
418
421
}
0 commit comments