From 1e4625ea38eb13deb341d39a02f3cb5ff7341804 Mon Sep 17 00:00:00 2001 From: Jens Johansen Date: Wed, 22 Nov 2017 14:30:37 +0000 Subject: [PATCH] Small changes to stacktrace_helper to prepare for ddc usage Bug: Change-Id: Iab4fb0536456cded152646bf2725e8c918e4a8e8 Reviewed-on: https://dart-review.googlesource.com/23020 Reviewed-by: Johnni Winther Commit-Queue: Jens Johansen --- .../lib/src/stacktrace_helper.dart | 28 +++++++++++++------ .../dart2js/sourcemaps/stacktrace_test.dart | 3 +- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pkg/sourcemap_testing/lib/src/stacktrace_helper.dart b/pkg/sourcemap_testing/lib/src/stacktrace_helper.dart index 9ee7c425a60..4a2ebdac769 100644 --- a/pkg/sourcemap_testing/lib/src/stacktrace_helper.dart +++ b/pkg/sourcemap_testing/lib/src/stacktrace_helper.dart @@ -11,8 +11,7 @@ import 'package:source_maps/src/utils.dart'; import 'annotated_code_helper.dart'; -const String EXCEPTION_MARKER = '>ExceptionMarker<'; -const String INPUT_FILE_NAME = 'in.dart'; +const String INPUT_FILE_NAME = 'input.dart'; class Test { final String code; @@ -73,6 +72,9 @@ Test processTestCode(String code, Iterable configs) { /// function returns `true` if the compilation succeeded. typedef Future CompileFunc(String input, String output); +List emptyPreamble(input, output) => const []; +String identityConverter(String name) => name; + /// Tests the stack trace of [test] using the expectations for [config]. /// /// The [compile] function is called to compile the Dart code in [test] to @@ -92,9 +94,12 @@ Future testStackTrace(Test test, String config, CompileFunc compile, {bool printJs: false, bool writeJs: false, bool verbose: false, - List jsPreambles: const [], + List Function(String input, String output) jsPreambles: + emptyPreamble, List beforeExceptions: const [], - List afterExceptions: const []}) async { + List afterExceptions: const [], + bool useJsMethodNamesOnAbsence: false, + String Function(String name) jsNameConverter: identityConverter}) async { Expect.isTrue(test.expectationMap.keys.contains(config), "No expectations found for '$config' in ${test.expectationMap.keys}"); @@ -121,7 +126,7 @@ Future testStackTrace(Test test, String config, CompileFunc compile, } print("Running d8 $output"); List d8Arguments = []; - d8Arguments.addAll(jsPreambles); + d8Arguments.addAll(jsPreambles(input, output)); d8Arguments.add(output); ProcessResult runResult = Process.runSync(d8executable, d8Arguments); String out = '${runResult.stderr}\n${runResult.stdout}'; @@ -139,14 +144,16 @@ Future testStackTrace(Test test, String config, CompileFunc compile, List dartStackTrace = []; for (StackTraceLine line in jsStackTrace) { - TargetEntry targetEntry = _findColumn(line.lineNo - 1, line.columnNo - 1, - _findLine(sourceMap, line.lineNo - 1)); + TargetEntry targetEntry = _findColumn( + line.lineNo - 1, line.columnNo - 1, _findLine(sourceMap, line)); if (targetEntry == null || targetEntry.sourceUrlId == null) { dartStackTrace.add(line); } else { String methodName; if (targetEntry.sourceNameId != null) { methodName = sourceMap.names[targetEntry.sourceNameId]; + } else if (useJsMethodNamesOnAbsence) { + methodName = jsNameConverter(line.methodName); } String fileName; if (targetEntry.sourceUrlId != null) { @@ -321,7 +328,12 @@ class StackTraceLine { /// number is lower or equal to [line]. /// /// Copied from [SingleMapping._findLine]. -TargetLineEntry _findLine(SingleMapping sourceMap, int line) { +TargetLineEntry _findLine(SingleMapping sourceMap, StackTraceLine stLine) { + String filename = stLine.fileName + .substring(stLine.fileName.lastIndexOf(new RegExp("[\\\/]")) + 1); + if (sourceMap.targetUrl != filename) return null; + + int line = stLine.lineNo - 1; int index = binarySearch(sourceMap.lines, (e) => e.line > line); return (index <= 0) ? null : sourceMap.lines[index - 1]; } diff --git a/tests/compiler/dart2js/sourcemaps/stacktrace_test.dart b/tests/compiler/dart2js/sourcemaps/stacktrace_test.dart index f4a837cba6b..5480d3eec3b 100644 --- a/tests/compiler/dart2js/sourcemaps/stacktrace_test.dart +++ b/tests/compiler/dart2js/sourcemaps/stacktrace_test.dart @@ -94,7 +94,8 @@ Future runTest(Test test, String config, CompilationResult compilationResult = await entry.internalMain(arguments); return compilationResult.isSuccess; }, - jsPreambles: ['sdk/lib/_internal/js_runtime/lib/preambles/d8.js'], + jsPreambles: (input, output) => + ['sdk/lib/_internal/js_runtime/lib/preambles/d8.js'], afterExceptions: testAfterExceptions, beforeExceptions: beforeExceptions); }