jaroslav@560: /** jaroslav@560: * Back 2 Browser Bytecode Translator jaroslav@560: * Copyright (C) 2012 Jaroslav Tulach jaroslav@560: * jaroslav@560: * This program is free software: you can redistribute it and/or modify jaroslav@560: * it under the terms of the GNU General Public License as published by jaroslav@560: * the Free Software Foundation, version 2 of the License. jaroslav@560: * jaroslav@560: * This program is distributed in the hope that it will be useful, jaroslav@560: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@560: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@560: * GNU General Public License for more details. jaroslav@560: * jaroslav@560: * You should have received a copy of the GNU General Public License jaroslav@560: * along with this program. Look for COPYING file in the top folder. jaroslav@560: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@560: */ jaroslav@560: package org.apidesign.bck2brwsr.emul.lang; jaroslav@560: jaroslav@694: import java.lang.reflect.Method; jaroslav@568: import org.apidesign.bck2brwsr.core.JavaScriptBody; jaroslav@568: jaroslav@560: /** jaroslav@560: * jaroslav@560: * @author Jaroslav Tulach jaroslav@560: */ jaroslav@560: public class System { jaroslav@560: private System() { jaroslav@560: } jaroslav@560: jaroslav@568: @JavaScriptBody(args = { "value", "srcBegin", "dst", "dstBegin", "count" }, body = jaroslav@568: "if (srcBegin < dstBegin) {\n" + jaroslav@568: " while (count-- > 0) {\n" + jaroslav@568: " dst[dstBegin + count] = value[srcBegin + count];\n" + jaroslav@568: " }\n" + jaroslav@568: "} else {\n" + jaroslav@568: " while (count-- > 0) {\n" + jaroslav@568: " dst[dstBegin++] = value[srcBegin++];\n" + jaroslav@568: " }\n" + jaroslav@568: "}" jaroslav@568: ) jaroslav@694: public static void arraycopy(Object src, int srcBegin, Object dst, int dstBegin, int count) { jaroslav@694: try { jaroslav@694: Class system = Class.forName("java.lang.System"); jaroslav@694: Method m = system.getMethod("arraycopy", Object.class, int.class, Object.class, int.class, int.class); jaroslav@694: m.invoke(null, src, srcBegin, dst, dstBegin, count); jaroslav@694: } catch (Exception ex) { jaroslav@694: throw new IllegalStateException(ex); jaroslav@694: } jaroslav@694: } jaroslav@595: jaroslav@595: @JavaScriptBody(args = { "arr", "expectedSize" }, body = jaroslav@595: "while (expectedSize-- > arr.length) { arr.push(0); }; return arr;" jaroslav@595: ) jaroslav@595: public static native byte[] expandArray(byte[] arr, int expectedSize); jaroslav@599: lubomir@688: @JavaScriptBody(args = {}, body = "return new Date().getMilliseconds();") jaroslav@636: public static native long currentTimeMillis(); jaroslav@604: jaroslav@636: public static long nanoTime() { jaroslav@668: return 1000000L * currentTimeMillis(); jaroslav@636: } jaroslav@604: @JavaScriptBody(args = { "obj" }, body="return vm.java_lang_Object(false).hashCode__I.call(obj);") jaroslav@604: public static native int identityHashCode(Object obj); jaroslav@560: }