From: Matthias Miller <Blog@OutOfHanwell.com> - 2006-08-15 03:19:07
Johan Rosman wrote:
> Hi Matthias,
> It happened that I found some weird issue in Drip/Sieve. In one of our
> web applications we have a construction where we make a clone of a clone.
> Let me try to explain the problem step by step:
> - we have some DOM node having a property called ‘myid’ with the value
> “the original”
> - we make a clone of that object and named it ‘clone’
> - we set some property ‘myid’ on ‘clone’ with clone.myid = “the clone”
> - then we make a clone of the clone with cloneOfClone =
> - then we observe the value of cloneOfClone.myid. The value of that
> property should be “the clone” but when running in Drip it shows the
> value “the orginal”
> I have attached a test page, when you run this page inside ‘Drip0.5’
> it will show you the error. However when you run this page in ‘IE’ it
> goes fine. In ‘sIEve’ I had the same problem. I analyzed the problem
> and the problem is caused by the cloneNode method overriding. I have
> attached a 2^nd page where you can simulate the error when running
> without Drip but straight in the IE browser.
> For my sIEve project I made straight forward work around in the
> you are talking about ‘preserving the this pointer’. Did you encounter
> similar problems? May be you can explain more in detail what you are
> trying to solve in that particular function.
Thanks for the test case.
If I recall correctly, after certain of the overridden functions are
executed (I believe it was cloneNode), "this" will point to a different
node. That's why I'm using the "self" parameter. This is unrelated to
the problem that you're seeing.
The reason for this problem is that when you clone a node, the cloneNode
override is copied from the original node to the cloned node. Since this
override contains a reference to the native function for the original
node, it clones the wrong node. I've changed drip.js to dynamically
retrieve the native function to prevent this problem. You can see how I
implemented this in __drip_createOverrideFunction in drip.js.