Skip to content

Commit

Permalink
[Wasm] Add tests for jsenum boxing with partial inlining to check box…
Browse files Browse the repository at this point in the history
…ing around cases such as `checkNotNull`

PiperOrigin-RevId: 592687191
  • Loading branch information
Googler authored and copybara-github committed Dec 21, 2023
1 parent c50b1c4 commit b3ff9e2
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.google.j2cl.integration.testing.Asserts.assertFalse;
import static com.google.j2cl.integration.testing.Asserts.assertThrows;
import static com.google.j2cl.integration.testing.Asserts.assertThrowsClassCastException;
import static com.google.j2cl.integration.testing.Asserts.assertThrowsNullPointerException;
import static com.google.j2cl.integration.testing.Asserts.assertTrue;
import static com.google.j2cl.integration.testing.Asserts.assertUnderlyingTypeEquals;
import static com.google.j2cl.integration.testing.Asserts.fail;
Expand Down Expand Up @@ -72,6 +73,7 @@ public static void main(String... args) {
testAutoBoxing_intersectionCasts();
testSpecializedSuperType();
testSpecializedSuperTypeUnderlyingType();
testBoxingPartialInlining();
}

@Wasm("nop") // TODO(b/288145698): Support native JsEnum.
Expand Down Expand Up @@ -925,4 +927,23 @@ private static Object passThrough(Object o) {
assertTrue(o instanceof String || o instanceof Double || o instanceof Boolean);
return o;
}

private static void testBoxingPartialInlining() {
// TODO(b/315214896) Check the size difference to see if cases such as these take advantage of
// partial inlining in Wasm to turn this into a simple null check, avoiding boxing.
PlainJsEnum nonnullJsEnum = PlainJsEnum.ONE;
checkNotNull(nonnullJsEnum);
// Use the local so it doesn't get removed.
assertTrue(nonnullJsEnum == PlainJsEnum.ONE);

PlainJsEnum nullJsEnum = null;
assertThrowsNullPointerException(() -> checkNotNull(nullJsEnum));
assertTrue(nullJsEnum == null);
}

private static void checkNotNull(Object obj) {
if (obj == null) {
throw new NullPointerException();
}
}
}

0 comments on commit b3ff9e2

Please sign in to comment.