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