Re: [FlexJS] String.match()

2017-07-21 Thread Harbs
lists.apache.org  displays it fine:
https://lists.apache.org/thread.html/ec0b951752140ad0cd56319b9629cc4a7e097487fd47c84649ffc352@%3Cdev.flex.apache.org%3E
 


I think you missed my last point.

The fact that JS throws an error actually uncovered a bug in my code. When you 
construct an invalid regex in Flash, you get a RegExp object which will NEVER 
match anything. It’s a valid RegExp object with an invalid expression. That’s 
nonsensical. There’s no legitimate reason to use a regex which does nothing.

The JS behavior which throws an error makes much more sense, so I’m currently 
of the opinion that we shouldn’t be fixing this at all.

Harbs

> On Jul 21, 2017, at 5:13 PM, Alex Harui  wrote:
> 
> My email totally mangled your post.  Anyway, if you think you've got code
> that is equivalent to Flash's  String.match, that's good enough for now.
> If folks find issues later we can improve on the utility function.
> 
> If you want to alter the compiler output, see how I handled Array.sortOn
> in FunctionCallEmitter.java.  I think you can do something similar for
> String.match and String.search.
> 
> Thanks,
> -Alex
> 
> On 7/20/17, 2:28 PM, "Harbs"  > wrote:
> 
>> No. We thought that the “?” found the string in Flash. It does not.
>> 
>> trace("https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fww 
>> 
>> w.google.com 
>> %2Fsearch%3Fq%3Ddogs=02%7C01%7C%7Ce68f4223e52d48e8c03908d
>> 4cfb6524c%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636361829356324151&
>> sdata=voY1pLBiaj2u1GDu0YeKMipu%2FGRHwMWQzRRA0JCTkZc%3D=0".match("
>> ?"));
>> trace("https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fww 
>> 
>> w.google.com 
>> %2Fsearch%3Fq%3Ddogs=02%7C01%7C%7Ce68f4223e52d48e8c03908d
>> 4cfb6524c%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636361829356324151&
>> sdata=voY1pLBiaj2u1GDu0YeKMipu%2FGRHwMWQzRRA0JCTkZc%3D=0".search(
>> "?"));
>> trace("https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fww 
>> 
>> w.google.com 
>> %2Fsearch%3Fq%3Ddogs=02%7C01%7C%7Ce68f4223e52d48e8c03908d
>> 4cfb6524c%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636361829356324151&
>> sdata=voY1pLBiaj2u1GDu0YeKMipu%2FGRHwMWQzRRA0JCTkZc%3D=0".indexOf
>> ("?"));
>> 
>> outputs:
>> 
>> null
>> -1
>> 29
>> 
>>> On Jul 21, 2017, at 12:00 AM, Alex Harui >> >
>>> wrote:
>>> 
>>> I think I'm still confused.  My current thinking is that in Flash there
>>> are strings you can pass in that are "invalid RegExp" that will still
>>> find
>>> matches in a string.  Isn't that what Yishay showed?  IOW, passing in
>>> just
>>> "?" in Flash will find question marks in a string but is an error in JS
>>> because it isn't valid RegExp.
>>> 
>>> So, right now I think the utility function needs to catch the error and
>>> either escape the string so it is valid RegExp and call match() or use
>>> indexOf() and compute the same result.  It should not always return
>>> null.
>>> Then I think it would completely implement how it worked in Flash and
>>> the
>>> users won't have to figure out how to regex-ify the strings in the apps
>>> they are porting.
>>> 
>>> My 2 cents,
>>> -Alex
>>> 
>>> 
>>> 
>>> On 7/20/17, 12:55 PM, "Harbs" >> 
>>> >> wrote:
>>> 
 After all this discussion, I’m having second thoughts about this whole
 thing.
 
 What’s the point of using an invalid RegExp that will not match
 anything?
 
 I think the JS behavior makes more sense than the Flash behavior. If a
 RegExp is invalid, it should throw an error rather than never matching
 anything. The use of such a RegExp in the first place can only be
 described as a bug.
 
 “Fixing” the JS behavior to match the Flash behavior is the wrong thing
 to do.
 
> On Jul 20, 2017, at 10:34 PM, Harbs  > wrote:
> 
> new RegExp({})
> returns:
> /[object Object]/
> 
> I think the wrapping that I did in the code I already committed is
> correct:
> 
> try{return input.match(pattern);}
> catch (e:Error){return null;}
> 
> If the try fails, that means the RegExp is an invalid expression and
> will not match anything in Flash. In that case, match should always
> return null and search should always return -1.
> 
> I do think that 

Re: [FlexJS] String.match()

2017-07-21 Thread Alex Harui
My email totally mangled your post.  Anyway, if you think you've got code
that is equivalent to Flash's  String.match, that's good enough for now.
If folks find issues later we can improve on the utility function.

If you want to alter the compiler output, see how I handled Array.sortOn
in FunctionCallEmitter.java.  I think you can do something similar for
String.match and String.search.

Thanks,
-Alex

On 7/20/17, 2:28 PM, "Harbs"  wrote:

>No. We thought that the “?” found the string in Flash. It does not.
>
>trace("https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fww
>w.google.com%2Fsearch%3Fq%3Ddogs=02%7C01%7C%7Ce68f4223e52d48e8c03908d
>4cfb6524c%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636361829356324151&
>sdata=voY1pLBiaj2u1GDu0YeKMipu%2FGRHwMWQzRRA0JCTkZc%3D=0".match("
>?"));
>trace("https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fww
>w.google.com%2Fsearch%3Fq%3Ddogs=02%7C01%7C%7Ce68f4223e52d48e8c03908d
>4cfb6524c%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636361829356324151&
>sdata=voY1pLBiaj2u1GDu0YeKMipu%2FGRHwMWQzRRA0JCTkZc%3D=0".search(
>"?"));
>trace("https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fww
>w.google.com%2Fsearch%3Fq%3Ddogs=02%7C01%7C%7Ce68f4223e52d48e8c03908d
>4cfb6524c%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636361829356324151&
>sdata=voY1pLBiaj2u1GDu0YeKMipu%2FGRHwMWQzRRA0JCTkZc%3D=0".indexOf
>("?"));
>
>outputs:
>
>null
>-1
>29
>
>> On Jul 21, 2017, at 12:00 AM, Alex Harui 
>>wrote:
>> 
>> I think I'm still confused.  My current thinking is that in Flash there
>> are strings you can pass in that are "invalid RegExp" that will still
>>find
>> matches in a string.  Isn't that what Yishay showed?  IOW, passing in
>>just
>> "?" in Flash will find question marks in a string but is an error in JS
>> because it isn't valid RegExp.
>> 
>> So, right now I think the utility function needs to catch the error and
>> either escape the string so it is valid RegExp and call match() or use
>> indexOf() and compute the same result.  It should not always return
>>null.
>> Then I think it would completely implement how it worked in Flash and
>>the
>> users won't have to figure out how to regex-ify the strings in the apps
>> they are porting.
>> 
>> My 2 cents,
>> -Alex
>> 
>> 
>> 
>> On 7/20/17, 12:55 PM, "Harbs" >> wrote:
>> 
>>> After all this discussion, I’m having second thoughts about this whole
>>> thing.
>>> 
>>> What’s the point of using an invalid RegExp that will not match
>>>anything?
>>> 
>>> I think the JS behavior makes more sense than the Flash behavior. If a
>>> RegExp is invalid, it should throw an error rather than never matching
>>> anything. The use of such a RegExp in the first place can only be
>>> described as a bug.
>>> 
>>> “Fixing” the JS behavior to match the Flash behavior is the wrong thing
>>> to do.
>>> 
 On Jul 20, 2017, at 10:34 PM, Harbs  wrote:
 
 new RegExp({})
 returns:
 /[object Object]/
 
 I think the wrapping that I did in the code I already committed is
 correct:
 
 try{return input.match(pattern);}
 catch (e:Error){return null;}
 
 If the try fails, that means the RegExp is an invalid expression and
 will not match anything in Flash. In that case, match should always
 return null and search should always return -1.
 
 I do think that warning developers against using strings is a good
 idea. Accepting any value and automatically converting it to RegExp
 seems like a poorly conceived idea to me...
 
> On Jul 20, 2017, at 9:48 PM, Alex Harui  >>
>wrote:
> 
> I'm confused.  Doesn't Yishay's example use syntax that Harbs claimed
> threw an error?
> 
> Anyway, I can believe the three steps Harbs listed are correct for JS
> since step 1 might just happen via implicit type coercion. I suppose
> someone could test it by seeing if JS handles "new RegExp({})";
> 
> But since there are differences between SWF and JS I want to first
>make
> sure we have agreement that the goal here is to be backward
>compatible
> with SWF if we can.  I don't think we should be requiring folks to
> modify
> existing passing of strings or getting the compiler to try to modify
> those
> strings if we can figure out how to get match() in JS to be
>equivalent
> to
> SWF's match().
> 
> So I think Herbs suggested wrapping in try catch like this, correct?
> 
> public function match(input:String, pattern:*):Array
> {
> COMPILE::SWF
> {
>   return input.match(pattern);
> }
> COMPILE::JS
> {
>   try
>   {
> return input.match(pattern);
>   }
>   catch (e:Error)
>   {
> 

Re: [FlexJS] String.match()

2017-07-20 Thread Harbs
No. We thought that the “?” found the string in Flash. It does not.

trace("https://www.google.com/search?q=dogs".match("?"));
trace("https://www.google.com/search?q=dogs".search("?"));
trace("https://www.google.com/search?q=dogs".indexOf("?"));

outputs:

null
-1
29

> On Jul 21, 2017, at 12:00 AM, Alex Harui  wrote:
> 
> I think I'm still confused.  My current thinking is that in Flash there
> are strings you can pass in that are "invalid RegExp" that will still find
> matches in a string.  Isn't that what Yishay showed?  IOW, passing in just
> "?" in Flash will find question marks in a string but is an error in JS
> because it isn't valid RegExp.
> 
> So, right now I think the utility function needs to catch the error and
> either escape the string so it is valid RegExp and call match() or use
> indexOf() and compute the same result.  It should not always return null.
> Then I think it would completely implement how it worked in Flash and the
> users won't have to figure out how to regex-ify the strings in the apps
> they are porting.
> 
> My 2 cents,
> -Alex
> 
> 
> 
> On 7/20/17, 12:55 PM, "Harbs"  > wrote:
> 
>> After all this discussion, I’m having second thoughts about this whole
>> thing.
>> 
>> What’s the point of using an invalid RegExp that will not match anything?
>> 
>> I think the JS behavior makes more sense than the Flash behavior. If a
>> RegExp is invalid, it should throw an error rather than never matching
>> anything. The use of such a RegExp in the first place can only be
>> described as a bug.
>> 
>> “Fixing” the JS behavior to match the Flash behavior is the wrong thing
>> to do.
>> 
>>> On Jul 20, 2017, at 10:34 PM, Harbs  wrote:
>>> 
>>> new RegExp({})
>>> returns:
>>> /[object Object]/
>>> 
>>> I think the wrapping that I did in the code I already committed is
>>> correct:
>>> 
>>> try{return input.match(pattern);}
>>> catch (e:Error){return null;}
>>> 
>>> If the try fails, that means the RegExp is an invalid expression and
>>> will not match anything in Flash. In that case, match should always
>>> return null and search should always return -1.
>>> 
>>> I do think that warning developers against using strings is a good
>>> idea. Accepting any value and automatically converting it to RegExp
>>> seems like a poorly conceived idea to me...
>>> 
 On Jul 20, 2017, at 9:48 PM, Alex Harui >> wrote:
 
 I'm confused.  Doesn't Yishay's example use syntax that Harbs claimed
 threw an error?
 
 Anyway, I can believe the three steps Harbs listed are correct for JS
 since step 1 might just happen via implicit type coercion. I suppose
 someone could test it by seeing if JS handles "new RegExp({})";
 
 But since there are differences between SWF and JS I want to first make
 sure we have agreement that the goal here is to be backward compatible
 with SWF if we can.  I don't think we should be requiring folks to
 modify
 existing passing of strings or getting the compiler to try to modify
 those
 strings if we can figure out how to get match() in JS to be equivalent
 to
 SWF's match().
 
 So I think Herbs suggested wrapping in try catch like this, correct?
 
 public function match(input:String, pattern:*):Array
 {
 COMPILE::SWF
 {
   return input.match(pattern);
 }
 COMPILE::JS
 {
   try
   {
 return input.match(pattern);
   }
   catch (e:Error)
   {
 pattern = pattern.toString();
 if (input.indexOf(pattern) != -1)
   return [ pattern ]; // or whatever should be returned
 return null;
   }
 }
 }
 
 I don't think we should use trace to tell folks not to use String.  You
 are welcome to add it to the ASDoc though.
 
 -Alex
 
 
 On 7/20/17, 10:52 AM, "yishayw" 
 >> wrote:
 
> I think there would still be a difference between flash and js
> because the
> flash implementation (counter to AS3 documentation) always returns
> null
> when
> an invalid regex is passed as a string. So according to your suggested
> implementation for
> 
> Var s: String = "m?o";
> Var a:Array = s.match("?")
> 
> a  is null in flash but ["?"] in JS.
> 
> 
> 
> --
> View this message in context:
> 
> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache- 
> 
> fle 
>  

Re: [FlexJS] String.match()

2017-07-20 Thread Alex Harui
I think I'm still confused.  My current thinking is that in Flash there
are strings you can pass in that are "invalid RegExp" that will still find
matches in a string.  Isn't that what Yishay showed?  IOW, passing in just
"?" in Flash will find question marks in a string but is an error in JS
because it isn't valid RegExp.

So, right now I think the utility function needs to catch the error and
either escape the string so it is valid RegExp and call match() or use
indexOf() and compute the same result.  It should not always return null.
Then I think it would completely implement how it worked in Flash and the
users won't have to figure out how to regex-ify the strings in the apps
they are porting.

My 2 cents,
-Alex



On 7/20/17, 12:55 PM, "Harbs"  wrote:

>After all this discussion, I’m having second thoughts about this whole
>thing.
>
>What’s the point of using an invalid RegExp that will not match anything?
>
>I think the JS behavior makes more sense than the Flash behavior. If a
>RegExp is invalid, it should throw an error rather than never matching
>anything. The use of such a RegExp in the first place can only be
>described as a bug.
>
>“Fixing” the JS behavior to match the Flash behavior is the wrong thing
>to do.
>
>> On Jul 20, 2017, at 10:34 PM, Harbs  wrote:
>> 
>> new RegExp({})
>> returns:
>> /[object Object]/
>> 
>> I think the wrapping that I did in the code I already committed is
>>correct:
>> 
>> try{return input.match(pattern);}
>> catch (e:Error){return null;}
>> 
>> If the try fails, that means the RegExp is an invalid expression and
>>will not match anything in Flash. In that case, match should always
>>return null and search should always return -1.
>> 
>> I do think that warning developers against using strings is a good
>>idea. Accepting any value and automatically converting it to RegExp
>>seems like a poorly conceived idea to me...
>> 
>>> On Jul 20, 2017, at 9:48 PM, Alex Harui >>> wrote:
>>> 
>>> I'm confused.  Doesn't Yishay's example use syntax that Harbs claimed
>>> threw an error?
>>> 
>>> Anyway, I can believe the three steps Harbs listed are correct for JS
>>> since step 1 might just happen via implicit type coercion. I suppose
>>> someone could test it by seeing if JS handles "new RegExp({})";
>>> 
>>> But since there are differences between SWF and JS I want to first make
>>> sure we have agreement that the goal here is to be backward compatible
>>> with SWF if we can.  I don't think we should be requiring folks to
>>>modify
>>> existing passing of strings or getting the compiler to try to modify
>>>those
>>> strings if we can figure out how to get match() in JS to be equivalent
>>>to
>>> SWF's match().
>>> 
>>> So I think Herbs suggested wrapping in try catch like this, correct?
>>> 
>>> public function match(input:String, pattern:*):Array
>>> {
>>>  COMPILE::SWF
>>>  {
>>>return input.match(pattern);
>>>  }
>>>  COMPILE::JS
>>>  {
>>>try
>>>{
>>>  return input.match(pattern);
>>>}
>>>catch (e:Error)
>>>{
>>>  pattern = pattern.toString();
>>>  if (input.indexOf(pattern) != -1)
>>>return [ pattern ]; // or whatever should be returned
>>>  return null;
>>>}
>>>  }
>>> }
>>> 
>>> I don't think we should use trace to tell folks not to use String.  You
>>> are welcome to add it to the ASDoc though.
>>> 
>>> -Alex
>>> 
>>> 
>>> On 7/20/17, 10:52 AM, "yishayw" >>> wrote:
>>> 
 I think there would still be a difference between flash and js
because the
 flash implementation (counter to AS3 documentation) always returns
null
 when
 an invalid regex is passed as a string. So according to your suggested
 implementation for
 
 Var s: String = "m?o";
 Var a:Array = s.match("?")
 
 a  is null in flash but ["?"] in JS.
 
 
 
 --
 View this message in context:
 
https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-
fle 

 x-development.247.n4.nabble.com
%2FFlexJS-String-match-tp63392p63467.ht
 
ml=02%7C01%7C%7C381f79bbe2594b1cab0808d4cf9af1a0%7Cfa7b1b5a7b34438
794
 
aed2c178decee1%7C0%7C0%7C636361711762211281=gA2I9N%2Bq%2F%2FvILp7
C3c
 UQHenXZDXmu0lK3PtJ%2FnhetW4%3D=0
 Sent from the Apache Flex Development mailing list archive at
Nabble.com 


Re: [FlexJS] String.match()

2017-07-20 Thread piotrz
Harbs,

Your second thought in my opinion is better solution. My daily job is in
.NET/WPF and in C# following code

 var str = "m?o";
Regex reg = new Regex("?");
var match = reg.Match(str);

Will throw "ArgumentException A regular expression parsing error occurred.",
so there is no possibility to pass wrong format of regex. 

Piotr



-
Apache Flex PMC
piotrzarzyck...@gmail.com
--
View this message in context: 
http://apache-flex-development.247.n4.nabble.com/FlexJS-String-match-tp63392p63472.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.


Re: [FlexJS] String.match()

2017-07-20 Thread Harbs
After all this discussion, I’m having second thoughts about this whole thing.

What’s the point of using an invalid RegExp that will not match anything?

I think the JS behavior makes more sense than the Flash behavior. If a RegExp 
is invalid, it should throw an error rather than never matching anything. The 
use of such a RegExp in the first place can only be described as a bug.

“Fixing” the JS behavior to match the Flash behavior is the wrong thing to do.

> On Jul 20, 2017, at 10:34 PM, Harbs  wrote:
> 
> new RegExp({})
> returns:
> /[object Object]/
> 
> I think the wrapping that I did in the code I already committed is correct:
> 
> try{return input.match(pattern);}
> catch (e:Error){return null;}
> 
> If the try fails, that means the RegExp is an invalid expression and will not 
> match anything in Flash. In that case, match should always return null and 
> search should always return -1.
> 
> I do think that warning developers against using strings is a good idea. 
> Accepting any value and automatically converting it to RegExp seems like a 
> poorly conceived idea to me...
> 
>> On Jul 20, 2017, at 9:48 PM, Alex Harui > > wrote:
>> 
>> I'm confused.  Doesn't Yishay's example use syntax that Harbs claimed
>> threw an error?
>> 
>> Anyway, I can believe the three steps Harbs listed are correct for JS
>> since step 1 might just happen via implicit type coercion. I suppose
>> someone could test it by seeing if JS handles "new RegExp({})";
>> 
>> But since there are differences between SWF and JS I want to first make
>> sure we have agreement that the goal here is to be backward compatible
>> with SWF if we can.  I don't think we should be requiring folks to modify
>> existing passing of strings or getting the compiler to try to modify those
>> strings if we can figure out how to get match() in JS to be equivalent to
>> SWF's match().
>> 
>> So I think Herbs suggested wrapping in try catch like this, correct?
>> 
>> public function match(input:String, pattern:*):Array
>> {
>>  COMPILE::SWF
>>  {
>>return input.match(pattern);
>>  }
>>  COMPILE::JS
>>  {
>>try
>>{
>>  return input.match(pattern);
>>}
>>catch (e:Error)
>>{
>>  pattern = pattern.toString();
>>  if (input.indexOf(pattern) != -1)
>>return [ pattern ]; // or whatever should be returned
>>  return null; 
>>}
>>  }
>> }
>> 
>> I don't think we should use trace to tell folks not to use String.  You
>> are welcome to add it to the ASDoc though.
>> 
>> -Alex
>> 
>> 
>> On 7/20/17, 10:52 AM, "yishayw" > > wrote:
>> 
>>> I think there would still be a difference between flash and js because the
>>> flash implementation (counter to AS3 documentation) always returns null
>>> when
>>> an invalid regex is passed as a string. So according to your suggested
>>> implementation for
>>> 
>>> Var s: String = "m?o";
>>> Var a:Array = s.match("?")
>>> 
>>> a  is null in flash but ["?"] in JS.
>>> 
>>> 
>>> 
>>> --
>>> View this message in context:
>>> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-fle 
>>> 
>>> x-development.247.n4.nabble.com 
>>> %2FFlexJS-String-match-tp63392p63467.ht
>>> ml=02%7C01%7C%7C381f79bbe2594b1cab0808d4cf9af1a0%7Cfa7b1b5a7b34438794
>>> aed2c178decee1%7C0%7C0%7C636361711762211281=gA2I9N%2Bq%2F%2FvILp7C3c
>>> UQHenXZDXmu0lK3PtJ%2FnhetW4%3D=0
>>> Sent from the Apache Flex Development mailing list archive at Nabble.com 
>>> .
> 



Re: [FlexJS] String.match()

2017-07-20 Thread Harbs
new RegExp({})
returns:
/[object Object]/

I think the wrapping that I did in the code I already committed is correct:

try{return input.match(pattern);}
catch (e:Error){return null;}

If the try fails, that means the RegExp is an invalid expression and will not 
match anything in Flash. In that case, match should always return null and 
search should always return -1.

I do think that warning developers against using strings is a good idea. 
Accepting any value and automatically converting it to RegExp seems like a 
poorly conceived idea to me...

> On Jul 20, 2017, at 9:48 PM, Alex Harui  wrote:
> 
> I'm confused.  Doesn't Yishay's example use syntax that Harbs claimed
> threw an error?
> 
> Anyway, I can believe the three steps Harbs listed are correct for JS
> since step 1 might just happen via implicit type coercion. I suppose
> someone could test it by seeing if JS handles "new RegExp({})";
> 
> But since there are differences between SWF and JS I want to first make
> sure we have agreement that the goal here is to be backward compatible
> with SWF if we can.  I don't think we should be requiring folks to modify
> existing passing of strings or getting the compiler to try to modify those
> strings if we can figure out how to get match() in JS to be equivalent to
> SWF's match().
> 
> So I think Herbs suggested wrapping in try catch like this, correct?
> 
> public function match(input:String, pattern:*):Array
> {
>  COMPILE::SWF
>  {
>return input.match(pattern);
>  }
>  COMPILE::JS
>  {
>try
>{
>  return input.match(pattern);
>}
>catch (e:Error)
>{
>  pattern = pattern.toString();
>  if (input.indexOf(pattern) != -1)
>return [ pattern ]; // or whatever should be returned
>  return null; 
>}
>  }
> }
> 
> I don't think we should use trace to tell folks not to use String.  You
> are welcome to add it to the ASDoc though.
> 
> -Alex
> 
> 
> On 7/20/17, 10:52 AM, "yishayw"  > wrote:
> 
>> I think there would still be a difference between flash and js because the
>> flash implementation (counter to AS3 documentation) always returns null
>> when
>> an invalid regex is passed as a string. So according to your suggested
>> implementation for
>> 
>> Var s: String = "m?o";
>> Var a:Array = s.match("?")
>> 
>> a  is null in flash but ["?"] in JS.
>> 
>> 
>> 
>> --
>> View this message in context:
>> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-fle 
>> 
>> x-development.247.n4.nabble.com 
>> %2FFlexJS-String-match-tp63392p63467.ht
>> ml=02%7C01%7C%7C381f79bbe2594b1cab0808d4cf9af1a0%7Cfa7b1b5a7b34438794
>> aed2c178decee1%7C0%7C0%7C636361711762211281=gA2I9N%2Bq%2F%2FvILp7C3c
>> UQHenXZDXmu0lK3PtJ%2FnhetW4%3D=0
>> Sent from the Apache Flex Development mailing list archive at Nabble.com 
>> .



Re: [FlexJS] String.match()

2017-07-20 Thread Alex Harui
I'm confused.  Doesn't Yishay's example use syntax that Harbs claimed
threw an error?

Anyway, I can believe the three steps Harbs listed are correct for JS
since step 1 might just happen via implicit type coercion. I suppose
someone could test it by seeing if JS handles "new RegExp({})";

But since there are differences between SWF and JS I want to first make
sure we have agreement that the goal here is to be backward compatible
with SWF if we can.  I don't think we should be requiring folks to modify
existing passing of strings or getting the compiler to try to modify those
strings if we can figure out how to get match() in JS to be equivalent to
SWF's match().

So I think Herbs suggested wrapping in try catch like this, correct?

public function match(input:String, pattern:*):Array
{
  COMPILE::SWF
  {
return input.match(pattern);
  }
  COMPILE::JS
  {
try
{
  return input.match(pattern);
}
catch (e:Error)
{
  pattern = pattern.toString();
  if (input.indexOf(pattern) != -1)
return [ pattern ]; // or whatever should be returned
  return null; 
}
  }
}

I don't think we should use trace to tell folks not to use String.  You
are welcome to add it to the ASDoc though.

-Alex


On 7/20/17, 10:52 AM, "yishayw"  wrote:

>I think there would still be a difference between flash and js because the
>flash implementation (counter to AS3 documentation) always returns null
>when
>an invalid regex is passed as a string. So according to your suggested
>implementation for
>
>Var s: String = "m?o";
>Var a:Array = s.match("?")
>
>a  is null in flash but ["?"] in JS.
>
>
>
>--
>View this message in context:
>https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-fle
>x-development.247.n4.nabble.com%2FFlexJS-String-match-tp63392p63467.ht
>ml=02%7C01%7C%7C381f79bbe2594b1cab0808d4cf9af1a0%7Cfa7b1b5a7b34438794
>aed2c178decee1%7C0%7C0%7C636361711762211281=gA2I9N%2Bq%2F%2FvILp7C3c
>UQHenXZDXmu0lK3PtJ%2FnhetW4%3D=0
>Sent from the Apache Flex Development mailing list archive at Nabble.com.



Re: [FlexJS] String.match()

2017-07-20 Thread Harbs
Right. That’s why I was suggesting wrapping the call in a try/catch and 
returning null/-1 from the catch.

Additionally, the array returned from String.match() is a non-standard one. It 
has input and index properties.

> On Jul 20, 2017, at 8:52 PM, yishayw  wrote:
> 
> I think there would still be a difference between flash and js because the
> flash implementation (counter to AS3 documentation) always returns null when
> an invalid regex is passed as a string. So according to your suggested
> implementation for
> 
> Var s: String = "m?o";
> Var a:Array = s.match("?")
> 
> a  is null in flash but ["?"] in JS.
> 
> 
> 
> --
> View this message in context: 
> http://apache-flex-development.247.n4.nabble.com/FlexJS-String-match-tp63392p63467.html
> Sent from the Apache Flex Development mailing list archive at Nabble.com.



Re: [FlexJS] String.match()

2017-07-20 Thread yishayw
I think there would still be a difference between flash and js because the
flash implementation (counter to AS3 documentation) always returns null when
an invalid regex is passed as a string. So according to your suggested
implementation for

Var s: String = "m?o";
Var a:Array = s.match("?")

a  is null in flash but ["?"] in JS.



--
View this message in context: 
http://apache-flex-development.247.n4.nabble.com/FlexJS-String-match-tp63392p63467.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.


Re: [FlexJS] String.match()

2017-07-20 Thread Harbs
Both Flash and JS environments return the same thing for this:
"foo".match({foo:1});

["o", index: 1, input: "foo"]0: "o"index: 1input: "foo"length: 1

It matches the first “o” in foo. I believe the reason for this is that 
Object.toString() is [object Object]. When that is evaluated to a RegExp it 
becomes a character class and matches the first character in the class which in 
my case is “o”.

I confirmed that with this:
var foo = {foo:1};
"foo".search(foo)//1
foo.toString = function(){return "baz"}
"foo".search(foo)//-1
"baz".search(foo)//0

It results in 1,-1,0 on both platforms.

So, despite what the docs say, what seems to happen on both platforms is:

1. toString() is called.
2. new RegExp() is being called with the result of that.
3. The result of #2 is being used as the parameter for match and search.

I tested this in Chrome and Firefox as well as Node.

Harbs

> On Jul 20, 2017, at 8:30 PM, Alex Harui <aha...@adobe.com.INVALID> wrote:
> 
> I just took a closer look at the ASDoc [1] and Mozilla doc [2].
> 
> Both imply that they take more than one type of input, so any utility
> function probably should as well and thus be of type "*".
> One difference in the two docs that stands out to me is in [1] where it
> says:
> 
> "If the pattern is not a regular expression or a string, then the method
> converts it to a string before executing."
> 
> But [2] says:
> 
> "If a non-RegExp object obj is passed, it is implicitly converted to a
> RegExp by using new RegExp(obj)"
> 
> 
> So, assuming this is true, then yes, we need a utility function to wrap
> and hide the differences.  I would think we want to be backward compatible
> with AS in order to ease migration effort, so I think it would look
> something like:
> 
> public function match(input:String, pattern:*):Array
> {
>  COMPILE::SWF
>  {
>return input.match(pattern);
>  }
>  COMPILE::JS
>  {
>if (pattern is RegExp)
>  return input.match(pattern);
>else
>{
>  pattern = pattern.toString();
>  if (input.indexOf(pattern) != -1)
>return [ pattern ];
>  return null;
>}
>  }
> }
> 
> Of course, I could be wrong...
> 
> -Alex
> 
> [1] 
> http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/String.h
> tml#match()
> [2] 
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Ob
> jects/String/match
> 
> On 7/20/17, 9:58 AM, "Harbs" <harbs.li...@gmail.com> wrote:
> 
>> Really simply:
>> new RegExp(“?”)
>> 
>> In Flash, that will produce a RegExp object which matches nothing.
>> 
>> In JS, it throws an error that the RegExp is not valid.
>> 
>> match and search seem to call the RegExp constructor under the hood. In
>> Flash it succeeds. In JS it throws an error.
>> 
>> Utility functions serve two purposes:
>> 
>> 1. It prevents the error from being thrown.
>> 2. It warns the developer to not pass in a string as it’s converted to a
>> RegExp anyway and is less predictable.
>> 
>> An alternate (possibly better) way to handle this would be to have the
>> compiler issue a warning.
>> 
>>> On Jul 20, 2017, at 7:05 PM, Alex Harui <aha...@adobe.com.INVALID>
>>> wrote:
>>> 
>>> I think I'm lost.  If both behave the same, then why do we need to call
>>> some utility function?
>>> 
>>> -Alex
>>> 
>>> On 7/20/17, 5:00 AM, "Yishay Weiss" <yishayj...@hotmail.com> wrote:
>>> 
>>>> Good catch. I was misled by the docs [1].
>>>> 
>>>> [1] 
>>>> 
>>>> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fhelp.ado
>>>> be
>>>> 
>>>> .com%2Fen_US%2FFlashPlatform%2Freference%2Factionscript%2F3%2FString.htm
>>>> l%
>>>> 
>>>> 23match=02%7C01%7C%7C66b63f8228ab4f80a39408d4cf66f9a9%7Cfa7b1b5a7b3
>>>> 44
>>>> 
>>>> 38794aed2c178decee1%7C0%7C0%7C636361488561328745=CbWB8sk4vOv1vId9a
>>>> T7
>>>> WkDjQrkqarHU2aAAoWw9UBNA%3D=0()
>>>> 
>>>> From: Harbs<mailto:harbs.li...@gmail.com>
>>>> Sent: Thursday, July 20, 2017 9:40 AM
>>>> To: dev@flex.apache.org<mailto:dev@flex.apache.org>
>>>> Subject: Re: [FlexJS] String.match()
>>>> 
>>>> Both Flash and JS engines automatically convert to RegExp. I had not
>>>> realized that at first.
>>>> 
>>>> It seems that the 

Re: [FlexJS] String.match()

2017-07-20 Thread Alex Harui
I just took a closer look at the ASDoc [1] and Mozilla doc [2].

Both imply that they take more than one type of input, so any utility
function probably should as well and thus be of type "*".
One difference in the two docs that stands out to me is in [1] where it
says:

"If the pattern is not a regular expression or a string, then the method
converts it to a string before executing."

But [2] says:

"If a non-RegExp object obj is passed, it is implicitly converted to a
RegExp by using new RegExp(obj)"


So, assuming this is true, then yes, we need a utility function to wrap
and hide the differences.  I would think we want to be backward compatible
with AS in order to ease migration effort, so I think it would look
something like:

public function match(input:String, pattern:*):Array
{
  COMPILE::SWF
  {
return input.match(pattern);
  }
  COMPILE::JS
  {
if (pattern is RegExp)
  return input.match(pattern);
else
{
  pattern = pattern.toString();
  if (input.indexOf(pattern) != -1)
return [ pattern ];
  return null;
}
  }
}

Of course, I could be wrong...

-Alex

[1] 
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/String.h
tml#match()
[2] 
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Ob
jects/String/match

On 7/20/17, 9:58 AM, "Harbs" <harbs.li...@gmail.com> wrote:

>Really simply:
>new RegExp(“?”)
>
>In Flash, that will produce a RegExp object which matches nothing.
>
>In JS, it throws an error that the RegExp is not valid.
>
>match and search seem to call the RegExp constructor under the hood. In
>Flash it succeeds. In JS it throws an error.
>
>Utility functions serve two purposes:
>
>1. It prevents the error from being thrown.
>2. It warns the developer to not pass in a string as it’s converted to a
>RegExp anyway and is less predictable.
>
>An alternate (possibly better) way to handle this would be to have the
>compiler issue a warning.
>
>> On Jul 20, 2017, at 7:05 PM, Alex Harui <aha...@adobe.com.INVALID>
>>wrote:
>> 
>> I think I'm lost.  If both behave the same, then why do we need to call
>> some utility function?
>> 
>> -Alex
>> 
>> On 7/20/17, 5:00 AM, "Yishay Weiss" <yishayj...@hotmail.com> wrote:
>> 
>>> Good catch. I was misled by the docs [1].
>>> 
>>> [1] 
>>> 
>>>https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fhelp.ado
>>>be
>>> 
>>>.com%2Fen_US%2FFlashPlatform%2Freference%2Factionscript%2F3%2FString.htm
>>>l%
>>> 
>>>23match=02%7C01%7C%7C66b63f8228ab4f80a39408d4cf66f9a9%7Cfa7b1b5a7b3
>>>44
>>> 
>>>38794aed2c178decee1%7C0%7C0%7C636361488561328745=CbWB8sk4vOv1vId9a
>>>T7
>>> WkDjQrkqarHU2aAAoWw9UBNA%3D=0()
>>> 
>>> From: Harbs<mailto:harbs.li...@gmail.com>
>>> Sent: Thursday, July 20, 2017 9:40 AM
>>> To: dev@flex.apache.org<mailto:dev@flex.apache.org>
>>> Subject: Re: [FlexJS] String.match()
>>> 
>>> Both Flash and JS engines automatically convert to RegExp. I had not
>>> realized that at first.
>>> 
>>> It seems that the only difference between the Flash engine and JS
>>>engines
>>> is what happens when constructing a RegExp object from invalid input.
>>> Flash matches nothing, while JS throws an error.
>>> 
>>> By just wrapping the call in a try/catch, that seems to resolve the
>>>issue.
>>> 
>>> I added the trace because I think it’s bad practice to use strings
>>> instead of RegExp because it can lead to unexpected results and a new
>>> RegExp instance needs to be constructed every time.
>>> 
>>>> On Jul 20, 2017, at 3:32 AM, Alex Harui <aha...@adobe.com.INVALID>
>>>> wrote:
>>>> 
>>>> It looks like they just trace a warning instead of trying to convert
>>>>to
>>>> a
>>>> RegExp.  Is that what we want to do?  Or should we add code that
>>>> converts
>>>> a string to regex?
>>>> 
>>>> Thoughts?
>>>> -Alex
>>>> 
>>>> On 7/19/17, 4:32 AM, "Harbs" <harbs.li...@gmail.com> wrote:
>>>> 
>>>>> I added the utility functions. I think they can be very simple.
>>>>> 
>>>>>> On Jul 19, 2017, at 9:30 AM, Alex Harui <aha...@adobe.com.INVALID>
>>>>>> wrote:
>>>>>> 
>>>>>> Unless we are absolutely sure that everybody will need the code
>>>>>> generat

Re: [FlexJS] String.match()

2017-07-20 Thread Harbs
Really simply:
new RegExp(“?”)

In Flash, that will produce a RegExp object which matches nothing.

In JS, it throws an error that the RegExp is not valid.

match and search seem to call the RegExp constructor under the hood. In Flash 
it succeeds. In JS it throws an error.

Utility functions serve two purposes:

1. It prevents the error from being thrown.
2. It warns the developer to not pass in a string as it’s converted to a RegExp 
anyway and is less predictable.

An alternate (possibly better) way to handle this would be to have the compiler 
issue a warning.

> On Jul 20, 2017, at 7:05 PM, Alex Harui <aha...@adobe.com.INVALID> wrote:
> 
> I think I'm lost.  If both behave the same, then why do we need to call
> some utility function?
> 
> -Alex
> 
> On 7/20/17, 5:00 AM, "Yishay Weiss" <yishayj...@hotmail.com> wrote:
> 
>> Good catch. I was misled by the docs [1].
>> 
>> [1] 
>> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fhelp.adobe
>> .com%2Fen_US%2FFlashPlatform%2Freference%2Factionscript%2F3%2FString.html%
>> 23match=02%7C01%7C%7C66b63f8228ab4f80a39408d4cf66f9a9%7Cfa7b1b5a7b344
>> 38794aed2c178decee1%7C0%7C0%7C636361488561328745=CbWB8sk4vOv1vId9aT7
>> WkDjQrkqarHU2aAAoWw9UBNA%3D=0()
>> 
>> From: Harbs<mailto:harbs.li...@gmail.com>
>> Sent: Thursday, July 20, 2017 9:40 AM
>> To: dev@flex.apache.org<mailto:dev@flex.apache.org>
>> Subject: Re: [FlexJS] String.match()
>> 
>> Both Flash and JS engines automatically convert to RegExp. I had not
>> realized that at first.
>> 
>> It seems that the only difference between the Flash engine and JS engines
>> is what happens when constructing a RegExp object from invalid input.
>> Flash matches nothing, while JS throws an error.
>> 
>> By just wrapping the call in a try/catch, that seems to resolve the issue.
>> 
>> I added the trace because I think it’s bad practice to use strings
>> instead of RegExp because it can lead to unexpected results and a new
>> RegExp instance needs to be constructed every time.
>> 
>>> On Jul 20, 2017, at 3:32 AM, Alex Harui <aha...@adobe.com.INVALID>
>>> wrote:
>>> 
>>> It looks like they just trace a warning instead of trying to convert to
>>> a
>>> RegExp.  Is that what we want to do?  Or should we add code that
>>> converts
>>> a string to regex?
>>> 
>>> Thoughts?
>>> -Alex
>>> 
>>> On 7/19/17, 4:32 AM, "Harbs" <harbs.li...@gmail.com> wrote:
>>> 
>>>> I added the utility functions. I think they can be very simple.
>>>> 
>>>>> On Jul 19, 2017, at 9:30 AM, Alex Harui <aha...@adobe.com.INVALID>
>>>>> wrote:
>>>>> 
>>>>> Unless we are absolutely sure that everybody will need the code
>>>>> generated
>>>>> by the compiler, having the compiler call a framework function makes
>>>>> it
>>>>> easier for an app developer to make any adjustments to that code.  It
>>>>> is
>>>>> easier to monkey-patch a utility function than find-and-replace some
>>>>> sequence of code the compiler has sprinkled throughout the output.
>>>>> 
>>>>> My 2 cents,
>>>>> -Alex
>>>>> 
>>>>> On 7/18/17, 11:36 AM, "yishayw" <yishayj...@hotmail.com> wrote:
>>>>> 
>>>>>> Alex Harui-2 wrote
>>>>>>> By
>>>>>>> calling new utility functions, the developer has control over the
>>>>>>> conversion.
>>>>>> 
>>>>>> I don't understand that point. Do you mean an app developer?
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> --
>>>>>> View this message in context:
>>>>>> 
>>>>>> 
>>>>>> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache
>>>>>> -f
>>>>>> le
>>>>>> 
>>>>>> 
>>>>>> x-development.247.n4.nabble.com%2FFlexJS-String-match-tp63392p6340
>>>>>> 5.
>>>>>> ht
>>>>>> 
>>>>>> 
>>>>>> ml=02%7C01%7C%7C9ff1088402ef439ca27908d4ce0e97eb%7Cfa7b1b5a7b3443
>>>>>> 87
>>>>>> 94
>>>>>> 
>>>>>> 
>>>>>> aed2c178decee1%7C0%7C0%7C636360009448210304=nprl9yHUtlsTHbIZxeFq
>>>>>> 2h
>>>>>> %2
>>>>>> FQNWmtimM%2BxAt0kJA8EcA%3D=0
>>>>>> Sent from the Apache Flex Development mailing list archive at
>>>>>> Nabble.com.
>>>>> 
>>>> 
>>> 
>> 
> 



Re: [FlexJS] String.match()

2017-07-20 Thread Alex Harui
I think I'm lost.  If both behave the same, then why do we need to call
some utility function?

-Alex

On 7/20/17, 5:00 AM, "Yishay Weiss" <yishayj...@hotmail.com> wrote:

>Good catch. I was misled by the docs [1].
>
>[1] 
>https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fhelp.adobe
>.com%2Fen_US%2FFlashPlatform%2Freference%2Factionscript%2F3%2FString.html%
>23match=02%7C01%7C%7C66b63f8228ab4f80a39408d4cf66f9a9%7Cfa7b1b5a7b344
>38794aed2c178decee1%7C0%7C0%7C636361488561328745=CbWB8sk4vOv1vId9aT7
>WkDjQrkqarHU2aAAoWw9UBNA%3D=0()
>
>From: Harbs<mailto:harbs.li...@gmail.com>
>Sent: Thursday, July 20, 2017 9:40 AM
>To: dev@flex.apache.org<mailto:dev@flex.apache.org>
>Subject: Re: [FlexJS] String.match()
>
>Both Flash and JS engines automatically convert to RegExp. I had not
>realized that at first.
>
>It seems that the only difference between the Flash engine and JS engines
>is what happens when constructing a RegExp object from invalid input.
>Flash matches nothing, while JS throws an error.
>
>By just wrapping the call in a try/catch, that seems to resolve the issue.
>
>I added the trace because I think it’s bad practice to use strings
>instead of RegExp because it can lead to unexpected results and a new
>RegExp instance needs to be constructed every time.
>
>> On Jul 20, 2017, at 3:32 AM, Alex Harui <aha...@adobe.com.INVALID>
>>wrote:
>>
>> It looks like they just trace a warning instead of trying to convert to
>>a
>> RegExp.  Is that what we want to do?  Or should we add code that
>>converts
>> a string to regex?
>>
>> Thoughts?
>> -Alex
>>
>> On 7/19/17, 4:32 AM, "Harbs" <harbs.li...@gmail.com> wrote:
>>
>>> I added the utility functions. I think they can be very simple.
>>>
>>>> On Jul 19, 2017, at 9:30 AM, Alex Harui <aha...@adobe.com.INVALID>
>>>> wrote:
>>>>
>>>> Unless we are absolutely sure that everybody will need the code
>>>> generated
>>>> by the compiler, having the compiler call a framework function makes
>>>>it
>>>> easier for an app developer to make any adjustments to that code.  It
>>>>is
>>>> easier to monkey-patch a utility function than find-and-replace some
>>>> sequence of code the compiler has sprinkled throughout the output.
>>>>
>>>> My 2 cents,
>>>> -Alex
>>>>
>>>> On 7/18/17, 11:36 AM, "yishayw" <yishayj...@hotmail.com> wrote:
>>>>
>>>>> Alex Harui-2 wrote
>>>>>> By
>>>>>> calling new utility functions, the developer has control over the
>>>>>> conversion.
>>>>>
>>>>> I don't understand that point. Do you mean an app developer?
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> View this message in context:
>>>>>
>>>>> 
>>>>>https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache
>>>>>-f
>>>>> le
>>>>>
>>>>> 
>>>>>x-development.247.n4.nabble.com%2FFlexJS-String-match-tp63392p6340
>>>>>5.
>>>>> ht
>>>>>
>>>>> 
>>>>>ml=02%7C01%7C%7C9ff1088402ef439ca27908d4ce0e97eb%7Cfa7b1b5a7b3443
>>>>>87
>>>>> 94
>>>>>
>>>>> 
>>>>>aed2c178decee1%7C0%7C0%7C636360009448210304=nprl9yHUtlsTHbIZxeFq
>>>>>2h
>>>>> %2
>>>>> FQNWmtimM%2BxAt0kJA8EcA%3D=0
>>>>> Sent from the Apache Flex Development mailing list archive at
>>>>> Nabble.com.
>>>>
>>>
>>
>



RE: [FlexJS] String.match()

2017-07-20 Thread Yishay Weiss
Good catch. I was misled by the docs [1].

[1] 
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/String.html#match()

From: Harbs<mailto:harbs.li...@gmail.com>
Sent: Thursday, July 20, 2017 9:40 AM
To: dev@flex.apache.org<mailto:dev@flex.apache.org>
Subject: Re: [FlexJS] String.match()

Both Flash and JS engines automatically convert to RegExp. I had not realized 
that at first.

It seems that the only difference between the Flash engine and JS engines is 
what happens when constructing a RegExp object from invalid input. Flash 
matches nothing, while JS throws an error.

By just wrapping the call in a try/catch, that seems to resolve the issue.

I added the trace because I think it’s bad practice to use strings instead of 
RegExp because it can lead to unexpected results and a new RegExp instance 
needs to be constructed every time.

> On Jul 20, 2017, at 3:32 AM, Alex Harui <aha...@adobe.com.INVALID> wrote:
>
> It looks like they just trace a warning instead of trying to convert to a
> RegExp.  Is that what we want to do?  Or should we add code that converts
> a string to regex?
>
> Thoughts?
> -Alex
>
> On 7/19/17, 4:32 AM, "Harbs" <harbs.li...@gmail.com> wrote:
>
>> I added the utility functions. I think they can be very simple.
>>
>>> On Jul 19, 2017, at 9:30 AM, Alex Harui <aha...@adobe.com.INVALID>
>>> wrote:
>>>
>>> Unless we are absolutely sure that everybody will need the code
>>> generated
>>> by the compiler, having the compiler call a framework function makes it
>>> easier for an app developer to make any adjustments to that code.  It is
>>> easier to monkey-patch a utility function than find-and-replace some
>>> sequence of code the compiler has sprinkled throughout the output.
>>>
>>> My 2 cents,
>>> -Alex
>>>
>>> On 7/18/17, 11:36 AM, "yishayw" <yishayj...@hotmail.com> wrote:
>>>
>>>> Alex Harui-2 wrote
>>>>> By
>>>>> calling new utility functions, the developer has control over the
>>>>> conversion.
>>>>
>>>> I don't understand that point. Do you mean an app developer?
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>>
>>>> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-f
>>>> le
>>>>
>>>> x-development.247.n4.nabble.com%2FFlexJS-String-match-tp63392p63405.
>>>> ht
>>>>
>>>> ml=02%7C01%7C%7C9ff1088402ef439ca27908d4ce0e97eb%7Cfa7b1b5a7b344387
>>>> 94
>>>>
>>>> aed2c178decee1%7C0%7C0%7C636360009448210304=nprl9yHUtlsTHbIZxeFq2h
>>>> %2
>>>> FQNWmtimM%2BxAt0kJA8EcA%3D=0
>>>> Sent from the Apache Flex Development mailing list archive at
>>>> Nabble.com.
>>>
>>
>



Re: [FlexJS] String.match()

2017-07-20 Thread Harbs
Yes. trace is stripped out in release. (We still need to remove the dead code, 
but that will happen too.)

> On Jul 20, 2017, at 9:37 AM, piotrz  wrote:
> 
> Hi Harbs,
> 
> I'm not so convinced by the trace. Maybe something from your debugger to
> have everything in debug. Does trace stripped out in release version of JS? 
> 
> Thanks,
> Piotr
> 
> 
> 
> -
> Apache Flex PMC
> piotrzarzyck...@gmail.com
> --
> View this message in context: 
> http://apache-flex-development.247.n4.nabble.com/FlexJS-String-match-tp63392p63435.html
> Sent from the Apache Flex Development mailing list archive at Nabble.com.



Re: [FlexJS] String.match()

2017-07-20 Thread piotrz
Hi Harbs,

I'm not so convinced by the trace. Maybe something from your debugger to
have everything in debug. Does trace stripped out in release version of JS? 

Thanks,
Piotr



-
Apache Flex PMC
piotrzarzyck...@gmail.com
--
View this message in context: 
http://apache-flex-development.247.n4.nabble.com/FlexJS-String-match-tp63392p63435.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.


Re: [FlexJS] String.match()

2017-07-20 Thread Harbs
Both Flash and JS engines automatically convert to RegExp. I had not realized 
that at first.

It seems that the only difference between the Flash engine and JS engines is 
what happens when constructing a RegExp object from invalid input. Flash 
matches nothing, while JS throws an error.

By just wrapping the call in a try/catch, that seems to resolve the issue.

I added the trace because I think it’s bad practice to use strings instead of 
RegExp because it can lead to unexpected results and a new RegExp instance 
needs to be constructed every time.

> On Jul 20, 2017, at 3:32 AM, Alex Harui  wrote:
> 
> It looks like they just trace a warning instead of trying to convert to a
> RegExp.  Is that what we want to do?  Or should we add code that converts
> a string to regex?
> 
> Thoughts?
> -Alex
> 
> On 7/19/17, 4:32 AM, "Harbs"  wrote:
> 
>> I added the utility functions. I think they can be very simple.
>> 
>>> On Jul 19, 2017, at 9:30 AM, Alex Harui 
>>> wrote:
>>> 
>>> Unless we are absolutely sure that everybody will need the code
>>> generated
>>> by the compiler, having the compiler call a framework function makes it
>>> easier for an app developer to make any adjustments to that code.  It is
>>> easier to monkey-patch a utility function than find-and-replace some
>>> sequence of code the compiler has sprinkled throughout the output.
>>> 
>>> My 2 cents,
>>> -Alex
>>> 
>>> On 7/18/17, 11:36 AM, "yishayw"  wrote:
>>> 
 Alex Harui-2 wrote
> By
> calling new utility functions, the developer has control over the
> conversion.
 
 I don't understand that point. Do you mean an app developer?
 
 
 
 
 --
 View this message in context:
 
 https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-f
 le
 
 x-development.247.n4.nabble.com%2FFlexJS-String-match-tp63392p63405.
 ht
 
 ml=02%7C01%7C%7C9ff1088402ef439ca27908d4ce0e97eb%7Cfa7b1b5a7b344387
 94
 
 aed2c178decee1%7C0%7C0%7C636360009448210304=nprl9yHUtlsTHbIZxeFq2h
 %2
 FQNWmtimM%2BxAt0kJA8EcA%3D=0
 Sent from the Apache Flex Development mailing list archive at
 Nabble.com.
>>> 
>> 
> 



Re: [FlexJS] String.match()

2017-07-19 Thread Alex Harui
It looks like they just trace a warning instead of trying to convert to a
RegExp.  Is that what we want to do?  Or should we add code that converts
a string to regex?

Thoughts?
-Alex

On 7/19/17, 4:32 AM, "Harbs"  wrote:

>I added the utility functions. I think they can be very simple.
>
>> On Jul 19, 2017, at 9:30 AM, Alex Harui 
>>wrote:
>> 
>> Unless we are absolutely sure that everybody will need the code
>>generated
>> by the compiler, having the compiler call a framework function makes it
>> easier for an app developer to make any adjustments to that code.  It is
>> easier to monkey-patch a utility function than find-and-replace some
>> sequence of code the compiler has sprinkled throughout the output.
>> 
>> My 2 cents,
>> -Alex
>> 
>> On 7/18/17, 11:36 AM, "yishayw"  wrote:
>> 
>>> Alex Harui-2 wrote
 By
 calling new utility functions, the developer has control over the
 conversion.
>>> 
>>> I don't understand that point. Do you mean an app developer?
>>> 
>>> 
>>> 
>>> 
>>> --
>>> View this message in context:
>>> 
>>>https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-f
>>>le
>>> 
>>>x-development.247.n4.nabble.com%2FFlexJS-String-match-tp63392p63405.
>>>ht
>>> 
>>>ml=02%7C01%7C%7C9ff1088402ef439ca27908d4ce0e97eb%7Cfa7b1b5a7b344387
>>>94
>>> 
>>>aed2c178decee1%7C0%7C0%7C636360009448210304=nprl9yHUtlsTHbIZxeFq2h
>>>%2
>>> FQNWmtimM%2BxAt0kJA8EcA%3D=0
>>> Sent from the Apache Flex Development mailing list archive at
>>>Nabble.com.
>> 
>



Re: [FlexJS] String.match()

2017-07-19 Thread Harbs
I added the utility functions. I think they can be very simple.

> On Jul 19, 2017, at 9:30 AM, Alex Harui  wrote:
> 
> Unless we are absolutely sure that everybody will need the code generated
> by the compiler, having the compiler call a framework function makes it
> easier for an app developer to make any adjustments to that code.  It is
> easier to monkey-patch a utility function than find-and-replace some
> sequence of code the compiler has sprinkled throughout the output.
> 
> My 2 cents,
> -Alex
> 
> On 7/18/17, 11:36 AM, "yishayw"  wrote:
> 
>> Alex Harui-2 wrote
>>> By
>>> calling new utility functions, the developer has control over the
>>> conversion.
>> 
>> I don't understand that point. Do you mean an app developer?
>> 
>> 
>> 
>> 
>> --
>> View this message in context:
>> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-fle
>> x-development.247.n4.nabble.com%2FFlexJS-String-match-tp63392p63405.ht
>> ml=02%7C01%7C%7C9ff1088402ef439ca27908d4ce0e97eb%7Cfa7b1b5a7b34438794
>> aed2c178decee1%7C0%7C0%7C636360009448210304=nprl9yHUtlsTHbIZxeFq2h%2
>> FQNWmtimM%2BxAt0kJA8EcA%3D=0
>> Sent from the Apache Flex Development mailing list archive at Nabble.com.
> 



Re: [FlexJS] String.match()

2017-07-19 Thread Alex Harui
Unless we are absolutely sure that everybody will need the code generated
by the compiler, having the compiler call a framework function makes it
easier for an app developer to make any adjustments to that code.  It is
easier to monkey-patch a utility function than find-and-replace some
sequence of code the compiler has sprinkled throughout the output.

My 2 cents,
-Alex

On 7/18/17, 11:36 AM, "yishayw"  wrote:

>Alex Harui-2 wrote
>>  By
>> calling new utility functions, the developer has control over the
>> conversion.
>
>I don't understand that point. Do you mean an app developer?
>
>
>
>
>--
>View this message in context:
>https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-fle
>x-development.247.n4.nabble.com%2FFlexJS-String-match-tp63392p63405.ht
>ml=02%7C01%7C%7C9ff1088402ef439ca27908d4ce0e97eb%7Cfa7b1b5a7b34438794
>aed2c178decee1%7C0%7C0%7C636360009448210304=nprl9yHUtlsTHbIZxeFq2h%2
>FQNWmtimM%2BxAt0kJA8EcA%3D=0
>Sent from the Apache Flex Development mailing list archive at Nabble.com.



Re: [FlexJS] String.match()

2017-07-18 Thread Harbs
Here seems to be the explanation for that:

new RegExp("?”)

In Flash, this creates a RegExp object.

In JS, it throws an “Invalid regular expression” error.

> On Jul 18, 2017, at 9:38 PM, Harbs  wrote:
> 
> The “?” case seems to be an outlier.



Re: [FlexJS] String.match()

2017-07-18 Thread yishayw
Alex Harui-2 wrote
>  By
> calling new utility functions, the developer has control over the
> conversion.

I don't understand that point. Do you mean an app developer?




--
View this message in context: 
http://apache-flex-development.247.n4.nabble.com/FlexJS-String-match-tp63392p63405.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.


Re: [FlexJS] String.match()

2017-07-18 Thread Harbs
Calling language functions at first seemed unnecessarily expensive to me.

I just did a bit of research, and it looks like I was wrong about replacing 
search with indexOf. That will only work for simple string searches. 
str.search(“.”) will always return 0 unless the string is empty, because the 
“.” is evaluated to new RegExp(“.”). This is true both in Flash and JS 
environments. The “?” case seems to be an outlier. Either way, I’m not sure how 
my code ever worked. str.match(“?”) seems to always return null.

Language functions seem like they are more expensive, but you might be right 
that it might be the best way to go.

The implementation should probably use a try/catch to construct a RegExp object 
from the string and return null/-1 if the constructor causes an error. That 
would be the same as the Flash implementation. We could also use debug.warn() 
to let the developer know that using strings is not recommended.

Harbs

> On Jul 18, 2017, at 6:37 PM, Alex Harui  wrote:
> 
> This feels like something that the compiler should just call
> Language.stringMatch and Language.stringSearch (or standalone
> equivalents).  I'm not clear that we should always modify the string.  By
> calling new utility functions, the developer has control over the
> conversion.
> 
> -Alex
> 
> On 7/18/17, 4:11 AM, "Harbs"  > wrote:
> 
>> The same issue applies to String.search(), although it might make sense
>> to replace String.search() with String.indexOf() if the parameter is a
>> string.
>> 
>>> On Jul 18, 2017, at 12:36 PM, yishayw  wrote:
>>> 
>>> In flash String.match() can take either a string or a regex. In JS it's
>>> always considered to be a regex. So str.match("?") is valid in flash but
>>> will fail in JS. We ran into that porting our app which includes some
>>> code
>>> to test for url params.
>>> 
>>> So maybe the compiler should identify that the input is a string and
>>> replace
>>> all special chars as suggested here [1]?
>>> 
>>> [1]
>>> 
>>> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstackove 
>>> 
>>> rflow.com 
>>> %2Fquestions%2F3561493%2Fis-there-a-regexp-escape-function-in-ja
>>> vascript=02%7C01%7C%7C2260cdfd26d74274ba4a08d4cdcde8ea%7Cfa7b1b5a7b3
>>> 4438794aed2c178decee1%7C0%7C0%7C636359731646059595=LKSeBWNfrL6CCQRg
>>> eMI48HJSvACdKoNp5X3AZuMoZeU%3D=0
>>> 
>>> 
>>> 
>>> 
>>> --
>>> View this message in context:
>>> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-fl 
>>> 
>>> ex-development.247.n4.nabble.com 
>>> %2FFlexJS-String-match-tp63392.html
>>> ata=02%7C01%7C%7C2260cdfd26d74274ba4a08d4cdcde8ea%7Cfa7b1b5a7b34438794aed
>>> 2c178decee1%7C0%7C0%7C636359731646069605=X0ZlS9B3AUiglpM5ywHSi4aqui
>>> jF55mWfBbbEfnJE6E%3D=0
>>> Sent from the Apache Flex Development mailing list archive at
>>> Nabble.com .



Re: [FlexJS] String.match()

2017-07-18 Thread Alex Harui
This feels like something that the compiler should just call
Language.stringMatch and Language.stringSearch (or standalone
equivalents).  I'm not clear that we should always modify the string.  By
calling new utility functions, the developer has control over the
conversion.

-Alex

On 7/18/17, 4:11 AM, "Harbs"  wrote:

>The same issue applies to String.search(), although it might make sense
>to replace String.search() with String.indexOf() if the parameter is a
>string.
>
>> On Jul 18, 2017, at 12:36 PM, yishayw  wrote:
>> 
>> In flash String.match() can take either a string or a regex. In JS it's
>> always considered to be a regex. So str.match("?") is valid in flash but
>> will fail in JS. We ran into that porting our app which includes some
>>code
>> to test for url params.
>> 
>> So maybe the compiler should identify that the input is a string and
>>replace
>> all special chars as suggested here [1]?
>> 
>> [1]
>> 
>>https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstackove
>>rflow.com%2Fquestions%2F3561493%2Fis-there-a-regexp-escape-function-in-ja
>>vascript=02%7C01%7C%7C2260cdfd26d74274ba4a08d4cdcde8ea%7Cfa7b1b5a7b3
>>4438794aed2c178decee1%7C0%7C0%7C636359731646059595=LKSeBWNfrL6CCQRg
>>eMI48HJSvACdKoNp5X3AZuMoZeU%3D=0
>> 
>> 
>> 
>> 
>> --
>> View this message in context:
>>https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-fl
>>ex-development.247.n4.nabble.com%2FFlexJS-String-match-tp63392.html
>>ata=02%7C01%7C%7C2260cdfd26d74274ba4a08d4cdcde8ea%7Cfa7b1b5a7b34438794aed
>>2c178decee1%7C0%7C0%7C636359731646069605=X0ZlS9B3AUiglpM5ywHSi4aqui
>>jF55mWfBbbEfnJE6E%3D=0
>> Sent from the Apache Flex Development mailing list archive at
>>Nabble.com.
>



Re: [FlexJS] String.match()

2017-07-18 Thread Harbs
The same issue applies to String.search(), although it might make sense to 
replace String.search() with String.indexOf() if the parameter is a string.

> On Jul 18, 2017, at 12:36 PM, yishayw  wrote:
> 
> In flash String.match() can take either a string or a regex. In JS it's
> always considered to be a regex. So str.match("?") is valid in flash but
> will fail in JS. We ran into that porting our app which includes some code
> to test for url params. 
> 
> So maybe the compiler should identify that the input is a string and replace
> all special chars as suggested here [1]?
> 
> [1]
> https://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
> 
> 
> 
> 
> --
> View this message in context: 
> http://apache-flex-development.247.n4.nabble.com/FlexJS-String-match-tp63392.html
> Sent from the Apache Flex Development mailing list archive at Nabble.com.



[FlexJS] String.match()

2017-07-18 Thread yishayw
In flash String.match() can take either a string or a regex. In JS it's
always considered to be a regex. So str.match("?") is valid in flash but
will fail in JS. We ran into that porting our app which includes some code
to test for url params. 

So maybe the compiler should identify that the input is a string and replace
all special chars as suggested here [1]?

[1]
https://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
 



--
View this message in context: 
http://apache-flex-development.247.n4.nabble.com/FlexJS-String-match-tp63392.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.