diff options
author | 2022-07-05 00:55:43 -0700 | |
---|---|---|
committer | 2022-07-05 00:55:43 -0700 | |
commit | 18290dee8b7e338e5ee1a33348fdf27275b91ec5 (patch) | |
tree | 81a37082b7d8571c5ae6fbac10a64e770889830c /src/bun.js/javascript.zig | |
parent | 9137862bc7777ce5fed0e155e11eb5d04957a839 (diff) | |
download | bun-18290dee8b7e338e5ee1a33348fdf27275b91ec5.tar.gz bun-18290dee8b7e338e5ee1a33348fdf27275b91ec5.tar.zst bun-18290dee8b7e338e5ee1a33348fdf27275b91ec5.zip |
[jsc] More careful code in dynamic require
Diffstat (limited to 'src/bun.js/javascript.zig')
-rw-r--r-- | src/bun.js/javascript.zig | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index 0908505a3..90356fafa 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -1074,18 +1074,18 @@ pub const VirtualMachine = struct { jsc_vm.bundler.linker.import_counter = 0; var printer = source_code_printer.?.*; - defer source_code_printer.?.* = printer; printer.ctx.reset(); - var written: usize = 0; - - written = try jsc_vm.bundler.printWithSourceMap( - parse_result, - @TypeOf(&printer), - &printer, - .esm_ascii, - SavedSourceMap.SourceMapHandler.init(&jsc_vm.source_mappings), - ); + const written = brk: { + defer source_code_printer.?.* = printer; + break :brk try jsc_vm.bundler.printWithSourceMap( + parse_result, + @TypeOf(&printer), + &printer, + .esm_ascii, + SavedSourceMap.SourceMapHandler.init(&jsc_vm.source_mappings), + ); + }; if (written == 0) { return error.PrintingErrorWriteFailed; @@ -1097,11 +1097,14 @@ pub const VirtualMachine = struct { return ResolvedSource{ .allocator = null, - .source_code = ZigString.init(printer.ctx.writtenWithoutTrailingZero()), + .source_code = ZigString.init(try default_allocator.dupe(u8, printer.ctx.getWritten())), .specifier = ZigString.init(specifier), .source_url = ZigString.init(path.text), - // TODO: change hash to a bitfield - .hash = 1, + // // TODO: change hash to a bitfield + // .hash = 1, + + // having JSC own the memory causes crashes + .hash = 0, }; }, // provideFetch() should be called |