Strict mode and early errors

Oliver Hunt oliver at apple.com
Wed Oct 13 10:01:06 PDT 2010


Could you file a bug on this -- I clearly interpreted the spec incorrectly, i presume I decided to treat it as a syntax error as I implemented this just after all the other early errors.

For all of our implementation I tended towards the most strict interpretation/earliest breakage as I figured that incorrectly being too strict was safer than being to lax.

--Oliver

On Oct 13, 2010, at 8:28 AM, Mark S. Miller wrote:

> It is a bug in WebKit. Consider
> 
>   (function(global) {
>     'use strict';
>     global['foo'] = 88;
>     foo = 99;
>   })(this);
> 
> This code is not erroneous. By the time it assigns to global foo, there is a global foo and so there's no problem to report. Minefield (FF nightly) does this correctly. WebKit reports this as a SyntaxError (I just checked), since "early" is too early to tell in general that there will be nothing wrong by the time the assignment is executed.
> 
> 
> That aside, I'd like to offer my congratulations to WebKit for taking this huge step towards strict mode support!
> 
> 
> On Wed, Oct 13, 2010 at 6:59 AM, Juriy Zaytsev <kangax.dev at gmail.com> wrote:
> 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
> 
> _______________________________________________
> es5-discuss mailing list
> es5-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es5-discuss
> 
> 
> 
> -- 
>     Cheers,
>     --MarkM
> _______________________________________________
> es5-discuss mailing list
> es5-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es5-discuss

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


More information about the es5-discuss mailing list