Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/lib/js_rti.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/lib/js_rti.dart b/sdk/lib/_internal/compiler/implementation/lib/js_rti.dart |
| index fd64f48144278759c59dc44513f79f1dc68821af..edef7ec9056f62c43c5a882793411d6b2485744e 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/lib/js_rti.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/lib/js_rti.dart |
| @@ -121,7 +121,7 @@ bool checkSubtype(Object object, String isField, List checks, String asField) { |
| // TODO(sra): It could be a more specialized interceptor since [object] is not |
| // `null` or a primitive. |
| // TODO(9586): Move type info for static functions onto an interceptor. |
| - var interceptor = isJsFunction(object) ? object : getInterceptor(object); |
| + var interceptor = getInterceptor(object); |
| bool isSubclass = getField(interceptor, isField); |
| // When we read the field and it is not there, [isSubclass] will be [:null:]. |
| if (isSubclass == null || !isSubclass) return false; |
| @@ -130,6 +130,22 @@ bool checkSubtype(Object object, String isField, List checks, String asField) { |
| return checkArguments(substitution, arguments, checks); |
| } |
| +Object assertSubtype(Object object, String isField, List checks, String asField) { |
|
ngeoffray
2013/05/13 09:10:59
Line too long.
karlklose
2013/05/14 13:49:41
Done.
|
| + if (object == null) return null; |
| + var target = getInterceptor(object); |
| + // When we read the field and it is not there, [isSubclass] will be [:null:]. |
| + bool isSubclass = (getField(target, isField) == true); |
| + if (!isSubclass) { |
| + propertyTypeError(object, isField); |
| + } |
| + var substitution = getField(target, asField); |
| + var arguments = getRuntimeTypeInfo(object); |
| + if (!checkArguments(substitution, arguments, checks)) { |
| + propertyTypeError(object, isField); |
| + } |
| + return object; |
| +} |
| + |
| /** |
| * Check that the types in the list [arguments] are subtypes of the types in |
| * list [checks] (at the respective positions), possibly applying [substitution] |
| @@ -195,6 +211,13 @@ bool objectIsSubtype(Object o, var t) { |
| return isSubtype(type, t); |
| } |
| +Object assertObjectIsSubtype(Object o, var t) { |
| + if (!objectIsSubtype(o, t)) { |
| + throw new TypeErrorImplementation(o, runtimeTypeToString(t)); |
| + } |
| + return o; |
| +} |
| + |
| /** |
| * Check whether the type represented by [s] is a subtype of the type |
| * represented by [t]. |
| @@ -220,6 +243,10 @@ bool isSubtype(var s, var t) { |
| // constructed from the type of [t]. |
| var typeOfS = isJsArray(s) ? s[0] : s; |
| var typeOfT = isJsArray(t) ? t[0] : t; |
| + // TODO(johnniwinther): replace this with the real function subtype test. |
| + if (JS('bool', '#.func', s) == true || JS('bool', '#.func', t) == true ) { |
| + return true; |
| + } |
| // Check for a subtyping flag. |
| var test = '${JS_OPERATOR_IS_PREFIX()}${runtimeTypeToString(typeOfT)}'; |
| if (getField(typeOfS, test) == null) return false; |