Closed Bug 584890 Opened 14 years ago Closed 9 years ago

Long sequence of JavaScript chained function calls causes "too much recursion" error

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: bowdidge, Unassigned)

References

()

Details

(Keywords: testcase)

User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7
Build Identifier: Firefox 3.6.8, Mozilla Firefox for Ubuntu canonical-1.0

A long set of chained function calls in a single JavaScript statement appears to blow out the stack when parsing the JavaScript, and causes the page to fail to load and a "too much recursion" error to occur.  I've reproduced this on Firefox 3.5.11 on Mac OS X and on Firefox 3.6.8 on Firefox for Ubuntu - Canonical-1.0.

This bug has been really painful for web development on Ubuntu because the failure occurs on smaller expressions - in 64 bit Firefox, it fails at 183 calls in the same statement; on Mac OS X / 32 bit, it fails with 300 calls in the same statement.

The offending code is generated, so we do have the workaround of breaking up our statements into smaller chunks.

Other browsers (such as Safari) have no problem with the same code. 

Reproducible: Always

Steps to Reproduce:
1.Create a set of chained function calls (a().b().c()) longer than around 180 calls on 64 bit firefox, or 300 on 32 bit Firefox.
2. Parse the JavaScript.
3.Watch for the "too much recursion error."

Or, 

1. Load http://home.earthlink.net/~bowdidge/chain.html into a web browser.
2. Note that "too much recursion" appeared in the console, and the expected alert did not appear.
Actual Results:  
Page does not finish loading because of "too much recursion" error during parsing.

Expected Results:  
Page should load correctly and throw up an alert showing how many times the chained function was called.
Probably a variant on bug 543100, though I'm not sure it's the same parser recursion causing the problem.
Confirmed on Mozilla/5.0 (Macintosh; Intel Mac OS X 10.5; rv:2.0b6pre) Gecko/20100903 Firefox/4.0b6pre
Assignee: nobody → general
Status: UNCONFIRMED → NEW
Component: General → JavaScript Engine
Ever confirmed: true
Keywords: testcase
Product: Firefox → Core
QA Contact: general → general
Hardware: x86_64 → All
Version: unspecified → Trunk
Depends on: 543100
Just loaded the URL and got a prompt saying "300" and nothing in the error console. Windows 7 x64 edition (32bit m-c build).
Assignee: general → nobody
No longer reproducible, I've tried up to 2000 chained calls. Resolving as WFM.
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → WORKSFORME
I reproduced this issue in Firefox 42 x64 on Windows 10.
Alexander, can you perhaps try the latest Nightly build, too? http://nightly.mozilla.org/
Flags: needinfo?(ziborov.sasha)
Till, I checked on Nightly 45.0a1 (2015-11-19) and got the same result.
Flags: needinfo?(ziborov.sasha)
Interesting. It's still not reproducible for me even when using the same set-up (Win10 64bit, Nightly 45.0a1 (2015-11-19) 64bit). Just for reference, I've used the following script to generate the test data:
---
function generate(k) {
  var defs = "", access = "";
  for (var i = 1; i <= k; ++i) {
    defs += `obj.k${i} = function () { return obj };\n`;
    access += `.k${i}()`;
    if (i % 10 == 0) access += "\n";
  }
  return `
<html><body><script>
var obj = {};
${defs}
obj
${access};
alert('ok');
</script></body></html>
`;
}
generate(2000);
---
Andre, I get this issue in real cases (in my web application). Note, that Firefox 42 x32 works fine in the same scenario.
Can you provide a (reduced) test case so it's easier to identity how the test from comment #8 differs from your actual web app? Thanks!
Please, refer to http://jsfiddle.net/tLun99kb/show/ to reproduce this issue.
Thanks for the test case! The issue you're experiencing is different compared to the problem described in comment #0: Comment #0 is about a recursion warning within the JavaScript parser, whereas the recursion warning in dx.all.js is triggered by recursive calls during program execution (similar to bug 966173 or bug 1178360). It probably doesn't hurt to create a new bug report to track this issue with dx.all.js.
Andre, thank you for clarification!
You need to log in before you can comment on or make changes to this bug.