@@ -6354,8 +6354,8 @@ export class Compiler extends DiagnosticEmitter {
6354
6354
var originalName = original . internalName ;
6355
6355
var originalParameterTypes = originalSignature . parameterTypes ;
6356
6356
var originalParameterDeclarations = original . prototype . signatureNode . parameters ;
6357
- var commonReturnType = originalSignature . returnType ;
6358
- var commonThisType = originalSignature . thisType ;
6357
+ var returnType = originalSignature . returnType ;
6358
+ var thisType = originalSignature . thisType ;
6359
6359
var isInstance = original . is ( CommonFlags . INSTANCE ) ;
6360
6360
6361
6361
// arguments excl. `this`, operands incl. `this`
@@ -6386,7 +6386,7 @@ export class Compiler extends DiagnosticEmitter {
6386
6386
assert ( operandIndex == minOperands ) ;
6387
6387
6388
6388
// create the trampoline element
6389
- var trampolineSignature = new Signature ( originalParameterTypes , commonReturnType , commonThisType ) ;
6389
+ var trampolineSignature = new Signature ( originalParameterTypes , returnType , thisType ) ;
6390
6390
trampolineSignature . requiredParameters = maxArguments ;
6391
6391
trampolineSignature . parameterNames = originalSignature . parameterNames ;
6392
6392
trampoline = new Function (
@@ -6401,7 +6401,8 @@ export class Compiler extends DiagnosticEmitter {
6401
6401
// compile initializers of omitted arguments in scope of the trampoline function
6402
6402
// this is necessary because initializers might need additional locals and a proper this context
6403
6403
var previousFlow = this . currentFlow ;
6404
- this . currentFlow = trampoline . flow ;
6404
+ var flow = trampoline . flow ;
6405
+ this . currentFlow = flow ;
6405
6406
6406
6407
// create a br_table switching over the number of optional parameters provided
6407
6408
var numNames = numOptional + 1 ; // incl. outer block
@@ -6452,25 +6453,28 @@ export class Compiler extends DiagnosticEmitter {
6452
6453
] ) ;
6453
6454
forwardedOperands [ operandIndex ] = module . local_get ( operandIndex , type . toNativeType ( ) ) ;
6454
6455
}
6455
- this . currentFlow = previousFlow ;
6456
6456
assert ( operandIndex == maxOperands ) ;
6457
6457
6458
+ var stmts : ExpressionRef [ ] = [ body ] ;
6459
+ var theCall = module . call ( originalName , forwardedOperands , returnType . toNativeType ( ) ) ;
6460
+ if ( returnType != Type . void ) {
6461
+ this . performAutoreleasesWithValue ( flow , theCall , returnType , stmts ) ;
6462
+ } else {
6463
+ stmts . push ( theCall ) ;
6464
+ this . performAutoreleases ( flow , stmts ) ;
6465
+ }
6466
+ flow . freeScopedLocals ( ) ;
6467
+ this . currentFlow = previousFlow ;
6468
+
6458
6469
var funcRef = module . addFunction (
6459
6470
trampoline . internalName ,
6460
6471
this . ensureFunctionType (
6461
6472
trampolineSignature . parameterTypes ,
6462
- trampolineSignature . returnType ,
6463
- trampolineSignature . thisType
6473
+ returnType ,
6474
+ thisType
6464
6475
) ,
6465
6476
typesToNativeTypes ( trampoline . additionalLocals ) ,
6466
- module . block ( null , [
6467
- body ,
6468
- module . call (
6469
- originalName ,
6470
- forwardedOperands ,
6471
- commonReturnType . toNativeType ( )
6472
- )
6473
- ] , commonReturnType . toNativeType ( ) )
6477
+ module . block ( null , stmts , returnType . toNativeType ( ) )
6474
6478
) ;
6475
6479
trampoline . finalize ( module , funcRef ) ;
6476
6480
return trampoline ;
0 commit comments