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

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: Remove some obsolete code. 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..9a1f97f600290209bfec8c8ab2eeb8ab08113b2a 100644
--- a/sdk/lib/_internal/compiler/implementation/lib/js_helper.dart
+++ b/sdk/lib/_internal/compiler/implementation/lib/js_helper.dart
@@ -1541,18 +1541,49 @@ 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;
+ // Check for native objects and use the interceptor instead of the object.
+ var rti = getRuntimeTypeInfo(o);
ngeoffray 2013/02/26 14:11:37 Create rti closer to where it is used.
karlklose 2013/02/27 10:12:58 o can potentially be replaced by the intercecptor,
+ if (isJsArray(o) || o is int || o is String || o is double) {
ngeoffray 2013/02/26 14:11:37 How about calling getInterceptor unconditionally a
karlklose 2013/02/27 10:12:58 Done.
+ o = getInterceptor(o);
+ }
+ // We can use the object as its own type representation because we install
+ // the subtype flags and the substitution on the prototype, so they are
+ // properties of the object in JS.
+ var type;
+ if (JS('bool', '# != null', rti)) {
+ // If the type has type variables (that is, [:rti != null:]), make a copy of
+ // the type arguments and insert [o] in the first position to create a
+ // compound type representation, otherwise use [o] itself.
ngeoffray 2013/02/26 14:11:37 The 'otherhwise' part applies to the else. Please
karlklose 2013/02/27 10:12:58 Done.
+ type = JS('List', '#.slice()', rti);
+ JS('', '#.splice(0, 0, #)', type, o);
+ } else {
+ type = 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: this is the interceptor instance for a native type.
+ * 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