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 part of dart._runtime; | 4 part of dart._runtime; |
5 | 5 |
6 /// This library defines a set of general javascript utilities for us | 6 /// This library defines a set of general javascript utilities for us |
7 /// by the Dart runtime. | 7 /// by the Dart runtime. |
8 // TODO(ochafik): Rewrite some of these in Dart when possible. | 8 // TODO(ochafik): Rewrite some of these in Dart when possible. |
9 | 9 |
10 defineProperty(obj, name, desc) => | 10 defineProperty(obj, name, desc) => |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 })()'''); | 78 })()'''); |
79 | 79 |
80 void defineLazy(to, from) => JS( | 80 void defineLazy(to, from) => JS( |
81 '', | 81 '', |
82 '''(() => { | 82 '''(() => { |
83 for (let name of $getOwnNamesAndSymbols($from)) { | 83 for (let name of $getOwnNamesAndSymbols($from)) { |
84 $defineLazyProperty($to, name, $getOwnPropertyDescriptor($from, name)); | 84 $defineLazyProperty($to, name, $getOwnPropertyDescriptor($from, name)); |
85 } | 85 } |
86 })()'''); | 86 })()'''); |
87 | 87 |
88 defineMemoizedGetter(obj, String name, getter) { | 88 defineMemoizedGetter(obj, name, getter) { |
89 return defineLazyProperty(obj, name, JS('', '{get: #}', getter)); | 89 return defineLazyProperty(obj, name, JS('', '{get: #}', getter)); |
90 } | 90 } |
91 | 91 |
92 copyTheseProperties(to, from, names) => JS( | 92 copyTheseProperties(to, from, names) => JS( |
93 '', | 93 '', |
94 '''(() => { | 94 '''(() => { |
95 for (let i = 0; i < $names.length; ++i) { | 95 for (let i = 0; i < $names.length; ++i) { |
96 $copyProperty($to, $from, $names[i]); | 96 $copyProperty($to, $from, $names[i]); |
97 } | 97 } |
98 return $to; | 98 return $to; |
(...skipping 18 matching lines...) Expand all Loading... |
117 } | 117 } |
118 | 118 |
119 @JSExportName('export') | 119 @JSExportName('export') |
120 exportProperty(to, from, name) => copyProperty(to, from, name); | 120 exportProperty(to, from, name) => copyProperty(to, from, name); |
121 | 121 |
122 /// Copy properties from source to destination object. | 122 /// Copy properties from source to destination object. |
123 /// This operation is commonly called `mixin` in JS. | 123 /// This operation is commonly called `mixin` in JS. |
124 copyProperties(to, from) { | 124 copyProperties(to, from) { |
125 return copyTheseProperties(to, from, getOwnNamesAndSymbols(from)); | 125 return copyTheseProperties(to, from, getOwnNamesAndSymbols(from)); |
126 } | 126 } |
OLD | NEW |