Subj : Re: E4X: calling appendChild method with existing child as the argument
To : netscape.public.mozilla.jseng
From : Martin Honnen
Date : Sat Apr 09 2005 05:14 pm
Brendan Eich wrote:
> 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).
If Spidermonkey is correct should it be able to deal with "recursive"
XML like the following?
var god = Kibo;
var infiniteGod = god.appendChild(god);
print('infiniteGod.nodeKind(): ' + infiniteGod.nodeKind());
print(god.toXMLString());
The Spidermonkey shell runs out of memory on the last line with
toXMLString():
js> load('mozillaBugs/e4x/recursiveXML1.js');
infiniteGod.nodeKind(): element
mozillaBugs/e4x/recursiveXML1.js:4: out of memory
I have a feeling that such cyclic structures will cause a lot of
troubles when using E4X. What is going to happen if I have an XML DOM with
KiboXibo;
then wrap it with
var xmlObject = XML(domNode);
and do the
xmlObject.appendChild(xmlObject.god[0])
In the DOM a node can only be at exactly one position so how would
xmlObject.domNode()
look then?
--
Martin Honnen
http://JavaScript.FAQTs.com/
.