hoisting past catch

Mark S. Miller erights at google.com
Mon Oct 11 19:26:55 PDT 2010

Sigh. You are completely correct. This is goofy and strict mode should have
disallowed it. It is so goofy that I have to observe: No one has yet shipped
even a beta implementation of full strict mode, so practically it is not too
late for the browser makers to all agree to reject this case with a static
error. If none disagree, perhaps it is not too late to add this to the ES5
errata, even though it is a spec change and not "really" an errata. It won't
be our first such.

On Tue, Oct 12, 2010 at 1:40 AM, David Herman <dherman at mozilla.com> wrote:

> ES3 `catch' is block-scoped. At the last face-to-face, we talked about
> statically disallowing var-declarations from hoisting past let-declarations:
>    function f() {
>        {
>            let x = "inner";
>            {
>                var x = "outer"; // error: redeclaration
>            }
>        }
>    }
> I just noticed a case I missed in the discussion, which has actually
> existed since ES3:
>    function g() {
>        try {
>            throw "inner";
>        } catch (x) {
>            var x = "outer";
>        }
>    }
> This is allowed, and it binds a function-scoped variable x, while assigning
> "outer" to the catch-scoped variable x. This is pretty goofy, and almost
> certainly not what the programmer expects. And it's exactly analogous to the
> function f above, which SpiderMonkey currently rejects and we all agreed
> Harmony ought to reject.
> It's too late to add this case to ES5's strict mode restrictions, but I
> propose we ought to reject it in Harmony.
> Dave
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

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

More information about the es-discuss mailing list