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