A directive to solve the JavaScript arithmetic precision issue

David Bruant david.bruant at labri.fr
Mon Aug 15 12:26:00 PDT 2011

Le 15/08/2011 20:45, Kyle Simpson a écrit :
>> A directive would have the same benefits than use strict which is to not
>> break existing code in platform that do not support this directive.
> It would also have the same limitation that "use strict"; does, which
> is that it doesn't play well with (the quite common pattern of)
> concat'ing minified scripts together in build environment deployments,
> because your "use stict" declaration in one of your files bleeds over
> (probably unintentionally) to affecting other files when they are all
> combined into one file.
I intuit that the consequences are less harmful. Strict mode can trigger
some syntax errors or throw runtime errors that wouldn't happen in
non-strict code. Different arithmetic is less likely to cause this kind
of problem. I can't think of syntax errors (at worst, the directive can
be designed to avoid additional syntax errors). But runtime would
definitly be affected, that's true.
Do you have an idea of a current running program that would behave
significantly differently with an accidental bleed of arithmetic mode?

> Maybe something like:
> use "sensible arithmetic" {
> // ..
> };
Are you refering to the pragma proposal [1]? I am not used to it, but if
it's applicable, that's an idea too.


[1] http://wiki.ecmascript.org/doku.php?id=harmony:pragmas

More information about the es-discuss mailing list