Function.prototype.apply has a FormalParameterList of length two: Function.prototype.apply (thisArg, argArray) Accordingly, Function.prototype.apply.length should return 2. This is explicitly stated in Section 188.8.131.52 of ECMA-262 Edition 3. See http://www.mozilla.org/js/language/ for a reference. However, Rhino currently returns 1 instead of 2. This was reported by firstname.lastname@example.org.
This bug is the Rhino version of bug 145779 against SpiderMonkey. The corresponding testcase for this is: mozilla/js/tests/ecma_3/Function/regress-145779.js
Created attachment 84524 [details] [diff] [review] Extending ecma_3/Function/regress-145779.js to cover other Ecma deviations There are other problems with apply/call non-conformance. ECMA 184.108.40.206 requires for apply to behave in the same way when passing undefined as first or second argument as in case of passing null: <i>If thisArg is null or undefined, the called function is passed the global object as the this value. Otherwise, the called function is passed ToObject(thisArg) as the this value. If argArray is null or undefined, the called function is passed no arguments. Otherwise, if argArray is neither an array nor an arguments object (see 10.1.8), a TypeError exception is thrown. If argArray is either an array or an arguments object, the function is passed the (ToUint32(argArray.length)) arguments argArray, argArray, ..., argArray[ToUint32(argArray.length)�1].</i> Similarly ECMA 220.127.116.11 states for call: <i>If thisArg is null or undefined, the called function is passed the global object as the this value. Otherwise, the called function is passed ToObject(thisArg) as the this value.</i> Rhino does not behave as required for many cases of calling apply/call with null or undefined but I think there is no point in creating additional bug reports for this so the the patch extends ecma_3/Function/regress-145779.js to check against the cited text.
Igor: thank you for such thorough and precise tests! Following prevailing custom in the JS testsuite, I have CVS-deleted mozilla/js/tests/ecma_3/Function/regress-145779.js and added Igor's tests in the following two testcases: mozilla/js/tests/ecma_3/Function/18.104.22.168-1.js mozilla/js/tests/ecma_3/Function/22.214.171.124-1.js which test ECMA-262 Edition 3 Section 126.96.36.199 (Function.prototype.apply) Section 188.8.131.52 (Function.prototype.call) I can confirm that before Igor's patch, Rhino generated exceptions on both these testcases, but with Igor's patch, both tests pass -
I commited the patch
Igor, thanks! Marking Fixed, then -
And marking Verified FIXED. Both testcases now pass in Rhino: mozilla/js/tests/ecma_3/Function/184.108.40.206-1.js mozilla/js/tests/ecma_3/Function/220.127.116.11-1.js And that holds for both the compiled and interpreted modes of Rhino.
Targeting as resolved against 1.5R4