| 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 /* This library defines a set of general javascript utilities for us | 5 /* This library defines a set of general javascript utilities for us |
| 6 * by the Dart runtime. | 6 * by the Dart runtime. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 var dart_utils = | 9 var dart_utils = |
| 10 typeof module != "undefined" && module.exports || {}; | 10 typeof module != "undefined" && module.exports || {}; |
| 11 | 11 |
| 12 (function (dart_utils) { | 12 (function (dart_utils) { |
| 13 'use strict'; | 13 'use strict'; |
| 14 | 14 |
| 15 const defineProperty = Object.defineProperty; | 15 const defineProperty = Object.defineProperty; |
| 16 const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; | 16 const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; |
| 17 const getOwnPropertyNames = Object.getOwnPropertyNames; | 17 const getOwnPropertyNames = Object.getOwnPropertyNames; |
| 18 const getOwnPropertySymbols = Object.getOwnPropertySymbols; | 18 const getOwnPropertySymbols = Object.getOwnPropertySymbols; |
| 19 | 19 |
| 20 const hasOwnProperty = Object.prototype.hasOwnProperty; | 20 const hasOwnProperty = Object.prototype.hasOwnProperty; |
| 21 | 21 |
| 22 const slice = [].slice; | 22 const slice = [].slice; |
| 23 | 23 |
| 24 class StrongModeError extends Error { |
| 25 constructor(message) { |
| 26 super(message); |
| 27 } |
| 28 } |
| 29 |
| 30 /** This error indicates a strong mode specific failure. |
| 31 */ |
| 32 function throwStrongModeError(message) { |
| 33 throw new StrongModeError(message); |
| 34 } |
| 35 dart_utils.throwStrongModeError = throwStrongModeError; |
| 24 | 36 |
| 25 /** This error indicates a bug in the runtime or the compiler. | 37 /** This error indicates a bug in the runtime or the compiler. |
| 26 */ | 38 */ |
| 27 function throwError(message) { | 39 function throwInternalError(message) { |
| 28 throw Error(message); | 40 throw Error(message); |
| 29 } | 41 } |
| 30 dart_utils.throwError = throwError; | 42 dart_utils.throwInternalError = throwInternalError; |
| 31 | 43 |
| 32 function assert(condition) { | 44 function assert(condition) { |
| 33 if (!condition) throwError("The compiler is broken: failed assert"); | 45 if (!condition) throwInternalError("The compiler is broken: failed assert"); |
| 34 } | 46 } |
| 35 dart_utils.assert = assert; | 47 dart_utils.assert = assert; |
| 36 | 48 |
| 37 function getOwnNamesAndSymbols(obj) { | 49 function getOwnNamesAndSymbols(obj) { |
| 38 return getOwnPropertyNames(obj).concat(getOwnPropertySymbols(obj)); | 50 return getOwnPropertyNames(obj).concat(getOwnPropertySymbols(obj)); |
| 39 } | 51 } |
| 40 dart_utils.getOwnNamesAndSymbols = getOwnNamesAndSymbols; | 52 dart_utils.getOwnNamesAndSymbols = getOwnNamesAndSymbols; |
| 41 | 53 |
| 42 function safeGetOwnProperty(obj, name) { | 54 function safeGetOwnProperty(obj, name) { |
| 43 let desc = getOwnPropertyDescriptor(obj, name); | 55 let desc = getOwnPropertyDescriptor(obj, name); |
| 44 if (desc) return desc.value; | 56 if (desc) return desc.value; |
| 45 } | 57 } |
| 46 dart_utils.safeGetOwnProperty = safeGetOwnProperty; | 58 dart_utils.safeGetOwnProperty = safeGetOwnProperty; |
| 47 | 59 |
| 48 /** | 60 /** |
| 49 * Defines a lazy property. | 61 * Defines a lazy property. |
| 50 * After initial get or set, it will replace itself with a value property. | 62 * After initial get or set, it will replace itself with a value property. |
| 51 */ | 63 */ |
| 52 // TODO(jmesserly): reusing descriptor objects has been shown to improve | 64 // TODO(jmesserly): reusing descriptor objects has been shown to improve |
| 53 // performance in other projects (e.g. webcomponents.js ShadowDOM polyfill). | 65 // performance in other projects (e.g. webcomponents.js ShadowDOM polyfill). |
| 54 function defineLazyProperty(to, name, desc) { | 66 function defineLazyProperty(to, name, desc) { |
| 55 let init = desc.get; | 67 let init = desc.get; |
| 56 let value = null; | 68 let value = null; |
| 57 | 69 |
| 58 function lazySetter(x) { | 70 function lazySetter(x) { |
| 59 init = null; | 71 init = null; |
| 60 value = x; | 72 value = x; |
| 61 } | 73 } |
| 62 function circularInitError() { | 74 function circularInitError() { |
| 63 throwError('circular initialization for field ' + name); | 75 throwInternalError('circular initialization for field ' + name); |
| 64 } | 76 } |
| 65 function lazyGetter() { | 77 function lazyGetter() { |
| 66 if (init == null) return value; | 78 if (init == null) return value; |
| 67 | 79 |
| 68 // Compute and store the value, guarding against reentry. | 80 // Compute and store the value, guarding against reentry. |
| 69 let f = init; | 81 let f = init; |
| 70 init = circularInitError; | 82 init = circularInitError; |
| 71 lazySetter(f()); | 83 lazySetter(f()); |
| 72 return value; | 84 return value; |
| 73 } | 85 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 126 } |
| 115 if (hide != void 0) { | 127 if (hide != void 0) { |
| 116 var hideMap = new Set(hide); | 128 var hideMap = new Set(hide); |
| 117 show = show.filter((k) => !hideMap.has(k)); | 129 show = show.filter((k) => !hideMap.has(k)); |
| 118 } | 130 } |
| 119 return copyTheseProperties(to, from, show); | 131 return copyTheseProperties(to, from, show); |
| 120 } | 132 } |
| 121 dart_utils.export = export_; | 133 dart_utils.export = export_; |
| 122 | 134 |
| 123 })(dart_utils); | 135 })(dart_utils); |
| OLD | NEW |