Multiple globals and changing prototypes

# Anne van Kesteren (12 years ago)

I believe last time this came up here some people hard concerns so I was wondering whether that was still the case and what alternatives there might be.

In www.w3.org/Bugs/Public/show_bug.cgi?id=20567 we're considering to define the behavior Gecko exhibits when moving a node between trees in different global objects.

Event handlers and custom elements make this somewhat more tricky and we're discussion how to work with them in the bug.

The reason we want to change prototypes is to reduce the potential for memory leaks and give consistent behavior across nodes in a tree. I.e. they'll always be from the same global.

(There's also the more complicated document.open() scenario, which we should discuss separately at some point I think, but for those trying to figure out how to define multiple realms in ECMAScript that's worth looking into.)

# Mark S. Miller (12 years ago)

Keep in mind that if an object is non-extensible, its [[Prototype]] cannot be changed.

# Allen Wirfs-Brock (12 years ago)

On Oct 16, 2013, at 7:25 AM, Mark S. Miller wrote:

Keep in mind that if an object is non-extensible, its [[Prototype]] cannot be changed.

And objects that are implemented using a Proxy don't use their [[Prototype]] slot (a Proxy they doesn't have one) or necessarily even their target's [[Prototype]] to perform lookup of inherited properties. They can implement inheritance in come completely different manner and using any internal state they want. The only way I can imagine generalizing what you are describing is to call the [[SetPrototypeOf]] MOP operation on the object and even then there is no general guarantee that the request would be accepted or that it would do what you are imagining.

# Tom Van Cutsem (12 years ago)

The relevant invariant for [[SetPrototypeOf]] is that if the target is non-extensible, and the operation returns "true" (i.e. appears to succeed), then [[GetPrototypeOf]] must return the same result as the value passed into [[SetPrototypeOf]].

This is what I got from the current ES6 draft: people.mozilla.org/~jorendorff/es6-draft.html#sec-proxy-object-internal-methods-and-internal-data-properties-setprototypeof-v

It is always OK for [[SetPrototypeOf]] to return false to indicate reparenting is not possible.