jaroslav@1282: /** jaroslav@1282: * Back 2 Browser Bytecode Translator jaroslav@1282: * Copyright (C) 2012 Jaroslav Tulach jaroslav@1282: * jaroslav@1282: * This program is free software: you can redistribute it and/or modify jaroslav@1282: * it under the terms of the GNU General Public License as published by jaroslav@1282: * the Free Software Foundation, version 2 of the License. jaroslav@1282: * jaroslav@1282: * This program is distributed in the hope that it will be useful, jaroslav@1282: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@1282: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@1282: * GNU General Public License for more details. jaroslav@1282: * jaroslav@1282: * You should have received a copy of the GNU General Public License jaroslav@1282: * along with this program. Look for COPYING file in the top folder. jaroslav@1282: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@1282: */ jaroslav@1282: package org.apidesign.bck2brwsr.vmtest.impl; jaroslav@1282: jaroslav@1282: import net.java.html.js.JavaScriptBody; jaroslav@1282: import net.java.html.js.JavaScriptResource; jaroslav@1282: jaroslav@1282: /** jaroslav@1282: * jaroslav@1282: * @author Jaroslav Tulach jaroslav@1282: */ jaroslav@1282: @JavaScriptResource("htmlannotations.js") jaroslav@1282: public class HtmlAnnotations { jaroslav@1282: private Object callback; jaroslav@1282: jaroslav@1282: jaroslav@1282: @JavaScriptBody(args = {}, body = "return 42;") jaroslav@1282: public static int fourtyTwo() { jaroslav@1282: return -1; jaroslav@1282: } jaroslav@1282: jaroslav@1282: @JavaScriptBody(args = { "x", "y" }, body = "return mul(x, y);") jaroslav@1282: public static native int useExternalMul(int x, int y); jaroslav@1282: jaroslav@1282: public static int callback() { jaroslav@1282: final int[] arr = { 0 }; jaroslav@1282: callback(new Runnable() { jaroslav@1282: @Override jaroslav@1282: public void run() { jaroslav@1282: arr[0]++; jaroslav@1282: } jaroslav@1282: }); jaroslav@1282: return arr[0]; jaroslav@1282: } jaroslav@1282: jaroslav@1282: @JavaScriptBody(args = { "r" }, javacall=true, body = "r.@java.lang.Runnable::run()()") jaroslav@1282: private static native void callback(Runnable r); jaroslav@1282: jaroslav@1282: @JavaScriptBody(args = { }, javacall = true, body = "return @org.apidesign.bck2brwsr.vmtest.impl.HtmlAnnotations::callback()();") jaroslav@1282: public static native int staticCallback(); jaroslav@1635: jaroslav@1635: @JavaScriptBody(args = { }, wait4js = false, body = "/* do nothing */") jaroslav@1635: public static native void empty(); jaroslav@1282: jaroslav@1282: jaroslav@1282: protected long chooseLong(boolean takeFirst, boolean takeSecond, long first, long second) { jaroslav@1282: long l = 0; jaroslav@1282: if (takeFirst) l += first; jaroslav@1282: if (takeSecond) l += second; jaroslav@1282: return l; jaroslav@1282: } jaroslav@1282: jaroslav@1282: protected void onError(Object obj) throws Exception { jaroslav@1282: callback = obj; jaroslav@1282: } jaroslav@1282: jaroslav@1282: Object getError() { jaroslav@1282: return callback; jaroslav@1282: } jaroslav@1282: jaroslav@1282: public static Object create() { jaroslav@1282: return new HtmlAnnotations(); jaroslav@1282: } jaroslav@1282: @JavaScriptBody(args = { "impl", "a", "b" }, javacall = true, body = jaroslav@1282: "return impl.@org.apidesign.bck2brwsr.vmtest.impl.HtmlAnnotations::chooseLong(ZZJJ)(true, false, a, b);" jaroslav@1282: ) jaroslav@1282: public static native long first(Object impl, long a, long b); jaroslav@1282: jaroslav@1282: @JavaScriptBody(args = { "impl", "d" }, javacall = true, body = jaroslav@1282: "impl.@org.apidesign.bck2brwsr.vmtest.impl.HtmlAnnotations::onError(Ljava/lang/Object;)(d);" + jaroslav@1282: "return impl.@org.apidesign.bck2brwsr.vmtest.impl.HtmlAnnotations::getError()();" jaroslav@1282: ) jaroslav@1282: public static native Double onError(Object impl, Double d); jaroslav@1282: }