Closed Bug 1265734 Opened 9 years ago Closed 3 years ago

Should func.bind(null).bind(null)...(x1000)...bind(null) overflow call stack?

Categories

(Core :: JavaScript Engine, defect)

45 Branch
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: michalwadas, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0 Build ID: 20160407164938 Steps to reproduce: I entered following code: function a() { return [].reduce.call(arguments, (a,b)=>a+b); } var b = a; for(var i = 0; i < 5000; i++) { b = b.bind(null,i); } b(); Actual results: InternalError: too much recursion Expected results: I expect result of 12497500 (Chrome yields this result). Why this happens: Spidermonkey implementation of Function.prototype.bind directly follows ECMAScript specification there, resulting in 5000 items deep call stack.
Component: Untriaged → JavaScript Engine
Product: Firefox → Core
Would you mind trying this with a recent Firefox 46 beta? Here's a Win64 beta build for instance: https://archive.mozilla.org/pub/firefox/tinderbox-builds/mozilla-beta-win64/1461004916/firefox-46.0.en-US.win64.zip We changed a few things in Firefox 46: (1) Our fun.bind implementation is now self-hosted and doesn't consume as much stack space (bug 1000780) (2) We more than doubled our stack quota on Win64 builds (bug 1257234).
Flags: needinfo?(michalwadas)
It still fails here on OS X (with a larger stack than Windows), so I don't think FF 46 will fix this particular test case. Hopefully real-world cases will work better in Firefox 46 though - I don't think this particular edge case is worth optimizing.
Stable FF46 ("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0") doesn't change anything here.
Flags: needinfo?(michalwadas)
Still happens on "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:58.0) Gecko/20100101 Firefox/58.0"
This is one of these "just don't do that" bugs IMO - recursion limits are implementation specific and the testcase in comment 0 also throws an overrecursion error in Safari.
Status: UNCONFIRMED → RESOLVED
Closed: 3 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.