Strict mode and early errors

Juriy Zaytsev kangax.dev at gmail.com
Wed Oct 13 06:59:56 PDT 2010


Strict mode support has just landed in WebKit. While running few simple
tests on it (http://kangax.github.com/es5-compat-table/strict-mode/), I
noticed that WebKit reports some of the errors early. For example, as far as
I understand, assignment to an unresolvable reference (in strict mode) ought
to throw ReferenceError — as explained in 11.13.1 (Simple Assignment) and
8.7.2 (PutValue).

"use strict";
i_dont_exist = 1; // <-- should throw ReferenceError

However, in WebKit this is a SyntaxError (with a somewhat cryptic message of
"Parse Error", but that's irrelevant here).

What I'm not sure about is whether this is allowed per Chapter 16. The list
of early errors does not include this scenario. It does allow to treat
"assignment to non-reference" as an early error (e.g. 3 = 4), but says
nothing about assignment to an unresolvable reference. It also seems to
disallow any deviations in a very explicit manner:

  "An implementation shall not treat other kinds of errors as early errors
even if the compiler can prove that a construct cannot execute without error
under any circumstances. An implementation may issue an early warning in
such a case, but it should not report the error until the relevant construct
is actually executed."

The reason I'm bringing this up is because my test suite expected
ReferenceError, and so looked like:

try {
  i_dont_exist = 1;
}
catch(err) {
  assert(err instanceof ReferenceError);
}

...which resulted in SyntaxError, preventing entire set from running.

Is this kind of early errors allowed and I missed something in the specs? Or
should one of — WebKit or spec —  be changed accordingly? Note that nightly
FF — the only other browser with strict support at the moment — throws
ReferenceError, as expected.

cc'ing Oliver

Thank you.

-- 
kangax
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es5-discuss/attachments/20101013/80895165/attachment.html>


More information about the es5-discuss mailing list