> On Jul 18, 2017, at 6:13 PM, Alex Harui <[email protected]> wrote:
>
> I assume you tested this with regular Flex and not the Falcon compiler?
Yes.
> I just want to verify a couple of your findings.
>
> 1) Does passing empty string really produce an XML object with no children
> or is there a child textNode with “”?
new XML() and new XML(null) and new XML(“”) all produce identical XML objects.
By default, XML seems to have a nodeKind of text. If you set properties on the
XML, that changes. If you pass a string, it creates a text node with no
children:
The following:
var xml7:XML = new XML();
var xml8:XML = new XML("");
var xml9:XML = new XML(null);
var xml10:XML = new XML("foo");
var xml11:XML = new XML({foo:"baz"});
trace(xml7.children().length());
trace(xml8.children().length());
trace(xml9.children().length());
trace(xml10.children().length());
trace(xml11.children().length());
trace(xml7);
trace(xml8);
trace(xml9);
trace(xml10);
trace(xml11);
Outputs:
0
0
0
0
0
foo
[object Object]
> 2) If you pass in an XMLList with one element, doesn't
>
> var harbs:XML = XML(someXMLListWithOneElement)
>
> return the one element but
>
> var harbs:XML = new XML(someXMLListWithOneElement)
>
> return a clone?
Good call.
The following code:
var xml1:XML = new XML("foo");
var xml2:XML = XML(xml1);
var xml3:XML = new XML(xml1);
trace(xml1 === xml2);
trace(xml1 === xml3);
var xml4:XMLList = new XMLList(xml1);
var xml5:XML = new XML(xml4);
var xml6:XML = XML(xml4);
trace(xml1 === xml5);
trace(xml1 === xml6);
trace(xml5 === xml6);
Outputs:
true
false
false
true
false
(“==“ outputs true for all of the above.)
>
> IMO, toXML should do what Flash does unless it is really expensive. If
> you had code that relied on Flash behavior, what would you have to do to
> rework the code to the spec?
>
I think the observed behavior is bug-prone. The documented behavior makes much
more sense. I can’t think of a good reason to cast null or undefined to XML. If
you really want to cast on object to a string, you can always call toString().
Fixing such code should be really easy.
In terms of implementation, it’s not really harder one way or the other.
> My 2 cents,
> -Alex
>
> On 7/18/17, 1:29 AM, "Harbs" <[email protected]
> <mailto:[email protected]>> wrote:
>
>> Actually, it’s not really necessary to allow null and undefined to get an
>> empty XML object. The constructor can default to en empty string. So an
>> empty string could get an XML object while null and undefined could throw
>> an error.
>>
>> That might make more sense because it would likely catch more errors.
>>
>>> On Jul 18, 2017, at 11:07 AM, Harbs <[email protected]> wrote:
>>>
>>> I discovered that the documentation on the top level functions is wrong.
>>>
>>> According to the docs[1] the only valid expressions for XML and XMLList
>>> are: XML, XMLList, Boolean, Number and String. Anything else is supposed
>>> to throw an error.
>>>
>>> What actually happens is that null and undefined are simply swallowed
>>> and you get an empty XML text node object. Everything else simply has
>>> toString() called on it, so if you pass in an Object which does not have
>>> an implementation of toString(), you’ll get a text node with a value of
>>> [object Object].
>>>
>>> In my tests, new XML() and XML() behave identically.
>>>
>>> That’s not what I’d call great behavior…
>>>
>>> So the question is what to do. What I think makes sense is to make
>>> toXML() behave like the docs and new XML() behave like the observed
>>> behavior. At the least for null and undefined. There needs to be a way
>>> to instantiate an empty XML object. I’m on the fence about objects. I’m
>>> leaning toward always throwing an error if the argument is an object.
>>>
>>> Thoughts?
>>>
>>> Harbs
>>>
>>>
>>> [1]https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fhelp.a
>>> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fhelp.a>
>>> dobe.com
>>> <http://dobe.com/>%2Fen_US%2FFlashPlatform%2Freference%2Factionscript%2F3%2Fpackage
>>> .html%23XML&data=02%7C01%7C%7C9ab55b27d96c403de2e208d4cdb7a394%7Cfa7b1b5a
>>> 7b34438794aed2c178decee1%7C0%7C0%7C636359635983774211&sdata=rxcx9eUoc%2F%
>>> 2FufMzesTKqS8fp7bdV1yQUIoPyckupXGs%3D&reserved=0()
>>> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fhelp.ado
>>> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fhelp.ado>
>>> be.com
>>> <http://be.com/>%2Fen_US%2FFlashPlatform%2Freference%2Factionscript%2F3%2Fpackage.h
>>> tml%23XML&data=02%7C01%7C%7C9ab55b27d96c403de2e208d4cdb7a394%7Cfa7b1b5a7b
>>> 34438794aed2c178decee1%7C0%7C0%7C636359635983774211&sdata=rxcx9eUoc%2F%2F
>>> ufMzesTKqS8fp7bdV1yQUIoPyckupXGs%3D&reserved=0()>
>>>
>>>> On Jul 18, 2017, at 8:20 AM, Harbs <[email protected]
>>>> <mailto:[email protected]>
>>>> <mailto:[email protected] <mailto:[email protected]>>> wrote:
>>>>
>>>> I’ll try to write these functions today.