Handle StackOverflows (#49629)
This commit is contained in:
parent
f2865090fd
commit
e7984bd4f6
@ -59,6 +59,18 @@ class StackFrame {
|
|||||||
source: '<asynchronous suspension>',
|
source: '<asynchronous suspension>',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// A stack frame representing a Dart elided stack overflow frame.
|
||||||
|
static const StackFrame stackOverFlowElision = StackFrame(
|
||||||
|
number: -1,
|
||||||
|
column: -1,
|
||||||
|
line: -1,
|
||||||
|
method: '...',
|
||||||
|
packageScheme: '',
|
||||||
|
package: '',
|
||||||
|
packagePath: '',
|
||||||
|
source: '...',
|
||||||
|
);
|
||||||
|
|
||||||
/// Parses a list of [StackFrame]s from a [StackTrace] object.
|
/// Parses a list of [StackFrame]s from a [StackTrace] object.
|
||||||
///
|
///
|
||||||
/// This is normally useful with [StackTrace.current].
|
/// This is normally useful with [StackTrace.current].
|
||||||
@ -113,6 +125,8 @@ class StackFrame {
|
|||||||
assert(line != null);
|
assert(line != null);
|
||||||
if (line == '<asynchronous suspension>') {
|
if (line == '<asynchronous suspension>') {
|
||||||
return asynchronousSuspension;
|
return asynchronousSuspension;
|
||||||
|
} else if (line == '...') {
|
||||||
|
return stackOverFlowElision;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Web frames.
|
// Web frames.
|
||||||
|
@ -47,6 +47,28 @@ void main() {
|
|||||||
webStackTraceFrames,
|
webStackTraceFrames,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Parses ...', () {
|
||||||
|
expect(
|
||||||
|
StackFrame.fromStackTraceLine('...'),
|
||||||
|
StackFrame.stackOverFlowElision,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Live handling of Stack Overflows', () {
|
||||||
|
void overflow(int seed) {
|
||||||
|
overflow(seed + 1);
|
||||||
|
}
|
||||||
|
bool overflowed = false;
|
||||||
|
try {
|
||||||
|
overflow(1);
|
||||||
|
} on StackOverflowError catch (e, stack) {
|
||||||
|
overflowed = true;
|
||||||
|
final List<StackFrame> frames = StackFrame.fromStackTrace(stack);
|
||||||
|
expect(frames.contains(StackFrame.stackOverFlowElision), true);
|
||||||
|
}
|
||||||
|
expect(overflowed, true);
|
||||||
|
}, skip: isBrowser);
|
||||||
}
|
}
|
||||||
|
|
||||||
const String stackString = '''#0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:42:39)
|
const String stackString = '''#0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:42:39)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user