diff --git a/sdk/mx.sdk/mx_sdk.py b/sdk/mx.sdk/mx_sdk.py index 3858093e64c3..69c7284727de 100644 --- a/sdk/mx.sdk/mx_sdk.py +++ b/sdk/mx.sdk/mx_sdk.py @@ -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) diff --git a/sdk/mx.sdk/suite.py b/sdk/mx.sdk/suite.py index bd02f3ee3b22..bf9cebd50039 100644 --- a/sdk/mx.sdk/suite.py +++ b/sdk/mx.sdk/suite.py @@ -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"], @@ -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, diff --git a/sdk/src/org.graalvm.webimage.api/OWNERS.toml b/sdk/src/org.graalvm.webimage.api/OWNERS.toml new file mode 100644 index 000000000000..54570aa313a4 --- /dev/null +++ b/sdk/src/org.graalvm.webimage.api/OWNERS.toml @@ -0,0 +1,7 @@ +[[rule]] +files = "*" +all = [ + "patrick.ziegler@oracle.com", + "aleksandar.prokopec@oracle.com", + "david.leopoldseder@oracle.com", +] diff --git a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JS.java b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JS.java similarity index 88% rename from web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JS.java rename to sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JS.java index cb2ded0e0496..4207c5722e70 100644 --- a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JS.java +++ b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JS.java @@ -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; diff --git a/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSBigInt.java b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSBigInt.java new file mode 100644 index 000000000000..34f188a994d1 --- /dev/null +++ b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSBigInt.java @@ -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(); + } +} diff --git a/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSBoolean.java b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSBoolean.java new file mode 100644 index 000000000000..dca0cbc05cb3 --- /dev/null +++ b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSBoolean.java @@ -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(); + } +} diff --git a/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSError.java b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSError.java new file mode 100644 index 000000000000..52d810bd5366 --- /dev/null +++ b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSError.java @@ -0,0 +1,69 @@ +/* + * 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; + +/** + * Represents the error value thrown in JavaScript. + *
+ * Must not pass a {@link Throwable} instance, these should be thrown directly instead of being + * wrapped in a {@link JSError}. + */ +@SuppressWarnings("serial") +public final class JSError extends RuntimeException { + + private static final long serialVersionUID = -2343564169271174471L; + + /** + * JavaScript object that was thrown. + */ + private final Object thrownObject; + + public JSError(Object thrownObject) { + super(thrownObject.toString()); + this.thrownObject = thrownObject; + assert !(thrownObject instanceof Throwable) : "Tried creating JSError for a throwable: " + thrownObject; + } + + public Object getThrownObject() { + return thrownObject; + } +} diff --git a/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSNumber.java b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSNumber.java new file mode 100644 index 000000000000..f4983570a4f1 --- /dev/null +++ b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSNumber.java @@ -0,0 +1,122 @@ +/* + * 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 Number} value. + */ +public final class JSNumber extends JSValue { + + JSNumber() { + } + + @JS("return conversion.extractJavaScriptNumber(d[runtime.symbol.javaNative]);") + public static native JSNumber of(double d); + + @Override + public String typeof() { + return "number"; + } + + @JS("return conversion.toProxy(conversion.createJavaDouble(this));") + private native Double javaDouble(); + + @Override + protected String stringValue() { + return String.valueOf(javaDouble()); + } + + @Override + public Byte asByte() { + return javaDouble().byteValue(); + } + + @Override + public Short asShort() { + return javaDouble().shortValue(); + } + + @Override + public Character asChar() { + return (char) javaDouble().intValue(); + } + + @Override + public Integer asInt() { + return javaDouble().intValue(); + } + + @Override + public Float asFloat() { + return javaDouble().floatValue(); + } + + @Override + public Long asLong() { + return javaDouble().longValue(); + } + + @Override + public Double asDouble() { + return javaDouble().doubleValue(); + } + + @Override + public BigInteger asBigInteger() { + return BigInteger.valueOf(javaDouble().longValue()); + } + + @Override + public boolean equals(Object that) { + if (that instanceof JSNumber) { + return this.javaDouble().equals(((JSNumber) that).javaDouble()); + } + return super.equals(that); + } + + @Override + public int hashCode() { + return javaDouble().hashCode(); + } +} diff --git a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSObject.java b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSObject.java similarity index 90% rename from web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSObject.java rename to sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSObject.java index f4c033fac7a0..cbae872ab70e 100644 --- a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSObject.java +++ b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSObject.java @@ -1,26 +1,42 @@ /* - * 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. - * - * 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). - * - * 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. - * - * 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. + * 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; diff --git a/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSResource.java b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSResource.java new file mode 100644 index 000000000000..6e400b5ffacd --- /dev/null +++ b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSResource.java @@ -0,0 +1,62 @@ +/* + * 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.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE}) +@Repeatable(JSResource.Group.class) +public @interface JSResource { + String value(); + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.TYPE) + @interface Group { + + JSResource[] value(); + } +} diff --git a/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSString.java b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSString.java new file mode 100644 index 000000000000..e7ba442568c2 --- /dev/null +++ b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSString.java @@ -0,0 +1,85 @@ +/* + * 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 String} value. + */ +public final class JSString extends JSValue { + + JSString() { + } + + @JS("return conversion.extractJavaScriptString(s[runtime.symbol.javaNative]);") + public static native JSString of(String s); + + @Override + public String typeof() { + return "string"; + } + + @JS("return conversion.toProxy(toJavaString(this));") + private native String javaString(); + + @Override + protected String stringValue() { + return javaString(); + } + + @Override + public String asString() { + return javaString(); + } + + @Override + public boolean equals(Object that) { + if (that instanceof JSString) { + return this.javaString().equals(((JSString) that).javaString()); + } + return false; + } + + @Override + public int hashCode() { + return javaString().hashCode(); + } +} diff --git a/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSSymbol.java b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSSymbol.java new file mode 100644 index 000000000000..135ad522c429 --- /dev/null +++ b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSSymbol.java @@ -0,0 +1,90 @@ +/* + * 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 Symbol} value. + */ +public final class JSSymbol extends JSValue { + + JSSymbol() { + } + + @JS("return Symbol(conversion.extractJavaScriptString(s[runtime.symbol.javaNative]));") + public static native JSSymbol of(String s); + + @JS("return Symbol.for(conversion.extractJavaScriptString(s[runtime.symbol.javaNative]));") + public static native JSSymbol forString(String s); + + @JS("return sym0 === sym1;") + private static native JSBoolean referenceEquals(JSSymbol sym0, JSSymbol sym1); + + @Override + public String typeof() { + return "symbol"; + } + + @JS("return conversion.toProxy(toJavaString(this.toString()));") + private native String javaString(); + + @Override + protected String stringValue() { + return javaString(); + } + + public String description() { + return javaString(); + } + + @Override + public boolean equals(Object that) { + if (that instanceof JSSymbol) { + return referenceEquals(this, (JSSymbol) that).asBoolean(); + } + return false; + } + + @Override + public int hashCode() { + return javaString().hashCode(); + } +} diff --git a/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSUndefined.java b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSUndefined.java new file mode 100644 index 000000000000..2c2e82f15a3f --- /dev/null +++ b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSUndefined.java @@ -0,0 +1,67 @@ +/* + * 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 the JavaScript {@code undefined} value. + */ +public final class JSUndefined extends JSValue { + + private static final JSUndefined INSTANCE = new JSUndefined(); + + public static JSUndefined instance() { + return INSTANCE; + } + + JSUndefined() { + } + + @Override + public String typeof() { + return "undefined"; + } + + @Override + protected String stringValue() { + return "undefined"; + } +} diff --git a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSValue.java b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSValue.java similarity index 70% rename from web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSValue.java rename to sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSValue.java index 70aab7656514..5787460aa37c 100644 --- a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSValue.java +++ b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSValue.java @@ -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.math.BigInteger; diff --git a/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/package-info.java b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/package-info.java new file mode 100644 index 000000000000..8774203f911a --- /dev/null +++ b/sdk/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/package-info.java @@ -0,0 +1,50 @@ +/* + * 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. + */ +/** + * This package provides an interface between Java code and the embedding JavaScript code. + *
+ * This functionality is limited to the WebAssembly backend for Native Image. + *
+ * Any functionality specified here is experimental, subject to change, and may not fully work yet. + * + * @since 25.0 + */ +package org.graalvm.webimage.api; diff --git a/web-image/mx.web-image/mx_web_image.py b/web-image/mx.web-image/mx_web_image.py index 7671f68c4c48..a7d4293d5ed9 100644 --- a/web-image/mx.web-image/mx_web_image.py +++ b/web-image/mx.web-image/mx_web_image.py @@ -58,7 +58,6 @@ web_image_builder = "web-image:SVM_WASM" web_image_builder_jars = [ web_image_builder, - "web-image:SVM_WASM_API", "web-image:SVM_WASM_JIMFS", "web-image:SVM_WASM_GUAVA", "web-image:WEBIMAGE_CLOSURE_SUPPORT", @@ -472,7 +471,7 @@ def get_launcher_flags(names: [str], cp_suffix: str = None) -> [str]: (distributions, projects) with web image. Many internal distributions directly or indirectly depend on jars in the image builder itself - (e.g. svm-wasm-api.jar), which cannot be passed to the launcher again. + (e.g. svm-wasm.jar), which cannot be passed to the launcher again. Because of that we omit all the flags required for the image builder jars and their dependencies (since the image builder will already have the proper paths set up for those). @@ -753,7 +752,6 @@ def create_web_image_macro_builder( priority=0, builder_jar_distributions=[ "web-image:SVM_WASM", - "web-image:SVM_WASM_API", "web-image:SVM_WASM_JIMFS", "web-image:SVM_WASM_GUAVA", ], diff --git a/web-image/mx.web-image/suite.py b/web-image/mx.web-image/suite.py index f9a370c17234..d3dbb8249f8f 100644 --- a/web-image/mx.web-image/suite.py +++ b/web-image/mx.web-image/suite.py @@ -89,7 +89,7 @@ "compiler:GRAAL", "substratevm:SVM", "substratevm:SVM_CONFIGURE", - "org.graalvm.webimage.api", + "sdk:WEBIMAGE_PREVIEW", "SVM_WASM_JIMFS", ], "requires": [ @@ -116,17 +116,6 @@ "spotbugsIgnoresGenerated": True, "checkPackagePrefix": False, }, - "org.graalvm.webimage.api": { - "subDir": "src", - "sourceDirs": ["src"], - "dependencies": [], - "javaCompliance": "21+", - "spotbugs": "true", - "workingSets": "web-image", - "annotationProcessors": ["compiler:GRAAL_PROCESSOR"], - "checkstyle": "com.oracle.svm.webimage", - "spotbugsIgnoresGenerated": True, - }, "com.oracle.svm.webimage.tools": { "subDir": "src", "sourceDirs": [ @@ -160,7 +149,6 @@ "sourceDirs": ["src"], "dependencies": [ "substratevm:SVM", - "SVM_WASM_API", "WEBIMAGE_LIBRARY_SUPPORT", "mx:JUNIT", "NET_JAVA_HTML", @@ -281,7 +269,7 @@ ], "distDependencies": [ "substratevm:SVM", - "SVM_WASM_API", + "sdk:WEBIMAGE_PREVIEW", "SVM_WASM_JIMFS", ], "moduleInfo": { @@ -289,7 +277,6 @@ "requires": [ "org.graalvm.nativeimage.pointsto", "org.graalvm.nativeimage.builder", - "org.graalvm.webimage.api", "org.graalvm.collections", ], "opens": [ @@ -307,20 +294,6 @@ }, "maven": False, }, - "SVM_WASM_API": { - "subDir": "src", - "dependencies": [ - "org.graalvm.webimage.api", - ], - "distDependencies": [], - "moduleInfo": { - "name": "org.graalvm.webimage.api", - "exports": [ - "org.graalvm.webimage.api", - ], - }, - "maven": False, - }, "NATIVE_IMAGE_WASM_SUPPORT": { "native": True, "description": "Macro for the Native Image Wasm Backend", @@ -349,7 +322,6 @@ "requires": [ "jdk.graal.compiler", "org.graalvm.nativeimage.builder", - "org.graalvm.webimage.api", ], }, }, @@ -413,7 +385,6 @@ "com.oracle.svm.webimage.jtt", ], "distDependencies": [ - "SVM_WASM_API", "WEBIMAGE_LIBRARY_SUPPORT", ], "exclude": [ diff --git a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSBigInt.java b/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSBigInt.java deleted file mode 100644 index 02d089e84c1c..000000000000 --- a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSBigInt.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2025, 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. - * - * 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). - * - * 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. - * - * 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. - */ -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(); - } -} diff --git a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSBoolean.java b/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSBoolean.java deleted file mode 100644 index c216cb60e2c7..000000000000 --- a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSBoolean.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2025, 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. - * - * 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). - * - * 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. - * - * 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. - */ -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(); - } -} diff --git a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSError.java b/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSError.java deleted file mode 100644 index 084c8af507da..000000000000 --- a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSError.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2025, 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. - * - * 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). - * - * 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. - * - * 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. - */ - -package org.graalvm.webimage.api; - -/** - * Represents the error value thrown in JavaScript. - *
- * Must not pass a {@link Throwable} instance, these should be thrown directly instead of being - * wrapped in a {@link JSError}. - */ -@SuppressWarnings("serial") -public final class JSError extends RuntimeException { - - private static final long serialVersionUID = -2343564169271174471L; - - /** - * JavaScript object that was thrown. - */ - private final Object thrownObject; - - public JSError(Object thrownObject) { - super(thrownObject.toString()); - this.thrownObject = thrownObject; - assert !(thrownObject instanceof Throwable) : "Tried creating JSError for a throwable: " + thrownObject; - } - - public Object getThrownObject() { - return thrownObject; - } -} diff --git a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSNumber.java b/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSNumber.java deleted file mode 100644 index 7f163bb186cc..000000000000 --- a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSNumber.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2025, 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. - * - * 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). - * - * 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. - * - * 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. - */ -package org.graalvm.webimage.api; - -import java.math.BigInteger; - -/** - * Java representation of a JavaScript {@code Number} value. - */ -public final class JSNumber extends JSValue { - - JSNumber() { - } - - @JS("return conversion.extractJavaScriptNumber(d[runtime.symbol.javaNative]);") - public static native JSNumber of(double d); - - @Override - public String typeof() { - return "number"; - } - - @JS("return conversion.toProxy(conversion.createJavaDouble(this));") - private native Double javaDouble(); - - @Override - protected String stringValue() { - return String.valueOf(javaDouble()); - } - - @Override - public Byte asByte() { - return javaDouble().byteValue(); - } - - @Override - public Short asShort() { - return javaDouble().shortValue(); - } - - @Override - public Character asChar() { - return (char) javaDouble().intValue(); - } - - @Override - public Integer asInt() { - return javaDouble().intValue(); - } - - @Override - public Float asFloat() { - return javaDouble().floatValue(); - } - - @Override - public Long asLong() { - return javaDouble().longValue(); - } - - @Override - public Double asDouble() { - return javaDouble().doubleValue(); - } - - @Override - public BigInteger asBigInteger() { - return BigInteger.valueOf(javaDouble().longValue()); - } - - @Override - public boolean equals(Object that) { - if (that instanceof JSNumber) { - return this.javaDouble().equals(((JSNumber) that).javaDouble()); - } - return super.equals(that); - } - - @Override - public int hashCode() { - return javaDouble().hashCode(); - } -} diff --git a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSResource.java b/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSResource.java deleted file mode 100644 index 05581875a068..000000000000 --- a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSResource.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2025, 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. - * - * 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). - * - * 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. - * - * 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. - */ -package org.graalvm.webimage.api; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE}) -@Repeatable(JSResource.Group.class) -public @interface JSResource { - String value(); - - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.TYPE) - @interface Group { - - JSResource[] value(); - } -} diff --git a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSString.java b/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSString.java deleted file mode 100644 index 46083f746a76..000000000000 --- a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSString.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2025, 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. - * - * 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). - * - * 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. - * - * 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. - */ -package org.graalvm.webimage.api; - -/** - * Java representation of a JavaScript {@code String} value. - */ -public final class JSString extends JSValue { - - JSString() { - } - - @JS("return conversion.extractJavaScriptString(s[runtime.symbol.javaNative]);") - public static native JSString of(String s); - - @Override - public String typeof() { - return "string"; - } - - @JS("return conversion.toProxy(toJavaString(this));") - private native String javaString(); - - @Override - protected String stringValue() { - return javaString(); - } - - @Override - public String asString() { - return javaString(); - } - - @Override - public boolean equals(Object that) { - if (that instanceof JSString) { - return this.javaString().equals(((JSString) that).javaString()); - } - return false; - } - - @Override - public int hashCode() { - return javaString().hashCode(); - } -} diff --git a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSSymbol.java b/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSSymbol.java deleted file mode 100644 index f7239278c60d..000000000000 --- a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSSymbol.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2025, 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. - * - * 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). - * - * 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. - * - * 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. - */ -package org.graalvm.webimage.api; - -/** - * Java representation of a JavaScript {@code Symbol} value. - */ -public final class JSSymbol extends JSValue { - - JSSymbol() { - } - - @JS("return Symbol(conversion.extractJavaScriptString(s[runtime.symbol.javaNative]));") - public static native JSSymbol of(String s); - - @JS("return Symbol.for(conversion.extractJavaScriptString(s[runtime.symbol.javaNative]));") - public static native JSSymbol forString(String s); - - @JS("return sym0 === sym1;") - private static native JSBoolean referenceEquals(JSSymbol sym0, JSSymbol sym1); - - @Override - public String typeof() { - return "symbol"; - } - - @JS("return conversion.toProxy(toJavaString(this.toString()));") - private native String javaString(); - - @Override - protected String stringValue() { - return javaString(); - } - - public String description() { - return javaString(); - } - - @Override - public boolean equals(Object that) { - if (that instanceof JSSymbol) { - return referenceEquals(this, (JSSymbol) that).asBoolean(); - } - return false; - } - - @Override - public int hashCode() { - return javaString().hashCode(); - } -} diff --git a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSUndefined.java b/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSUndefined.java deleted file mode 100644 index 867f8ddd60e7..000000000000 --- a/web-image/src/org.graalvm.webimage.api/src/org/graalvm/webimage/api/JSUndefined.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2025, 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. - * - * 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). - * - * 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. - * - * 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. - */ -package org.graalvm.webimage.api; - -/** - * Java representation of the JavaScript {@code undefined} value. - */ -public final class JSUndefined extends JSValue { - - private static final JSUndefined INSTANCE = new JSUndefined(); - - public static JSUndefined instance() { - return INSTANCE; - } - - JSUndefined() { - } - - @Override - public String typeof() { - return "undefined"; - } - - @Override - protected String stringValue() { - return "undefined"; - } -}