Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,8 @@ 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());
return new BigInteger(stringValue());
}

@Override
Expand Down Expand Up @@ -116,14 +108,14 @@ public BigInteger asBigInteger() {

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

@Override
public int hashCode() {
return javaString().hashCode();
return stringValue().hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ public String typeof() {
@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ public String typeof() {
@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,6 @@ public String typeof() {
return typeofString().asString();
}

@Override
@JS("return conversion.toProxy(toJavaString(this.toString()));")
protected native String stringValue();

/**
* Returns the value of the key passed as the argument in the JavaScript object.
*
Expand Down Expand Up @@ -457,7 +453,7 @@ public <R> R get(Object key, Class<R> type) {
* underlying JavaScript function
* @return The result of the JavaScript function, converted to the corresponding Java value
*/
@JS("return this.apply(this, conversion.extractJavaScriptArray(args[runtime.symbol.javaNative]));")
@JS("return this.apply(this, [...args]);")
public native Object invoke(Object... args);

/**
Expand All @@ -469,109 +465,9 @@ public <R> R get(Object key, Class<R> type) {
* underlying JavaScript function
* @return The result of the JavaScript function, converted to the corresponding Java value
*/
@JS("return this.apply(thisArg, conversion.extractJavaScriptArray(args[runtime.symbol.javaNative]));")
@JS("return this.apply(thisArg, [...args]);")
public native Object call(Object thisArg, Object... args);

private ClassCastException classCastException(String targetType) {
return new ClassCastException(this + " cannot be coerced to '" + targetType + "'.");
}

@JS("if (this.constructor === Uint8Array) { this.hub = booleanArrayHub; return conversion.toProxy(this); } else { return null; };")
private native boolean[] extractBooleanArray();

@Override
public boolean[] asBooleanArray() {
boolean[] array = extractBooleanArray();
if (array != null) {
return array;
}
throw classCastException("boolean[]");
}

@JS("if (this.constructor === Int8Array) { this.hub = byteArrayHub; return conversion.toProxy(this); } else { return null; };")
private native byte[] extractByteArray();

@Override
public byte[] asByteArray() {
byte[] array = extractByteArray();
if (array != null) {
return array;
}
throw classCastException("byte[]");
}

@JS("if (this.constructor === Int16Array) { this.hub = shortArrayHub; return conversion.toProxy(this); } else { return null; };")
private native short[] extractShortArray();

@Override
public short[] asShortArray() {
short[] array = extractShortArray();
if (array != null) {
return array;
}
throw classCastException("short[]");
}

@JS("if (this.constructor === Uint16Array) { this.hub = charArrayHub; return conversion.toProxy(this); } else { return null; };")
private native char[] extractCharArray();

@Override
public char[] asCharArray() {
char[] array = extractCharArray();
if (array != null) {
return array;
}
throw classCastException("char[]");
}

@JS("if (this.constructor === Int32Array) { this.hub = intArrayHub; return conversion.toProxy(this); } else { return null; };")
private native int[] extractIntArray();

@Override
public int[] asIntArray() {
int[] array = extractIntArray();
if (array != null) {
return array;
}
throw classCastException("int[]");
}

@JS("if (this.constructor === Float32Array) { this.hub = floatArrayHub; return conversion.toProxy(this); } else { return null; };")
private native float[] extractFloatArray();

@Override
public float[] asFloatArray() {
float[] array = extractFloatArray();
if (array != null) {
return array;
}
throw classCastException("float[]");
}

@JS("if (this.constructor === BigInt64Array) { this.hub = longArrayHub; initComponentView(this); return conversion.toProxy(this); } else { return null; };")
private native long[] extractLongArray();

@Override
public long[] asLongArray() {
long[] array = extractLongArray();
if (array != null) {
return array;
}
throw classCastException("long[]");
}

@JS("if (this.constructor === Float64Array) { this.hub = doubleArrayHub; return conversion.toProxy(this); } else { return null; };")
private native double[] extractDoubleArray();

@Override
public double[] asDoubleArray() {
double[] array = extractDoubleArray();
if (array != null) {
return array;
}
throw classCastException("double[]");
}

@JS("return conversion.coerceToFacadeClass(this, cls);")
private native <T extends JSObject> T coerceToFacadeClass(Class<T> cls);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,26 @@ public String typeof() {
return "string";
}

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

/**
* Cannot use {@link #stringValue()} because the implementation of that method calls this
* method. The manual extraction of the Java string here ensures that no infinite recursion
* occurs.
*/
@Override
protected String stringValue() {
return javaString();
}

@Override
public String asString() {
return javaString();
}
@JS("return conversion.toProxy(toJavaString(this));")
public native String asString();

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

@Override
public int hashCode() {
return javaString().hashCode();
return stringValue().hashCode();
}

@JS.Coerce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ public String typeof() {
return "symbol";
}

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

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

@Override
public boolean equals(Object that) {
if (that instanceof JSSymbol) {
Expand All @@ -81,7 +73,7 @@ public boolean equals(Object that) {

@Override
public int hashCode() {
return javaString().hashCode();
return stringValue().hashCode();
}

@JS(value = "return Symbol.for(key);")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,4 @@ public boolean isUndefined() {
public String typeof() {
return "undefined";
}

@Override
protected String stringValue() {
return "undefined";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,15 @@ public static JSUndefined undefined() {

public abstract String typeof();

protected abstract String stringValue();
/**
* Returns the JS string representation of this value (by calling the JS {@code toString} method
* on it) and {@code "undefined"} for the JS {@code undefined} value.
*
* @since 25.1
*/
@JS.Coerce
@JS("return this?.toString()?? 'undefined';")
public final native String stringValue();

public Boolean asBoolean() {
throw classCastError("Boolean");
Expand Down Expand Up @@ -147,38 +155,6 @@ public String asString() {
throw classCastError("String");
}

public boolean[] asBooleanArray() {
throw classCastError("boolean[]");
}

public byte[] asByteArray() {
throw classCastError("byte[]");
}

public short[] asShortArray() {
throw classCastError("short[]");
}

public char[] asCharArray() {
throw classCastError("char[]");
}

public int[] asIntArray() {
throw classCastError("int[]");
}

public float[] asFloatArray() {
throw classCastError("float[]");
}

public long[] asLongArray() {
throw classCastError("long[]");
}

public double[] asDoubleArray() {
throw classCastError("double[]");
}

/**
* Coerces this JavaScript value to the requested Java type. See {@link JS.Coerce} for the
* JavaScript to Java coercion rules.
Expand Down Expand Up @@ -219,33 +195,6 @@ public <T> T as(Class<T> cls) {
if (String.class.equals(cls)) {
return (T) asString();
}
if (cls.isArray() && cls.getComponentType().isPrimitive()) {
// Dispatch to primitive array casts.
if (int[].class.equals(cls)) {
return (T) asIntArray();
}
if (float[].class.equals(cls)) {
return (T) asFloatArray();
}
if (long[].class.equals(cls)) {
return (T) asLongArray();
}
if (double[].class.equals(cls)) {
return (T) asDoubleArray();
}
if (byte[].class.equals(cls)) {
return (T) asByteArray();
}
if (short[].class.equals(cls)) {
return (T) asShortArray();
}
if (char[].class.equals(cls)) {
return (T) asCharArray();
}
if (boolean[].class.equals(cls)) {
return (T) asBooleanArray();
}
}
if (Character.class.equals(cls)) {
return (T) asChar();
}
Expand Down
4 changes: 4 additions & 0 deletions web-image/mx.web-image/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
"substratevm:SVM",
"WEBIMAGE_LIBRARY_SUPPORT",
"mx:JUNIT",
"mx:JUNIT-JUPITER-API",
"NET_JAVA_HTML",
"NET_JAVA_HTML_BOOT",
"NET_JAVA_HTML_JSON",
Expand Down Expand Up @@ -237,6 +238,7 @@
"sourceDirs": ["src"],
"dependencies": [
"mx:JUNIT",
"mx:JUNIT-JUPITER-API",
"compiler:GRAAL_TEST",
"com.oracle.svm.webimage.jtt",
"com.oracle.svm.hosted.webimage",
Expand Down Expand Up @@ -389,6 +391,7 @@
],
"exclude": [
"mx:JUNIT",
"mx:JUNIT-JUPITER-API",
],
"maven": False,
"testDistribution": True,
Expand All @@ -404,6 +407,7 @@
],
"exclude": [
"mx:JUNIT",
"mx:JUNIT-JUPITER-API",
],
"maven": False,
"testDistribution": True,
Expand Down
Loading