Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1018)

Unified Diff: pkg/dev_compiler/web/stack_trace_mapper.dart

Issue 2747513003: Inline source maps as part of each script. (Closed)
Patch Set: Inline source maps as part of each script. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/rtti.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/web/stack_trace_mapper.dart
diff --git a/pkg/dev_compiler/web/stack_trace_mapper.dart b/pkg/dev_compiler/web/stack_trace_mapper.dart
index 557e6fd6ddf1e4db0aaf3e67a442de81140b8549..e863fa7b44215574128f13627e61ea8d829ecb64 100644
--- a/pkg/dev_compiler/web/stack_trace_mapper.dart
+++ b/pkg/dev_compiler/web/stack_trace_mapper.dart
@@ -39,13 +39,14 @@ typedef void ReadyCallback();
external set dartStackTraceUtility(DartStackTraceUtility value);
typedef String StackTraceMapper(String stackTrace);
-typedef dynamic LoadSourceMaps(List<String> scripts, ReadyCallback callback);
+typedef String SourceMapProvider(String modulePath);
+typedef String SetSourceMapProvider(SourceMapProvider provider);
@JS()
@anonymous
class DartStackTraceUtility {
external factory DartStackTraceUtility(
- {StackTraceMapper mapper, LoadSourceMaps loadSourceMaps});
+ {StackTraceMapper mapper, SetSourceMapProvider setSourceMapProvider});
}
/// Source mapping that is waits to parse source maps until they match the uri
@@ -56,11 +57,9 @@ class DartStackTraceUtility {
/// LazyMapping is used.
class LazyMapping extends Mapping {
MappingBundle _bundle = new MappingBundle();
+ SourceMapProvider _provider;
- /// Map from url to unparsed source map.
- Map<String, String> _sourceMaps;
-
- LazyMapping(this._sourceMaps) {}
+ LazyMapping(this._provider);
List toJson() => _bundle.toJson();
@@ -69,17 +68,24 @@ class LazyMapping extends Mapping {
if (uri == null) {
throw new ArgumentError.notNull('uri');
}
- var rawMap = _sourceMaps[uri];
-
- if (rawMap != null && rawMap.isNotEmpty && !_bundle.containsMapping(uri)) {
- SingleMapping mapping = parse(rawMap);
- mapping
- ..targetUrl = uri
- ..sourceRoot = '${path.dirname(uri)}/';
- _bundle.addMapping(mapping);
- }
- return _bundle.spanFor(line, column, files: files, uri: uri);
+ if (!_bundle.containsMapping(uri)) {
+ var rawMap = _provider(uri);
+ if (rawMap != null) {
+ SingleMapping mapping = parse(rawMap);
+ mapping
+ ..targetUrl = uri
+ ..sourceRoot = '${path.dirname(uri)}/';
+ _bundle.addMapping(mapping);
+ }
+ }
+ var span = _bundle.spanFor(line, column, files: files, uri: uri);
+ // 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;
+ if (pathSegments.isNotEmpty && pathSegments.last == 'null') return null;
+ return span;
}
}
@@ -94,18 +100,6 @@ String _toSourceMapLocation(String url) {
return uri.replace(path: '${uri.path}.map').toString();
}
-/// Load a source map for the specified url.
-///
-/// Returns a null string rather than reporting an error if the file cannot be
-/// found as we don't want to throw errors if a few source maps are missing.
-Future<String> loadSourceMap(String url) async {
- try {
- return await HttpRequest.getString(_toSourceMapLocation(url));
- } catch (e) {
- return null;
- }
-}
-
LazyMapping _mapping;
String mapper(String rawStackTrace) {
@@ -117,18 +111,13 @@ String mapper(String rawStackTrace) {
return mapStackTrace(_mapping, new Trace.parse(rawStackTrace)).toString();
}
-Future<Null> loadSourceMaps(
- List<String> scripts, ReadyCallback callback) async {
- List<Future<String>> sourceMapFutures =
- scripts.map((script) => loadSourceMap(script)).toList();
- List<String> sourceMaps = await Future.wait(sourceMapFutures);
- _mapping = new LazyMapping(new Map.fromIterables(scripts, sourceMaps));
- callback();
+void setSourceMapProvider(SourceMapProvider provider) async {
+ _mapping = new LazyMapping(provider);
}
main() {
// Register with DDC.
dartStackTraceUtility = new DartStackTraceUtility(
mapper: allowInterop(mapper),
- loadSourceMaps: allowInterop(loadSourceMaps));
+ setSourceMapProvider: allowInterop(setSourceMapProvider));
}
« no previous file with comments | « pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/rtti.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698