| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 typedef Object ComputeValue(); | 5 typedef Object ComputeValue(); |
| 6 | 6 |
| 7 class _MeasurementRequest<T> { | 7 class _MeasurementRequest<T> { |
| 8 final ComputeValue computeValue; | 8 final ComputeValue computeValue; |
| 9 final Completer<T> completer; | 9 final Completer<T> completer; |
| 10 Object value; | 10 Object value; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 void _completeMeasurementFutures() { | 79 void _completeMeasurementFutures() { |
| 80 if (_nextMeasurementFrameScheduled == false) { | 80 if (_nextMeasurementFrameScheduled == false) { |
| 81 // Ignore spurious call to this function. | 81 // Ignore spurious call to this function. |
| 82 return; | 82 return; |
| 83 } | 83 } |
| 84 | 84 |
| 85 _nextMeasurementFrameScheduled = false; | 85 _nextMeasurementFrameScheduled = false; |
| 86 // We must compute all new values before fulfilling the futures as | 86 // We must compute all new values before fulfilling the futures as |
| 87 // the onComplete callbacks for the futures could modify the DOM making | 87 // the onComplete callbacks for the futures could modify the DOM making |
| 88 // subsequent measurement calculations expensive to compute. | 88 // subsequent measurement calculations expensive to compute. |
| 89 for (_MeasurementRequest request in _pendingRequests) { | 89 if (_pendingRequests !== null) { |
| 90 try { | 90 for (_MeasurementRequest request in _pendingRequests) { |
| 91 request.value = request.computeValue(); | 91 try { |
| 92 } catch(var e) { | 92 request.value = request.computeValue(); |
| 93 request.value = e; | 93 } catch(var e) { |
| 94 request.exception = true; | 94 request.value = e; |
| 95 request.exception = true; |
| 96 } |
| 95 } | 97 } |
| 96 } | 98 } |
| 97 | 99 |
| 98 final completedRequests = _pendingRequests; | 100 final completedRequests = _pendingRequests; |
| 99 final readyMeasurementFrameCallbacks = _pendingMeasurementFrameCallbacks; | 101 final readyMeasurementFrameCallbacks = _pendingMeasurementFrameCallbacks; |
| 100 _pendingRequests = null; | 102 _pendingRequests = null; |
| 101 _pendingMeasurementFrameCallbacks = null; | 103 _pendingMeasurementFrameCallbacks = null; |
| 102 for (_MeasurementRequest request in completedRequests) { | 104 if (completedRequests !== null) { |
| 103 if (request.exception) { | 105 for (_MeasurementRequest request in completedRequests) { |
| 104 request.completer.completeException(request.value); | 106 if (request.exception) { |
| 105 } else { | 107 request.completer.completeException(request.value); |
| 106 request.completer.complete(request.value); | 108 } else { |
| 109 request.completer.complete(request.value); |
| 110 } |
| 107 } | 111 } |
| 108 } | 112 } |
| 109 | 113 |
| 110 if (readyMeasurementFrameCallbacks !== null) { | 114 if (readyMeasurementFrameCallbacks !== null) { |
| 111 for (TimeoutHandler handler in readyMeasurementFrameCallbacks) { | 115 for (TimeoutHandler handler in readyMeasurementFrameCallbacks) { |
| 112 // TODO(jacobr): wrap each call to a handler in a try-catch block. | 116 // TODO(jacobr): wrap each call to a handler in a try-catch block. |
| 113 handler(); | 117 handler(); |
| 114 } | 118 } |
| 115 } | 119 } |
| 116 } | 120 } |
| OLD | NEW |