ES5 Function.prototype.apply does not require argArray be either Array or arguments

RESOLVED FIXED in mozilla2.0b3

Status

()

Core
JavaScript Engine
RESOLVED FIXED
7 years ago
7 years ago

People

(Reporter: brendan, Assigned: Waldo)

Tracking

({dev-doc-complete})

Trunk
mozilla2.0b3
dev-doc-complete
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: fixed-in-tracemonkey)

Attachments

(1 attachment, 1 obsolete attachment)

(Reporter)

Description

7 years ago
It treats the second parameter, if not null and not undefined, as an object from which to get "length" and index-named properties, i.e. a generic array-like.

/be
Keywords: dev-doc-needed
Created attachment 457930 [details] [diff] [review]
Patch and tests

I have a query going on es5-discuss about whether it's really intended/desirable to apply ToNumber twice (once via ToUint32) to argsArray.length, but with spec text as it is now, this patch is correct.
Assignee: general → jwalden+bmo
Status: NEW → ASSIGNED
Attachment #457930 - Flags: review?(brendan)
Created attachment 459839 [details] [diff] [review]
Patch and tests, now with less weird error-checking and double-evaluating
Attachment #457930 - Attachment is obsolete: true
Attachment #459839 - Flags: review?(brendan)
Attachment #457930 - Flags: review?(brendan)
(Reporter)

Comment 3

7 years ago
Comment on attachment 459839 [details] [diff] [review]
Patch and tests, now with less weird error-checking and double-evaluating

Nice, much improved and close to the spec.

>+        if (lenval.isInt32()) {
>+            length = jsuint(jsint(lenval.toInt32())); /* jsuint cast does ToUint32 */

Don't need the jsint case here.

r=me with that picked -- thanks.

/be
Attachment #459839 - Flags: review?(brendan) → review+
http://hg.mozilla.org/tracemonkey/rev/898b20672383

Picked that nit, added comments delineating algorithm steps for greater clarity and readability, and renamed a variable for the same reason -- pushed with those changes.
Whiteboard: fixed-in-tracemonkey
Target Milestone: --- → mozilla2.0b3
http://hg.mozilla.org/mozilla-central/rev/898b20672383
Status: ASSIGNED → RESOLVED
Last Resolved: 7 years ago
Resolution: --- → FIXED
Added a note to:

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/apply

And to the New in JavaScript 1.8.5 page.
Keywords: dev-doc-needed → dev-doc-complete
You need to log in before you can comment on or make changes to this bug.