Is \u006eew a valid Identifier?

Allen Wirfs-Brock allen at wirfs-brock.com
Sat Nov 7 16:52:19 UTC 2015


> On Nov 7, 2015, at 7:32 AM, Caitlin Potter <caitpotter88 at gmail.com> wrote:
> 
> That it works in Chrome is a bug, which will hopefully be fixed by Monday or Tuesday!
> 
> Per http://tc39.github.io/ecma262/#sec-keywords, “new” is a Keyword, which makes it a ReservedWord.
> 
> Per http://tc39.github.io/ecma262/#sec-identifiers-static-semantics-early-errors, under the
> “Identifier: IdentifierName but not ReservedWord” section, the second early error applies here. This applies to
> `new`, which is always a reserved word. So whenever an Identifier is expected, if it contains UnicodeEscapeSequences which result in the same StringValue as a ReservedWord, it’s an error.

yup
> 
> The spec is similarly explicit in saying that escaped ReservedWords are not valid as ReservedWords. Browsers behave differently here (for instance, http://jsfiddle.net/jd51pqae/ <<< at the time of this writing Webkit Nightly prints the text, while other browsers SyntaxError. in Chromes case, this is because it’s tokenized as an Identifier, so the second Identifier “f” is unexpected when parsing a MemberExpression. SpiderMonkey is doing a nice job of reporting clean errors for this kind of thing, that are easier to understand.
> 
> There are some odd points though:
> 
> 1. ReservedWord restrictions never apply to `get` or `set`, even in ObjectLiterals (though currently Chrome fails to treat `g\u{65}t` or `s\u{65}t` as an accessor prefix, this is a bug).

Chrome is doing the right thing here  and should not change.  The intent is that in the syntactic grammar a sequence of characters in bold font such as  get (for example, see  http://ecma-international.org/ecma-262/6.0/#sec-method-definitions <http://ecma-international.org/ecma-262/6.0/#sec-method-definitions> ) matches  exactly that sequence and does not match theescaped equivalences.  That is why the grammar says get rather than saying Identifier with a static semantic restriction that the StringValue of the Identifier must be “get”.

I think this is implicit in a careful reading of the grammars, but perhaps would benifit from a explicit note stating this.
> 
> 2. In the case of “new.target”, it’s technically legal to write `new.t\u{61}rget`, but this mostly just seems like an oversight in the spec.

no, for the same reason. http://ecma-international.org/ecma-262/6.0/#sec-left-hand-side-expressions <http://ecma-international.org/ecma-262/6.0/#sec-left-hand-side-expressions> says:

NewTarget :
   new  .  target

new is a keyword, target is an explicit character sequence that doesn’t allow for unicode escapes. 

Allen


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151107/fcf659e9/attachment.html>


More information about the es-discuss mailing list