jaroslav@123
|
1 |
/**
|
jaroslav@358
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
jaroslav@123
|
3 |
*
|
jaroslav@551
|
4 |
* Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
|
jaroslav@123
|
5 |
*
|
jaroslav@358
|
6 |
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
|
jaroslav@358
|
7 |
* Other names may be trademarks of their respective owners.
|
jaroslav@123
|
8 |
*
|
jaroslav@358
|
9 |
* The contents of this file are subject to the terms of either the GNU
|
jaroslav@358
|
10 |
* General Public License Version 2 only ("GPL") or the Common
|
jaroslav@358
|
11 |
* Development and Distribution License("CDDL") (collectively, the
|
jaroslav@358
|
12 |
* "License"). You may not use this file except in compliance with the
|
jaroslav@358
|
13 |
* License. You can obtain a copy of the License at
|
jaroslav@358
|
14 |
* http://www.netbeans.org/cddl-gplv2.html
|
jaroslav@358
|
15 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
jaroslav@358
|
16 |
* specific language governing permissions and limitations under the
|
jaroslav@358
|
17 |
* License. When distributing the software, include this License Header
|
jaroslav@358
|
18 |
* Notice in each file and include the License file at
|
jaroslav@358
|
19 |
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
|
jaroslav@358
|
20 |
* particular file as subject to the "Classpath" exception as provided
|
jaroslav@358
|
21 |
* by Oracle in the GPL Version 2 section of the License file that
|
jaroslav@358
|
22 |
* accompanied this code. If applicable, add the following below the
|
jaroslav@358
|
23 |
* License Header, with the fields enclosed by brackets [] replaced by
|
jaroslav@358
|
24 |
* your own identifying information:
|
jaroslav@358
|
25 |
* "Portions Copyrighted [year] [name of copyright owner]"
|
jaroslav@358
|
26 |
*
|
jaroslav@358
|
27 |
* Contributor(s):
|
jaroslav@358
|
28 |
*
|
jaroslav@358
|
29 |
* The Original Software is NetBeans. The Initial Developer of the Original
|
jaroslav@551
|
30 |
* Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
|
jaroslav@358
|
31 |
*
|
jaroslav@358
|
32 |
* If you wish your version of this file to be governed by only the CDDL
|
jaroslav@358
|
33 |
* or only the GPL Version 2, indicate your decision by adding
|
jaroslav@358
|
34 |
* "[Contributor] elects to include this software in this distribution
|
jaroslav@358
|
35 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a
|
jaroslav@358
|
36 |
* single choice of license, a recipient has the option to distribute
|
jaroslav@358
|
37 |
* your version of this file under either the CDDL, the GPL Version 2 or
|
jaroslav@358
|
38 |
* to extend the choice of license to its licensees as provided above.
|
jaroslav@358
|
39 |
* However, if you add GPL Version 2 code and therefore, elected the GPL
|
jaroslav@358
|
40 |
* Version 2 license, then the option applies only if the new code is
|
jaroslav@358
|
41 |
* made subject to such option by the copyright holder.
|
jaroslav@123
|
42 |
*/
|
jaroslav@362
|
43 |
package org.netbeans.html.boot.impl;
|
jaroslav@123
|
44 |
|
jaroslav@123
|
45 |
import net.java.html.js.JavaScriptBody;
|
jaroslav@163
|
46 |
import net.java.html.js.JavaScriptResource;
|
jaroslav@123
|
47 |
|
jaroslav@123
|
48 |
|
jaroslav@123
|
49 |
/**
|
jaroslav@123
|
50 |
*
|
jtulach@655
|
51 |
* @author Jaroslav Tulach
|
jaroslav@123
|
52 |
*/
|
jaroslav@163
|
53 |
@JavaScriptResource("jsmethods.js")
|
jaroslav@123
|
54 |
public class JsMethods {
|
jtulach@1041
|
55 |
private java.lang.Object value;
|
jaroslav@196
|
56 |
|
jaroslav@123
|
57 |
@JavaScriptBody(args = {}, body = "return 42;")
|
jtulach@1041
|
58 |
public static java.lang.Object fortyTwo() {
|
jaroslav@123
|
59 |
return -42;
|
jaroslav@123
|
60 |
}
|
jaroslav@123
|
61 |
|
jaroslav@123
|
62 |
@JavaScriptBody(args = {"x", "y" }, body = "return x + y;")
|
jaroslav@123
|
63 |
public static native int plus(int x, int y);
|
jaroslav@123
|
64 |
|
jaroslav@123
|
65 |
@JavaScriptBody(args = {"x"}, body = "return x;")
|
jaroslav@123
|
66 |
public static native int plus(int x);
|
jaroslav@123
|
67 |
|
jaroslav@123
|
68 |
@JavaScriptBody(args = {}, body = "return this;")
|
jtulach@1041
|
69 |
public static native java.lang.Object staticThis();
|
jaroslav@123
|
70 |
|
jaroslav@123
|
71 |
@JavaScriptBody(args = {}, body = "return this;")
|
jtulach@1041
|
72 |
public native java.lang.Object getThis();
|
jaroslav@123
|
73 |
@JavaScriptBody(args = {"x"}, body = "return x;")
|
jaroslav@123
|
74 |
public native int plusInst(int x);
|
jaroslav@153
|
75 |
|
jaroslav@153
|
76 |
@JavaScriptBody(args = {}, body = "return true;")
|
jaroslav@153
|
77 |
public static boolean truth() {
|
jaroslav@153
|
78 |
return false;
|
jaroslav@153
|
79 |
}
|
jaroslav@160
|
80 |
|
jaroslav@191
|
81 |
@JavaScriptBody(args = { "r" }, javacall=true, body = "r.@java.lang.Runnable::run()();")
|
jaroslav@160
|
82 |
public static native void callback(Runnable r);
|
jaroslav@161
|
83 |
|
jaroslav@161
|
84 |
@JavaScriptBody(args = { "at", "arr" }, javacall = true, body =
|
jaroslav@161
|
85 |
"var a = 0;\n"
|
jaroslav@161
|
86 |
+ "for (var i = 0; i < arr.length; i++) {\n"
|
jaroslav@362
|
87 |
+ " a = at.@org.netbeans.html.boot.impl.Arithm::sumTwo(II)(a, arr[i]);\n"
|
jaroslav@161
|
88 |
+ "}\n"
|
jaroslav@161
|
89 |
+ "return a;"
|
jaroslav@161
|
90 |
)
|
jaroslav@161
|
91 |
private static native int sumArr(Arithm at, int... arr);
|
jaroslav@161
|
92 |
|
jaroslav@161
|
93 |
public static int sumArr(int... arr) {
|
jaroslav@161
|
94 |
return sumArr(new Arithm(), arr);
|
jaroslav@161
|
95 |
}
|
jaroslav@163
|
96 |
|
jaroslav@163
|
97 |
@JavaScriptBody(args = { "x", "y" }, body = "return mul(x, y);")
|
jaroslav@163
|
98 |
public static native int useExternalMul(int x, int y);
|
jaroslav@171
|
99 |
|
jaroslav@362
|
100 |
@JavaScriptBody(args = { "m" }, javacall = true, body = "return m.@org.netbeans.html.boot.impl.JsMethods::getThis()();")
|
jaroslav@171
|
101 |
public static native JsMethods returnYourSelf(JsMethods m);
|
jaroslav@191
|
102 |
|
jaroslav@362
|
103 |
@JavaScriptBody(args = { "x", "y" }, javacall = true, body = "return @org.netbeans.html.boot.impl.JsMethods::useExternalMul(II)(x, y);")
|
jaroslav@191
|
104 |
public static native int staticCallback(int x, int y);
|
jaroslav@191
|
105 |
|
jaroslav@191
|
106 |
@JavaScriptBody(args = { "v" }, javacall = true, body = "return @java.lang.Integer::parseInt(Ljava/lang/String;)(v);")
|
jaroslav@191
|
107 |
public static native int parseInt(String v);
|
jaroslav@192
|
108 |
|
jtulach@933
|
109 |
@JavaScriptBody(args = { "v" }, body = "return v.toString();")
|
jtulach@933
|
110 |
public static native String fromEnum(Enm v);
|
jtulach@933
|
111 |
|
jaroslav@439
|
112 |
@JavaScriptBody(args = "arr", body = "return arr;")
|
jtulach@1041
|
113 |
public static native java.lang.Object[] arr(java.lang.Object[] arr);
|
jaroslav@439
|
114 |
|
jaroslav@192
|
115 |
@JavaScriptBody(args = { "useA", "useB", "a", "b" }, body = "var l = 0;"
|
jaroslav@192
|
116 |
+ "if (useA) l += a;\n"
|
jaroslav@192
|
117 |
+ "if (useB) l += b;\n"
|
jaroslav@192
|
118 |
+ "return l;\n"
|
jaroslav@192
|
119 |
)
|
jaroslav@192
|
120 |
public static native long chooseLong(boolean useA, boolean useB, long a, long b);
|
jaroslav@196
|
121 |
|
jtulach@1041
|
122 |
protected void onError(java.lang.Object o) throws Exception {
|
jaroslav@196
|
123 |
value = o;
|
jaroslav@196
|
124 |
}
|
jaroslav@196
|
125 |
|
jtulach@1041
|
126 |
java.lang.Object getError() {
|
jaroslav@196
|
127 |
return value;
|
jaroslav@196
|
128 |
}
|
jaroslav@196
|
129 |
|
jaroslav@196
|
130 |
@JavaScriptBody(args = { "err" }, javacall = true, body =
|
jaroslav@362
|
131 |
"this.@org.netbeans.html.boot.impl.JsMethods::onError(Ljava/lang/Object;)(err);"
|
jaroslav@362
|
132 |
+ "return this.@org.netbeans.html.boot.impl.JsMethods::getError()();"
|
jaroslav@196
|
133 |
)
|
jtulach@1041
|
134 |
public native java.lang.Object recordError(java.lang.Object err);
|
jaroslav@451
|
135 |
|
jaroslav@451
|
136 |
@JavaScriptBody(args = { "x", "y" }, body = "return x + y;")
|
jaroslav@451
|
137 |
public static int plusOrMul(int x, int y) {
|
jaroslav@451
|
138 |
return x * y;
|
jaroslav@451
|
139 |
}
|
jtulach@900
|
140 |
|
jtulach@900
|
141 |
@JavaScriptBody(args = { "x" }, keepAlive = false, body = "throw 'Do not call me!'")
|
jtulach@1041
|
142 |
public static native int checkAllowGC(java.lang.Object x);
|
jtulach@933
|
143 |
|
jtulach@933
|
144 |
enum Enm {
|
jtulach@933
|
145 |
A, B;
|
jtulach@933
|
146 |
}
|
jaroslav@123
|
147 |
}
|