Skip to content

[GR-65026] Move JS interop API into sdk #11308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/mx.sdk/mx_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def upx(args):
third_party_license_files=[],
dependencies=['sdkc'],
jar_distributions=[],
boot_jars=['sdk:NATIVEIMAGE', 'sdk:NATIVEIMAGE_LIBGRAAL'],
boot_jars=['sdk:NATIVEIMAGE', 'sdk:NATIVEIMAGE_LIBGRAAL', 'sdk:WEBIMAGE_PREVIEW'],
stability="supported",
)
mx_sdk_vm.register_graalvm_component(graalvm_sdk_native_image_component)
Expand Down
29 changes: 29 additions & 0 deletions sdk/mx.sdk/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,16 @@
"javaCompliance" : "21+"
},

"org.graalvm.webimage.api": {
"subDir": "src",
"sourceDirs": ["src"],
"dependencies": [],
"javaCompliance": "21+",
"spotbugs": "true",
"workingSets": "SDK",
"checkstyle": "org.graalvm.word",
},

"com.oracle.svm.core.annotate" : {
"subDir" : "src",
"sourceDirs" : ["src"],
Expand Down Expand Up @@ -906,6 +916,25 @@ class UniversalDetector {
},
},

"WEBIMAGE_PREVIEW": {
"subDir": "src",
"dependencies": [
"org.graalvm.webimage.api",
],
"distDependencies": [],
"moduleInfo": {
"name": "org.graalvm.webimage.api",
"exports": [
"org.graalvm.webimage.api",
],
},
"description": "The JavaScript interoperability API for GraalVM Web Image. This API is currently in preview and subject to change at any time.",
"maven": {
"artifactId": "webimage-preview",
"tag": ["default", "public"],
},
},

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

package org.graalvm.webimage.api;

import java.lang.annotation.ElementType;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or
* data (collectively the "Software"), free of charge and under any and all
* copyright rights in the Software, and any and all patent rights owned or
* freely licensable by each licensor hereunder covering either (i) the
* unmodified Software as contributed to or provided by such licensor, or (ii)
* the Larger Works (as defined below), to deal in both
*
* (a) the Software, and
*
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
*
* The above copyright notice and either this complete permission notice or at a
* minimum a reference to the UPL must be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package org.graalvm.webimage.api;

import java.math.BigInteger;

/**
* Java representation of a JavaScript {@code BigInt} value.
*/
public final class JSBigInt extends JSValue {

JSBigInt() {
}

@JS("return BigInt(conversion.extractJavaScriptString(s[runtime.symbol.javaNative]));")
private static native JSBigInt of(String s);

public static JSBigInt of(long n) {
return of(String.valueOf(n));
}

public static JSBigInt of(BigInteger b) {
return of(b.toString());
}

@Override
public String typeof() {
return "bigint";
}

@JS("return conversion.toProxy(toJavaString(this.toString()));")
private native String javaString();

@Override
protected String stringValue() {
return javaString();
}

private BigInteger bigInteger() {
return new BigInteger(javaString());
}

@Override
public Byte asByte() {
return bigInteger().byteValue();
}

@Override
public Short asShort() {
return bigInteger().shortValue();
}

@Override
public Character asChar() {
return (char) bigInteger().intValue();
}

@Override
public Integer asInt() {
return bigInteger().intValue();
}

@Override
public Float asFloat() {
return bigInteger().floatValue();
}

@Override
public Long asLong() {
return bigInteger().longValue();
}

@Override
public BigInteger asBigInteger() {
return bigInteger();
}

@Override
public boolean equals(Object that) {
if (that instanceof JSBigInt) {
return this.javaString().equals(((JSBigInt) that).javaString());
}
return false;
}

@Override
public int hashCode() {
return javaString().hashCode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or
* data (collectively the "Software"), free of charge and under any and all
* copyright rights in the Software, and any and all patent rights owned or
* freely licensable by each licensor hereunder covering either (i) the
* unmodified Software as contributed to or provided by such licensor, or (ii)
* the Larger Works (as defined below), to deal in both
*
* (a) the Software, and
*
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
*
* The above copyright notice and either this complete permission notice or at a
* minimum a reference to the UPL must be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.graalvm.webimage.api;

/**
* Java representation of a JavaScript {@code Boolean} value.
*/
public final class JSBoolean extends JSValue {

JSBoolean() {
}

@JS("return true;")
private static native JSBoolean createTrue();

@JS("return false;")
private static native JSBoolean createFalse();

public static JSBoolean of(boolean b) {
return b ? createTrue() : createFalse();
}

@Override
public String typeof() {
return "boolean";
}

@JS("return conversion.toProxy(conversion.createJavaBoolean(this));")
private native Boolean javaBoolean();

@Override
protected String stringValue() {
return String.valueOf(javaBoolean());
}

@Override
public Boolean asBoolean() {
return javaBoolean();
}

@Override
public boolean equals(Object that) {
if (that instanceof JSBoolean) {
return this.javaBoolean().equals(((JSBoolean) that).javaBoolean());
}
return false;
}

@Override
public int hashCode() {
return javaBoolean().hashCode();
}
}
Loading