Fun impossible Firefox JS challenge

Mathias Bynens mathias at qiwi.be
Thu Apr 12 07:49:52 PDT 2012


On Thu, Apr 12, 2012 at 3:51 PM, Lasse Reichstein wrote:
> /* MY CODE */
> tru\u0065();

That would only work if the `true` function was defined with at least
one Unicode escape in the name (not necessarily the same one). See
http://mathiasbynens.be/notes/javascript-identifiers#valid-identifier-names:

> […] This means that you can use `var \u0061` and `var a` interchangeably.
> Similarly, since `var 1` is invalid, so is `var \u0031`.
>
> For web browsers, there is an exception to this rule, namely when reserved
> words are used. Browsers must support identifiers that unescape to a
> reserved word, as long as at least one character is escaped using a Unicode
> escape sequence. For example, `var var;` wouldn’t work, but e.g.
> `var v\u0061r;` would — even though strictly speaking, the ECMAScript spec
> disallows it. Subsequent use of such identifiers must also have at least
> one character escaped (otherwise the reserved word will be used instead),
> but it doesn’t have to be the same character(s) that were originally used
> to create the identifier. For example, `var v\u0061r = 42; alert(va\u0072);`
> would alert `42`.

P.S. If you’re wondering why `function true() {}` is allowed in
Firefox, see https://bugzilla.mozilla.org/show_bug.cgi?id=638667.


More information about the es-discuss mailing list