Re: FlexJS XML string assignment

2016-08-08 Thread Harbs
No. You never get null for XML (unless it’s an XML typed variable which was never set). On Aug 8, 2016, at 12:45 AM, Alex Harui wrote: > > > On 8/7/16, 2:04 PM, "Harbs" wrote: > >> Yes. That would be better (only 1.5KB), but only in this case. Assigning >> a null value to a string should no

Re: FlexJS XML string assignment

2016-08-08 Thread Harbs
A directive is fine. On Aug 8, 2016, at 8:35 AM, Alex Harui wrote: > > > On 8/7/16, 2:04 PM, "Harbs" wrote: > >> Yes. That would be better (only 1.5KB), but only in this case. Assigning >> a null value to a string should not covert it into an empty string. >> >> I was suggesting to have an

Re: FlexJS XML string assignment

2016-08-07 Thread Alex Harui
On 8/7/16, 2:04 PM, "Harbs" wrote: >Yes. That would be better (only 1.5KB), but only in this case. Assigning >a null value to a string should not covert it into an empty string. > >I was suggesting to have an option to not do any conversions. > >Right now my code works without any string conver

Re: FlexJS XML string assignment

2016-08-07 Thread Alex Harui
On 8/7/16, 2:04 PM, "Harbs" wrote: >Yes. That would be better (only 1.5KB), but only in this case. Assigning >a null value to a string should not covert it into an empty string. For XML, do you ever get null? -Alex

Re: FlexJS XML string assignment

2016-08-07 Thread Harbs
Yes. That would be better (only 1.5KB), but only in this case. Assigning a null value to a string should not covert it into an empty string. I was suggesting to have an option to not do any conversions. Right now my code works without any string conversion at all. This is because of the “string

Re: FlexJS XML string assignment

2016-08-07 Thread Alex Harui
On 8/7/16, 12:09 PM, "Harbs" wrote: >Sure. > >Here’s a couple of examples: > >f.leading = xml.Properties.Leading; >f.tracking = xml.@Tracking; > >I have 492 some assignments like this scattered across my code. Adding >toString() to every one of these would add 5412 bytes to the final >minified

Re: FlexJS XML string assignment

2016-08-07 Thread Alex Harui
On 8/7/16, 9:42 AM, "Harbs" wrote: >Not faster. Smaller. > >I’m sure there’s no much difference speed-wise. Why are you so sure? Function call overhead is significant in AS. Why isn't it so in JS? -Alex

Re: FlexJS XML string assignment

2016-08-07 Thread Harbs
Sure. Here’s a couple of examples: f.leading = xml.Properties.Leading; f.tracking = xml.@Tracking; I have 492 some assignments like this scattered across my code. Adding toString() to every one of these would add 5412 bytes to the final minified code. That’s not including non-XML assignments t

Re: FlexJS XML string assignment

2016-08-07 Thread Harbs
Not faster. Smaller. I’m sure there’s no much difference speed-wise. Once we add type safety to default values, it’ll be a bigger difference in terms of code size. On Aug 7, 2016, at 5:47 PM, Alex Harui wrote: > > > On 8/7/16, 2:19 AM, "Harbs" wrote: > >> BTW, I think another change to La

Re: FlexJS XML string assignment

2016-08-07 Thread Alex Harui
On 8/7/16, 1:55 AM, "Harbs" wrote: >To sum up: > >There are a number of issues involved here. > >What started with a concern about implicit type conversions on XML turned >into a much broader issue. > >In ActionScript, when you assign any object type to typed variable of a >primitive type (or re

Re: FlexJS XML string assignment

2016-08-07 Thread Alex Harui
On 8/7/16, 2:19 AM, "Harbs" wrote: >BTW, I think another change to Language is a good idea: > >Currently default function parameters are compiled like this: > >public static function getBottomValue(value:Object, values:Object, >reference:Number = NaN):Number >{ >return getSideValue(value, v

Re: FlexJS XML string assignment

2016-08-07 Thread Harbs
> One thing that might not be clear: > > Coercion should only happen on *assignment*. Coercion on comparisons should > not happen because the conversions happen implicitly in the JS engine if > required. > > On Aug 7, 2016, at 7:39 AM, Harbs wrote: > >> This dis

Re: FlexJS XML string assignment

2016-08-07 Thread Harbs
bs >> Subject: Re: FlexJS XML string assignment >> Date: August 6, 2016 at 11:50:29 PM GMT+3 >> To: Alex Harui >> >> With the exception of XML, I cannot imagine a case where you’d want there to >> be an implicit conversion to a string. >> >> I’m fine

Re: FlexJS XML string assignment

2016-08-06 Thread Alex Harui
On 8/6/16, 9:39 PM, "Harbs" wrote: >This discussion fell off the dev list... > >Begin forwarded message: > >> From: Harbs >> Subject: Re: FlexJS XML string assignment >> Date: August 6, 2016 at 11:50:29 PM GMT+3 >> To: Alex Harui >> &

Fwd: FlexJS XML string assignment

2016-08-06 Thread Harbs
This discussion fell off the dev list... Begin forwarded message: > From: Harbs > Subject: Re: FlexJS XML string assignment > Date: August 6, 2016 at 11:50:29 PM GMT+3 > To: Alex Harui > > With the exception of XML, I cannot imagine a case where you’d want there to

Re: FlexJS XML string assignment

2016-08-05 Thread Alex Harui
On 8/5/16, 8:05 AM, "Harbs" wrote: >I just checked and Number(obj) is equivalent to Number(obj.valueOf()) > >Like so: >var a = {valueOf : function(){return "5"},toString:function(){return "6”}} > >Number(a) //5 >Number(a.valueOf()) //5 >Number(a.toString()) //6 > >So valueOf() needs to return a

Re: FlexJS XML string assignment

2016-08-05 Thread Harbs
I just checked and Number(obj) is equivalent to Number(obj.valueOf()) Like so: var a = {valueOf : function(){return "5"},toString:function(){return "6”}} Number(a) //5 Number(a.valueOf()) //5 Number(a.toString()) //6 So valueOf() needs to return a value that Number will properly accept. Harbs

Re: FlexJS XML string assignment

2016-08-05 Thread Harbs
On second thought, this is probably wrong. Number(xml) is probably enough as Number should call toString() and deal with all number types correctly. On Aug 5, 2016, at 5:42 PM, Harbs wrote: > If it knows it’s being assigned to a Number, I think it should call > valueOf(), or possibly(Number(x

Re: FlexJS XML string assignment

2016-08-05 Thread Harbs
For cases where the compiler knows that XML is being assigned to a string, it should add toString(). If it knows it’s being assigned to a Number, I think it should call valueOf(), or possibly(Number(xml.valueOf()) There will likely be cases where the compiler will not know the types that the X

Re: FlexJS XML string assignment

2016-08-05 Thread Alex Harui
I have not spent time thinking about this, but the compiler generally knows the destination type. The compiler is going to have to learn when to inject coercion code where AS would do an implicit conversion that JS won't. So fundamentally: what does XML valueOf do in AS? The XML JS implementatio

Re: FlexJS XML string assignment

2016-08-05 Thread Harbs
I implemented this locally and the idea works pretty well for the most part. We still need to do toString() when possible because of edge cases. For example: stringFromXmlList1 == stringFromXmlList2 fails because the Javascript engine does not try to convert them (correctly) to primitive values.

Re: FlexJS XML string assignment

2016-08-05 Thread Harbs
I’m thinking that I should implement valueOf() for XML like this: var str:String = this.toString(); var asInt:int = parseInt(str); if(asInt.toString() == str) return asInt; var asFloat:Number = parseFloat(str); if(asFloat.toString() == str) return asFloat; return str; Thi

Re: FlexJS XML string assignment

2016-08-04 Thread Harbs
Another error: var resultXML:XML = XML(resString); becomes: var /** @type {XML} */ resultXML = org.apache.flex.utils.Language.as(resString, XML, true); When in fact it should become: var /** @type {XML} */ resultXML = new XML(resString); Do you want me to create a JIRA for this? On Aug 4, 201

Re: FlexJS XML string assignment

2016-08-04 Thread Alex Harui
On 8/4/16, 7:22 AM, "Harbs" wrote: >I’m not sure how to deal with this case: > > >private var name:String; > >this.name = someXML.@Name; > >The above compiles to > >this.name = someXML.attribute('Name’); > >In Javascript this.name becomes an XMLList, but in Flash, the XMLList is >implicitly con

FlexJS XML string assignment

2016-08-04 Thread Harbs
I’m not sure how to deal with this case: private var name:String; this.name = someXML.@Name; The above compiles to this.name = someXML.attribute('Name’); In Javascript this.name becomes an XMLList, but in Flash, the XMLList is implicitly converted to a string. Is it possible to make the co