mirror of
https://github.com/flutter/flutter
synced 2024-10-13 11:42:54 +00:00
Handle StackOverflows (#49629)
This commit is contained in:
parent
f2865090fd
commit
e7984bd4f6
|
@ -59,6 +59,18 @@ class StackFrame {
|
|||
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.
|
||||
///
|
||||
/// This is normally useful with [StackTrace.current].
|
||||
|
@ -113,6 +125,8 @@ class StackFrame {
|
|||
assert(line != null);
|
||||
if (line == '<asynchronous suspension>') {
|
||||
return asynchronousSuspension;
|
||||
} else if (line == '...') {
|
||||
return stackOverFlowElision;
|
||||
}
|
||||
|
||||
// Web frames.
|
||||
|
|
|
@ -47,6 +47,28 @@ void main() {
|
|||
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)
|
||||
|
|
Loading…
Reference in a new issue