| 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 /// This error indicates a strong mode specific failure, other than a type | 24 /// This error indicates a strong mode specific failure, other than a type |
| 25 /// assertion failure (TypeError) or CastError. | 25 /// assertion failure (TypeError) or CastError. |
| 26 void throwStrongModeError(String message) { | 26 void throwStrongModeError(String message) { |
| 27 JS('', 'debugger'); | 27 if (_trapRuntimeErrors) JS('', 'debugger'); |
| 28 JS('', 'throw new #(#);', StrongModeErrorImplementation, message); | 28 JS('', 'throw new #(#);', StrongModeErrorImplementation, message); |
| 29 } | 29 } |
| 30 | 30 |
| 31 /// This error indicates a bug in the runtime or the compiler. | 31 /// This error indicates a bug in the runtime or the compiler. |
| 32 void throwInternalError(String message) { | 32 void throwInternalError(String message) { |
| 33 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, String name) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |