| 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 part of dart2js.js_emitter.startup_emitter.model_emitter; | 5 part of dart2js.js_emitter.startup_emitter.model_emitter; |
| 6 | 6 |
| 7 /// The name of the property that stores the tear-off getter on a static | 7 /// The name of the property that stores the tear-off getter on a static |
| 8 /// function. | 8 /// function. |
| 9 /// | 9 /// |
| 10 /// This property is only used when isolates are used. | 10 /// This property is only used when isolates are used. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 function mixin(cls, mixin) { | 127 function mixin(cls, mixin) { |
| 128 copyProperties(mixin.prototype, cls.prototype); | 128 copyProperties(mixin.prototype, cls.prototype); |
| 129 } | 129 } |
| 130 | 130 |
| 131 // Creates a lazy field. | 131 // Creates a lazy field. |
| 132 // | 132 // |
| 133 // A lazy field has a storage entry, [name], which holds the value, and a | 133 // A lazy field has a storage entry, [name], which holds the value, and a |
| 134 // getter ([getterName]) to access the field. If the field wasn't set before | 134 // getter ([getterName]) to access the field. If the field wasn't set before |
| 135 // the first access, it is initialized with the [initializer]. | 135 // the first access, it is initialized with the [initializer]. |
| 136 function lazy(holder, name, getterName, initializer) { | 136 function lazy(holder, name, getterName, initializer) { |
| 137 holder[name] = null; | 137 var uninitializedSentinel = holder; |
| 138 holder[name] = uninitializedSentinel; |
| 138 holder[getterName] = function() { | 139 holder[getterName] = function() { |
| 139 holder[getterName] = function() { #cyclicThrow(name) }; | 140 holder[getterName] = function() { #cyclicThrow(name) }; |
| 140 var result; | 141 var result; |
| 141 var sentinelInProgress = initializer; | 142 var sentinelInProgress = initializer; |
| 142 try { | 143 try { |
| 143 result = holder[name] = sentinelInProgress; | 144 if (holder[name] === uninitializedSentinel) { |
| 144 result = holder[name] = initializer(); | 145 result = holder[name] = sentinelInProgress; |
| 146 result = holder[name] = initializer(); |
| 147 } else { |
| 148 result = holder[name]; |
| 149 } |
| 145 } finally { | 150 } finally { |
| 146 // Use try-finally, not try-catch/throw as it destroys the stack | 151 // Use try-finally, not try-catch/throw as it destroys the stack |
| 147 // trace. | 152 // trace. |
| 148 if (result === sentinelInProgress) { | 153 if (result === sentinelInProgress) { |
| 149 // The lazy static (holder[name]) might have been set to a different | 154 // The lazy static (holder[name]) might have been set to a different |
| 150 // value. According to spec we still have to reset it to null, if | 155 // value. According to spec we still have to reset it to null, if |
| 151 // the initialization failed. | 156 // the initialization failed. |
| 152 holder[name] = null; | 157 holder[name] = null; |
| 153 } | 158 } |
| 154 // TODO(floitsch): for performance reasons the function should probably | 159 // TODO(floitsch): for performance reasons the function should probably |
| (...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1287 } | 1292 } |
| 1288 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);", | 1293 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);", |
| 1289 js.objectLiteral(interceptorsByTag))); | 1294 js.objectLiteral(interceptorsByTag))); |
| 1290 statements.add(js.js.statement("setOrUpdateLeafTags(#);", | 1295 statements.add(js.js.statement("setOrUpdateLeafTags(#);", |
| 1291 js.objectLiteral(leafTags))); | 1296 js.objectLiteral(leafTags))); |
| 1292 statements.add(subclassAssignment); | 1297 statements.add(subclassAssignment); |
| 1293 | 1298 |
| 1294 return new js.Block(statements); | 1299 return new js.Block(statements); |
| 1295 } | 1300 } |
| 1296 } | 1301 } |
| OLD | NEW |