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

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

Issue 2935933005: fix mixins with factory constructors (Closed)
Patch Set: d Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// This library defines the operations that define and manipulate Dart 5 /// This library defines the operations that define and manipulate Dart
6 /// classes. Included in this are: 6 /// classes. Included in this are:
7 /// - Generics 7 /// - Generics
8 /// - Class metadata 8 /// - Class metadata
9 /// - Extension methods 9 /// - Extension methods
10 /// 10 ///
(...skipping 28 matching lines...) Expand all
39 // Restore original Mixin JS constructor. 39 // Restore original Mixin JS constructor.
40 Mixin.prototype.constructor = constructor; 40 Mixin.prototype.constructor = constructor;
41 // Dart constructors: run mixin constructors, then the base constructors. 41 // Dart constructors: run mixin constructors, then the base constructors.
42 for (let memberName of $getOwnNamesAndSymbols($base)) { 42 for (let memberName of $getOwnNamesAndSymbols($base)) {
43 let member = $safeGetOwnProperty($base, memberName); 43 let member = $safeGetOwnProperty($base, memberName);
44 if (typeof member == "function" && member.prototype === base.prototype) { 44 if (typeof member == "function" && member.prototype === base.prototype) {
45 $defineValue(Mixin, memberName, function(...args) { 45 $defineValue(Mixin, memberName, function(...args) {
46 // Run mixin initializers. They cannot have arguments. 46 // Run mixin initializers. They cannot have arguments.
47 // Run them backwards so most-derived mixin is initialized first. 47 // Run them backwards so most-derived mixin is initialized first.
48 for (let i = $mixins.length - 1; i >= 0; i--) { 48 for (let i = $mixins.length - 1; i >= 0; i--) {
49 $mixins[i].new.call(this); 49 let m = $mixins[i];
50 (m[$mixinNew] || m.new).call(this);
50 } 51 }
51 // Run base initializer. 52 // Run base initializer.
52 $base[memberName].apply(this, args); 53 $base[memberName].apply(this, args);
53 }).prototype = Mixin.prototype; 54 }).prototype = Mixin.prototype;
54 } 55 }
55 } 56 }
56 57
57 // Set the signature of the Mixin class to be the composition 58 // Set the signature of the Mixin class to be the composition
58 // of the signatures of the mixins. 59 // of the signatures of the mixins.
59 $setSignature(Mixin, { 60 $setSignature(Mixin, {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 final _implements = JS('', 'Symbol("implements")'); 103 final _implements = JS('', 'Symbol("implements")');
103 104
104 getImplements(clazz) => JS('', 'Object.hasOwnProperty.call(#, #) ? #[#] : null', 105 getImplements(clazz) => JS('', 'Object.hasOwnProperty.call(#, #) ? #[#] : null',
105 clazz, _implements, clazz, _implements); 106 clazz, _implements, clazz, _implements);
106 107
107 /// The Symbol for storing type arguments on a specialized generic type. 108 /// The Symbol for storing type arguments on a specialized generic type.
108 final _typeArguments = JS('', 'Symbol("typeArguments")'); 109 final _typeArguments = JS('', 'Symbol("typeArguments")');
109 110
110 final _originalDeclaration = JS('', 'Symbol("originalDeclaration")'); 111 final _originalDeclaration = JS('', 'Symbol("originalDeclaration")');
111 112
113 final mixinNew = JS('', 'Symbol("dart.mixinNew")');
114
112 /// Wrap a generic class builder function with future flattening. 115 /// Wrap a generic class builder function with future flattening.
113 flattenFutures(builder) => JS( 116 flattenFutures(builder) => JS(
114 '', 117 '',
115 '''(() => { 118 '''(() => {
116 function flatten(T) { 119 function flatten(T) {
117 if (!T) return $builder($dynamic); 120 if (!T) return $builder($dynamic);
118 let futureClass = $getGenericClass($Future); 121 let futureClass = $getGenericClass($Future);
119 //TODO(leafp): This only handles the direct flattening case. 122 //TODO(leafp): This only handles the direct flattening case.
120 // It would probably be good to at least search up the class 123 // It would probably be good to at least search up the class
121 // hierarchy. If we keep doing flattening long term, we may 124 // hierarchy. If we keep doing flattening long term, we may
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 570
568 defineEnumValues(enumClass, names) { 571 defineEnumValues(enumClass, names) {
569 var values = []; 572 var values = [];
570 for (var i = 0; i < JS('int', '#.length', names); i++) { 573 for (var i = 0; i < JS('int', '#.length', names); i++) {
571 var value = const_(JS('', 'new #.new(#)', enumClass, i)); 574 var value = const_(JS('', 'new #.new(#)', enumClass, i));
572 JS('', '#.push(#)', values, value); 575 JS('', '#.push(#)', values, value);
573 defineValue(enumClass, JS('', '#[#]', names, i), value); 576 defineValue(enumClass, JS('', '#[#]', names, i), value);
574 } 577 }
575 JS('', '#.values = #', enumClass, constList(values, enumClass)); 578 JS('', '#.values = #', enumClass, constList(values, enumClass));
576 } 579 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/lib/src/compiler/code_generator.dart ('k') | tests/language_strong/mixin_factory_constructor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698