mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 09:43:08 +00:00
[ddc] Migrate stack trace utilities to null safety
Issue: https://github.com/dart-lang/sdk/issues/46617 Change-Id: Idfd614e3bcc4e3e8ae1597d69c97d007b7efd306 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/250351 Commit-Queue: Nicholas Shahan <nshahan@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
parent
4c6fcad188
commit
017401cb35
2 changed files with 14 additions and 16 deletions
|
@ -2,8 +2,7 @@
|
|||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'package:collection/collection.dart' show IterableNullableExtension;
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:source_maps/source_maps.dart';
|
||||
import 'package:stack_trace/stack_trace.dart';
|
||||
|
@ -17,7 +16,7 @@ import 'package:stack_trace/stack_trace.dart';
|
|||
/// [roots] are the paths (usually `http:` URI strings) that DDC applications
|
||||
/// are served from. This is used to identify sdk and package URIs.
|
||||
StackTrace mapStackTrace(Mapping sourceMap, StackTrace stackTrace,
|
||||
{List<String> roots}) {
|
||||
{required List<String?> roots}) {
|
||||
if (stackTrace is Chain) {
|
||||
return Chain(stackTrace.traces.map((trace) {
|
||||
return Trace.from(mapStackTrace(sourceMap, trace, roots: roots));
|
||||
|
@ -35,8 +34,8 @@ StackTrace mapStackTrace(Mapping sourceMap, StackTrace stackTrace,
|
|||
|
||||
// Subtract 1 because stack traces use 1-indexed lines and columns and
|
||||
// source maps uses 0-indexed.
|
||||
var span = sourceMap.spanFor(frame.line - 1, column - 1,
|
||||
uri: frame.uri?.toString());
|
||||
var span = sourceMap.spanFor(frame.line! - 1, column - 1,
|
||||
uri: frame.uri.toString());
|
||||
|
||||
// If we can't find a source span, ignore the frame. It's probably something
|
||||
// internal that the user doesn't care about.
|
||||
|
@ -68,8 +67,8 @@ StackTrace mapStackTrace(Mapping sourceMap, StackTrace stackTrace,
|
|||
}
|
||||
|
||||
return Frame(Uri.parse(sourceUrl), span.start.line + 1,
|
||||
span.start.column + 1, _prettifyMember(frame.member));
|
||||
}).where((frame) => frame != null));
|
||||
span.start.column + 1, _prettifyMember(frame.member!));
|
||||
}).whereNotNull());
|
||||
}
|
||||
|
||||
final escapedPipe = '\$124';
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
/// Standalone utility that manages loading source maps for all Dart scripts
|
||||
/// on the page compiled with DDC.
|
||||
///
|
||||
|
@ -49,7 +47,7 @@ typedef SetSourceMapProvider = void Function(SourceMapProvider);
|
|||
@anonymous
|
||||
class DartStackTraceUtility {
|
||||
external factory DartStackTraceUtility(
|
||||
{StackTraceMapper mapper, SetSourceMapProvider setSourceMapProvider});
|
||||
{StackTraceMapper? mapper, SetSourceMapProvider? setSourceMapProvider});
|
||||
}
|
||||
|
||||
@JS('JSON.stringify')
|
||||
|
@ -70,8 +68,8 @@ class LazyMapping extends Mapping {
|
|||
List toJson() => _bundle.toJson();
|
||||
|
||||
@override
|
||||
SourceMapSpan spanFor(int line, int column,
|
||||
{Map<String, SourceFile> files, String uri}) {
|
||||
SourceMapSpan? spanFor(int line, int column,
|
||||
{Map<String, SourceFile>? files, String? uri}) {
|
||||
if (uri == null) {
|
||||
throw ArgumentError.notNull('uri');
|
||||
}
|
||||
|
@ -91,24 +89,25 @@ class LazyMapping extends Mapping {
|
|||
// TODO(jacobr): we shouldn't have to filter out invalid sourceUrl entries
|
||||
// here.
|
||||
if (span == null || span.start.sourceUrl == null) return null;
|
||||
var pathSegments = span.start.sourceUrl.pathSegments;
|
||||
var pathSegments = span.start.sourceUrl!.pathSegments;
|
||||
if (pathSegments.isNotEmpty && pathSegments.last == 'null') return null;
|
||||
return span;
|
||||
}
|
||||
}
|
||||
|
||||
LazyMapping _mapping;
|
||||
LazyMapping? _mapping;
|
||||
|
||||
List<String> roots = rootDirectories.map((s) => '$s').toList();
|
||||
|
||||
String mapper(String rawStackTrace) {
|
||||
if (_mapping == null) {
|
||||
var mapping = _mapping;
|
||||
if (mapping == null) {
|
||||
// This should not happen if the user has waited for the ReadyCallback
|
||||
// to start the application.
|
||||
throw StateError('Source maps are not done loading.');
|
||||
}
|
||||
var trace = Trace.parse(rawStackTrace);
|
||||
return mapStackTrace(_mapping, trace, roots: roots).toString();
|
||||
return mapStackTrace(mapping, trace, roots: roots).toString();
|
||||
}
|
||||
|
||||
void setSourceMapProvider(SourceMapProvider provider) {
|
||||
|
|
Loading…
Reference in a new issue