loop unrolling and completion values in ES6

Brendan Eich brendan at mozilla.org
Wed Apr 8 17:13:06 UTC 2015


Allen Wirfs-Brock wrote:
> Well, they do for normal loop completions (according to the spec.) but not for breaks.  I this the latter is a bug.  In particular, I think it is pretty obvious that:
>     eval(“ {0; while (true) {1; break}; 2}”)

(single quotes might avoid the smart-dumb transformation that happened 
here, which frustrated copy-paste into JS console :-|.)

> should evaluate to 1

Why? Completion is on the 2; expression statement at the end. The break 
doesn't break from the block.

> It is a little less obvious for:
>     eval(“{0; L: while (true) {1; while (true) {2; break L; 3}; 4}; 5}”)
>
> but, I think that consistency with the first case requires this to evaluate to 2.

The 3; and 4; statements are not reached, but 5; is -- again something 
seems wrong with these examples.

/be


More information about the es-discuss mailing list