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

Dmitry Soshnikov dmitry.soshnikov at gmail.com
Thu Sep 9 10:33:20 PDT 2010


On Thu, Sep 9, 2010 at 6:32 PM, 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.



Actually it does (since a strict mode, and the directive prologue is an
initial statement):

"use strict";eval=10 // strict, error

but

;"use strict";eval = 10; // non-strict, OK


> The problem at real sites including an intel.com property is that
> subsequent parts of the concatenation have had strict mode errors.
>
>
The second part of the (combined) file is also evaluated in non-strict,
because again, "use strict" is placed not at the initial position. So, the
whole file is in non-strict.

However, as mentioned Mike Shaver, there can be issues with vice-versa,
turning to non-strict, e.g. non-object or even non-undefined /this/ value.

So, the suggestion is just a workaround.

Dmitry.


>
> > ;/*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.
>
> /be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20100909/af7ced44/attachment-0001.html>


More information about the es-discuss mailing list