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

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

Issue 1965213003: simplify constructors, fixes #564 (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « test/codegen/expect/temps.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ///
11 11
12 // TODO(leafp): Consider splitting some of this out. 12 // TODO(leafp): Consider splitting some of this out.
13 part of dart._runtime; 13 part of dart._runtime;
14 14
15 /// 15 ///
16 /// Returns a new type that mixes members from base and all mixins. 16 /// Returns a new type that mixes members from base and all mixins.
17 /// 17 ///
18 /// Each mixin applies in sequence, with further to the right ones overriding 18 /// Each mixin applies in sequence, with further to the right ones overriding
19 /// previous entries. 19 /// previous entries.
20 /// 20 ///
21 /// For each mixin, we only take its own properties, not anything from its 21 /// For each mixin, we only take its own properties, not anything from its
22 /// superclass (prototype). 22 /// superclass (prototype).
23 /// 23 ///
24 mixin(base, @rest mixins) => JS('', '''(() => { 24 mixin(base, @rest mixins) => JS('', '''(() => {
25 // Create an initializer for the mixin, so when derived constructor calls 25 // Create an initializer for the mixin, so when derived constructor calls
26 // super, we can correctly initialize base and mixins. 26 // super, we can correctly initialize base and mixins.
27 27
28 // Create a class that will hold all of the mixin methods. 28 // Create a class that will hold all of the mixin methods.
29 class Mixin extends $base { 29 class Mixin extends $base {}
30 // Initializer method: run mixin initializers, then the base.
31 [$base.name](...args) {
32 // Run mixin initializers. They cannot have arguments.
33 // Run them backwards so most-derived mixin is initialized first.
34 for (let i = $mixins.length - 1; i >= 0; i--) {
35 let mixin = $mixins[i];
36 let init = mixin.prototype[mixin.name];
37 if (init) init.call(this);
38 }
39 // Run base initializer.
40 let init = $base.prototype[base.name];
41 if (init) init.apply(this, args);
42 }
43 }
44 // Copy each mixin's methods, with later ones overwriting earlier entries. 30 // Copy each mixin's methods, with later ones overwriting earlier entries.
45 for (let m of $mixins) { 31 for (let m of $mixins) {
46 $copyProperties(Mixin.prototype, m.prototype); 32 $copyProperties(Mixin.prototype, m.prototype);
47 } 33 }
34 // Initializer method: run mixin initializers, then the base.
35 Mixin.prototype.new = function(...args) {
36 // Run mixin initializers. They cannot have arguments.
37 // Run them backwards so most-derived mixin is initialized first.
38 for (let i = $mixins.length - 1; i >= 0; i--) {
39 $mixins[i].prototype.new.call(this);
40 }
41 // Run base initializer.
42 $base.prototype.new.apply(this, args);
43 };
48 44
49 // Set the signature of the Mixin class to be the composition 45 // Set the signature of the Mixin class to be the composition
50 // of the signatures of the mixins. 46 // of the signatures of the mixins.
51 $setSignature(Mixin, { 47 $setSignature(Mixin, {
52 methods: () => { 48 methods: () => {
53 let s = {}; 49 let s = {};
54 for (let m of $mixins) { 50 for (let m of $mixins) {
55 $copyProperties(s, m[$_methodSig]); 51 $copyProperties(s, m[$_methodSig]);
56 } 52 }
57 return s; 53 return s;
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 })()'''); 417 })()''');
422 418
423 /// Sets the element type of a list literal. 419 /// Sets the element type of a list literal.
424 list(obj, elementType) => 420 list(obj, elementType) =>
425 JS('', '$setType($obj, ${getGenericClass(JSArray)}($elementType))'); 421 JS('', '$setType($obj, ${getGenericClass(JSArray)}($elementType))');
426 422
427 setBaseClass(derived, base) => JS('', '''(() => { 423 setBaseClass(derived, base) => JS('', '''(() => {
428 // Link the extension to the type it's extending as a base class. 424 // Link the extension to the type it's extending as a base class.
429 $derived.prototype.__proto__ = $base.prototype; 425 $derived.prototype.__proto__ = $base.prototype;
430 })()'''); 426 })()''');
OLDNEW
« no previous file with comments | « test/codegen/expect/temps.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698