1.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java Fri Feb 08 09:09:12 2013 +0100
1.2 +++ b/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java Fri Feb 08 11:12:02 2013 +0100
1.3 @@ -45,7 +45,7 @@
1.4 )
1.5 public static native byte[] expandArray(byte[] arr, int expectedSize);
1.6
1.7 - @JavaScriptBody(args = {}, body = "return new Date().getMilliseconds();")
1.8 + @JavaScriptBody(args = {}, body = "return new Date().getTime();")
1.9 public static native long currentTimeMillis();
1.10
1.11 public static long nanoTime() {
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/SystemTest.java Fri Feb 08 11:12:02 2013 +0100
2.3 @@ -0,0 +1,59 @@
2.4 +/**
2.5 + * Back 2 Browser Bytecode Translator
2.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
2.7 + *
2.8 + * This program is free software: you can redistribute it and/or modify
2.9 + * it under the terms of the GNU General Public License as published by
2.10 + * the Free Software Foundation, version 2 of the License.
2.11 + *
2.12 + * This program is distributed in the hope that it will be useful,
2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.15 + * GNU General Public License for more details.
2.16 + *
2.17 + * You should have received a copy of the GNU General Public License
2.18 + * along with this program. Look for COPYING file in the top folder.
2.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
2.20 + */
2.21 +package org.apidesign.vm4brwsr;
2.22 +
2.23 +import javax.script.Invocable;
2.24 +import org.testng.annotations.BeforeClass;
2.25 +import static org.testng.Assert.*;
2.26 +import org.testng.annotations.BeforeMethod;
2.27 +import org.testng.annotations.Test;
2.28 +
2.29 +/**
2.30 + *
2.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
2.32 + */
2.33 +public class SystemTest {
2.34 + @Test public void verifyJSTime() throws Exception {
2.35 + long now = System.currentTimeMillis();
2.36 +
2.37 + Object js = TestUtils.execCode(code, codeSeq, "Get js time",
2.38 + org.apidesign.bck2brwsr.emul.lang.System.class, "currentTimeMillis__J",
2.39 + null
2.40 + );
2.41 +
2.42 + assertTrue(js instanceof Double, "Double " + js);
2.43 + long time = ((Double)js).longValue();
2.44 +
2.45 + long later = System.currentTimeMillis();
2.46 +
2.47 + assertTrue(now <= time, "Lower bound is OK: " + now + " <= " + time);
2.48 + assertTrue(time <= later, "Upper bound is OK: " + time + " <= " + later);
2.49 + }
2.50 +
2.51 + private static CharSequence codeSeq;
2.52 + private static Invocable code;
2.53 +
2.54 + @BeforeClass
2.55 + public void compileTheCode() throws Exception {
2.56 + StringBuilder sb = new StringBuilder();
2.57 + code = StaticMethodTest.compileClass(sb, "org/apidesign/bck2brwsr/emul/lang/System");
2.58 + codeSeq = sb;
2.59 + }
2.60 +
2.61 +}
2.62 +
3.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/TestUtils.java Fri Feb 08 09:09:12 2013 +0100
3.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/TestUtils.java Fri Feb 08 11:12:02 2013 +0100
3.3 @@ -40,7 +40,7 @@
3.4 if (ret == null && expRes == null) {
3.5 return null;
3.6 }
3.7 - if (expRes.equals(ret)) {
3.8 + if (expRes != null && expRes.equals(ret)) {
3.9 return null;
3.10 }
3.11 if (expRes instanceof Number) {