The global object in browsers

Mark Miller erights at gmail.com
Tue Feb 17 20:17:36 PST 2009


On Tue, Feb 17, 2009 at 6:38 PM, Brendan Eich <brendan at mozilla.com> wrote:

> On Feb 17, 2009, at 6:31 PM, Mark Miller wrote:
>
>  Now that I think I understand "current" and how weak the legacy
>> constraints are, why not simply spec that your WindowProxy is the object to
>> treated as the ECMAScript global object? The consequence would be that both
>> f() and g() in your original example would return 2.
>>
>
> That either opens a huge security hole, or imposes costly runtime checks on
> all lexical references to global variables.
>

If Ian's Window object were provided as the ES global, then we'd have the
security problem you're concerned about. But, IIUC, with the WindowProxy we
don't. As for performance, wouldn't a shallow binding implementation[1] make
switching which page is current be more expensive, but variable access
within a page, even after a switch, would have no added expense?

[1] The two primary methods of implementing dynamic scoping were known as
"shallow binding" and "deep binding". Although "current" is not dynamic
scope, some of the same issues and tradeoffs apply. In a shallow bound
implementation. the WindowProxy's properties are direct properties -- not
forwarded. On page navigation, these properties are copied into the Window
object corresponding to the old page, and the properties on the Window
object corresponding to the new page are copied onto the WindowProxy.

Another analogy is with the register store in thread control blocks in an OS
implementation. One can describe the semantics of computation in a given OS
as directly updating the "current" per-thread register set. But instead of
paying the indirection on register access, we'd rather pay the copying
overhead on context switch.

-- 
Text by me above is hereby placed in the public domain

   Cheers,
   --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20090217/e9cf0bae/attachment.html>


More information about the Es-discuss mailing list