rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/HtmlAnnotations.java
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012-2015 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.vmtest.impl;
20 import java.util.concurrent.Callable;
21 import net.java.html.js.JavaScriptBody;
22 import net.java.html.js.JavaScriptResource;
26 * @author Jaroslav Tulach <jtulach@netbeans.org>
28 @JavaScriptResource("htmlannotations.js")
29 public class HtmlAnnotations {
30 private Object callback;
33 @JavaScriptBody(args = {}, body = "return 42;")
34 public static int fourtyTwo() {
38 @JavaScriptBody(args = { "x", "y" }, body = "return mul(x, y);")
39 public static native int useExternalMul(int x, int y);
41 public static int callback() {
42 final int[] arr = { 0 };
43 callback(new Runnable() {
52 @JavaScriptBody(args = { "r" }, javacall=true, body = "r.@java.lang.Runnable::run()()")
53 private static native void callback(Runnable r);
55 @JavaScriptBody(args = { }, javacall = true, body = "return @org.apidesign.bck2brwsr.vmtest.impl.HtmlAnnotations::callback()();")
56 public static native int staticCallback();
58 @JavaScriptBody(args = { }, wait4js = false, body = "/* do nothing */")
59 public static native void empty();
62 protected long chooseLong(boolean takeFirst, boolean takeSecond, long first, long second) {
64 if (takeFirst) l += first;
65 if (takeSecond) l += second;
69 protected void onError(Object obj) throws Exception {
77 public static Object create() {
78 return new HtmlAnnotations();
80 @JavaScriptBody(args = { "impl", "a", "b" }, javacall = true, body =
81 "return impl.@org.apidesign.bck2brwsr.vmtest.impl.HtmlAnnotations::chooseLong(ZZJJ)(true, false, a, b);"
83 public static native long first(Object impl, long a, long b);
85 @JavaScriptBody(args = { "impl", "d" }, javacall = true, body =
86 "impl.@org.apidesign.bck2brwsr.vmtest.impl.HtmlAnnotations::onError(Ljava/lang/Object;)(d);" +
87 "return impl.@org.apidesign.bck2brwsr.vmtest.impl.HtmlAnnotations::getError()();"
89 public static native Double onError(Object impl, Double d);
91 @JavaScriptBody(args = { }, body = "return new Date(2016, 4, 1);")
92 public static native Object april2016();
94 @JavaScriptBody(args = { "date" }, body = "return date.getFullYear()")
95 public static native int year(Object date);
97 @JavaScriptBody(args = { "call" }, javacall = true, body = ""
98 + "var b = call.@java.util.concurrent.Callable::call()();\n"
99 + "return b ? 'yes' : 'no';\n"
101 public static native String yesNo(Callable<Boolean> call);
103 @JavaScriptBody(args = { "arr", "val" }, body =
104 "return arr[0] === val;"
106 public static native boolean compareArr(Object[] arr, Object val);