"use strict"; prepended blindly to scripts in the wild

Brendan Eich brendan at mozilla.com
Thu Sep 9 09:33:03 PDT 2010


On Sep 9, 2010, at 8:46 AM, Dean Landolt wrote:

> On Thu, Sep 9, 2010 at 10:32 AM, Brendan Eich <brendan at mozilla.com> wrote:
> On Sep 9, 2010, at 1:09 AM, Dmitry Soshnikov wrote:
> 
> > Thus the site's combined file won't be globally strict, however since a lib is tested before a production release (at least I hope so ;), then the lib's code should pass the strictness, and therefore, a "use strict" may be even removed from the lib's file. However, if not to remove, then an empty statement is enough.
> 
> That does not disable strict mode. The problem at real sites including an intel.com property is that subsequent parts of the concatenation have had strict mode errors.
> 
> 
> > ;/*1st lib*/"use strict";eval = 10;/*2st lib*/"use strict";arguments=20;/*our code*/
> 
> 
> An example showing the problem would need a "use nonstrict"; directive after the first part of the concatenation, but there is no such directive.
> 
> 
> I recall reading that the "use strict"; directive was block-scoped. Is this true? If so, there's no need for function wrappers -- putting each script in its own block is easy and should have no ill effects on concatenation, right?

No, the "use strict"; directive is meaningful only at top of program and function bodies. See ES5 14.1:

14.1 Directive Prologues and the Use Strict Directive 

A Directive Prologue is the longest sequence of ExpressionStatement productions occurring as the initial SourceElement productions of a Program or FunctionBody and where each ExpressionStatement in the sequence consists entirely of a StringLiteral token followed a semicolon. The semicolon may appear explicitly or may be inserted by automatic semicolon insertion. A Directive Prologue may be an empty sequence. 


You may be thinking of ES4-era unquoted use strict; pragma syntax, which was block scoped. In Harmony, use ...; should be a block-scoped pragma -- real syntax, no quotes.

/be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20100909/b4982735/attachment.html>


More information about the es-discuss mailing list