[wasm_builder] Add method to deserialize just the sourceMapUrl
It is useful to be able to extract the sourceMapUrl without parsing
the rest of the module.
Change-Id: I595b615b07015597fc1b082aa320887d86f16204
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/455542
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
diff --git a/pkg/wasm_builder/lib/src/ir/module.dart b/pkg/wasm_builder/lib/src/ir/module.dart
index 112e514..000e3d9 100644
--- a/pkg/wasm_builder/lib/src/ir/module.dart
+++ b/pkg/wasm_builder/lib/src/ir/module.dart
@@ -119,7 +119,8 @@
SourceMapSection(sourceMapUrl).serialize(s);
}
- static Module deserialize(Deserializer d) {
+ static (Map<int, List<Deserializer>>, Map<String, List<Deserializer>>)
+ _deserializeTopLevel(Deserializer d) {
final preamble = d.readBytes(8);
if (preamble[0] != 0x00 ||
preamble[1] != 0x61 ||
@@ -151,6 +152,12 @@
}
}
+ return (sections, customSections);
+ }
+
+ static Module deserialize(Deserializer d) {
+ final (sections, customSections) = _deserializeTopLevel(d);
+
final Module module = Module.uninitialized();
// We read the sections in the order they should be in the binary.
@@ -235,6 +242,14 @@
);
}
+ /// Deserialize just the `sourceMapUrl` section of a module as a [Uri].
+ static Uri? deserializeSourceMapUrl(Deserializer d) {
+ final (sections, customSections) = _deserializeTopLevel(d);
+ final sourceMapUrl = SourceMapSection.deserialize(
+ customSections[SourceMapSection.customSectionName]?.single);
+ return sourceMapUrl;
+ }
+
String printAsWat() {
final mp = ModulePrinter(this);