W3C home > Mailing lists > Public > www-dom@w3.org > January to March 2013

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

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Tue, 15 Jan 2013 17:12:50 -0500
Message-ID: <50F5D462.8030607@mit.edu>
To: www-dom@w3.org
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.

Indeed.

>> 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.

Indeed.

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

Yes.

> 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!

-Boris
Received on Tuesday, 15 January 2013 22:13:20 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 15 January 2013 22:13:21 GMT