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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 '', | 53 '', |
54 '''(() => { | 54 '''(() => { |
55 let init = $desc.get; | 55 let init = $desc.get; |
56 let value = null; | 56 let value = null; |
57 | 57 |
58 function lazySetter(x) { | 58 function lazySetter(x) { |
59 init = null; | 59 init = null; |
60 value = x; | 60 value = x; |
61 } | 61 } |
62 function circularInitError() { | 62 function circularInitError() { |
63 $throwInternalError('circular initialization for field ' + $name); | 63 $throwCyclicInitializationError($name); |
64 } | 64 } |
65 function lazyGetter() { | 65 function lazyGetter() { |
66 if (init == null) return value; | 66 if (init == null) return value; |
67 | 67 |
68 // Compute and store the value, guarding against reentry. | 68 // Compute and store the value, guarding against reentry. |
69 let f = init; | 69 let f = init; |
70 init = circularInitError; | 70 init = circularInitError; |
71 lazySetter(f()); | 71 lazySetter(f()); |
72 return value; | 72 return value; |
73 } | 73 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |