From 001afcfc787312ba8e7c0f87dbe7b7ba81a4fa23 Mon Sep 17 00:00:00 2001 From: Nikolai Tillmann Date: Thu, 27 Sep 2018 11:36:29 -0700 Subject: [PATCH] Disable generation of .bind() calls instead of wrapper functions Release notes: None --- src/serializer/ResidualFunctions.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/serializer/ResidualFunctions.js b/src/serializer/ResidualFunctions.js index df61db1b2a..3b7582d238 100644 --- a/src/serializer/ResidualFunctions.js +++ b/src/serializer/ResidualFunctions.js @@ -663,16 +663,22 @@ export class ResidualFunctions { let firstUsage = this.firstFunctionUsages.get(functionValue); // todo: why can this be undefined? invariant(insertionPoint !== undefined); - if ( - // The same free variables in shared instances may refer to objects with different initialization values - // so a stub forward function is needed during delay initializations. + + let cannotBind = this.residualFunctionInitializers.hasInitializerStatement(functionValue) || usesThis || hasFunctionArg || (firstUsage === undefined || !firstUsage.isNotEarlierThan(insertionPoint)) || this.functionPrototypes.get(functionValue) !== undefined || - hasAnyLeakedIds - ) { + hasAnyLeakedIds; + + // TODO 2589: Code size reduction opportunity: bring back .bind calls + cannotBind = true; + + if (cannotBind) { + // The same free variables in shared instances may refer to objects with different initialization values + // so a stub forward function is needed during delay initializations. + let callArgs: Array = [t.thisExpression()]; for (let flatArg of flatArgs) callArgs.push(flatArg); for (let param of params) {