Chromium Code Reviews| 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 61f532e788af9c9594e51e7f7ac3cdd8436a34d8..2ea176fd511ecd90f7d6b57f24021716d116362a 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/lib/js_helper.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/lib/js_helper.dart |
| @@ -1521,6 +1521,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]. |
|
ngeoffray
2013/02/18 09:27:58
Is [t] the same thing as [t] in isSubtype?
karlklose
2013/02/18 16:02:01
Yes, added a comment.
|
| + */ |
| +bool objectIsSubtype(Object o, var t) { |
|
ngeoffray
2013/02/18 09:27:58
Why isn't o.runtimeType sufficient?
karlklose
2013/02/18 16:02:01
No, runtimeType will return a Type that is only us
|
| + if (JS('bool', '# == null', o) || JS('bool', '# == null', t)) return true; |
| + |
| + var nativeCheck = getField(t, '\$nativeCheck'); |
| + if (nativeCheck != null) { |
| + return invoke(nativeCheck, [o]); |
| + } else { |
|
ngeoffray
2013/02/18 09:27:58
Why are you not calling isSubtype here? Can't you
karlklose
2013/02/18 16:02:01
I could, but not directly, I would have to constru
ngeoffray
2013/02/19 09:00:41
Why would you have to construct it? Isn't it set w
karlklose
2013/02/19 12:39:28
Done.
|
| + 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]. |
| * |