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]. |
* |