jaroslav@424
|
1 |
/**
|
jaroslav@424
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
jaroslav@424
|
3 |
*
|
jaroslav@551
|
4 |
* Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
|
jaroslav@424
|
5 |
*
|
jaroslav@424
|
6 |
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
|
jaroslav@424
|
7 |
* Other names may be trademarks of their respective owners.
|
jaroslav@424
|
8 |
*
|
jaroslav@424
|
9 |
* The contents of this file are subject to the terms of either the GNU
|
jaroslav@424
|
10 |
* General Public License Version 2 only ("GPL") or the Common
|
jaroslav@424
|
11 |
* Development and Distribution License("CDDL") (collectively, the
|
jaroslav@424
|
12 |
* "License"). You may not use this file except in compliance with the
|
jaroslav@424
|
13 |
* License. You can obtain a copy of the License at
|
jaroslav@424
|
14 |
* http://www.netbeans.org/cddl-gplv2.html
|
jaroslav@424
|
15 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
jaroslav@424
|
16 |
* specific language governing permissions and limitations under the
|
jaroslav@424
|
17 |
* License. When distributing the software, include this License Header
|
jaroslav@424
|
18 |
* Notice in each file and include the License file at
|
jaroslav@424
|
19 |
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
|
jaroslav@424
|
20 |
* particular file as subject to the "Classpath" exception as provided
|
jaroslav@424
|
21 |
* by Oracle in the GPL Version 2 section of the License file that
|
jaroslav@424
|
22 |
* accompanied this code. If applicable, add the following below the
|
jaroslav@424
|
23 |
* License Header, with the fields enclosed by brackets [] replaced by
|
jaroslav@424
|
24 |
* your own identifying information:
|
jaroslav@424
|
25 |
* "Portions Copyrighted [year] [name of copyright owner]"
|
jaroslav@424
|
26 |
*
|
jaroslav@424
|
27 |
* Contributor(s):
|
jaroslav@424
|
28 |
*
|
jaroslav@424
|
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@424
|
31 |
*
|
jaroslav@424
|
32 |
* If you wish your version of this file to be governed by only the CDDL
|
jaroslav@424
|
33 |
* or only the GPL Version 2, indicate your decision by adding
|
jaroslav@424
|
34 |
* "[Contributor] elects to include this software in this distribution
|
jaroslav@424
|
35 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a
|
jaroslav@424
|
36 |
* single choice of license, a recipient has the option to distribute
|
jaroslav@424
|
37 |
* your version of this file under either the CDDL, the GPL Version 2 or
|
jaroslav@424
|
38 |
* to extend the choice of license to its licensees as provided above.
|
jaroslav@424
|
39 |
* However, if you add GPL Version 2 code and therefore, elected the GPL
|
jaroslav@424
|
40 |
* Version 2 license, then the option applies only if the new code is
|
jaroslav@424
|
41 |
* made subject to such option by the copyright holder.
|
jaroslav@424
|
42 |
*/
|
jaroslav@424
|
43 |
package net.java.html.js.tests;
|
jaroslav@424
|
44 |
|
jaroslav@424
|
45 |
import java.util.concurrent.Callable;
|
jaroslav@424
|
46 |
import net.java.html.js.JavaScriptBody;
|
jaroslav@424
|
47 |
|
jaroslav@424
|
48 |
/**
|
jaroslav@424
|
49 |
*
|
jaroslav@424
|
50 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@424
|
51 |
*/
|
jaroslav@424
|
52 |
final class Bodies {
|
jaroslav@424
|
53 |
@JavaScriptBody(args = { "a", "b" }, body = "return a + b;")
|
jaroslav@424
|
54 |
public static native int sum(int a, int b);
|
jaroslav@424
|
55 |
|
jaroslav@424
|
56 |
@JavaScriptBody(args = {"r"}, javacall = true, body = "r.@java.lang.Runnable::run()();")
|
jaroslav@424
|
57 |
static native void callback(Runnable r);
|
jaroslav@424
|
58 |
|
jaroslav@424
|
59 |
@JavaScriptBody(args = {"c"}, javacall = true, body = "return c.@java.util.concurrent.Callable::call()();")
|
jaroslav@430
|
60 |
static native Object callback(Callable<? extends Object> c);
|
jaroslav@430
|
61 |
|
jaroslav@430
|
62 |
@JavaScriptBody(args = {"c", "v"}, javacall = true, body = "var arr = c.@java.util.concurrent.Callable::call()(); arr.push(v); return arr;")
|
jaroslav@430
|
63 |
static native Object callbackAndPush(Callable<String[]> c, String v);
|
jaroslav@424
|
64 |
|
jaroslav@424
|
65 |
@JavaScriptBody(args = { "v" }, body = "return v;")
|
jaroslav@424
|
66 |
public static native Object id(Object v);
|
jaroslav@424
|
67 |
|
jaroslav@424
|
68 |
@JavaScriptBody(args = { "v" }, body = "return { 'x' : v };")
|
jaroslav@424
|
69 |
public static native Object instance(int v);
|
jaroslav@424
|
70 |
|
jaroslav@424
|
71 |
@JavaScriptBody(args = "o", body = "o.x++;")
|
jaroslav@424
|
72 |
public static native void incrementX(Object o);
|
jaroslav@424
|
73 |
|
jaroslav@424
|
74 |
@JavaScriptBody(args = "o", body = "return o.x;")
|
jaroslav@424
|
75 |
public static native int readX(Object o);
|
jaroslav@424
|
76 |
|
jaroslav@424
|
77 |
@JavaScriptBody(args = { "c" }, javacall = true, body =
|
jaroslav@424
|
78 |
"return c.@net.java.html.js.tests.Sum::sum(II)(40, 2);"
|
jaroslav@424
|
79 |
)
|
jaroslav@424
|
80 |
public static native int sumIndirect(Sum c);
|
jaroslav@424
|
81 |
|
jaroslav@424
|
82 |
@JavaScriptBody(args = { "arr", "index" }, body = "return arr[index];")
|
jaroslav@424
|
83 |
public static native Object select(Object[] arr, int index);
|
jaroslav@424
|
84 |
|
jaroslav@424
|
85 |
@JavaScriptBody(args = { "arr" }, body = "return arr.length;")
|
jaroslav@424
|
86 |
public static native int length(Object[] arr);
|
jaroslav@429
|
87 |
|
jaroslav@436
|
88 |
@JavaScriptBody(args = { "o", "vo" }, body = "if (vo) o = o.valueOf(); return typeof o;")
|
jaroslav@436
|
89 |
public static native String typeof(Object o, boolean useValueOf);
|
jaroslav@436
|
90 |
|
jaroslav@436
|
91 |
@JavaScriptBody(args = { "b" }, body = "return typeof b;")
|
jaroslav@436
|
92 |
public static native String typeof(boolean b);
|
jaroslav@424
|
93 |
|
jaroslav@429
|
94 |
@JavaScriptBody(args = { "o" }, body = "return Array.isArray(o);")
|
jaroslav@429
|
95 |
public static native boolean isArray(Object o);
|
jaroslav@429
|
96 |
|
jaroslav@429
|
97 |
@JavaScriptBody(args = { "arr", "i", "value" }, body = "arr[i] = value; return arr[i];")
|
jaroslav@429
|
98 |
public static native String modify(String[] arr, int i, String value);
|
jaroslav@424
|
99 |
|
jaroslav@424
|
100 |
@JavaScriptBody(args = {}, body = "return true;")
|
jaroslav@424
|
101 |
public static native boolean truth();
|
jaroslav@446
|
102 |
|
jaroslav@446
|
103 |
@JavaScriptBody(args = { "s" }, javacall = true, body =
|
jaroslav@446
|
104 |
"return s.@net.java.html.js.tests.Sum::sum([Ljava/lang/Object;)([1, 2, 3]);"
|
jaroslav@446
|
105 |
)
|
jaroslav@446
|
106 |
public static native int sumArr(Sum s);
|
jaroslav@424
|
107 |
}
|