| 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 class encapsulating the zone specification for a [Chain.capture] zone. | 12 /// A class encapsulating the zone specification for a [Chain.capture] zone. |
| 13 /// | 13 /// |
| 14 /// Until they're materialized and exposed to the user, stack chains are tracked | 14 /// 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 | 15 /// as linked lists of [Trace]s using the [_Node] class. These nodes are stored |
| 16 /// in three distinct ways: | 16 /// in three distinct ways: |
| 17 /// | 17 /// |
| 18 /// * When a callback is registered, a node is created and stored as a captured | 18 /// * When a callback is registered, a node is created and stored as a captured |
| 19 /// local variable until the callback is run. | 19 /// local variable until the callback is run. |
| 20 /// | 20 /// |
| 21 /// * When a callback is run, its captured node is set as the [_currentNode] so | 21 /// * When a callback is run, its captured node is set as the [_currentNode] so |
| 22 /// it can be available to [Chain.current] and to be linked into additional | 22 /// it can be available to [Chain.current] and to be linked into additional |
| 23 /// chains when more callbacks are scheduled. | 23 /// chains when more callbacks are scheduled. |
| 24 /// | 24 /// |
| 25 /// * When a callback throws an error or a [Chain.track]ed Future or Stream | 25 /// * When a callback throws an error or a Future or Stream emits an error, the |
| 26 /// emits an error, the current node is associated with that error's stack | 26 /// current node is associated with that error's stack trace using the |
| 27 /// trace using the [_chains] expando. | 27 /// [_chains] expando. |
| 28 /// | 28 /// |
| 29 /// Since [ZoneSpecification] can't be extended or even implemented, in order to | 29 /// Since [ZoneSpecification] can't be extended or even implemented, in order to |
| 30 /// get a real [ZoneSpecification] instance it's necessary to call [toSpec]. | 30 /// get a real [ZoneSpecification] instance it's necessary to call [toSpec]. |
| 31 class StackZoneSpecification { | 31 class StackZoneSpecification { |
| 32 /// The expando that associates stack chains with [StackTrace]s. | 32 /// The expando that associates stack chains with [StackTrace]s. |
| 33 /// | 33 /// |
| 34 /// The chains are associated with stack traces rather than errors themselves | 34 /// The chains are associated with stack traces rather than errors themselves |
| 35 /// because it's a common practice to throw strings as errors, which can't be | 35 /// because it's a common practice to throw strings as errors, which can't be |
| 36 /// used with expandos. | 36 /// used with expandos. |
| 37 /// | 37 /// |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 Chain toChain() { | 232 Chain toChain() { |
| 233 var nodes = <Trace>[]; | 233 var nodes = <Trace>[]; |
| 234 var node = this; | 234 var node = this; |
| 235 while (node != null) { | 235 while (node != null) { |
| 236 nodes.add(node.trace); | 236 nodes.add(node.trace); |
| 237 node = node.previous; | 237 node = node.previous; |
| 238 } | 238 } |
| 239 return new Chain(nodes); | 239 return new Chain(nodes); |
| 240 } | 240 } |
| 241 } | 241 } |
| OLD | NEW |