emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 08 Feb 2013 11:12:02 +0100
changeset 704 4fe8b3dfc55f
parent 688 fd47ec497fb2
child 747 ae352b763959
permissions -rw-r--r--
Proper implementation of System.currentTimeMillis with so desired test
jaroslav@560
     1
/**
jaroslav@560
     2
 * Back 2 Browser Bytecode Translator
jaroslav@560
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@560
     4
 *
jaroslav@560
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@560
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@560
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@560
     8
 *
jaroslav@560
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@560
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@560
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@560
    12
 * GNU General Public License for more details.
jaroslav@560
    13
 *
jaroslav@560
    14
 * You should have received a copy of the GNU General Public License
jaroslav@560
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@560
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@560
    17
 */
jaroslav@560
    18
package org.apidesign.bck2brwsr.emul.lang;
jaroslav@560
    19
jaroslav@568
    20
import org.apidesign.bck2brwsr.core.JavaScriptBody;
jaroslav@568
    21
jaroslav@560
    22
/**
jaroslav@560
    23
 *
jaroslav@560
    24
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@560
    25
 */
jaroslav@560
    26
public class System {
jaroslav@560
    27
    private System() {
jaroslav@560
    28
    }
jaroslav@560
    29
jaroslav@568
    30
    @JavaScriptBody(args = { "value", "srcBegin", "dst", "dstBegin", "count" }, body = 
jaroslav@568
    31
        "if (srcBegin < dstBegin) {\n" +
jaroslav@568
    32
        "    while (count-- > 0) {\n" +
jaroslav@568
    33
        "        dst[dstBegin + count] = value[srcBegin + count];\n" +
jaroslav@568
    34
        "    }\n" +
jaroslav@568
    35
        "} else {\n" +
jaroslav@568
    36
        "    while (count-- > 0) {\n" +
jaroslav@568
    37
        "        dst[dstBegin++] = value[srcBegin++];\n" +
jaroslav@568
    38
        "    }\n" +
jaroslav@568
    39
        "}"
jaroslav@568
    40
    )
jaroslav@568
    41
    public static native void arraycopy(Object value, int srcBegin, Object dst, int dstBegin, int count);
jaroslav@595
    42
jaroslav@595
    43
    @JavaScriptBody(args = { "arr", "expectedSize" }, body = 
jaroslav@595
    44
        "while (expectedSize-- > arr.length) { arr.push(0); }; return arr;"
jaroslav@595
    45
    )
jaroslav@595
    46
    public static native byte[] expandArray(byte[] arr, int expectedSize);
jaroslav@599
    47
jaroslav@704
    48
    @JavaScriptBody(args = {}, body = "return new Date().getTime();")
jaroslav@636
    49
    public static native long currentTimeMillis();
jaroslav@604
    50
    
jaroslav@636
    51
    public static long nanoTime() {
jaroslav@668
    52
        return 1000000L * currentTimeMillis();
jaroslav@636
    53
    }
jaroslav@604
    54
    @JavaScriptBody(args = { "obj" }, body="return vm.java_lang_Object(false).hashCode__I.call(obj);")
jaroslav@604
    55
    public static native int identityHashCode(Object obj);
jaroslav@604
    56
    
jaroslav@560
    57
}