OLD | NEW |
1 dart_library.library('dart/_utils', null, /* Imports */[ | 1 dart_library.library('dart/_utils', null, /* Imports */[ |
2 ], /* Lazy imports */[ | 2 ], /* Lazy imports */[ |
3 ], function(exports, dart) { | 3 ], function(exports, dart) { |
4 'use strict'; | 4 'use strict'; |
5 const defineProperty = Object.defineProperty; | 5 const defineProperty = Object.defineProperty; |
6 const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; | 6 const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; |
7 const getOwnPropertyNames = Object.getOwnPropertyNames; | 7 const getOwnPropertyNames = Object.getOwnPropertyNames; |
8 const getOwnPropertySymbols = Object.getOwnPropertySymbols; | 8 const getOwnPropertySymbols = Object.getOwnPropertySymbols; |
9 const hasOwnProperty = Object.prototype.hasOwnProperty; | 9 const hasOwnProperty = Object.prototype.hasOwnProperty; |
10 const StrongModeError = (function() { | 10 const StrongModeError = (function() { |
11 function StrongModeError(message) { | 11 function StrongModeError(message) { |
12 Error.call(this); | 12 Error.call(this); |
13 this.message = message; | 13 this.message = message; |
14 } | 14 } |
15 ; | 15 ; |
16 Object.setPrototypeOf(StrongModeError.prototype, Error.prototype); | 16 Object.setPrototypeOf(StrongModeError.prototype, Error.prototype); |
17 return StrongModeError; | 17 return StrongModeError; |
18 })(); | 18 })(); |
19 function throwStrongModeError(message) { | 19 function throwStrongModeError(message) { |
20 throw new StrongModeError(message); | 20 throw new StrongModeError(message); |
21 } | 21 } |
22 function throwInternalError(message) { | 22 function throwInternalError(message) { |
23 throw Error(message); | 23 throw Error(message); |
24 } | 24 } |
25 function assert_(condition) { | 25 function assert_(condition) { |
26 if (!condition) | 26 if (!condition) throwInternalError("The compiler is broken: failed assert"); |
27 throwInternalError("The compiler is broken: failed assert"); | |
28 } | 27 } |
29 function getOwnNamesAndSymbols(obj) { | 28 function getOwnNamesAndSymbols(obj) { |
30 return getOwnPropertyNames(obj).concat(getOwnPropertySymbols(obj)); | 29 return getOwnPropertyNames(obj).concat(getOwnPropertySymbols(obj)); |
31 } | 30 } |
32 function safeGetOwnProperty(obj, name) { | 31 function safeGetOwnProperty(obj, name) { |
33 let desc = getOwnPropertyDescriptor(obj, name); | 32 let desc = getOwnPropertyDescriptor(obj, name); |
34 if (desc) | 33 if (desc) return desc.value; |
35 return desc.value; | |
36 } | 34 } |
37 function defineLazyProperty(to, name, desc) { | 35 function defineLazyProperty(to, name, desc) { |
38 let init = desc.get; | 36 let init = desc.get; |
39 let value = null; | 37 let value = null; |
40 function lazySetter(x) { | 38 function lazySetter(x) { |
41 init = null; | 39 init = null; |
42 value = x; | 40 value = x; |
43 } | 41 } |
44 function circularInitError() { | 42 function circularInitError() { |
45 throwInternalError('circular initialization for field ' + name); | 43 throwInternalError('circular initialization for field ' + name); |
46 } | 44 } |
47 function lazyGetter() { | 45 function lazyGetter() { |
48 if (init == null) | 46 if (init == null) return value; |
49 return value; | |
50 let f = init; | 47 let f = init; |
51 init = circularInitError; | 48 init = circularInitError; |
52 lazySetter(f()); | 49 lazySetter(f()); |
53 return value; | 50 return value; |
54 } | 51 } |
55 desc.get = lazyGetter; | 52 desc.get = lazyGetter; |
56 desc.configurable = true; | 53 desc.configurable = true; |
57 if (desc.set) | 54 if (desc.set) desc.set = lazySetter; |
58 desc.set = lazySetter; | |
59 return defineProperty(to, name, desc); | 55 return defineProperty(to, name, desc); |
60 } | 56 } |
61 function defineLazy(to, from) { | 57 function defineLazy(to, from) { |
62 for (let name of getOwnNamesAndSymbols(from)) { | 58 for (let name of getOwnNamesAndSymbols(from)) { |
63 defineLazyProperty(to, name, getOwnPropertyDescriptor(from, name)); | 59 defineLazyProperty(to, name, getOwnPropertyDescriptor(from, name)); |
64 } | 60 } |
65 } | 61 } |
66 function defineMemoizedGetter(obj, name, getter) { | 62 function defineMemoizedGetter(obj, name, getter) { |
67 return defineLazyProperty(obj, name, {get: getter}); | 63 return defineLazyProperty(obj, name, {get: getter}); |
68 } | 64 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 exports.assert_ = assert_; | 98 exports.assert_ = assert_; |
103 exports.getOwnNamesAndSymbols = getOwnNamesAndSymbols; | 99 exports.getOwnNamesAndSymbols = getOwnNamesAndSymbols; |
104 exports.safeGetOwnProperty = safeGetOwnProperty; | 100 exports.safeGetOwnProperty = safeGetOwnProperty; |
105 exports.defineLazyProperty = defineLazyProperty; | 101 exports.defineLazyProperty = defineLazyProperty; |
106 exports.defineLazy = defineLazy; | 102 exports.defineLazy = defineLazy; |
107 exports.defineMemoizedGetter = defineMemoizedGetter; | 103 exports.defineMemoizedGetter = defineMemoizedGetter; |
108 exports.copyTheseProperties = copyTheseProperties; | 104 exports.copyTheseProperties = copyTheseProperties; |
109 exports.copyProperties = copyProperties; | 105 exports.copyProperties = copyProperties; |
110 exports.export_ = export_; | 106 exports.export_ = export_; |
111 }); | 107 }); |
OLD | NEW |