Closed
Bug 202168
Opened 21 years ago
Closed 21 years ago
"arguments" passed as an argument not treated as an array
Categories
(Rhino Graveyard :: Core, defect)
Tracking
(Not tracked)
VERIFIED
INVALID
1.5R5
People
(Reporter: lmb, Assigned: norrisboyd)
Details
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 Build Identifier: Rhino 1.5R4 Date: Tue, 15 Apr 2003 21:01:15 +0200 From: "Igor Bukanov" <igor@fastmail.fm> Subject: Re: Is "arguments" an array or not in Rhino? Larry Blair wrote: > The following function works in spidermonkey, but not in Rhino: > > function f(){ > var c = [].concat(arguments); > return c;} > var x = f("A", "B"); > die (x.length+"|"+x[0]+"|"+x[1]); > > Spidermonkey results = 2|A|B > Rhino results = 1|[object Arguments]|undefined > > Btw, the following variation works in Rhino. Unfortunately, our 1900 > app files don't use it: > > function f(){ > var c = [].concat([arguments[0], arguments[1]]); > return c;} > var x = f("A", "B"); > die (x.length+"|"+x[0]+"|"+x[1]); > This is a bug in Rhino. In fact, this is a regression since 1.5R3. Could you file a bugzilla.mozilla.org report for it? Regards, Igor Reproducible: Always Steps to Reproduce: 1. 2. 3.
Reporter | ||
Updated•21 years ago
|
Summary: arguments.concat() doesn't work → "arguments" passed as an argument not trerated as an array
Comment 1•21 years ago
|
||
Larry, what version of SpiderMonkey are you using? The current versions of SpiderMonkey and Rhino give essentially the same output for your test: --- function f() { var c = [].concat(arguments); return c; } var x = f("A", "B"); print(x.length + "|" + x[0] + "|" +x[1]); --- OUTPUT IN SPIDERMONKEY 1|[object Object]|undefined OUTPUT IN RHINO 1|[object Arguments]|undefined This is correct. The |arguments| object inside a function is just an object that happens to have a |length| property, and properties |0|, |1|, etc. storing the function's parameters. But it is just an ordinary object, not an instance of an Array. To see this, we use the |instanceof| operator : function test() { print(arguments instanceof Array); } The output of this in both SpiderMonkey and Rhino is "false".
Comment 2•21 years ago
|
||
Here is the relevant portion of the ECMA-262 Edition 3 spec (See http://www.mozilla.org/js/language/E262-3.pdf) --- 10.1.8 Arguments Object When control enters an execution context for function code, an arguments object is created and initialised as follows: • The value of the internal [[Prototype]] property of the arguments object is the original Object prototype object, the one that is the initial value of Object.prototype (section 15.2.3.1). • A property is created with name callee and property attributes {DontEnum}. The initial value of this property is the Function object being executed. This allows anonymous functions to be recursive. • A property is created with name length and property attributes {DontEnum}. The initial value of this property is the number of actual parameter values supplied by the caller. • For each non-negative integer, arg, less than the value of the length property, a property is created with name ToString(arg) and property attributes {DontEnum}. The initial value of this property is the value of the corresponding actual parameter supplied by the caller. The first actual parameter value corresponds to arg = 0, the second to arg = 1, and so on. In the case when arg is less than the number of formal parameters for the Function object, this property shares its value with the corresponding property of the activation object. This means that changing this property changes the corresponding property of the activation object and vice versa. --- Note in particular, the [[Prototype]] property of the arguments object is the original Object prototype object, not the Array prototype object. Have to mark this one Invalid, sorry -
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → INVALID
Comment 3•21 years ago
|
||
Marking verified. Thank you for this report, it illuminates an interesting question. For details on Array.prototype.concat(), and what it does when it is supplied a non-array parameter, see bug 169795, "Array.concat(function) doesn't add function (or anything with .length but no elements) to the array"
Status: RESOLVED → VERIFIED
Updated•21 years ago
|
Summary: "arguments" passed as an argument not trerated as an array → "arguments" passed as an argument not treated as an array
You need to log in
before you can comment on or make changes to this bug.
Description
•