Handle StackOverflows (#49629)

This commit is contained in:
Dan Field 2020-01-28 16:38:02 -08:00 committed by GitHub
parent f2865090fd
commit e7984bd4f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View file

@ -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.

View file

@ -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)