1.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/Zips.java Mon Feb 11 19:55:00 2013 +0100
1.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/Zips.java Tue Feb 12 16:46:13 2013 +0100
1.3 @@ -32,12 +32,12 @@
1.4 private final FastJar fj;
1.5
1.6 private Zips(String path, byte[] zipData) throws IOException {
1.7 - long bef = currentTimeMillis();
1.8 + long bef = timeNow();
1.9 fj = new FastJar(zipData);
1.10 for (FastJar.Entry e : fj.list()) {
1.11 putRes(e.name, e);
1.12 }
1.13 - log("Iterating thru " + path + " took " + (currentTimeMillis() - bef) + "ms");
1.14 + log("Iterating thru " + path + " took " + (timeNow() - bef) + "ms");
1.15 }
1.16
1.17 public static void init() {
1.18 @@ -79,11 +79,11 @@
1.19 private byte[] findRes(String res) throws IOException {
1.20 Object arr = findResImpl(res);
1.21 if (arr instanceof FastJar.Entry) {
1.22 - long bef = currentTimeMillis();
1.23 + long bef = timeNow();
1.24 InputStream zip = fj.getInputStream((FastJar.Entry)arr);
1.25 arr = readFully(new byte[512], zip);
1.26 putRes(res, arr);
1.27 - log("Reading " + res + " took " + (currentTimeMillis() - bef) + "ms");
1.28 + log("Reading " + res + " took " + (timeNow() - bef) + "ms");
1.29 }
1.30 return (byte[]) arr;
1.31 }
1.32 @@ -151,10 +151,18 @@
1.33 return arr;
1.34 }
1.35
1.36 - private static long currentTimeMillis() {
1.37 - return (long)m();
1.38 + private static long timeNow() {
1.39 + double time = m();
1.40 + if (time >= 0) {
1.41 + return (long)time;
1.42 + }
1.43 + return org.apidesign.bck2brwsr.emul.lang.System.currentTimeMillis();
1.44 }
1.45 - @JavaScriptBody(args = { }, body = "return window.performance.now();")
1.46 + @JavaScriptBody(args = {}, body =
1.47 + "if (typeof window.performance === 'undefined') return -1;\n"
1.48 + + "if (typeof window.performance.now === 'undefined') return -1;\n"
1.49 + + "return window.performance.now();"
1.50 + )
1.51 private static native double m();
1.52
1.53