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 22 matching lines...) Expand all Loading... |
33 if (_trapRuntimeErrors) JS('', 'debugger'); | 33 if (_trapRuntimeErrors) JS('', 'debugger'); |
34 JS('', 'throw Error(#)', message); | 34 JS('', 'throw Error(#)', message); |
35 } | 35 } |
36 | 36 |
37 getOwnNamesAndSymbols(obj) { | 37 getOwnNamesAndSymbols(obj) { |
38 var names = getOwnPropertyNames(obj); | 38 var names = getOwnPropertyNames(obj); |
39 var symbols = getOwnPropertySymbols(obj); | 39 var symbols = getOwnPropertySymbols(obj); |
40 return JS('', '#.concat(#)', names, symbols); | 40 return JS('', '#.concat(#)', names, symbols); |
41 } | 41 } |
42 | 42 |
43 safeGetOwnProperty(obj, String name) { | 43 safeGetOwnProperty(obj, name) { |
44 var desc = getOwnPropertyDescriptor(obj, name); | 44 var desc = getOwnPropertyDescriptor(obj, name); |
45 if (desc != null) return JS('', '#.value', desc); | 45 if (desc != null) return JS('', '#.value', desc); |
46 } | 46 } |
47 | 47 |
48 /// Defines a lazy property. | 48 /// Defines a lazy property. |
49 /// After initial get or set, it will replace itself with a value property. | 49 /// After initial get or set, it will replace itself with a value property. |
50 // TODO(jmesserly): reusing descriptor objects has been shown to improve | 50 // TODO(jmesserly): reusing descriptor objects has been shown to improve |
51 // performance in other projects (e.g. webcomponents.js ShadowDOM polyfill). | 51 // performance in other projects (e.g. webcomponents.js ShadowDOM polyfill). |
52 defineLazyProperty(to, name, desc) => JS( | 52 defineLazyProperty(to, name, desc) => JS( |
53 '', | 53 '', |
(...skipping 63 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 |