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

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

Issue 803103004: Revert "dart2js: put all type-test related properties on the prototype and not on the constructor." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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/js_lib/js_rti.dart
diff --git a/sdk/lib/_internal/compiler/js_lib/js_rti.dart b/sdk/lib/_internal/compiler/js_lib/js_rti.dart
index 08c52dd960e7d83d819a8576b981035b8a8cf6e8..ce595394166a6b007438b8e57a199033445d1b2f 100644
--- a/sdk/lib/_internal/compiler/js_lib/js_rti.dart
+++ b/sdk/lib/_internal/compiler/js_lib/js_rti.dart
@@ -390,24 +390,17 @@ bool checkSubtypeOfRuntimeType(o, t) {
// overwrite o with the interceptor below.
var rti = getRuntimeTypeInfo(o);
o = getInterceptor(o);
- var type = JS('', '#.constructor', o);
+ // We can use the object as its own type representation because we install
+ var type;
if (rti != null) {
// If the type has type variables (that is, `rti != null`), make a copy of
// the type arguments and insert [o] in the first position to create a
// compound type representation.
- rti = JS('JSExtendableArray', '#.slice()', rti); // Make a copy.
- JS('', '#.splice(0, 0, #)', rti, type); // Insert type at position 0.
- type = rti;
- } else if (hasField(t, '${JS_FUNCTION_TYPE_TAG()}')) {
- // Functions are treated specially and have their type information stored
- // directly in the instance.
- var signatureName =
- '${JS_OPERATOR_IS_PREFIX()}_${getField(t, JS_FUNCTION_TYPE_TAG())}';
- if (hasField(o, signatureName)) return true;
- var targetSignatureFunction = getField(o, '${JS_SIGNATURE_NAME()}');
- if (targetSignatureFunction == null) return false;
- type = invokeOn(targetSignatureFunction, o, null);
- return isFunctionSubtype(type, t);
+ type = JS('JSExtendableArray', '#.slice()', rti);
+ JS('', '#.splice(0, 0, #)', type, o);
+ } else {
+ // Use the object as representation of the raw type.
+ type = o;
}
return isSubtype(type, t);
}
@@ -441,9 +434,6 @@ getArguments(var type) {
*
* See the comment in the beginning of this file for a description of type
* representations.
- *
- * The arguments [s] and [t] must be types, usually represented by the
- * constructor of the class, or an array (for generic types).
*/
bool isSubtype(var s, var t) {
// Subtyping is reflexive.
@@ -451,13 +441,21 @@ bool isSubtype(var s, var t) {
// If either type is dynamic, [s] is a subtype of [t].
if (s == null || t == null) return true;
if (hasField(t, '${JS_FUNCTION_TYPE_TAG()}')) {
+ if (hasNoField(s, '${JS_FUNCTION_TYPE_TAG()}')) {
+ var signatureName =
+ '${JS_OPERATOR_IS_PREFIX()}_${getField(t, JS_FUNCTION_TYPE_TAG())}';
+ if (hasField(s, signatureName)) return true;
+ var targetSignatureFunction = getField(s, '${JS_SIGNATURE_NAME()}');
+ if (targetSignatureFunction == null) return false;
+ s = invokeOn(targetSignatureFunction, s, null);
+ }
return isFunctionSubtype(s, t);
}
// Check function types against the Function class.
- if (hasField(s, '${JS_FUNCTION_TYPE_TAG()}')) {
- return getConstructorName(t) == JS_FUNCTION_CLASS_NAME();
+ if (getConstructorName(t) == JS_FUNCTION_CLASS_NAME() &&
+ hasField(s, '${JS_FUNCTION_TYPE_TAG()}')) {
+ return true;
}
-
// Get the object describing the class and check for the subtyping flag
// constructed from the type of [t].
var typeOfS = isJsArray(s) ? getIndex(s, 0) : s;
@@ -468,10 +466,9 @@ bool isSubtype(var s, var t) {
var substitution;
if (isNotIdentical(typeOfT, typeOfS)) {
var test = '${JS_OPERATOR_IS_PREFIX()}${name}';
- var typeOfSPrototype = JS('', '#.prototype', typeOfS);
- if (hasNoField(typeOfSPrototype, test)) return false;
+ if (hasNoField(typeOfS, test)) return false;
var field = '${JS_OPERATOR_AS_PREFIX()}${runtimeTypeToString(typeOfT)}';
- substitution = getField(typeOfSPrototype, field);
+ substitution = getField(typeOfS, field);
}
// The class of [s] is a subclass of the class of [t]. If [s] has no type
// arguments and no substitution, it is used as raw type. If [t] has no

Powered by Google App Engine
This is Rietveld 408576698