Skip to content

Commit 2547ccd

Browse files
srujzsCommit Queue
authored andcommitted
Add compiler-specific expectations for object_members_test
This test was intended to capture the existing state of object members for JS interop and dart:html objects. At some point, it started failing in ddc, so we add the correct compiler-specific expectations instead to get it to pass. Change-Id: I130efc9927a5cb74dafa1b5beb856c7a6ee5a9aa Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425882 Reviewed-by: Nicholas Shahan <[email protected]> Commit-Queue: Srujan Gaddam <[email protected]>
1 parent 87b118b commit 2547ccd

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

tests/web/internal/object_members_test.dart

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import 'package:js/js.dart';
1313
import 'package:expect/legacy/minitest.dart'; // ignore: deprecated_member_use_from_same_package
1414

1515
import 'dart:html';
16-
import 'dart:_interceptors' show JSObject;
16+
import 'dart:_interceptors' show JSObject, LegacyJavaScriptObject;
17+
18+
const isDart2JS = const bool.fromEnvironment('dart.library._dart2js_only');
1719

1820
@JS()
1921
external void eval(String code);
@@ -54,17 +56,27 @@ void main() {
5456
expect(noSuchMethodErrorThrown, isTrue);
5557
expect(div.runtimeType, DivElement);
5658

57-
// `toString` for `dart:html` types that do not have an overridden `toString`
58-
// should look up the type through the proto.
59-
expect(window.navigator.toString(), "Instance of 'Navigator'");
59+
// `toString` for `dart:html` types depend on the implementation. dart2js
60+
// provides a more readable string, whereas DDC just uses the underlying
61+
// `toString`.
62+
final navigatorToString = window.navigator.toString();
63+
if (isDart2JS) {
64+
expect(navigatorToString, "Instance of 'Navigator'");
65+
} else {
66+
expect(navigatorToString, "[object Navigator]");
67+
}
6068

6169
// Interop type.
6270
var js = JSClass();
6371
expect(js == js, true);
6472
expect(js == JSClass(), false);
65-
// TODO(srujzs): Modify this once interop has random hash codes.
6673
hashCode = js.hashCode;
67-
expect(hashCode, 0);
74+
if (isDart2JS) {
75+
// DDC adds a random hash code to the object (should use a weak map), but
76+
// dart2js returns 0 for all `LegacyJavaScriptObject`s.
77+
// TODO(srujzs): Modify this once interop has random hash codes.
78+
expect(hashCode, 0);
79+
}
6880
expect(hashCode, js.hashCode);
6981
expect(js.toString, isNotNull);
7082
// Should forward to underlying `toString` call.
@@ -76,5 +88,12 @@ void main() {
7688
noSuchMethodErrorThrown = false;
7789
} catch (_) {}
7890
expect(noSuchMethodErrorThrown, isTrue);
79-
expect(js.runtimeType, JSObject);
91+
final runtimeType = js.runtimeType;
92+
if (isDart2JS) {
93+
// dart2js explicitly returns `JSObject` as the `runtimeType` for all
94+
// `LegacyJavaScriptObject`s.
95+
expect(runtimeType, JSObject);
96+
} else {
97+
expect(runtimeType, LegacyJavaScriptObject);
98+
}
8099
}

0 commit comments

Comments
 (0)