Re: [dom] Need to describe the interaction of adoptNode with prototype chains

On 1/15/13 4:59 PM, Geoffrey Garen wrote:
> FWIW, I don't buy the instanceof argument.
> 	(a) Passing any object between windows breaks instanceof.

Which is something else we should just fix, for what it's worth.

> 	(c) node.onclick instanceof Function, and instanceof any custom properties, will still fail.


>> 2)  If a script adopts a node from a subframe and then unloads the
>> subframe or removes it from the DOM, remembering the proto means you
>> leak the entire global object _and_ the entire DOM of the subframe
> Changing the prototype doesn't resolve this issue.

It doesn't _necessarily_ resolve it.  It's necessary, but not sufficient.

> Any event listener on the node will keep the entire global object and DOM alive, through the scope chain's link to the lexical environment and its .document property.


> Also, any custom properties on the node wrapper may point to the old lexical environment, directly or indirectly.


> Fundamentally, the DOM is one giant memory leak.

It can be.  In some cases it's nice to have it be just one, not two 
memory leaks.

> In a way, I think this is asking the wrong question. Our task isn't to pick a prototype -- it's to pick a set of observable properties. In a prototype-based language, the prototype is just one way to associate some properties with an object.

Assuming we fix instanceof to not be insane, agreed.

> If that's the goal, I think the best solution is to create a second wrapper. Direct references to the old wrapper would continue to see that wrapper's identity and custom properties (including those implemented by its prototypes), but new references returned by the DOM (e.g. via getElementById) would use a new wrapper, with a new identity and a new set of custom properties defined by its new prototypes.

I think changing object identity on adopt would unfortunately break web 
sites... but I'd welcome an existence proof that my fear is groundless!


Received on Tuesday, 15 January 2013 22:13:20 UTC