Skip to content

Commit 224766e

Browse files
committed
[GR-65026] Move JS interop API into sdk
PullRequest: graal/20905
2 parents a61b9bb + 5de818c commit 224766e

File tree

25 files changed

+909
-670
lines changed

25 files changed

+909
-670
lines changed

sdk/mx.sdk/mx_sdk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def upx(args):
162162
third_party_license_files=[],
163163
dependencies=['sdkc'],
164164
jar_distributions=[],
165-
boot_jars=['sdk:NATIVEIMAGE', 'sdk:NATIVEIMAGE_LIBGRAAL'],
165+
boot_jars=['sdk:NATIVEIMAGE', 'sdk:NATIVEIMAGE_LIBGRAAL', 'sdk:WEBIMAGE_PREVIEW'],
166166
stability="supported",
167167
)
168168
mx_sdk_vm.register_graalvm_component(graalvm_sdk_native_image_component)

sdk/mx.sdk/suite.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,16 @@
456456
"javaCompliance" : "21+"
457457
},
458458

459+
"org.graalvm.webimage.api": {
460+
"subDir": "src",
461+
"sourceDirs": ["src"],
462+
"dependencies": [],
463+
"javaCompliance": "21+",
464+
"spotbugs": "true",
465+
"workingSets": "SDK",
466+
"checkstyle": "org.graalvm.word",
467+
},
468+
459469
"com.oracle.svm.core.annotate" : {
460470
"subDir" : "src",
461471
"sourceDirs" : ["src"],
@@ -951,6 +961,25 @@ class UniversalDetector {
951961
},
952962
},
953963

964+
"WEBIMAGE_PREVIEW": {
965+
"subDir": "src",
966+
"dependencies": [
967+
"org.graalvm.webimage.api",
968+
],
969+
"distDependencies": [],
970+
"moduleInfo": {
971+
"name": "org.graalvm.webimage.api",
972+
"exports": [
973+
"org.graalvm.webimage.api",
974+
],
975+
},
976+
"description": "The JavaScript interoperability API for GraalVM Web Image. This API is currently in preview and subject to change at any time.",
977+
"maven": {
978+
"artifactId": "webimage-preview",
979+
"tag": ["default", "public"],
980+
},
981+
},
982+
954983
"POLYGLOT_VERSION": {
955984
"type": "dir",
956985
"platformDependent": False,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[[rule]]
2+
files = "*"
3+
all = [
4+
5+
6+
7+
]

web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JS.java renamed to sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JS.java

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,44 @@
11
/*
2-
* Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
5-
* This code is free software; you can redistribute it and/or modify it
6-
* under the terms of the GNU General Public License version 2 only, as
7-
* published by the Free Software Foundation. Oracle designates this
8-
* particular file as subject to the "Classpath" exception as provided
9-
* by Oracle in the LICENSE file that accompanied this code.
5+
* The Universal Permissive License (UPL), Version 1.0
106
*
11-
* This code is distributed in the hope that it will be useful, but WITHOUT
12-
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13-
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14-
* version 2 for more details (a copy is included in the LICENSE file that
15-
* accompanied this code).
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
1614
*
17-
* You should have received a copy of the GNU General Public License version
18-
* 2 along with this work; if not, write to the Free Software Foundation,
19-
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
15+
* (a) the Software, and
2016
*
21-
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22-
* or visit www.oracle.com if you need additional information or have any
23-
* questions.
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
2440
*/
41+
2542
package org.graalvm.webimage.api;
2643

2744
import java.lang.annotation.ElementType;
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
42+
package org.graalvm.webimage.api;
43+
44+
import java.math.BigInteger;
45+
46+
/**
47+
* Java representation of a JavaScript {@code BigInt} value.
48+
*/
49+
public final class JSBigInt extends JSValue {
50+
51+
JSBigInt() {
52+
}
53+
54+
@JS("return BigInt(conversion.extractJavaScriptString(s[runtime.symbol.javaNative]));")
55+
private static native JSBigInt of(String s);
56+
57+
public static JSBigInt of(long n) {
58+
return of(String.valueOf(n));
59+
}
60+
61+
public static JSBigInt of(BigInteger b) {
62+
return of(b.toString());
63+
}
64+
65+
@Override
66+
public String typeof() {
67+
return "bigint";
68+
}
69+
70+
@JS("return conversion.toProxy(toJavaString(this.toString()));")
71+
private native String javaString();
72+
73+
@Override
74+
protected String stringValue() {
75+
return javaString();
76+
}
77+
78+
private BigInteger bigInteger() {
79+
return new BigInteger(javaString());
80+
}
81+
82+
@Override
83+
public Byte asByte() {
84+
return bigInteger().byteValue();
85+
}
86+
87+
@Override
88+
public Short asShort() {
89+
return bigInteger().shortValue();
90+
}
91+
92+
@Override
93+
public Character asChar() {
94+
return (char) bigInteger().intValue();
95+
}
96+
97+
@Override
98+
public Integer asInt() {
99+
return bigInteger().intValue();
100+
}
101+
102+
@Override
103+
public Float asFloat() {
104+
return bigInteger().floatValue();
105+
}
106+
107+
@Override
108+
public Long asLong() {
109+
return bigInteger().longValue();
110+
}
111+
112+
@Override
113+
public BigInteger asBigInteger() {
114+
return bigInteger();
115+
}
116+
117+
@Override
118+
public boolean equals(Object that) {
119+
if (that instanceof JSBigInt) {
120+
return this.javaString().equals(((JSBigInt) that).javaString());
121+
}
122+
return false;
123+
}
124+
125+
@Override
126+
public int hashCode() {
127+
return javaString().hashCode();
128+
}
129+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package org.graalvm.webimage.api;
42+
43+
/**
44+
* Java representation of a JavaScript {@code Boolean} value.
45+
*/
46+
public final class JSBoolean extends JSValue {
47+
48+
JSBoolean() {
49+
}
50+
51+
@JS("return true;")
52+
private static native JSBoolean createTrue();
53+
54+
@JS("return false;")
55+
private static native JSBoolean createFalse();
56+
57+
public static JSBoolean of(boolean b) {
58+
return b ? createTrue() : createFalse();
59+
}
60+
61+
@Override
62+
public String typeof() {
63+
return "boolean";
64+
}
65+
66+
@JS("return conversion.toProxy(conversion.createJavaBoolean(this));")
67+
private native Boolean javaBoolean();
68+
69+
@Override
70+
protected String stringValue() {
71+
return String.valueOf(javaBoolean());
72+
}
73+
74+
@Override
75+
public Boolean asBoolean() {
76+
return javaBoolean();
77+
}
78+
79+
@Override
80+
public boolean equals(Object that) {
81+
if (that instanceof JSBoolean) {
82+
return this.javaBoolean().equals(((JSBoolean) that).javaBoolean());
83+
}
84+
return false;
85+
}
86+
87+
@Override
88+
public int hashCode() {
89+
return javaBoolean().hashCode();
90+
}
91+
}

0 commit comments

Comments
 (0)