Skip to content

Commit bf3e8e9

Browse files
rakudramaCommit Queue
authored andcommitted
[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 <[email protected]> Commit-Queue: Stephen Adams <[email protected]>
1 parent b243e6a commit bf3e8e9

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

pkg/wasm_builder/lib/src/ir/module.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ class Module implements Serializable {
119119
SourceMapSection(sourceMapUrl).serialize(s);
120120
}
121121

122-
static Module deserialize(Deserializer d) {
122+
static (Map<int, List<Deserializer>>, Map<String, List<Deserializer>>)
123+
_deserializeTopLevel(Deserializer d) {
123124
final preamble = d.readBytes(8);
124125
if (preamble[0] != 0x00 ||
125126
preamble[1] != 0x61 ||
@@ -151,6 +152,12 @@ class Module implements Serializable {
151152
}
152153
}
153154

155+
return (sections, customSections);
156+
}
157+
158+
static Module deserialize(Deserializer d) {
159+
final (sections, customSections) = _deserializeTopLevel(d);
160+
154161
final Module module = Module.uninitialized();
155162

156163
// We read the sections in the order they should be in the binary.
@@ -235,6 +242,14 @@ class Module implements Serializable {
235242
);
236243
}
237244

245+
/// Deserialize just the `sourceMapUrl` section of a module as a [Uri].
246+
static Uri? deserializeSourceMapUrl(Deserializer d) {
247+
final (sections, customSections) = _deserializeTopLevel(d);
248+
final sourceMapUrl = SourceMapSection.deserialize(
249+
customSections[SourceMapSection.customSectionName]?.single);
250+
return sourceMapUrl;
251+
}
252+
238253
String printAsWat() {
239254
final mp = ModulePrinter(this);
240255

0 commit comments

Comments
 (0)