Revision: 4121
          http://vexi.svn.sourceforge.net/vexi/?rev=4121&view=rev
Author:   mkpg2
Date:     2011-05-10 15:02:10 +0000 (Tue, 10 May 2011)

Log Message:
-----------
JS api.
  - add 3rd param to eval to indicate 'location' of script.
  - Decimal arithmetic return null if any argument is null.

Modified Paths:
--------------
    trunk/org.vexi-build.shared/meta/module.revisions
    trunk/org.vexi-library.js/src/main/java/org/ibex/js/Methods.java
    trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSDecimal.jpp
    trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSU.jpp
    trunk/org.vexi-library.js/src/test/java/test/js/exec/decimal/methods.js

Modified: trunk/org.vexi-build.shared/meta/module.revisions
===================================================================
--- trunk/org.vexi-build.shared/meta/module.revisions   2011-05-10 13:39:37 UTC 
(rev 4120)
+++ trunk/org.vexi-build.shared/meta/module.revisions   2011-05-10 15:02:10 UTC 
(rev 4121)
@@ -1 +1 @@
-{"https:\/\/svn.origo.ethz.ch\/ebuild":"439"}
\ No newline at end of file
+{"https:\/\/svn.origo.ethz.ch\/ebuild":"451"}
\ No newline at end of file

Modified: trunk/org.vexi-library.js/src/main/java/org/ibex/js/Methods.java
===================================================================
--- trunk/org.vexi-library.js/src/main/java/org/ibex/js/Methods.java    
2011-05-10 13:39:37 UTC (rev 4120)
+++ trunk/org.vexi-library.js/src/main/java/org/ibex/js/Methods.java    
2011-05-10 15:02:10 UTC (rev 4121)
@@ -8,7 +8,6 @@
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
-
 import org.ibex.js.parse.Function;
 
 /**
@@ -136,12 +135,15 @@
      *    - the evaluation scope as args[1] (optional)
      * @return result of eval (may be null)
      */
+    static final JS EMPTY_SCOPE = new JS.Obj();
     static public JS eval(JS[] args) throws JSExn {
-        JS arg = args[0];
-        JS globalScope = args.length<2?new JS.Obj():args[1];
-        String s = JSU.toString(arg);
-        Function f = ExecParser.fromReader("<eval>", 1,
-                    new StringReader(s));
+        JS scriptText = JSU.expectArg(args,0);
+        JS globalScope = JSU.getArg(args,1,EMPTY_SCOPE);//;args.length<2?new 
JS.Obj():args[1];
+        JS description = JSU.getArg(args, 2);
+        Function f = ExecParser.fromReader(
+             description==null?"<eval>":JSU.toString(description), 
+             1,
+             new StringReader(JSU.toString(scriptText)));
 
         return JSU.cloneWithNewGlobalScope(f, globalScope).apply(null, 
EMPTY_JS_ARRAY);
     }

Modified: trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSDecimal.jpp
===================================================================
--- trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSDecimal.jpp    
2011-05-10 13:39:37 UTC (rev 4120)
+++ trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSDecimal.jpp    
2011-05-10 15:02:10 UTC (rev 4121)
@@ -76,9 +76,7 @@
         }
         
         public JS new_(JS[] args) throws JSExn {
-            BigDecimal arg;
-            if(args.length>0) arg = cast(args,0);
-            else arg = new BigDecimal(0);
+            BigDecimal arg = cast(JSU.expectArg(args,0));
             return new JSDecimal(arg);
         }
         
@@ -117,9 +115,10 @@
             }
                 
             if(args.length>=2){
-                BigDecimal a = cast(args,0); 
-                BigDecimal b = cast(args,1); 
-                 
+                BigDecimal a = cast(args[0]); 
+                BigDecimal b = cast(args[1]); 
+                if(a==null || b==null) return null; 
+                
                 //#switch(methodStr)
                 case "add": return new JSDecimal(a.add(b));
                 case "compare": return JSU.N(a.compareTo(b));

Modified: trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSU.jpp
===================================================================
--- trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSU.jpp  2011-05-10 
13:39:37 UTC (rev 4120)
+++ trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSU.jpp  2011-05-10 
15:02:10 UTC (rev 4121)
@@ -254,6 +254,17 @@
         }
     }
     
+    static public JS expectArg(JS[] args, int index) throws JSExn { 
+        if(args.length<=index) throw new JSExn("Expected argument 
["+index+"]");
+        return args[index];
+    }
+    static public JS getArg(JS[] args, int index) { return getArg(args, index, 
null); }
+    static public JS getArg(JS[] args, int index, JS default_) {
+        if(args.length<=index) return default_;
+        return args[index];
+    }
+
+    
     /** lets us put multi-level get/put/call keys all in the same method */
     static public class Sub extends JS.Obj {
         final JS main;

Modified: 
trunk/org.vexi-library.js/src/test/java/test/js/exec/decimal/methods.js
===================================================================
--- trunk/org.vexi-library.js/src/test/java/test/js/exec/decimal/methods.js     
2011-05-10 13:39:37 UTC (rev 4120)
+++ trunk/org.vexi-library.js/src/test/java/test/js/exec/decimal/methods.js     
2011-05-10 15:02:10 UTC (rev 4121)
@@ -24,10 +24,13 @@
 assertEquals("-0.1", Decimal.tryParseString("-.1")+"");
 
 
+assertEquals(d123, Decimal.cast("123"));
+assertEquals(d123, Decimal.cast("123"));
 
 assertEquals(d123, Decimal.cast("123"));
 assertEquals(d123, Decimal.cast(123));
 assertEquals(d123, Decimal.cast(d123));
+assertEquals(null, Decimal.cast(null));
 //assertEquals("-0.1", Decimal.tryParseString("-.")+"");
 
 //assertEquals("102.5000", Decimal.remainder(d123.round(4),d1_23.round(1))+"");
@@ -35,3 +38,10 @@
 
 assert(0 < Decimal.compare(d123,d1_23));
 assert(0 > Decimal.compare(d1_23,d123));
+
+
+////////////// null values
+assertEquals(null, Decimal.multiply(d123,null));
+
+
+


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to