Throwing errors on mutating immutable bindings

Jason Orendorff jason.orendorff at gmail.com
Wed Oct 1 11:32:36 PDT 2014


I think there is a way that the error could occur at runtime even in
all-strict-mode code: when a new const is added at toplevel in a
second script.

    <script>
      "use strict";
      function f(value) { x = value; }
    </script>
    <script>
      "use strict";
      const x = 0;
      f(1);
    </script>

-j


On Wed, Oct 1, 2014 at 11:15 AM, Allen Wirfs-Brock
<allen at wirfs-brock.com> wrote:
>
> On Oct 1, 2014, at 9:05 AM, Mark S. Miller wrote:
>
> Good point. If we can require all such assignments to be rejected
> statically, why is a runtime assignment to a const variable even possible?
> Can't we just assert that this cannot occur?
>
>
> The runtime cases I meant are the ones you mentioned. Sloppy with or eval
> dynamically shadowing a sloppy a [[Set]] reference to a const binding.
> Can't be a early error, should be a runtime error.
>
> Allen
>
>
>
>
>
>
> On Wed, Oct 1, 2014 at 8:59 AM, Allen Wirfs-Brock <allen at wirfs-brock.com>
> wrote:
>>
>>
>> On Oct 1, 2014, at 8:39 AM, Mark S. Miller wrote:
>>
>> ...
>>
>> I was with you until you got to the following point
>>
>> >
>> > If there is an intervening "with" or sloppy direct eval, then there is
>> > not a statically apparent assignment to a const variable. Since this can
>> > only occur in sloppy code anyway, it seems more consistent with the rest of
>> > sloppy mode for this failed assignment to be silent, rather than dynamically
>> > throwing an error.
>> >
>>
>> const is a new kind of declaration unlike any declaration form that
>> previous existed in ES, so Ii don't think its handling introduces any legacy
>> consistency issues.  If somebody is using const, regard less of mode, they
>> pretty clearly expect assignments to any const bindings to be illegal.  And,
>> I don't think any body wants new silent failure errors, even in sloppy mode.
>> The most consistent thing is for runtime detected assignments to const
>> bindings to always be noisy errors.  Early where possible, at runtime in the
>> rest of the cases.
>>
>> Allen
>>
>
>
>
> --
>     Cheers,
>     --MarkM
>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>


More information about the es-discuss mailing list