Skip to content

Commit

Permalink
[WASM] Make type literals use getMetadataTypeDeclaration when gener…
Browse files Browse the repository at this point in the history
…ating the call to `$getClassMetadata`.

This is in preparation for JsEnum, where the original type is removed and replaced by the overlay type.

Note that this is a no-op for the most part, but completely breaks `MyJsFunction.class`, where it tries to call "$getClassMetadata__java_lang_Class@vmbootstrap.JavaScriptFunction"

PiperOrigin-RevId: 571102974
  • Loading branch information
Googler authored and copybara-github committed Oct 5, 2023
1 parent 3d37812 commit d77bd49
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ private Expression implementTypeLiteral(TypeDescriptor typeDescriptor) {
.setArguments(NumberLiteral.fromInt(arrayTypeDescriptor.getDimensions()))
.build();
}
if (typeDescriptor instanceof DeclaredTypeDescriptor) {
return getClassLiteralMethodCall(
typeDescriptor.getMetadataTypeDeclaration().toRawTypeDescriptor());
}
return getClassLiteralMethodCall(typeDescriptor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,9 @@ private interface NativeFunction {
@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")
private interface NativeInterface {}

@Wasm(
"nop") // TODO(b/301385322): remove when class literals on native JS objects are implemented.
private static void testNative() {
// TODO(b/301385322) getClass() on Native JavaScript objects is not supported in Wasm.
// Native types don't apply in the context of the JVM.
if (!isJavaScript()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static com.google.j2cl.integration.testing.Asserts.assertTrue;
import static com.google.j2cl.integration.testing.TestUtils.isWasm;

import javaemul.internal.annotations.Wasm;
import jsinterop.annotations.JsEnum;
import jsinterop.annotations.JsFunction;
import jsinterop.annotations.JsPackage;
Expand Down Expand Up @@ -136,11 +137,9 @@ interface NativeFunction {
void f();
}

@Wasm(
"nop") // TODO(b/301385322): remove when class literals on native JS objects are implemented.
private static void testNative() {
// TODO(b/301385322) getClass() on Native JavaScript objects is not supported in Wasm.
if (isWasm()) {
return;
}
assertClass(NativeInterface.class);
assertClass(NativeFunction.class);
assertClass(NativeClass.class);
Expand Down

0 comments on commit d77bd49

Please sign in to comment.