ECMA conformance: Function.prototype.apply(), Function.prototype.call()

VERIFIED FIXED in 1.5R4

Status

Rhino
Core
VERIFIED FIXED
16 years ago
14 years ago

People

(Reporter: Phil Schwartau, Assigned: Norris Boyd)

Tracking

Details

(Whiteboard: [Bug 145779 filed against SpiderMonkey])

Attachments

(2 attachments)

(Reporter)

Description

16 years ago
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 15.3.4.3 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 igor3@apochta.com.
(Reporter)

Comment 1

16 years ago
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
Whiteboard: [Bug 145779 filed against SpiderMonkey for same issue]

Comment 2

16 years ago
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 15.3.4.3
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[0], argArray[1], ...,
argArray[ToUint32(argArray.length)&#65533;1].</i>

Similarly ECMA 15.3.4.4 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.

Comment 3

16 years ago
Created attachment 84531 [details] [diff] [review]
Fixes to org/mozilla/javascript/baseFunction.java

The patch makes apply.length to return 2 and addresses apply(undefined) etc.
issues.
(Reporter)

Comment 4

16 years ago
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/15.3.4.3-1.js
  mozilla/js/tests/ecma_3/Function/15.3.4.4-1.js

which test ECMA-262 Edition 3

  Section 15.3.4.3 (Function.prototype.apply)
  Section 15.3.4.4 (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 -
Summary: Function.prototype.apply.length should return 2 → ECMA conformance: Function.prototype.apply(), Function.prototype.call()
Whiteboard: [Bug 145779 filed against SpiderMonkey for same issue] → [Bug 145779 filed against SpiderMonkey]

Comment 5

16 years ago
I commited the patch
(Reporter)

Comment 6

16 years ago
Igor, thanks! Marking Fixed, then -
Status: NEW → RESOLVED
Last Resolved: 16 years ago
Resolution: --- → FIXED
(Reporter)

Comment 7

16 years ago
And marking Verified FIXED. Both testcases now pass in Rhino:

          mozilla/js/tests/ecma_3/Function/15.3.4.3-1.js
          mozilla/js/tests/ecma_3/Function/15.3.4.4-1.js

And that holds for both the compiled and interpreted modes of Rhino.
Status: RESOLVED → VERIFIED

Comment 8

14 years ago
Targeting as resolved against 1.5R4
Target Milestone: --- → 1.5R4
You need to log in before you can comment on or make changes to this bug.