Skip to content

Commit

Permalink
Test and fix for stack overflow when rendering very large arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Pepijn Verlaan committed Aug 20, 2012
1 parent abfe811 commit fc77a5c
Show file tree
Hide file tree
Showing 5 changed files with 10,018 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/mu/renderer.js
Expand Up @@ -12,7 +12,11 @@ function render(tokens, context, partials, stream, callback) {
return _render(tokens, context, partials, stream, callback); return _render(tokens, context, partials, stream, callback);
} }


function _render(tokens, context, partials, stream, callback) { function _render() {
process.nextTick(Function.prototype.bind.apply(__render, [this].concat(Array.prototype.slice.call(arguments))));
}

function __render(tokens, context, partials, stream, callback) {
if (tokens[0] !== 'multi') { if (tokens[0] !== 'multi') {
throw new Error('Mu - WTF did you give me? I expected mustache tokens.'); throw new Error('Mu - WTF did you give me? I expected mustache tokens.');
} }
Expand Down
2 changes: 2 additions & 0 deletions test/examples/tenthousand.html
@@ -0,0 +1,2 @@
{{#foo}}{{value}}
{{/foo}}
9 changes: 9 additions & 0 deletions test/examples/tenthousand.js
@@ -0,0 +1,9 @@
(function () {
var result = { foo: [] };

for (var i = 0; i < 10000; i++) {
result.foo.push({ value: i });
}

return result;
}())

0 comments on commit fc77a5c

Please sign in to comment.