| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 } | 91 } |
| 92 return $to; | 92 return $to; |
| 93 })()'''); | 93 })()'''); |
| 94 | 94 |
| 95 copyProperty(to, from, name) { | 95 copyProperty(to, from, name) { |
| 96 var desc = getOwnPropertyDescriptor(from, name); | 96 var desc = getOwnPropertyDescriptor(from, name); |
| 97 if (JS('bool', '# == Symbol.iterator', name)) { | 97 if (JS('bool', '# == Symbol.iterator', name)) { |
| 98 // On native types, Symbol.iterator may already be present. | 98 // On native types, Symbol.iterator may already be present. |
| 99 // TODO(jmesserly): investigate if we still need this. | 99 // TODO(jmesserly): investigate if we still need this. |
| 100 // If so, we need to find a better solution. | 100 // If so, we need to find a better solution. |
| 101 // See: https://github.com/dart-lang/dev_compiler/issues/487 | 101 // See https://github.com/dart-lang/sdk/issues/28324 |
| 102 var existing = getOwnPropertyDescriptor(to, name); | 102 var existing = getOwnPropertyDescriptor(to, name); |
| 103 if (existing != null) { | 103 if (existing != null) { |
| 104 if (JS('bool', '#.writable', existing)) { | 104 if (JS('bool', '#.writable', existing)) { |
| 105 JS('', '#[#] = #.value', to, name, desc); | 105 JS('', '#[#] = #.value', to, name, desc); |
| 106 } | 106 } |
| 107 return; | 107 return; |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 defineProperty(to, name, desc); | 110 defineProperty(to, name, desc); |
| 111 } | 111 } |
| 112 | 112 |
| 113 @JSExportName('export') | 113 @JSExportName('export') |
| 114 exportProperty(to, from, name) => copyProperty(to, from, name); | 114 exportProperty(to, from, name) => copyProperty(to, from, name); |
| 115 | 115 |
| 116 /// Copy properties from source to destination object. | 116 /// Copy properties from source to destination object. |
| 117 /// This operation is commonly called `mixin` in JS. | 117 /// This operation is commonly called `mixin` in JS. |
| 118 copyProperties(to, from) { | 118 copyProperties(to, from) { |
| 119 return copyTheseProperties(to, from, getOwnNamesAndSymbols(from)); | 119 return copyTheseProperties(to, from, getOwnNamesAndSymbols(from)); |
| 120 } | 120 } |
| OLD | NEW |