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

Unified Diff: sdk/lib/_internal/compiler/implementation/lib/js_rti.dart

Issue 15563003: Add the cast equivalent of assertSubtype and assertSubtypeOfRuntimeType. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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_rti.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/lib/js_rti.dart (revision 22932)
+++ sdk/lib/_internal/compiler/implementation/lib/js_rti.dart (working copy)
@@ -134,14 +134,27 @@
return checkArguments(substitution, arguments, checks);
}
+String computeTypeName(String isField, List checks) {
+ // Shorten the field name to the class name and append the textual
+ // representation of the type arguments.
+ int prefixLength = JS_OPERATOR_IS_PREFIX().length;
+ return '${isField.substring(prefixLength, isField.length)}'
+ '${joinArguments(checks, 0)}';
+}
+
+Object subtypeCast(Object object, String isField, List checks, String asField) {
+ if (!checkSubtype(object, isField, checks, asField)) {
+ String actualType = Primitives.objectTypeName(object);
+ String typeName = computeTypeName(isField, checks);
+ throw new CastErrorImplementation(object, typeName);
+ }
+ return object;
+}
+
Object assertSubtype(Object object, String isField, List checks,
String asField) {
if (!checkSubtype(object, isField, checks, asField)) {
- // Shorten the field name to the class name and append the textual
- // representation of the type arguments.
- int prefixLength = JS_OPERATOR_IS_PREFIX().length;
- String typeName = '${isField.substring(prefixLength, isField.length)}'
- '${joinArguments(checks, 0)}';
+ String typeName = computeTypeName(isField, checks);
throw new TypeErrorImplementation(object, typeName);
}
return object;
@@ -212,6 +225,14 @@
return isSubtype(type, t);
}
+Object subtypeOfRuntimeTypeCast(Object object, var type) {
+ if (!checkSubtypeOfRuntimeType(object, type)) {
+ String actualType = Primitives.objectTypeName(object);
+ throw new CastErrorImplementation(actualType, runtimeTypeToString(type));
+ }
+ return object;
+}
+
Object assertSubtypeOfRuntimeType(Object object, var type) {
if (!checkSubtypeOfRuntimeType(object, type)) {
throw new TypeErrorImplementation(object, runtimeTypeToString(type));

Powered by Google App Engine
This is Rietveld 408576698