From: Jorge on
On Feb 20, 10:21 am, Asen Bozhilov <asen.bozhi...(a)gmail.com> wrote:
> Richard Cornford wrote:
> > That is an explanation, but not a full explanation because it does not
> > state why +++ must be interpreted as the tokens ++ followed by the token
> > +, rather than + followed by ++. The answer to that is in the spec, in
> > the last sentence of the first paragraph of section 7, where it says
> > "The source text is scanned from left to right, repeatedly taking the
> > longest possible sequence of characters as the next input element". So
> > given +++, the longest possible sequence of characters that can be a
> > token is ++, leaving the last + to be the next token.
>
> How can you explain:
>
> var x = 10;
> +++x;
>
> There SyntaxError instead of runtime error.

As Richard said, the parser tries to math the longest sequence of
characters that makes sense. In this case ++ makes sense, but as soon
as the next character found is +, it stops making sense and throws.
--
Jorge.
From: Jorge on
On Feb 20, 10:46 am, Jorge <jo...(a)jorgechamorro.com> wrote:
>
> As Richard said, the parser tries to math the longest sequence of
> characters that makes sense. In this case ++ makes sense, but as soon
> as the next character found is +, it stops making sense and throws.

s/math/match/
--
Jorge.
From: Asen Bozhilov on
Jorge wrote:
> Asen Bozhilov wrote:
> > Richard Cornford wrote:

> > > "The source text is scanned from left to right, repeatedly taking the
> > > longest possible sequence of characters as the next input element". So
> > > given +++, the longest possible sequence of characters that can be a
> > > token is ++, leaving the last + to be the next token.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> > There SyntaxError instead of runtime error.

> As Richard said, the parser tries to math the longest sequence of
> characters that makes sense. In this case ++ makes sense, but as soon
> as the next character found is +, it stops making sense and throws.

From which grammar rules `+y` isn't valid `UnaryExpression`?

And why in next example there runtime exception instead of
SyntaxError?

++ function(){}(); //ReferenceError
++ function(){}; //SyntaxError

`++` operator works with ReferenceType "13.2.1 [[Call]]", never return
ReferenceType, which is logical because if [[Call]] return
ReferenceType will be have reference to Activation Object of execution
context which is finish. And AO cannot be marked as garbage collection
when execution context exit.





From: Jorge on
On Feb 20, 11:36 am, Asen Bozhilov <asen.bozhi...(a)gmail.com> wrote:
> Jorge wrote:
> > Asen Bozhilov wrote:
> > > Richard Cornford wrote:
> > > > "The source text is scanned from left to right, repeatedly taking the
> > > > longest possible sequence of characters as the next input element". So
> > > > given +++, the longest possible sequence of characters that can be a
> > > > token is ++, leaving the last + to be the next token.
>
>                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> > > There SyntaxError instead of runtime error.
> > As Richard said, the parser tries to math the longest sequence of
> > characters that makes sense. In this case ++ makes sense, but as soon
> > as the next character found is +, it stops making sense and throws.
>
> From which grammar rules `+y` isn't valid `UnaryExpression`?

For the same reason that ++2 throws: +y is a number not a reference.

> And why in next example there runtime exception instead of
> SyntaxError?
>
> ++ function(){}(); //ReferenceError
> ++ function(){}; //SyntaxError

In Safari both throw a referenceError: Prefix ++ operator applied to
value that is not a reference.

> `++` operator works with ReferenceType "13.2.1 [[Call]]", never return
> ReferenceType, which is logical because if [[Call]] return
> ReferenceType will be have reference to Activation Object of execution
> context which is finish. And AO cannot be marked as garbage collection
> when execution context exit.

And ? It can return a reference to a function, isn't it?
--
Jorge.

From: kangax on
On 2/20/10 4:21 AM, Asen Bozhilov wrote:
> Richard Cornford wrote:
>
>> That is an explanation, but not a full explanation because it does not
>> state why +++ must be interpreted as the tokens ++ followed by the token
>> +, rather than + followed by ++. The answer to that is in the spec, in
>> the last sentence of the first paragraph of section 7, where it says
>> "The source text is scanned from left to right, repeatedly taking the
>> longest possible sequence of characters as the next input element". So
>> given +++, the longest possible sequence of characters that can be a
>> token is ++, leaving the last + to be the next token.
>
> How can you explain:
>
> var x = 10;
> +++x;
>
> There SyntaxError instead of runtime error.

If this gives SyntaxError, that's a bug in implementation (should be
ReferenceError of course, as per PutValue). I know that Mozilla is
rather non-conforming in this regard. For example, in Mozilla,
CallExpression on the left hand side of AssignmentExpression results in
SyntaxError, rather than what should really be a ReferenceError:

function f(){}
f() = 1;

gives "SyntaxError: invalid assignment left-hand side" whereas in WebKit
there's an expected "ReferenceError: Left side of assignment is not a
reference."

--
kangax