« Bugzilla Issues Index

#278 — Coverage: Test for 7.6, keywords with unicode escapes.

There is no test checking the correct treatment of keywords with identifier names, and Section 7.6 of the spec isn't particularly clear on the subject either (see bug 277).

Implementations differ. For example,

v\u0061r x = 0
eval("v\\u0061r y = 1")

Is accepted by FF 10, rejected by V8 3.8, and JSC seems to reject the former
but accepts the latter. Conversely,

var v\u0061r = 1
eval("var v\\u0061r = 2")

is rejected by FF but accepted by V8 (actually introducing a variable named

Note that test262 contains several tests of the form

eval("var v\u0061r = 2")

which is rejected by all implementations. However, here the escape sequence is decoded as part of string parsing in the meta program, not as part of identifier parsing in the object program.

Related from Mathias Byens:
I recently did some research on valid JavaScript identifiers ( and found some interesting implementation bugs.

E.g. `a\u200c\u200d` is a valid identifier as per ES5.1 (, yet a lot of JavaScript engines claiming full ES5 support fail to support it. Out of all stable browser versions, Firefox 10 and IE9 are the only two that handle it correctly.

For this reason, I propose a new test is added to the suite. Something like:

var supportsZeroWidthInIdentifierPart = (function() {
try {
return eval('var a\u200c\u200d = true');
} catch(e) { }

`supportsZeroWidthInIdentifierPart` will be `true` if ZWJ and ZWNJ characters are supported in `IdentifierPart`, else `undefined` (which is falsy).

Along with 7.6, there are other places that need unicode escape tests. ES5 spec section 11.1.2 explains that identifiers can be used as expressions. Test cases targeting expressions should also be included.

// Invalid use of a reserved keyword in an expression. Should throw a syntax error
var c = var;
var c = v\\u0061r;
var c = else;
var c = els\\u0065;

// valid uses
var a = fals\\u0065;
var b = tru\\u0065;

// Also unicode escape tests should include properties and function names
var x2={};
x2.els\\u0065 = 10

var x2={};
x2.doubl\\u0065 = 10;

function else\\u0065() {};

function doubl\\u0065() {};

I’ll just link to my old (but still relevant) tests on the subject:

The tests expect the non-standard `var v\u0061r;` behavior (where keywords are allowed as identifiers as long as at least one character is escaped) to throw an error, as browser vendors seemed to agree that this behavior isn’t required for Web compatibility. (For this reason, it has been removed from as well.)