| 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'; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 var node = _createNode(1); | 138 var node = _createNode(1); |
| 139 return parent.registerBinaryCallback(zone, (arg1, arg2) { | 139 return parent.registerBinaryCallback(zone, (arg1, arg2) { |
| 140 return _run(() => f(arg1, arg2), node); | 140 return _run(() => f(arg1, arg2), node); |
| 141 }); | 141 }); |
| 142 } | 142 } |
| 143 | 143 |
| 144 /// Looks up the chain associated with [stackTrace] and passes it either to | 144 /// Looks up the chain associated with [stackTrace] and passes it either to |
| 145 /// [_onError] or [parent]'s error handler. | 145 /// [_onError] or [parent]'s error handler. |
| 146 handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone, error, | 146 handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone, error, |
| 147 StackTrace stackTrace) { | 147 StackTrace stackTrace) { |
| 148 var stackChain = chainFor(stackTrace); |
| 148 if (_onError == null) { | 149 if (_onError == null) { |
| 149 return parent.handleUncaughtError(zone, error, chainFor(stackTrace)); | 150 return parent.handleUncaughtError(zone, error, stackChain); |
| 150 } else { | 151 } |
| 151 _onError(error, chainFor(stackTrace)); | 152 |
| 153 // TODO(nweiz): Currently this copies a lot of logic from [runZoned]. Just |
| 154 // allow [runBinary] to throw instead once issue 18134 is fixed. |
| 155 try { |
| 156 return parent.runBinary(zone, _onError, error, stackChain); |
| 157 } catch (newError, newStackTrace) { |
| 158 if (identical(newError, error)) { |
| 159 return parent.handleUncaughtError(zone, error, stackChain); |
| 160 } else { |
| 161 return parent.handleUncaughtError(zone, newError, newStackTrace); |
| 162 } |
| 152 } | 163 } |
| 153 } | 164 } |
| 154 | 165 |
| 155 /// Creates a [_Node] with the current stack trace and linked to | 166 /// Creates a [_Node] with the current stack trace and linked to |
| 156 /// [_currentNode]. | 167 /// [_currentNode]. |
| 157 /// | 168 /// |
| 158 /// By default, the first frame of the first trace will be the line where | 169 /// By default, the first frame of the first trace will be the line where |
| 159 /// [_createNode] is called. If [level] is passed, the first trace will start | 170 /// [_createNode] is called. If [level] is passed, the first trace will start |
| 160 /// that many frames up instead. | 171 /// that many frames up instead. |
| 161 _Node _createNode([int level=0]) => | 172 _Node _createNode([int level=0]) => |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 Chain toChain() { | 207 Chain toChain() { |
| 197 var nodes = <Trace>[]; | 208 var nodes = <Trace>[]; |
| 198 var node = this; | 209 var node = this; |
| 199 while (node != null) { | 210 while (node != null) { |
| 200 nodes.add(node.trace); | 211 nodes.add(node.trace); |
| 201 node = node.previous; | 212 node = node.previous; |
| 202 } | 213 } |
| 203 return new Chain(nodes); | 214 return new Chain(nodes); |
| 204 } | 215 } |
| 205 } | 216 } |
| OLD | NEW |