Creation of the `arguments` object
On 4 July 2012 16:03, Mathias Bynens <mathias at qiwi.be> wrote:
ecma-international.org/ecma-262/5.1/#sec-10.6 says:
When control enters an execution context for function code, an arguments object is created unless (as specified in 10.5) the identifier arguments occurs as an Identifier in the function’s FormalParameterList or occurs as the Identifier of a VariableDeclaration or FunctionDeclaration contained in the function code.
The text is wrong. The order of steps in the normative part of the spec (Section 10.5, esp. step 6) makes clear that variable declarations are not taken into account (but parameters and function declarations are).
I suggest filing a bug, if there isn't one already: bugs.ecmascript.org/describecomponents.cgi?product=ECMA
This looks like a regression in the spec from ES3 to ES5.
On Wed, Jul 4, 2012 at 4:27 PM, Andreas Rossberg <rossberg at google.com> wrote:
The text is wrong. The order of steps in the normative part of the spec (Section 10.5, esp. step 6) makes clear that variable declarations are not taken into account (but parameters and function declarations are).
Thanks for confirming. I filed it here: ecmascript#440.
The text is wrong. The order of steps in the normative part of the spec (Section 10.5, esp. step 6) makes clear that variable declarations are not taken into account (but parameters and function declarations are).
If I understand correctly, the arguments
object is created in step
7, but then overwritten by the variable declaration in step 8.
So shouldn’t the first two examples in my mail (quoted below) get the
same result, then? Or are var arguments;
and var arguments = undefined;
not both VariableDeclaration
s?
On Wed, Jul 4, 2012 at 4:03 PM, Mathias Bynens <mathias at qiwi.be> wrote:
Following that logic, I would expect the following code to return
"undefined"
:function fn() { var arguments; return typeof arguments; }; fn(); // "object"
However, in all engines I tested this in, it returns
"object"
instead.On the other hand, this:
function fn() { var arguments = undefined; return typeof arguments; }; fn(); // "undefined"
…does return
"undefined"
.
Thanks for helping me understand!
In the execution phase, their behavior is different.
section 12.2 ecma-international.org/ecma-262/5.1/#sec-12.2
var arguments = undefined
performs PutValue with reference and undefined.
- Let lhs be the result of evaluating Identifier as described in 11.1.2.
- Let rhs be the result of evaluating Initialiser.
- Let value be GetValue(rhs).
- Call PutValue(lhs, value).
- Return a String value containing the same sequence of characters as in the Identifier.
But
var arguments;
doesn't perform any assignment.
- Return a String value containing the same sequence of characters as in
the Identifier.
, Yusuke Suzuki
Thanks, Yusuke!
ecma-international.org/ecma-262/5.1/#sec-10.6 says:
Following that logic, I would expect the following code to return
"undefined"
:However, in all engines I tested this in, it returns
"object"
instead.On the other hand, this:
…does return
"undefined"
. And so does this, in all engines except Opera:Did I misunderstand the spec?