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

Unified Diff: pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart

Issue 2859703003: fix #29544, mixins to a class with named constructors (Closed)
Patch Set: fix to use safeGetOwnProperty Created 3 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: pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart
diff --git a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart
index 7d48033577925893ea6a616c65b1ead567126a62..ca3f810efefff793e7aeace8997be7194b3755f9 100644
--- a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart
+++ b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart
@@ -33,7 +33,7 @@ mixin(base, @rest mixins) => JS(
for (let m of $mixins) {
$copyProperties(Mixin.prototype, m.prototype);
}
- // Initializer method: run mixin initializers, then the base.
+ // Initializer methods: run mixin initializers, then the base.
Mixin.prototype.new = function(...args) {
// Run mixin initializers. They cannot have arguments.
// Run them backwards so most-derived mixin is initialized first.
@@ -43,6 +43,20 @@ mixin(base, @rest mixins) => JS(
// Run base initializer.
$base.prototype.new.apply(this, args);
};
+ let namedCtors = ${safeGetOwnProperty(base, _namedConstructors)};
+ if ($base[$_namedConstructors] != null) {
+ for (let namedCtor of $base[$_namedConstructors]) {
+ Mixin.prototype[namedCtor] = function(...args) {
+ // Run mixin initializers. They cannot have arguments.
+ // Run them backwards so most-derived mixin is initialized first.
+ for (let i = $mixins.length - 1; i >= 0; i--) {
+ $mixins[i].prototype.new.call(this);
+ }
+ // Run base initializer.
+ $base.prototype[namedCtor].apply(this, args);
+ };
+ }
+ }
// Set the signature of the Mixin class to be the composition
// of the signatures of the mixins.
@@ -424,13 +438,18 @@ defineNamedConstructor(clazz, name) => JS(
let proto = $clazz.prototype;
let initMethod = proto[$name];
let ctor = function(...args) { initMethod.apply(this, args); };
- ctor[$isNamedConstructor] = true;
ctor.prototype = proto;
// Use defineProperty so we don't hit a property defined on Function,
// like `caller` and `arguments`.
$defineProperty($clazz, $name, { value: ctor, configurable: true });
+
+ let namedCtors = ${safeGetOwnProperty(clazz, _namedConstructors)};
+ if (namedCtors == null) $clazz[$_namedConstructors] = namedCtors = [];
+ namedCtors.push($name);
})()''');
+final _namedConstructors = JS('', 'Symbol("_namedConstructors")');
+
final _extensionType = JS('', 'Symbol("extensionType")');
getExtensionType(obj) => JS('', '#[#]', obj, _extensionType);
« no previous file with comments | « pkg/dev_compiler/test/browser/language_tests.js ('k') | pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/rtti.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698