Skip to content

Commit f9401b1

Browse files
Jennifer Messerlyvsmenon
Jennifer Messerly
authored andcommitted
fix #29544, mixins to a class with named constructors
[email protected] Review-Url: https://codereview.chromium.org/2859703003 .
1 parent 7452c51 commit f9401b1

File tree

14 files changed

+121
-37
lines changed

14 files changed

+121
-37
lines changed

pkg/dev_compiler/lib/js/amd/dart_sdk.js

Lines changed: 16 additions & 6 deletions
Large diffs are not rendered by default.

pkg/dev_compiler/lib/js/amd/dart_sdk.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/dev_compiler/lib/js/common/dart_sdk.js

Lines changed: 16 additions & 6 deletions
Large diffs are not rendered by default.

pkg/dev_compiler/lib/js/common/dart_sdk.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/dev_compiler/lib/js/es6/dart_sdk.js

Lines changed: 16 additions & 6 deletions
Large diffs are not rendered by default.

pkg/dev_compiler/lib/js/es6/dart_sdk.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/dev_compiler/lib/js/legacy/dart_sdk.js

Lines changed: 16 additions & 6 deletions
Large diffs are not rendered by default.

pkg/dev_compiler/lib/js/legacy/dart_sdk.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/dev_compiler/lib/sdk/ddc_sdk.sum

-104 Bytes
Binary file not shown.

pkg/dev_compiler/test/browser/language_tests.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,8 @@ define(['dart_sdk', 'async_helper', 'expect', 'unittest', 'is', 'require'],
191191
'memory_swap_test': skip_timeout,
192192
'method_invocation_test': fail,
193193
'mint_arithmetic_test': fail,
194-
'mixin_forwarding_constructor3_test': fail,
195194
'mixin_implements_test': fail,
196195
'mixin_regress_13688_test': fail,
197-
'mixin_super_constructor_test': fail, // https://github.com/dart-lang/sdk/issues/28059
198-
'mixin_super_constructor2_test': fail, // Issue 28059
199-
'mixin_super_constructor_named_test_none_multi': fail, // Issue 28059
200196
'mixin_super_constructor_positionals_test_none_multi': fail, // Issue 28059
201197
'modulo_test': fail,
202198
'named_parameter_clash_test': fail,

pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mixin(base, @rest mixins) => JS(
3333
for (let m of $mixins) {
3434
$copyProperties(Mixin.prototype, m.prototype);
3535
}
36-
// Initializer method: run mixin initializers, then the base.
36+
// Initializer methods: run mixin initializers, then the base.
3737
Mixin.prototype.new = function(...args) {
3838
// Run mixin initializers. They cannot have arguments.
3939
// Run them backwards so most-derived mixin is initialized first.
@@ -43,6 +43,20 @@ mixin(base, @rest mixins) => JS(
4343
// Run base initializer.
4444
$base.prototype.new.apply(this, args);
4545
};
46+
let namedCtors = ${safeGetOwnProperty(base, _namedConstructors)};
47+
if ($base[$_namedConstructors] != null) {
48+
for (let namedCtor of $base[$_namedConstructors]) {
49+
Mixin.prototype[namedCtor] = function(...args) {
50+
// Run mixin initializers. They cannot have arguments.
51+
// Run them backwards so most-derived mixin is initialized first.
52+
for (let i = $mixins.length - 1; i >= 0; i--) {
53+
$mixins[i].prototype.new.call(this);
54+
}
55+
// Run base initializer.
56+
$base.prototype[namedCtor].apply(this, args);
57+
};
58+
}
59+
}
4660
4761
// Set the signature of the Mixin class to be the composition
4862
// of the signatures of the mixins.
@@ -424,13 +438,18 @@ defineNamedConstructor(clazz, name) => JS(
424438
let proto = $clazz.prototype;
425439
let initMethod = proto[$name];
426440
let ctor = function(...args) { initMethod.apply(this, args); };
427-
ctor[$isNamedConstructor] = true;
428441
ctor.prototype = proto;
429442
// Use defineProperty so we don't hit a property defined on Function,
430443
// like `caller` and `arguments`.
431444
$defineProperty($clazz, $name, { value: ctor, configurable: true });
445+
446+
let namedCtors = ${safeGetOwnProperty(clazz, _namedConstructors)};
447+
if (namedCtors == null) $clazz[$_namedConstructors] = namedCtors = [];
448+
namedCtors.push($name);
432449
})()''');
433450

451+
final _namedConstructors = JS('', 'Symbol("_namedConstructors")');
452+
434453
final _extensionType = JS('', 'Symbol("extensionType")');
435454

436455
getExtensionType(obj) => JS('', '#[#]', obj, _extensionType);

pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/rtti.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ lazyFn(closure, computeType) {
7272

7373
// TODO(vsm): How should we encode the runtime type?
7474
final _runtimeType = JS('', 'Symbol("_runtimeType")');
75-
final isNamedConstructor = JS('', 'Symbol("isNamedConstructor")');
7675

7776
final _moduleName = JS('', 'Symbol("_moduleName")');
7877

@@ -188,7 +187,6 @@ lazyAnonymousJSType(name) {
188187
unwrapType(WrappedType obj) => obj._wrappedType;
189188

190189
_getRuntimeType(value) => JS('', '#[#]', value, _runtimeType);
191-
getIsNamedConstructor(value) => JS('', '#[#]', value, isNamedConstructor);
192190

193191
/// Return the module name for a raw library object.
194192
getModuleName(value) => JS('', '#[#]', value, _moduleName);

pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ getOwnNamesAndSymbols(obj) {
4040
return JS('', '#.concat(#)', names, symbols);
4141
}
4242

43-
safeGetOwnProperty(obj, String name) {
43+
safeGetOwnProperty(obj, name) {
4444
var desc = getOwnPropertyDescriptor(obj, name);
4545
if (desc != null) return JS('', '#.value', desc);
4646
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import "package:expect/expect.dart";
6+
7+
var calls = <String>[];
8+
9+
abstract class A {
10+
bool _done = true;
11+
var a = calls.add('A()') as dynamic;
12+
}
13+
14+
abstract class B {
15+
B.protected() {
16+
calls.add('B.protected()');
17+
}
18+
}
19+
20+
class C extends B with A {
21+
C() : super.protected() {
22+
calls.add('C()');
23+
}
24+
}
25+
26+
void main() {
27+
var c = new C();
28+
print(calls.join(', '));
29+
Expect.isTrue(c._done);
30+
Expect.equals(calls.join(', '), 'A(), B.protected(), C()');
31+
}

0 commit comments

Comments
 (0)