Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -87,14 +87,16 @@ public int hashCode() {
@JS(value = "return String.fromCharCode(...codeUnits);")
public static native JSString fromCharCode(int... codeUnits);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use use char... codeUnits instead here? The function only accepts numbers from 0 to 65535 anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using int... matches JavaScript’s fromCharCode, which takes numbers, not characters. While char... would work for values ≤ 65535, it forces explicit casting for int values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, we should have an overload that accepts char...


@JS.Coerce
@JS(value = "return String.fromCharCode(...codeUnits);")
public static native JSString fromCharCode(char... codeUnits);


@JS.Coerce
@JS(value = "return String.fromCodePoint(...codePoints);")
public static native JSString fromCodePoint(int... codePoints);

@JS(value = """
const sub = Array.from(substitutions);
console.log(sub);
return String.raw(template, ...sub);""")
@JS(value = "return String.raw(template, ...Array.from(substitutions));")
public static native JSString raw(JSObject template, Object... substitutions);

@JS.Coerce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public int hashCode() {

public static String keyFor(JSSymbol sym) {
JSValue result = keyForRaw(sym);
return result.typeof().equals("undefined") ? null : result.asString();
return result instanceof JSUndefined ? null : result.asString();
}

@JS.Coerce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ protected void lowerClassEnd() {

// Store the mapping from the imported JavaScript class constructor to the Java facade class
// under which the JavaScript class was imported.
if (isImportedClass) {
// if (isImportedClass) {
buffer.emitScopeBegin();
buffer.emitLetDeclPrefix("facades");
buffer.emitText("runtime.ensureFacadeSetFor(" + internalMirrorClassName(codeGenTool, type) + ");");
Expand All @@ -570,6 +570,6 @@ protected void lowerClassEnd() {
buffer.emitScopeEnd();
buffer.emitNewLine();
buffer.emitNewLine();
}
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ class Conversion {
const facades = runtime.findFacadesFor(obj.constructor);
const rawJavaHub = cls[runtime.symbol.javaNative];
const internalJavaClass = rawJavaHub[runtime.symbol.jsClass];
if (facades.has(internalJavaClass)) {
if (obj.constructor === ({}).constructor || facades.has(internalJavaClass)) {
const rawJavaMirror = new internalJavaClass();
// Note: only one-way handshake, since the JavaScript object could be recast to a different Java facade class.
this.setJavaScriptNative(rawJavaMirror, obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ public static void testTrim() {
assertEquals(" To be, or not to be", padded.trimEnd().asString());
}


public static void testSubstring() {
JSString text = JSString.of("JavaScript");

Expand Down