| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library stack_trace.stack_zone_specification; | 5 library stack_trace.stack_zone_specification; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'trace.dart'; | 9 import 'trace.dart'; |
| 10 import 'chain.dart'; | 10 import 'chain.dart'; |
| 11 | 11 |
| 12 /// A function that handles errors in the zone wrapped by [Chain.capture]. |
| 13 typedef void _ChainHandler(error, Chain chain); |
| 14 |
| 12 /// A class encapsulating the zone specification for a [Chain.capture] zone. | 15 /// A class encapsulating the zone specification for a [Chain.capture] zone. |
| 13 /// | 16 /// |
| 14 /// Until they're materialized and exposed to the user, stack chains are tracked | 17 /// Until they're materialized and exposed to the user, stack chains are tracked |
| 15 /// as linked lists of [Trace]s using the [_Node] class. These nodes are stored | 18 /// as linked lists of [Trace]s using the [_Node] class. These nodes are stored |
| 16 /// in three distinct ways: | 19 /// in three distinct ways: |
| 17 /// | 20 /// |
| 18 /// * When a callback is registered, a node is created and stored as a captured | 21 /// * When a callback is registered, a node is created and stored as a captured |
| 19 /// local variable until the callback is run. | 22 /// local variable until the callback is run. |
| 20 /// | 23 /// |
| 21 /// * When a callback is run, its captured node is set as the [_currentNode] so | 24 /// * When a callback is run, its captured node is set as the [_currentNode] so |
| (...skipping 14 matching lines...) Expand all Loading... |
| 36 /// used with expandos. | 39 /// used with expandos. |
| 37 /// | 40 /// |
| 38 /// The chain associated with a given stack trace doesn't contain a node for | 41 /// The chain associated with a given stack trace doesn't contain a node for |
| 39 /// that stack trace. | 42 /// that stack trace. |
| 40 final _chains = new Expando<_Node>("stack chains"); | 43 final _chains = new Expando<_Node>("stack chains"); |
| 41 | 44 |
| 42 /// The error handler for the zone. | 45 /// The error handler for the zone. |
| 43 /// | 46 /// |
| 44 /// If this is null, that indicates that any unhandled errors should be passed | 47 /// If this is null, that indicates that any unhandled errors should be passed |
| 45 /// to the parent zone. | 48 /// to the parent zone. |
| 46 final ChainHandler _onError; | 49 final _ChainHandler _onError; |
| 47 | 50 |
| 48 /// The most recent node of the current stack chain. | 51 /// The most recent node of the current stack chain. |
| 49 _Node _currentNode; | 52 _Node _currentNode; |
| 50 | 53 |
| 51 StackZoneSpecification([this._onError]); | 54 StackZoneSpecification([this._onError]); |
| 52 | 55 |
| 53 /// Converts [this] to a real [ZoneSpecification]. | 56 /// Converts [this] to a real [ZoneSpecification]. |
| 54 ZoneSpecification toSpec() { | 57 ZoneSpecification toSpec() { |
| 55 return new ZoneSpecification( | 58 return new ZoneSpecification( |
| 56 handleUncaughtError: handleUncaughtError, | 59 handleUncaughtError: handleUncaughtError, |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 Chain toChain() { | 230 Chain toChain() { |
| 228 var nodes = <Trace>[]; | 231 var nodes = <Trace>[]; |
| 229 var node = this; | 232 var node = this; |
| 230 while (node != null) { | 233 while (node != null) { |
| 231 nodes.add(node.trace); | 234 nodes.add(node.trace); |
| 232 node = node.previous; | 235 node = node.previous; |
| 233 } | 236 } |
| 234 return new Chain(nodes); | 237 return new Chain(nodes); |
| 235 } | 238 } |
| 236 } | 239 } |
| OLD | NEW |