Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Created January 16, 2012 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwaldron/1621916 to your computer and use it in GitHub Desktop.
Save rwaldron/1621916 to your computer and use it in GitHub Desktop.
var stackLimit = (function() {
var result = 0;
function recurse() {
result++;
recurse();
}
try {
recurse();
} catch(e) { }
return result;
}());
var o = {
'foo': function() {
return this;
}
};
global.onerror = function(message) {
console.log(message);
};
console.log('About to start the test');
var foo = Function('return o.foo()' + Array(stackLimit + 1).join('.foo()'))();
console.log(foo);
@rwaldron
Copy link
Author

About to start the test

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
RangeError: Maximum call stack size exceeded

@jdalton
Copy link

jdalton commented Jan 16, 2012

I typoed, should be:

var foo = Function('return o.foo()' + Array(stackLimit + 1).join('.foo()'))();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment