non-ES5 strict mode restrictions

Dave Fugate dfugate at microsoft.com
Mon Jun 20 10:50:02 PDT 2011


http://wiki.ecmascript.org/doku.php?id=conventions:no_non_standard_strict_decls describes the fact that FunctionDeclaration grammar productions cannot be substituted for Statement productions under Strict Mode.  This obviously makes snippets like:
                "use strict";
try {
                                function f() {}
                } catch(e) { /*never called - statement above is an early error*/}

early syntax errors.


What's not so clear though is when the offending FunctionDeclaration is generated via an eval:
                "use strict";
try {
                                eval("function f() {}");
                } catch(e) { /*should this be called?*/}


In this snippet, there is no early syntax error here, but there is a bit of a dilemma:

1.       Direct evals are subject to strict mode restrictions if the scope they're being called from is in strict mode.  In other words, where (grammatically-speaking) a direct call to eval is made already affects its behavior. This isn't covered in 15.1.2.1 ('eval(x)'), but it is covered elsewhere in ES5

2.       This FunctionDeclaration is technically within a try/catch, although strict mode ensures 'f' doesn't exist outside of the eval's context

The million dollar question then is should "/*should this be called?*/" in the snippet above be called or does the eval call succeed without throwing?  From ES5 alone, I would argue no exception should be thrown, but this isn't an ES5 feature per-se:)

Thanks!

Dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110620/8a41b9f0/attachment-0001.html>


More information about the es-discuss mailing list