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 3fa0f5df29a5183c84c48a74249baae5d98946e5..894ae6ca262c3e3f635667e0fe1d851ff1dec7b5 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/lib/js_helper.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/lib/js_helper.dart |
| @@ -1632,23 +1632,22 @@ String getClassName(var object) { |
| } |
| String getTypeArgumentAsString(List runtimeType) { |
| - String className = runtimeTypeToString(runtimeType[0]); |
| + String className = getConstructorName(runtimeType[0]); |
| if (runtimeType.length == 1) return className; |
| return '$className<${joinArguments(runtimeType, 1)}>'; |
| } |
| +String getConstructorName(type) => JS('String', r'#.builtin$cls', type); |
| + |
| String runtimeTypeToString(type) { |
| if (type == null) { |
| return 'dynamic'; |
| - } else if (type is String) { |
| - // A native class. The string is the unique name. |
| - return type; |
| } else if (isJsArray(type)) { |
| // A list representing a type with arguments. |
| return getTypeArgumentAsString(type); |
| } else { |
| // A reference to the constructor. |
| - return JS('String', r'#.builtin$cls', type); |
| + return getConstructorName(type); |
| } |
| } |
| @@ -1676,10 +1675,12 @@ String getRuntimeTypeString(var object) { |
| bool isSubtype(var s, var t) { |
| if (s == null || t == null) return true; |
| - if (!isJsArray(s)) return s == t; |
| - // TODO(karlklose): support subtyping: if s[0] != t[0], check if there is |
| - // a function is$s[0] on t[0] and call it with substitutes type arguments. |
| - if (s[0] != t[0]) return false; |
| + var typeOfS = isJsArray(s) ? s[0] : s; |
| + var typeOfT = isJsArray(t) ? t[0] : t; |
| + if (typeOfS == typeOfT) return true; |
| + var test = 'is\$${runtimeTypeToString(typeOfT)}'; |
| + if (JS('var', r'#[#]', typeOfS, test) == null) return false; |
| + if (!isJsArray(s) || !isJsArray(t)) return true; |
| int len = s.length; |
|
kasperl
2012/12/12 12:09:45
Are s and t guaranteed to have the same length? Ad
karlklose
2012/12/12 14:50:47
No, they are not. Added a test.
|
| for (int i = 1; i < len; i++) { |
| if (!isSubtype(s[i], t[i])) { |