diff options
author | 2023-08-23 22:22:55 -0700 | |
---|---|---|
committer | 2023-08-23 22:22:55 -0700 | |
commit | ad326b77342dd3d8585a30b7da803d32f9c11fe2 (patch) | |
tree | fda755bf32e4361eebbf4228994204ae031cae80 /src/bun.js/javascript.zig | |
parent | aa08c35c062d0db004b9aaedcd8d427eda8aa7c7 (diff) | |
download | bun-ad326b77342dd3d8585a30b7da803d32f9c11fe2.tar.gz bun-ad326b77342dd3d8585a30b7da803d32f9c11fe2.tar.zst bun-ad326b77342dd3d8585a30b7da803d32f9c11fe2.zip |
[Inspector] Fix bug with sourcemaps including internal metadata bytes
Diffstat (limited to 'src/bun.js/javascript.zig')
-rw-r--r-- | src/bun.js/javascript.zig | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index 492b9fbee..062bd52a2 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -113,6 +113,8 @@ const ParsedSourceMap = SourceMap.Mapping.ParsedSourceMap; const MappingList = SourceMap.Mapping.List; pub const SavedSourceMap = struct { + pub const vlq_offset = 24; + // For bun.js, we store the number of mappings and how many bytes the final list is at the beginning of the array // The first 8 bytes are the length of the array // The second 8 bytes are the number of mappings @@ -120,7 +122,7 @@ pub const SavedSourceMap = struct { data: [*]u8, pub fn vlq(this: SavedMappings) []u8 { - return this.data[24..this.len()]; + return this.data[vlq_offset..this.len()]; } pub inline fn len(this: SavedMappings) usize { @@ -134,7 +136,7 @@ pub const SavedSourceMap = struct { pub fn toMapping(this: SavedMappings, allocator: Allocator, path: string) anyerror!ParsedSourceMap { const result = SourceMap.Mapping.parse( allocator, - this.data[24..this.len()], + this.data[vlq_offset..this.len()], @as(usize, @bitCast(this.data[8..16].*)), 1, @as(usize, @bitCast(this.data[16..24].*)), @@ -527,7 +529,7 @@ pub const VirtualMachine = struct { pub fn onChunk(this: *SourceMapHandlerGetter, chunk: SourceMap.Chunk, source: logger.Source) anyerror!void { var temp_json_buffer = bun.MutableString.initEmpty(bun.default_allocator); defer temp_json_buffer.deinit(); - temp_json_buffer = try chunk.printSourceMapContents(source, temp_json_buffer, true, true); + temp_json_buffer = try chunk.printSourceMapContentsAtOffset(source, temp_json_buffer, true, SavedSourceMap.vlq_offset, true); const source_map_url_prefix_start = "//# sourceMappingURL=data:application/json;base64,"; // TODO: do we need to %-encode the path? const source_url_len = source.path.text.len; |