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

Unified Diff: sdk/lib/_internal/compiler/implementation/lib/js_helper.dart

Issue 12210142: Implement is-checks against type variables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix computation of classes that need rti. Created 7 years, 10 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: sdk/lib/_internal/compiler/implementation/lib/js_helper.dart
diff --git a/sdk/lib/_internal/compiler/implementation/lib/js_helper.dart b/sdk/lib/_internal/compiler/implementation/lib/js_helper.dart
index ee23e0dbb08ec629f16073732225897c4dc55c7f..f083720bbac75f2070f36fed8fecc569b3258af9 100644
--- a/sdk/lib/_internal/compiler/implementation/lib/js_helper.dart
+++ b/sdk/lib/_internal/compiler/implementation/lib/js_helper.dart
@@ -1541,18 +1541,44 @@ getArguments(var type) => JS('var', r'#.slice(1)', type);
getField(var object, var name) => JS('var', r'#[#]', object, name);
/**
+ * Tests whether the Dart object [o] is a subtype of the runtime type
+ * representation [t], which is a type representation as described in the
+ * comment on [isSubtype].
+ */
+bool objectIsSubtype(Object o, var t) {
+ if (JS('bool', '# == null', o) || JS('bool', '# == null', t)) return true;
+
+ var nativeCheck = getField(t, '\$nativeCheck');
+ if (nativeCheck != null) {
+ return invoke(nativeCheck, [o]);
+ } else {
+ var type = o;
ngeoffray 2013/02/21 10:26:18 Please add a comment on why o could be the type.
karlklose 2013/02/21 14:48:44 Done.
+ var rti = getRuntimeTypeInfo(o);
+ if (JS('bool', '# != null', rti)) {
ngeoffray 2013/02/21 10:26:18 Add a comment on why it could be null.
karlklose 2013/02/21 14:48:44 Done.
+ // Make a copy of the type arguments and insert [o] in the first position
+ // to create a compound type representation.
+ type = JS('List', '#.slice().splice(0, 0, #)', rti, o);
+ }
+ return isSubtype(type, t);
+ }
+}
+
+
+/**
* Check whether the type represented by [s] is a subtype of the type
* represented by [t].
*
* Type representations can be:
* 1) a JavaScript constructor for a class C: the represented type is the raw
* type C.
- * 2) a JavaScript object: this represents a class for which there is no
+ * 2) a Dart object.
ngeoffray 2013/02/21 10:26:18 That is very confusing, how can a Dart object be a
karlklose 2013/02/21 14:48:44 As discussed, the checks and substitutions are on
+ * 3) a JavaScript object: this represents a class for which there is no
* JavaScript constructor, because it is only used in type arguments or it
* is native. The represented type is the raw type of this class.
- * 3) a JavaScript array: the first entry is of type 1 or 2 and identifies the
- * class of the type and the rest of the array are the type arguments.
- * 4) [:null:]: the dynamic type.
+ * 4) a JavaScript array: the first entry is of type 1, 2 or 3 and contains the
+ * subtyping flags and the substitution of the type and the rest of the
+ * array are the type arguments.
+ * 5) [:null:]: the dynamic type.
*/
bool isSubtype(var s, var t) {
// If either type is dynamic, [s] is a subtype of [t].

Powered by Google App Engine
This is Rietveld 408576698