What do you think of the idea of moving these helper functions out of the
html template and have the compiler codegen them on-demand somehow.  IMO, it
is a slippery slope to keep adding code to the html template that might not
actually be used by the app, and it is one more thing that can be screwed up
as the user customizes the html file.


On 4/20/13 3:54 AM, "erikdebr...@apache.org" <erikdebr...@apache.org> wrote:

> [FalconJX] updated NativeUtils and support/tests
> 
> I've updated NativeUtils to more closely match the desired state of JS
> 'native' support for AS global objects and functions. Updated the tests for
> Object, int and uint again, together with the addition of support methods in
> the Publisher.
> 
> Signed-off-by: Erik de Bruin <e...@ixsoftware.nl>
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
> Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/6f8e8f9e
> Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/6f8e8f9e
> Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/6f8e8f9e
> 
> Branch: refs/heads/develop
> Commit: 6f8e8f9e4a315213a13f935dcf4084477abe41e8
> Parents: 0420b98
> Author: Erik de Bruin <e...@ixsoftware.nl>
> Authored: Sat Apr 20 12:48:58 2013 +0200
> Committer: Erik de Bruin <e...@ixsoftware.nl>
> Committed: Sat Apr 20 12:48:58 2013 +0200
> 
> ----------------------------------------------------------------------
>  .../js/flexjs/TestFlexJSGlobalFunctions.java       |   35 +++-----------
>  .../codegen/mxml/flexjs/MXMLFlexJSPublisher.java   |   21 ++++++++-
>  .../apache/flex/compiler/utils/NativeUtils.java    |   27 ++++++++++-
>  3 files changed, 50 insertions(+), 33 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6f8e8f9e/compiler.jx.t
> ests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalF
> unctions.java
> ----------------------------------------------------------------------
> diff --git 
> a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/Te
> stFlexJSGlobalFunctions.java
> b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/Te
> stFlexJSGlobalFunctions.java
> index a3f6207..7cdeebc 100644
> --- 
> a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/Te
> stFlexJSGlobalFunctions.java
> +++ 
> b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/Te
> stFlexJSGlobalFunctions.java
> @@ -48,33 +48,6 @@ public class TestFlexJSGlobalFunctions extends
> TestGoogGlobalFunctions
>  
>      @Override
>      @Test
> -    public void testInt()
> -    {
> -        IVariableNode node = getVariable("var a:int = int(1.8);");
> -        asBlockWalker.visitVariable(node);
> -        assertOut("var /** @type {number} */ a = 1.8/** Cast to int */");
> -    }
> -
> -    @Override
> -    @Test
> -    public void testObject()
> -    {
> -        IVariableNode node = getVariable("var a:Object = Object(\"1\");");
> -        asBlockWalker.visitVariable(node);
> -        assertOut("var /** @type {Object} */ a = \"1\"/** Cast to Object
> */");
> -    }
> -
> -    @Override
> -    @Test
> -    public void testUint()
> -    {
> -        IVariableNode node = getVariable("var a:uint = uint(-100);");
> -        asBlockWalker.visitVariable(node);
> -        assertOut("var /** @type {number} */ a = -100/** Cast to uint */");
> -    }
> -
> -    @Override
> -    @Test
>      public void testVector()
>      {
>          IVariableNode node = getVariable("var a:Vector.<String> =
> Vector.<String>(['Hello', 'World']);");
> @@ -93,6 +66,10 @@ public class TestFlexJSGlobalFunctions extends
> TestGoogGlobalFunctions
>          //     <@/>  or something like that?
>          // I cannot find any reference to creating an XML object via a
>          // global function
> +        
> +        // (erikdebruin) E4X in Javascript is obsolete.
> +        //               Ref.: https://developer.mozilla.org/en-US/docs/E4X
> +        
>          assertOut("var /** @type {XML} */ a = XML('@')");
>      }
>  
> @@ -107,6 +84,10 @@ public class TestFlexJSGlobalFunctions extends
> TestGoogGlobalFunctions
>          //     <@/>  or something like that?
>          // I cannot find any reference to creating an XML object via a
>          // global function
> +
> +        // (erikdebruin) E4X in Javascript is obsolete.
> +        //               Ref.: https://developer.mozilla.org/en-US/docs/E4X
> +        
>          assertOut("var /** @type {XMLList} */ a = XMLList('<!-- comment
> -->')");
>      }
>  
> 
> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6f8e8f9e/compiler.jx/s
> rc/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.j
> ava
> ----------------------------------------------------------------------
> diff --git 
> a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFl
> exJSPublisher.java
> b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFl
> exJSPublisher.java
> index f6b358a..137dd61 100644
> --- 
> a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFl
> exJSPublisher.java
> +++ 
> b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFl
> exJSPublisher.java
> @@ -284,13 +284,28 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher
> implements
>          htmlFile.append("\t\t\treturn true;\n");
>          htmlFile.append("\t\t};\n");
>          htmlFile.append("\t\t\n");
> +        // int()
> +        htmlFile.append("\t\tfunction int(value) {\n");
> +        htmlFile.append("\t\t\treturn value >> 0;\n");
> +        htmlFile.append("\t\t};\n");
> +        htmlFile.append("\t\t\n");
>          // trace()
>          htmlFile.append("\t\tfunction trace(value) {\n");
> -        htmlFile.append("\t\t\tif (console && console.log)\n");
> -        htmlFile.append("\t\t\t\tconsole.log(value);\n");
> +        htmlFile.append("\t\t\ttry {\n");
> +        htmlFile.append("\t\t\t\tif (console && console.log) {\n");
> +        htmlFile.append("\t\t\t\t\tconsole.log(value);\n");
> +        htmlFile.append("\t\t\t\t}\n");
> +        htmlFile.append("\t\t\t} catch (e) {\n");
> +        htmlFile.append("\t\t\t\t// ignore; at least we tried ;-)\n");
> +        htmlFile.append("\t\t\t}\n");
>          htmlFile.append("\t\t};\n");
>          htmlFile.append("\t\t\n");
> -
> +        // uint()
> +        htmlFile.append("\t\tfunction uint(value) {\n");
> +        htmlFile.append("\t\t\treturn value >>> 0;\n");
> +        htmlFile.append("\t\t};\n");
> +        htmlFile.append("\t\t\n");
> +        
>          htmlFile.append("\t\tnew ");
>          htmlFile.append(projectName);
>          htmlFile.append("()");
> 
> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6f8e8f9e/compiler.jx/s
> rc/org/apache/flex/compiler/utils/NativeUtils.java
> ----------------------------------------------------------------------
> diff --git a/compiler.jx/src/org/apache/flex/compiler/utils/NativeUtils.java
> b/compiler.jx/src/org/apache/flex/compiler/utils/NativeUtils.java
> index 361f178..4f53496 100644
> --- a/compiler.jx/src/org/apache/flex/compiler/utils/NativeUtils.java
> +++ b/compiler.jx/src/org/apache/flex/compiler/utils/NativeUtils.java
> @@ -86,9 +86,10 @@ public class NativeUtils
>  
>      public enum NativeJSType
>      {
> +        // (erikdebruin) Ref.:
> https://cwiki.apache.org/confluence/display/FLEX/Full+Table
> +        
> +        Array("Array"),
>          Boolean("Boolean"),
> -        Number("Number"),
> -        String("String"),
>          decodeURI("decodeURI"),
>          decodeURIComponent("decodeURIComponent"),
>          encodeURI("encodeURI"),
> @@ -96,10 +97,30 @@ public class NativeUtils
>          escape("escape"),
>          isFinite("isFinite"),
>          isNaN("isNaN"),
> +        Number("Number"),
> +        Object("Object"),
>          parseFloat("parseFloat"),
>          parseInt("parseInt"),
> -        unescape("unescape");
> +        String("String"),
> +        unescape("unescape"),
> +
> +        // (erikdebruin) These aren't strictly 'native' to JS, but the
> +        //               Publisher provides global functions, so, for all
> +        //               intends and purposes they behave like they are.
> +        _int("int"),
> +        trace("trace"),
> +        uint("uint"),
> +        
> +        // (erikdebruin) These are left out, but should, at some point, be
> +        //               treated as if they actually are 'native'.
> +        /*
> +        isXMLName("isXMLName"),
> +        Vector("Vector"),
> +        XML("XML"),
> +        XMLList("XMLList"),
> +        */
>          
> +        ;
>          private final String value;
>  
>          NativeJSType(String value)
> 

-- 
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui

Reply via email to