[test_runner] Use constructor to detect async main

This is needed to avoid the dependency on the current runtime
type representation. This is still not an ideal solution and should
be moved into a logic that DDC controls.

Issue: https://github.com/dart-lang/sdk/issues/46377
Change-Id: I6418bff546e63b01059841c1128b4ebeeacdcc39
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/265564
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
This commit is contained in:
Nicholas Shahan 2022-10-25 19:33:38 +00:00 committed by Commit Queue
parent 278815b192
commit 1e9445060a

View file

@ -242,7 +242,9 @@ requirejs(["$testName", "dart_sdk", "async_helper"],
// go through our async tracking (e.g. DOM events). For those tests, check
// if the result of calling `main()` is a Future, and if so, wait for it.
let result = $testId.$testIdAlias.main();
if (sdk.async.Future.is(result)) {
// TODO(46377) DDC should control this code and expose a mechanism to run
// the main method that properly waits for completion.
if (result?.constructor?.name == '_Future') {
sdk.dart.addAsyncCallback();
result.whenComplete(sdk.dart.removeAsyncCallback);
}