| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |