Permalink
Browse files

Test and fix for stack overflow when rendering very large arrays

  • Loading branch information...
1 parent abfe811 commit fc77a5c2debc8fb133c6042e500dc68be658a416 @pepve committed Aug 20, 2012
Showing with 10,018 additions and 1 deletion.
  1. +5 −1 lib/mu/renderer.js
  2. +2 −0 test/examples/tenthousand.html
  3. +9 −0 test/examples/tenthousand.js
  4. +10,001 −0 test/examples/tenthousand.txt
  5. +1 −0 test/run_examples_test.js
View
@@ -12,7 +12,11 @@ function 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') {
throw new Error('Mu - WTF did you give me? I expected mustache tokens.');
}
@@ -0,0 +1,2 @@
+{{#foo}}{{value}}
+{{/foo}}
@@ -0,0 +1,9 @@
+(function () {
+ var result = { foo: [] };
+
+ for (var i = 0; i < 10000; i++) {
+ result.foo.push({ value: i });
+ }
+
+ return result;
+}())
Oops, something went wrong. Retry.

0 comments on commit fc77a5c

Please sign in to comment.