Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Unified Diff: pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/types.dart

Issue 2789663005: Fix type checks and display for JS interop types. (Closed)
Patch Set: Fix type checks and display for JS interop types. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/types.dart
diff --git a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/types.dart b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/types.dart
index 4475a546052da9e2686174fc12db9158f1e385ac..61d99e9483db999172ef6bcc1ba521bc9d6ea610 100644
--- a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/types.dart
+++ b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/types.dart
@@ -66,7 +66,7 @@ class Dynamic extends TypeRep {
toString() => 'dynamic';
}
-class LazyJSType implements Type {
+class LazyJSType extends TypeRep {
final _jsTypeCallback;
final _dartName;
@@ -114,7 +114,9 @@ _asInstanceOfLazyJSType(o, LazyJSType t) {
return o;
}
-bool _isJSObject(o) => JS('bool', '!dart.getReifiedType(o)[dart._runtimeType]');
+bool _isJSObject(o) =>
+ JS('bool', '!dart.getReifiedType(#)[dart._runtimeType]', o);
+bool _isJSType(t) => JS('bool', '!#[dart._runtimeType]', t);
@JSExportName('dynamic')
final _dynamic = new Dynamic();
@@ -577,12 +579,12 @@ getImplicitFunctionType(type) {
bool isFunctionType(type) => JS('bool', '# instanceof # || # === #', type,
AbstractFunctionType, type, Function);
-isLazyJSSubtype(LazyJSType t1, LazyJSType t2, isCovariant) {
- if (t1 == t2) return true;
-
- // All anonymous JS types are subtypes of each other.
- if (t1._jsTypeCallback == null || t2._jsTypeCallback == null) return true;
- return isClassSubType(t1._rawJSType, t2._rawJSType, isCovariant);
+isLazyJSSubtype(t1, LazyJSType t2, isCovariant) {
+ // All JS types are subtypes of anonymous JS types.
+ if (t2._jsTypeCallback == null) {
+ return _isJSType(t1);
+ }
+ return isClassSubType(t1, t2._rawJSType, isCovariant);
vsm 2017/03/31 15:14:08 Depending on where you call this below, it may be
Jacob 2017/04/01 00:51:13 switched to _isSubtype. Agree that seems safer.
}
/// Returns true if [ft1] <: [ft2].
@@ -714,6 +716,10 @@ bool _isFutureOr(type) =>
_isSubtype(t1, t2, isCovariant) => JS(
'',
'''(() => {
+ if ($t2 instanceof $LazyJSType) {
vsm 2017/03/31 15:14:08 Can this be dropped to below the "trivial" checks?
Jacob 2017/04/01 00:51:13 Moved down to right before t1 is forced to be a fu
+ return $isLazyJSSubtype($t1, $t2, $isCovariant);
+ }
+
if ($t1 === $t2) return true;
// Trivially true.
@@ -775,11 +781,7 @@ _isSubtype(t1, t2, isCovariant) => JS(
if ($isFunctionType($t1) && $isFunctionType($t2)) {
return $isFunctionSubtype($t1, $t2, $isCovariant);
}
-
- if ($t1 instanceof $LazyJSType && $t2 instanceof $LazyJSType) {
- return $isLazyJSSubtype($t1, $t2, $isCovariant);
- }
-
+
return false;
})()''');

Powered by Google App Engine
This is Rietveld 408576698