non-ES5 strict mode restrictions

Dave Fugate dfugate at
Mon Jun 20 10:50:02 PDT 2011 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 ('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:)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list