Subj : Re: E4X: calling appendChild method with existing child as the argument To : Martin.Honnen From : Brendan Eich Date : Fri Apr 08 2005 03:51 pm Martin Honnen wrote: > > In E4X XML objects have a method called appendChild which behaves > differently in regardance to object identity when the method is called > with an existing child as the argument: > > Spidermonkey: > > js> var gods = KiboXibo; > js> gods > > Kibo > Xibo > > js> gods.appendChild(gods.god[0]) > > Kibo > Xibo > Kibo > > js> gods.god[0] === gods.god[2] > true SpiderMonkey is correct if you follow ECMA-357 9.2.1.2 XMLList [[Put]], in particular 2(g)(ii)(2). I say file a Rhino bug, although 9.2.1.2 is a confusingly complicated part of the spec, and in particular, it wastes cycles and space making a new element node to insert as gods.god[2], then replaces it in 2(g) with a reference to gods.god[0]. Bcc'ing some folks who may have an opinion on how the spec might be improved here. /be > > so here after the appendChild the XML objects has two identical child > elements at different positions. > > Compare to Rhino 1.6 release 1 2004 11 30 > js> var gods = KiboXibo; > js> gods > > Kibo > Xibo > > js> gods.appendChild(gods.god[0]) > > Kibo > Xibo > Kibo > > js> gods.god[0] === gods.god[2] > false > > Which behaviour is right, Spidermonkey's or Rhino's? > .