From 9a2d1d6009406915d1ca177ed5321e4727b9776f Mon Sep 17 00:00:00 2001
From: kpdecker <kpdecker@gmail.com>
Date: Tue, 18 Aug 2015 23:54:04 -0700
Subject: [PATCH] Pass container rather than exec as context

There is no real need for us to do `.call(container` other than for backwards compatibility with legacy versions. Using the 4.x release as a chance to optimize this behavior.
---
 .../compiler/javascript-compiler.js           | 20 +++++++++----------
 lib/handlebars/runtime.js                     |  4 ++--
 spec/expected/empty.amd.js                    |  2 +-
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js
index bed2add3e..b8fc9761f 100644
--- a/lib/handlebars/compiler/javascript-compiler.js
+++ b/lib/handlebars/compiler/javascript-compiler.js
@@ -20,7 +20,7 @@ JavaScriptCompiler.prototype = {
     }
   },
   depthedLookup: function(name) {
-    return [this.aliasable('this.lookup'), '(depths, "', name, '")'];
+    return [this.aliasable('container.lookup'), '(depths, "', name, '")'];
   },
 
   compilerInfo: function() {
@@ -189,7 +189,7 @@ JavaScriptCompiler.prototype = {
       }
     }
 
-    let params = ['depth0', 'helpers', 'partials', 'data'];
+    let params = ['container', 'depth0', 'helpers', 'partials', 'data'];
 
     if (this.useBlockParams || this.useDepths) {
       params.push('blockParams');
@@ -359,7 +359,7 @@ JavaScriptCompiler.prototype = {
   // Escape `value` and append it to the buffer
   appendEscaped: function() {
     this.pushSource(this.appendToBuffer(
-        [this.aliasable('this.escapeExpression'), '(', this.popStack(), ')']));
+        [this.aliasable('container.escapeExpression'), '(', this.popStack(), ')']));
   },
 
   // [getContext]
@@ -428,7 +428,7 @@ JavaScriptCompiler.prototype = {
     if (!depth) {
       this.pushStackLiteral('data');
     } else {
-      this.pushStackLiteral('this.data(data, ' + depth + ')');
+      this.pushStackLiteral('container.data(data, ' + depth + ')');
     }
 
     this.resolvePath('data', parts, 0, true, strict);
@@ -466,7 +466,7 @@ JavaScriptCompiler.prototype = {
   // If the `value` is a lambda, replace it on the stack by
   // the return value of the lambda
   resolvePossibleLambda: function() {
-    this.push([this.aliasable('this.lambda'), '(', this.popStack(), ', ', this.contextName(0), ')']);
+    this.push([this.aliasable('container.lambda'), '(', this.popStack(), ', ', this.contextName(0), ')']);
   },
 
   // [pushStringParam]
@@ -669,7 +669,7 @@ JavaScriptCompiler.prototype = {
     options = this.objectLiteral(options);
     params.push(options);
 
-    this.push(this.source.functionCall('this.invokePartial', '', params));
+    this.push(this.source.functionCall('container.invokePartial', '', params));
   },
 
   // [assignToHash]
@@ -771,7 +771,7 @@ JavaScriptCompiler.prototype = {
       programParams.push('depths');
     }
 
-    return 'this.program(' + programParams.join(', ') + ')';
+    return 'container.program(' + programParams.join(', ') + ')';
   },
 
   useRegister: function(name) {
@@ -965,8 +965,8 @@ JavaScriptCompiler.prototype = {
     // Avoid setting fn and inverse if neither are set. This allows
     // helpers to do a check for `if (options.fn)`
     if (program || inverse) {
-      options.fn = program || 'this.noop';
-      options.inverse = inverse || 'this.noop';
+      options.fn = program || 'container.noop';
+      options.inverse = inverse || 'container.noop';
     }
 
     // The parameters go on to the stack in order (making sure that they are evaluated in order)
@@ -1061,7 +1061,7 @@ function strictLookup(requireTerminal, compiler, parts, type) {
   }
 
   if (requireTerminal) {
-    return [compiler.aliasable('this.strict'), '(', stack, ', ', compiler.quotedString(parts[i]), ')'];
+    return [compiler.aliasable('container.strict'), '(', stack, ', ', compiler.quotedString(parts[i]), ')'];
   } else {
     return stack;
   }
diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js
index 744e6eb76..fed72fb07 100644
--- a/lib/handlebars/runtime.js
+++ b/lib/handlebars/runtime.js
@@ -142,7 +142,7 @@ export function template(templateSpec, env) {
       }
     }
 
-    return '' + templateSpec.main.call(container, context, container.helpers, container.partials, data, blockParams, depths);
+    return '' + templateSpec.main(container, context, container.helpers, container.partials, data, blockParams, depths);
   }
   ret.isTop = true;
 
@@ -179,7 +179,7 @@ export function wrapProgram(container, i, fn, data, declaredBlockParams, blockPa
       currentDepths = [context].concat(depths);
     }
 
-    return fn.call(container,
+    return fn(container,
         context,
         container.helpers, container.partials,
         options.data || data,
diff --git a/spec/expected/empty.amd.js b/spec/expected/empty.amd.js
index 852733b2f..0b39884f5 100644
--- a/spec/expected/empty.amd.js
+++ b/spec/expected/empty.amd.js
@@ -1,6 +1,6 @@
 define(['handlebars.runtime'], function(Handlebars) {
   Handlebars = Handlebars["default"];  var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
-return templates['empty'] = template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
+return templates['empty'] = template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(container,depth0,helpers,partials,data) {
     return "";
 },"useData":true});
 });
