Updating pkg:sourcemap_testing function resolution for method definition syntax.

Change-Id: Ia3aa2d64226fa178eee72787c12ca0569390eb67
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206327
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
This commit is contained in:
Mark Zhou 2021-07-08 22:59:17 +00:00 committed by commit-bot@chromium.org
parent 1bfc46ec2b
commit 978c4fe6ef

View file

@ -436,12 +436,39 @@ class LineException {
TargetEntry findEnclosingFunction( TargetEntry findEnclosingFunction(
String sources, SourceFile file, int start, SingleMapping mapping) { String sources, SourceFile file, int start, SingleMapping mapping) {
if (sources == null) return null; if (sources == null) return null;
int index = sources.lastIndexOf(': function(', start); var index = start;
if (index < 0) return null; while (true) {
index += 2; index = nextDeclarationCandidate(sources, index);
var line = file.getLine(index); if (index < 0) return null;
var lineEntry = _findLineInternal(mapping, line); var line = file.getLine(index);
return _findColumn(line, file.getColumn(index), lineEntry); var lineEntry = _findLineInternal(mapping, line);
var result = _findColumn(line, file.getColumn(index), lineEntry);
if (result?.column == file.getColumn(index)) return result;
index--;
}
}
/// Returns the index of a candidate location of a enclosing function
/// declaration. We try to find the beginning of a `function` keyword or the
/// `(` of an ES6 method definition, but the search contains some false
/// positives. To rule out false positives, [findEnclosingFunction]
/// validates that the returned location contains a source-map entry, searching
/// for another candidate if not.
int nextDeclarationCandidate(String sources, int start) {
var indexForFunctionKeyword = sources.lastIndexOf('function', start);
// We attempt to identify potential method definitions by looking for any '('
// that precedes a '{'. This method will fail if 1) Dart2JS starts emitting
// functions with initializers or 2) sourcemap boundaries appear at '(' for
// non-method-definition constructs.
var indexForMethodDefinition = sources.lastIndexOf('{', start);
if (indexForFunctionKeyword > indexForMethodDefinition ||
indexForFunctionKeyword < 0) {
return indexForFunctionKeyword;
}
indexForMethodDefinition = sources.lastIndexOf('(', indexForMethodDefinition);
return indexForFunctionKeyword > indexForMethodDefinition
? indexForFunctionKeyword
: indexForMethodDefinition;
} }
Map<int, List<FrameEntry>> _loadInlinedFrameData( Map<int, List<FrameEntry>> _loadInlinedFrameData(