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 library dart._utils; | 5 library dart._utils; |
6 | 6 |
7 import 'dart:_foreign_helper' show JS; | 7 import 'dart:_foreign_helper' show JS, JSExportName; |
8 | 8 |
9 /// This library defines a set of general javascript utilities for us | 9 /// This library defines a set of general javascript utilities for us |
10 /// by the Dart runtime. | 10 /// by the Dart runtime. |
11 // TODO(ochafik): Rewrite some of these in Dart when possible. | 11 // TODO(ochafik): Rewrite some of these in Dart when possible. |
12 | 12 |
13 final defineProperty = JS('', 'Object.defineProperty'); | 13 final defineProperty = JS('', 'Object.defineProperty'); |
14 final getOwnPropertyDescriptor = JS('', 'Object.getOwnPropertyDescriptor'); | 14 final getOwnPropertyDescriptor = JS('', 'Object.getOwnPropertyDescriptor'); |
15 final getOwnPropertyNames = JS('', 'Object.getOwnPropertyNames'); | 15 final getOwnPropertyNames = JS('', 'Object.getOwnPropertyNames'); |
16 final getOwnPropertySymbols = JS('', 'Object.getOwnPropertySymbols'); | 16 final getOwnPropertySymbols = JS('', 'Object.getOwnPropertySymbols'); |
17 | 17 |
(...skipping 14 matching lines...) Expand all Loading... |
32 throw new StrongModeError($message); | 32 throw new StrongModeError($message); |
33 })()'''); | 33 })()'''); |
34 | 34 |
35 /// This error indicates a bug in the runtime or the compiler. | 35 /// This error indicates a bug in the runtime or the compiler. |
36 void throwInternalError(String message) => JS('', '''(() => { | 36 void throwInternalError(String message) => JS('', '''(() => { |
37 throw Error($message); | 37 throw Error($message); |
38 })()'''); | 38 })()'''); |
39 | 39 |
40 // TODO(ochafik): Re-introduce a @JS annotation in the SDK (same as package:js) | 40 // TODO(ochafik): Re-introduce a @JS annotation in the SDK (same as package:js) |
41 // so that this is named 'assert' in JavaScript. | 41 // so that this is named 'assert' in JavaScript. |
| 42 @JSExportName('assert') |
42 void assert_(bool condition) => JS('', '''(() => { | 43 void assert_(bool condition) => JS('', '''(() => { |
43 if (!condition) throwInternalError("The compiler is broken: failed assert"); | 44 if (!condition) throwInternalError("The compiler is broken: failed assert"); |
44 })()'''); | 45 })()'''); |
45 | 46 |
46 getOwnNamesAndSymbols(obj) => JS('', '''(() => { | 47 getOwnNamesAndSymbols(obj) => JS('', '''(() => { |
47 return getOwnPropertyNames(obj).concat(getOwnPropertySymbols(obj)); | 48 return getOwnPropertyNames(obj).concat(getOwnPropertySymbols(obj)); |
48 })()'''); | 49 })()'''); |
49 | 50 |
50 safeGetOwnProperty(obj, String name) => JS('', '''(() => { | 51 safeGetOwnProperty(obj, String name) => JS('', '''(() => { |
51 let desc = getOwnPropertyDescriptor($obj, $name); | 52 let desc = getOwnPropertyDescriptor($obj, $name); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 export_(to, from, show, hide) => JS('', '''(() => { | 117 export_(to, from, show, hide) => JS('', '''(() => { |
117 if ($show == void 0 || $show.length == 0) { | 118 if ($show == void 0 || $show.length == 0) { |
118 $show = $getOwnNamesAndSymbols($from); | 119 $show = $getOwnNamesAndSymbols($from); |
119 } | 120 } |
120 if ($hide != void 0) { | 121 if ($hide != void 0) { |
121 var hideMap = new Set($hide); | 122 var hideMap = new Set($hide); |
122 $show = $show.filter((k) => !hideMap.has(k)); | 123 $show = $show.filter((k) => !hideMap.has(k)); |
123 } | 124 } |
124 return $copyTheseProperties($to, $from, $show); | 125 return $copyTheseProperties($to, $from, $show); |
125 })()'''); | 126 })()'''); |
OLD | NEW |