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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } | 75 } |
76 return s; | 76 return s; |
77 } | 77 } |
78 }); | 78 }); |
79 | 79 |
80 // Save mixins for reflection | 80 // Save mixins for reflection |
81 Mixin[$_mixins] = $mixins; | 81 Mixin[$_mixins] = $mixins; |
82 return Mixin; | 82 return Mixin; |
83 })()'''); | 83 })()'''); |
84 | 84 |
| 85 /// |
| 86 /// Support for virtualizing fields on-demand. |
| 87 /// |
| 88 final _virtualNames = JS('', '{}'); |
| 89 |
| 90 virtualName(key) => JS( |
| 91 '', |
| 92 '''(() => { |
| 93 return #[key] || (#[key] = Symbol(key)); |
| 94 })()''', |
| 95 _virtualNames, |
| 96 _virtualNames); |
| 97 |
| 98 virtualize(object, keys) => JS( |
| 99 '', |
| 100 '''(() => { |
| 101 for (var i = 0; i < keys.length; i += 2) { |
| 102 let name = keys[i]; |
| 103 let symbol = keys[i + 1]; |
| 104 Object.defineProperty(object, name, { |
| 105 configurable: true, |
| 106 set: function(value) { |
| 107 object[symbol] = value; |
| 108 delete object[name]; |
| 109 } |
| 110 }); |
| 111 } |
| 112 })()'''); |
| 113 |
85 /// The Symbol for storing type arguments on a specialized generic type. | 114 /// The Symbol for storing type arguments on a specialized generic type. |
86 final _mixins = JS('', 'Symbol("mixins")'); | 115 final _mixins = JS('', 'Symbol("mixins")'); |
87 | 116 |
88 getMixins(clazz) => JS('', 'Object.hasOwnProperty.call(#, #) ? #[#] : null', | 117 getMixins(clazz) => JS('', 'Object.hasOwnProperty.call(#, #) ? #[#] : null', |
89 clazz, _mixins, clazz, _mixins); | 118 clazz, _mixins, clazz, _mixins); |
90 | 119 |
91 @JSExportName('implements') | 120 @JSExportName('implements') |
92 final _implements = JS('', 'Symbol("implements")'); | 121 final _implements = JS('', 'Symbol("implements")'); |
93 | 122 |
94 getImplements(clazz) => JS('', 'Object.hasOwnProperty.call(#, #) ? #[#] : null', | 123 getImplements(clazz) => JS('', 'Object.hasOwnProperty.call(#, #) ? #[#] : null', |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 '''(() => { | 663 '''(() => { |
635 let values = []; | 664 let values = []; |
636 for (var i = 0; i < $names.length; i++) { | 665 for (var i = 0; i < $names.length; i++) { |
637 let value = $const_(new $enumClass(i)); | 666 let value = $const_(new $enumClass(i)); |
638 values.push(value); | 667 values.push(value); |
639 Object.defineProperty($enumClass, $names[i], | 668 Object.defineProperty($enumClass, $names[i], |
640 { value: value, configurable: true }); | 669 { value: value, configurable: true }); |
641 } | 670 } |
642 $enumClass.values = $constList(values, $enumClass); | 671 $enumClass.values = $constList(values, $enumClass); |
643 })()'''); | 672 })()'''); |
OLD | NEW |