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

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: Do not emit Object.isObject. 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 844ee78c9aeec4f7d3beff36806de95ad2b3fdcf..a1d94d2aef76e0d53d1aa9d01da7d2018b28d2e9 100644
--- a/sdk/lib/_internal/compiler/implementation/lib/js_helper.dart
+++ b/sdk/lib/_internal/compiler/implementation/lib/js_helper.dart
@@ -1522,6 +1522,31 @@ 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].
+ */
+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 {
+ bool hasArguments = isJsArray(t);
+ String typeOfT = runtimeTypeToString(hasArguments ? t[0] : t);
+ // Check for a subtyping flag.
+ String test = '${JS_OPERATOR_IS_PREFIX()}$typeOfT';
+ if (getField(o, test) == null) return false;
+ if (!hasArguments) return true;
+ // Get the necessary substitution of the type arguments, if there is one.
+ String field = '${JS_OPERATOR_AS_PREFIX()}$typeOfT';
+ var substitution = getField(o, field);
+ // Recursively check the type arguments.
+ return checkArguments(substitution, getRuntimeTypeInfo(o), getArguments(t));
+ }
+}
+
+/**
* Check whether the type represented by [s] is a subtype of the type
* represented by [t].
*

Powered by Google App Engine
This is Rietveld 408576698