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

Unified Diff: lib/runtime/dart_runtime.js

Issue 1058653002: implement mixins in subtype checks, more codegen fixes (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 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: lib/runtime/dart_runtime.js
diff --git a/lib/runtime/dart_runtime.js b/lib/runtime/dart_runtime.js
index f91a9347cac41280ed7591adf0c7ef7c044e6d5e..149543b21313802e1b5d86b7c21f6dd22122e3dc 100644
--- a/lib/runtime/dart_runtime.js
+++ b/lib/runtime/dart_runtime.js
@@ -96,7 +96,7 @@ var dart, _js_helper;
dart.dbinary = dbinary;
function cast(obj, type) {
- //TODO(vsm): handle non-nullable types
+ // TODO(vsm): handle non-nullable types
if (obj == null) return obj;
let actual = getRuntimeType(obj);
if (isSubtype(actual, type)) return obj;
@@ -189,7 +189,11 @@ var dart, _js_helper;
}
// Function subtyping.
- // TODO(jmesserly): implement.
+ // TODO(jmesserly): implement this properly.
+ if (isClassSubType(t1, core.Function) &&
+ isClassSubType(t2, core.Function)) {
+ return true;
+ }
return false;
}
@@ -235,6 +239,15 @@ var dart, _js_helper;
// Check superclass.
if (isClassSubType(t1.__proto__, t2)) return true;
+ // Check mixins.
+ let mixins = safeGetOwnProperty(t1, dart.mixins);
+ if (mixins) {
+ for (let m1 of mixins) {
+ // TODO(jmesserly): remove the != null check once we can load core libs.
+ if (m1 != null && isClassSubType(m1, t2)) return true;
+ }
+ }
+
// Check interfaces.
let getInterfaces = safeGetOwnProperty(t1, dart.implements);
if (getInterfaces) {
@@ -371,10 +384,12 @@ var dart, _js_helper;
// Run them backwards so most-derived mixin is initialized first.
for (let i = mixins.length - 1; i >= 0; i--) {
let mixin = mixins[i];
- mixin.prototype[mixin.name].call(this);
+ let init = mixin.prototype[mixin.name];
+ if (init) init.call(this);
}
// Run base initializer.
- base.prototype[base.name].apply(this, arguments);
+ let init = base.prototype[base.name];
+ if (init) init.apply(this, arguments);
}
}
// Copy each mixin's methods, with later ones overwriting earlier entries.

Powered by Google App Engine
This is Rietveld 408576698