Skip to content

Commit 9a2d1d6

Browse files
committed
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.
1 parent 08093d7 commit 9a2d1d6

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

lib/handlebars/compiler/javascript-compiler.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ JavaScriptCompiler.prototype = {
2020
}
2121
},
2222
depthedLookup: function(name) {
23-
return [this.aliasable('this.lookup'), '(depths, "', name, '")'];
23+
return [this.aliasable('container.lookup'), '(depths, "', name, '")'];
2424
},
2525

2626
compilerInfo: function() {
@@ -189,7 +189,7 @@ JavaScriptCompiler.prototype = {
189189
}
190190
}
191191

192-
let params = ['depth0', 'helpers', 'partials', 'data'];
192+
let params = ['container', 'depth0', 'helpers', 'partials', 'data'];
193193

194194
if (this.useBlockParams || this.useDepths) {
195195
params.push('blockParams');
@@ -359,7 +359,7 @@ JavaScriptCompiler.prototype = {
359359
// Escape `value` and append it to the buffer
360360
appendEscaped: function() {
361361
this.pushSource(this.appendToBuffer(
362-
[this.aliasable('this.escapeExpression'), '(', this.popStack(), ')']));
362+
[this.aliasable('container.escapeExpression'), '(', this.popStack(), ')']));
363363
},
364364

365365
// [getContext]
@@ -428,7 +428,7 @@ JavaScriptCompiler.prototype = {
428428
if (!depth) {
429429
this.pushStackLiteral('data');
430430
} else {
431-
this.pushStackLiteral('this.data(data, ' + depth + ')');
431+
this.pushStackLiteral('container.data(data, ' + depth + ')');
432432
}
433433

434434
this.resolvePath('data', parts, 0, true, strict);
@@ -466,7 +466,7 @@ JavaScriptCompiler.prototype = {
466466
// If the `value` is a lambda, replace it on the stack by
467467
// the return value of the lambda
468468
resolvePossibleLambda: function() {
469-
this.push([this.aliasable('this.lambda'), '(', this.popStack(), ', ', this.contextName(0), ')']);
469+
this.push([this.aliasable('container.lambda'), '(', this.popStack(), ', ', this.contextName(0), ')']);
470470
},
471471

472472
// [pushStringParam]
@@ -669,7 +669,7 @@ JavaScriptCompiler.prototype = {
669669
options = this.objectLiteral(options);
670670
params.push(options);
671671

672-
this.push(this.source.functionCall('this.invokePartial', '', params));
672+
this.push(this.source.functionCall('container.invokePartial', '', params));
673673
},
674674

675675
// [assignToHash]
@@ -771,7 +771,7 @@ JavaScriptCompiler.prototype = {
771771
programParams.push('depths');
772772
}
773773

774-
return 'this.program(' + programParams.join(', ') + ')';
774+
return 'container.program(' + programParams.join(', ') + ')';
775775
},
776776

777777
useRegister: function(name) {
@@ -965,8 +965,8 @@ JavaScriptCompiler.prototype = {
965965
// Avoid setting fn and inverse if neither are set. This allows
966966
// helpers to do a check for `if (options.fn)`
967967
if (program || inverse) {
968-
options.fn = program || 'this.noop';
969-
options.inverse = inverse || 'this.noop';
968+
options.fn = program || 'container.noop';
969+
options.inverse = inverse || 'container.noop';
970970
}
971971

972972
// 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) {
10611061
}
10621062

10631063
if (requireTerminal) {
1064-
return [compiler.aliasable('this.strict'), '(', stack, ', ', compiler.quotedString(parts[i]), ')'];
1064+
return [compiler.aliasable('container.strict'), '(', stack, ', ', compiler.quotedString(parts[i]), ')'];
10651065
} else {
10661066
return stack;
10671067
}

lib/handlebars/runtime.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export function template(templateSpec, env) {
142142
}
143143
}
144144

145-
return '' + templateSpec.main.call(container, context, container.helpers, container.partials, data, blockParams, depths);
145+
return '' + templateSpec.main(container, context, container.helpers, container.partials, data, blockParams, depths);
146146
}
147147
ret.isTop = true;
148148

@@ -179,7 +179,7 @@ export function wrapProgram(container, i, fn, data, declaredBlockParams, blockPa
179179
currentDepths = [context].concat(depths);
180180
}
181181

182-
return fn.call(container,
182+
return fn(container,
183183
context,
184184
container.helpers, container.partials,
185185
options.data || data,

spec/expected/empty.amd.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
define(['handlebars.runtime'], function(Handlebars) {
22
Handlebars = Handlebars["default"]; var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
3-
return templates['empty'] = template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
3+
return templates['empty'] = template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(container,depth0,helpers,partials,data) {
44
return "";
55
},"useData":true});
66
});

0 commit comments

Comments
 (0)