Need to flush the stack before destroying it with return value of a function closure
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 26 May 2014 14:33:11 +0200
branchclosure
changeset 159519d0484c1916
parent 1594 d7c375541fb7
child 1596 c5720b98ab4e
Need to flush the stack before destroying it with return value of a function
rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java
rt/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java
rt/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java
     1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Mon May 26 10:19:43 2014 +0200
     1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Mon May 26 14:33:11 2014 +0200
     1.3 @@ -1598,6 +1598,7 @@
     1.4          }
     1.5  
     1.6          if (returnType[0] != 'V') {
     1.7 +            mapper.flush(this);
     1.8              append("var ")
     1.9                 .append(mapper.pushT(VarType.fromFieldType(returnType[0])))
    1.10                 .append(" = ");
     2.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java	Mon May 26 10:19:43 2014 +0200
     2.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java	Mon May 26 14:33:11 2014 +0200
     2.3 @@ -216,6 +216,14 @@
     2.4              false, 30
     2.5          );
     2.6      }
     2.7 +    
     2.8 +    @Test public void computeAround() throws Exception {
     2.9 +        double exp = Numbers.around(new Object(), 5, 8);
    2.10 +        assertExec("Computes the same value", 
    2.11 +            Numbers.class, "around__ILjava_lang_Object_2II", 
    2.12 +            exp, null, 5, 8
    2.13 +        );
    2.14 +    }
    2.15  
    2.16      private static TestVM code;
    2.17  
     3.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java	Mon May 26 10:19:43 2014 +0200
     3.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java	Mon May 26 14:33:11 2014 +0200
     3.3 @@ -107,4 +107,19 @@
     3.4      
     3.5      @JavaScriptBody(args = { "o" }, body = "return o.valueOf();")
     3.6      private static native boolean bvalueOf(Object o);
     3.7 +    
     3.8 +    public static int around(Object model, int x, int y) {
     3.9 +        return minesAt(model, x - 1, y - 1)
    3.10 +            + minesAt(model, x - 1, y)
    3.11 +            + minesAt(model, x - 1, y + 1)
    3.12 +            + minesAt(model, x, y - 1)
    3.13 +            + minesAt(model, x, y + 1)
    3.14 +            + minesAt(model, x + 1, y - 1)
    3.15 +            + minesAt(model, x + 1, y)
    3.16 +            + minesAt(model, x + 1, y + 1);
    3.17 +    }
    3.18 +
    3.19 +    private static int minesAt(Object model, int x, int y) {
    3.20 +        return x + y;
    3.21 +    }    
    3.22  }