Skip to content

Commit

Permalink
Pass container rather than exec as context
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kpdecker committed Aug 19, 2015
1 parent 08093d7 commit 9a2d1d6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
20 changes: 10 additions & 10 deletions lib/handlebars/compiler/javascript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -771,7 +771,7 @@ JavaScriptCompiler.prototype = {
programParams.push('depths');
}

return 'this.program(' + programParams.join(', ') + ')';
return 'container.program(' + programParams.join(', ') + ')';
},

useRegister: function(name) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/handlebars/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion spec/expected/empty.amd.js
Original file line number Diff line number Diff line change
@@ -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});
});

0 comments on commit 9a2d1d6

Please sign in to comment.