From: kangax on
On 2/20/10 4:09 AM, Garrett Smith wrote:

[...]

> Answer to my "response question" is explained by Ecma-262, r3 s 10.1.8
> "Arguments Object":
>
> | 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.
> |
>
> alert(
> function(x, y) {
> // arguments.length = 1.
> }(1));
>
> | 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 }.
>
> alert(
> function(x, y) {
> // arguments.length = 1.
> // arguments["0"] {DontEnum}
> x = 10;
> y = 20;
> }(1));
>
> | The initial value of this property is the
> | value of the corresponding actual parameter supplied by the caller.
>
> Updating the code comments to reflect that:
>
> alert(
> function(x, y) {
> // arguments.length = 2.
^^^
I don't see why arguments.length should change from 1 to 2 here. Typo?

> // arguments["0"] = 1 {DontEnum}
> x = 10;
> y = 20;
> }(1));
>
> | 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.
>
> At this point, `y` would share its value with arguments[1], but
> arguments does not have "1" property. Since no "1" property exists on
> the arguments object, the property `y` has nothing to share its value
> with. To handle this situation, Chrome *creates* a property of the
> arguments object to share value with.

These kind of things should really be caught by a conformance test suite
like Sputniktests [1]. The fact that they're not (I'm not sure, haven't
checked) shows that test suite has gaps and still needs work.

[...]

[1] <http://code.google.com/p/sputniktests/>
(my web runner: <http://kangax.github.com/sputniktests-webrunner/>)

--
kangax
From: Garrett Smith on
kangax wrote:
> On 2/20/10 4:09 AM, Garrett Smith wrote:
>
[...]

>>
>> alert(
>> function(x, y) {
>> // arguments.length = 1.

Right.

>> }(1));
>>
>> | 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 }.
>>
>> alert(
>> function(x, y) {
>> // arguments.length = 1.

Still right.

>> // arguments["0"] {DontEnum}
>> x = 10;
>> y = 20;
>> }(1));
>>
>> | The initial value of this property is the
>> | value of the corresponding actual parameter supplied by the caller.
>>
>> Updating the code comments to reflect that:
>>
>> alert(
>> function(x, y) {
>> // arguments.length = 2.
> ^^^

What happened to `1`?

> I don't see why arguments.length should change from 1 to 2 here. Typo?

`1` is correct because there was one actual argument passed in that
example.

It's not like copy'n'paste is all that hard. Apparently I copied right
the first time, but not the second. I should take my own advice about
late-night messages. Plus I need more sleep anyway.

[...]

I did file a bug on it, too, using another example.
http://code.google.com/p/chromium/issues/detail?id=36350

>
> These kind of things should really be caught by a conformance test suite
> like Sputniktests [1]. The fact that they're not (I'm not sure, haven't
> checked) shows that test suite has gaps and still needs work.
>

I think that bug reflects the problems with too much complexity around
`arguments` feature. Even in a very recent build of a major
implementation has an issue. The other issues I listed support my
argument that the complexity around `arguments` causes implementation
problems.

In an es-discuss thread about fixing `arguments` Brendan made a remark
about it being something like "polishing a turd," which I thought both
funny and appropriate.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
From: Dmitry A. Soshnikov on
On Feb 20, 12:09 pm, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote:

>
> #6 is better. Seems Chrome gets that feature wrong.
>

Yeah, that's right, Chrome still cannot get it right. Regarding to
ECMA-262-3, 10.1.8:

|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*.

function foo(x) {
x = 42;
console.log(arguments.length); // 0
console.log(arguments[0]); // undefined
return arguments[0];
}

// number of actual
// parameter values is 0
f(); // undefined

/ds
From: kangax on
On 2/20/10 8:47 PM, Garrett Smith wrote:
> kangax wrote:
>> On 2/20/10 4:09 AM, Garrett Smith wrote:
[...]
>>> alert(
>>> function(x, y) {
>>> // arguments.length = 2.
>> ^^^
>
> What happened to `1`?
>
>> I don't see why arguments.length should change from 1 to 2 here. Typo?
>
> `1` is correct because there was one actual argument passed in that
> example.
>
> It's not like copy'n'paste is all that hard. Apparently I copied right
> the first time, but not the second. I should take my own advice about
> late-night messages. Plus I need more sleep anyway.
>
> [...]
>
> I did file a bug on it, too, using another example.
> http://code.google.com/p/chromium/issues/detail?id=36350

Did you mean: <http://code.google.com/p/chromium/issues/detail?id=36328> ?

36350 returns 403. Late night message again? ;)

Btw, in ES5, there are few changes in bounding of `arguments` object and
function arguments. E.g., from Annex C:

� Arguments objects for strict mode functions do not dynamically share
their array indexed property values with the corresponding formal
parameter bindings of their functions. (10.6).

� For strict mode functions, if an arguments object is created the
binding of the local identifier arguments to the arguments object is
immutable and hence may not be the target of an assignment expression.
(10.5).

[...]

--
kangax
From: Richard Cornford on
kangax" wrote:
> On 2/20/10 8:47 PM, Garrett Smith wrote:
<snip>
>> I did file a bug on it, too, using another example.
>> http://code.google.com/p/chromium/issues/detail?id=36350
>
> Did you mean:
> <http://code.google.com/p/chromium/issues/detail?id=36328> ?
>
> 36350 returns 403. Late night message again? ;)
<snip>

It could be argued that this is not a bug. The spec's conformance
section explicitly allows objects to have properties in addition to
those specified. There would be a problem if the - arguments.length -
changed when - arguments[0] - was added to the object, but as that does
not happed the result is an arguments object with all the specified
properties having all the specified values and behaviour, and no more
than the additional properties that ES3 allows.

Richard.