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) => |
11 JS('', 'Object.defineProperty(#, #, #)', obj, name, desc); | 11 JS('', 'Object.defineProperty(#, #, #)', obj, name, desc); |
12 | 12 |
13 getOwnPropertyDescriptor(obj, name) => | 13 getOwnPropertyDescriptor(obj, name) => |
14 JS('', 'Object.getOwnPropertyDescriptor(#, #)', obj, name); | 14 JS('', 'Object.getOwnPropertyDescriptor(#, #)', obj, name); |
15 | 15 |
16 Iterable getOwnPropertyNames(obj) => | 16 Iterable getOwnPropertyNames(obj) => |
17 JS('', 'Object.getOwnPropertyNames(#)', obj); | 17 JS('', 'Object.getOwnPropertyNames(#)', obj); |
18 | 18 |
19 Iterable getOwnPropertySymbols(obj) => | 19 Iterable getOwnPropertySymbols(obj) => |
20 JS('', 'Object.getOwnPropertySymbols(#)', obj); | 20 JS('', 'Object.getOwnPropertySymbols(#)', obj); |
21 | 21 |
22 final hasOwnProperty = JS('', 'Object.prototype.hasOwnProperty'); | 22 final hasOwnProperty = JS('', 'Object.prototype.hasOwnProperty'); |
23 | 23 |
24 // TODO(ochafik): Add ES6 class syntax support to JS intrinsics to avoid this. | 24 /// This error indicates a strong mode specific failure, other than a type |
25 final StrongModeError = JS('', '''(function() { | 25 /// assertion failure (TypeError) or CastError. |
26 function StrongModeError(message) { | |
27 Error.call(this); | |
28 this.message = message; | |
29 }; | |
30 Object.setPrototypeOf(StrongModeError.prototype, Error.prototype); | |
31 return StrongModeError; | |
32 })()'''); | |
33 | |
34 /// This error indicates a strong mode specific failure. | |
35 void throwStrongModeError(String message) { | 26 void throwStrongModeError(String message) { |
36 JS('', 'throw new #(#);', StrongModeError, message); | 27 JS('', 'throw new #(#);', StrongModeErrorImplementation, message); |
37 } | 28 } |
38 | 29 |
39 /// This error indicates a bug in the runtime or the compiler. | 30 /// This error indicates a bug in the runtime or the compiler. |
40 void throwInternalError(String message) { | 31 void throwInternalError(String message) { |
41 JS('', 'throw Error(#)', message); | 32 JS('', 'throw Error(#)', message); |
42 } | 33 } |
43 | 34 |
44 getOwnNamesAndSymbols(obj) { | 35 getOwnNamesAndSymbols(obj) { |
45 var names = getOwnPropertyNames(obj); | 36 var names = getOwnPropertyNames(obj); |
46 var symbols = getOwnPropertySymbols(obj); | 37 var symbols = getOwnPropertySymbols(obj); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 109 } |
119 | 110 |
120 @JSExportName('export') | 111 @JSExportName('export') |
121 exportProperty(to, from, name) => copyProperty(to, from, name); | 112 exportProperty(to, from, name) => copyProperty(to, from, name); |
122 | 113 |
123 /// Copy properties from source to destination object. | 114 /// Copy properties from source to destination object. |
124 /// This operation is commonly called `mixin` in JS. | 115 /// This operation is commonly called `mixin` in JS. |
125 copyProperties(to, from) { | 116 copyProperties(to, from) { |
126 return copyTheseProperties(to, from, getOwnNamesAndSymbols(from)); | 117 return copyTheseProperties(to, from, getOwnNamesAndSymbols(from)); |
127 } | 118 } |
OLD | NEW |