No more modes?

David Herman dherman at mozilla.com
Thu Oct 14 08:57:58 PDT 2010


> Given <script type="harmony"> as an opt-in, I'm puzzled about how it would work anyway. Since it is per script, not per frame, presumably
> 
> <script type="harmony">"use strict"; var e1 = eval;</script>
> <script>"use strict"; var e2 = eval;</script>
> <script ...>"use strict"; e1 === e2 /*results in true*/ </script>

That's not quite right, at least according to the simple modules design. But it's my fault for not spelling it out clearly enough in the strawman. In particular:

- Harmony scripts would not have the legacy global object as a record in their scope chain
- Harmony eval retains the same value and behavior as ES5-strict eval, i.e., it evaluates its code as legacy code, not as Harmony code.

Both of these are open to discussion, of course, but I offer them at least as counter-evidence to your implication that there's no answer to the versioning question other than eliminating modes.

The invariants of Harmony do *not* rely on not interacting with legacy code. You still get lexical scope, and ES5-strict eval is sufficient for that purpose. (When you run eval, of course, you're running code in a language that doesn't have full lexical scope.)

> In other words, that both harmony and non harmony code on the same page have the same binding for the global "eval" function. In that case, what does the following code do:
> 
>     e2(' "use strict"; var module = 8;');
> 
> This is currently legal es5/strict code. As suggested by the modules strawman, it is not legal harmony code.

It's perfectly legal. It's an indirect eval, regardless of whether it's being called from ES5-strict or Harmony.

> es5/strict and harmony share a heap.

Yep, and that's fine.

> I do not see a good answer.

As you say, that's why it's worth discussing.

Dave



More information about the es-discuss mailing list