diff options
author | 2021-05-08 14:23:52 -0700 | |
---|---|---|
committer | 2021-05-08 14:23:52 -0700 | |
commit | 18794b18b32e5cfeb190f29fe29590d742a327e8 (patch) | |
tree | b353a9a2f4893af782b5cdb95c68a338c26bd080 /src | |
parent | e70ac2ce825ecf5f2d6aa16152801612bf23be8d (diff) | |
download | bun-18794b18b32e5cfeb190f29fe29590d742a327e8.tar.gz bun-18794b18b32e5cfeb190f29fe29590d742a327e8.tar.zst bun-18794b18b32e5cfeb190f29fe29590d742a327e8.zip |
Fix for loop initializer
Former-commit-id: 6b863d5d51f7f1bc293e56ed395fe4ad49174f63
Diffstat (limited to 'src')
-rw-r--r-- | src/api/demo/lib/api.ts | 2 | ||||
-rw-r--r-- | src/js_printer.zig | 6 | ||||
-rw-r--r-- | src/logger.zig | 4 | ||||
-rw-r--r-- | src/main_wasm.zig | 27 | ||||
-rw-r--r-- | src/test/fixtures/for-loop-bug.js | 5 |
5 files changed, 32 insertions, 12 deletions
diff --git a/src/api/demo/lib/api.ts b/src/api/demo/lib/api.ts index d2e19218e..e8a626b10 100644 --- a/src/api/demo/lib/api.ts +++ b/src/api/demo/lib/api.ts @@ -176,7 +176,7 @@ export class ESDev { const resp_ptr = ESDev.wasm_exports.transform(ptr); var _bb = new ByteBuffer(this._wasmPtrToSlice(resp_ptr)); const response = Schema.decodeTransformResponse(_bb); - ESDev.wasm_exports.cycle(); + ESDev.wasm_exports.cycle(ptr, resp_ptr); return response; } } diff --git a/src/js_printer.zig b/src/js_printer.zig index 8322d8e3a..c858a45f2 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -2305,6 +2305,12 @@ pub fn NewPrinter(comptime ascii_only: bool) type { p.printSpace(); p.print("("); + if (s.init) |init_| { + p.printForLoopInit(init_); + } + + p.print(";"); + if (s.test_) |test_| { p.printExpr(test_, .lowest, ExprFlag.None()); } diff --git a/src/logger.zig b/src/logger.zig index c82f2d85d..1b286380f 100644 --- a/src/logger.zig +++ b/src/logger.zig @@ -480,8 +480,8 @@ test "ErrorPosition" { const source = Source{ .contents = @embedFile("./test/fixtures/simple.jsx"), .path = fs.Path.init("/src/test/fixtures/simple.jsx"), .identifier_name = "simple" }; const error_position = source.initErrorPosition(Loc{ .start = 979 }); - std.testing.expectEqual(973, error_position.line_start); - std.testing.expectEqual(1016, error_position.line_end); + std.testing.expectEqual(@as(usize, 973), @as(usize, error_position.line_start)); + std.testing.expectEqual(@as(usize, 1016), @as(usize, error_position.line_end)); var msgs = ArrayList(Msg).init(std.testing.allocator); var log = Log{ .msgs = msgs }; diff --git a/src/main_wasm.zig b/src/main_wasm.zig index 026e310eb..250f5c444 100644 --- a/src/main_wasm.zig +++ b/src/main_wasm.zig @@ -147,7 +147,7 @@ pub extern fn console_warn(abi: Uint8Array.Abi) void; pub extern fn console_info(abi: Uint8Array.Abi) void; const ZeeAlloc = zee.ZeeAlloc(.{}); -var arena: std.heap.ArenaAllocator = undefined; +var zee_instance: ZeeAlloc = undefined; pub const Exports = struct { fn init() callconv(.C) i32 { // const Gpa = std.heap.GeneralPurposeAllocator(.{}); @@ -183,11 +183,10 @@ pub const Exports = struct { ) catch return -1; if (alloc.needs_setup) { - arena = std.heap.ArenaAllocator.init(ZeeAlloc.wasm_allocator); - alloc.setup(&arena.allocator) catch return -1; + alloc.setup(ZeeAlloc.wasm_allocator) catch return -1; } - _ = @wasmMemoryGrow(0, 300); + _ = @wasmMemoryGrow(0, 600); Output.printErrorable("Initialized.", .{}) catch |err| { var name = alloc.static.alloc(u8, @errorName(err).len) catch unreachable; @@ -204,14 +203,24 @@ pub const Exports = struct { // Output.print("Req {s}", .{req}); // alloc.dynamic.free(Uint8Array.toSlice(abi)); const resp = api.?.transform(req) catch return Uint8Array.empty(); - return Uint8Array.encode(Schema.TransformResponse, resp) catch return Uint8Array.empty(); + alloc.dynamic.free(req.contents); + + if (req.path) |path| alloc.dynamic.free(path); + + var res = Uint8Array.encode(Schema.TransformResponse, resp) catch return Uint8Array.empty(); + // this is stupid. + for (resp.files) |file| { + alloc.dynamic.free(file.data); + alloc.dynamic.free(file.path); + } + + return res; } // Reset - fn cycle() callconv(.C) void { - arena.deinit(); - arena = std.heap.ArenaAllocator.init(ZeeAlloc.wasm_allocator); - alloc.setup(&arena.allocator) catch return; + fn cycle(req: Uint8Array.Abi, res: Uint8Array.Abi) callconv(.C) void { + alloc.dynamic.free(Uint8Array.toSlice(res)); + alloc.dynamic.free(Uint8Array.toSlice(req)); } fn malloc(size: usize) callconv(.C) ?*c_void { diff --git a/src/test/fixtures/for-loop-bug.js b/src/test/fixtures/for-loop-bug.js new file mode 100644 index 000000000..6539caaa0 --- /dev/null +++ b/src/test/fixtures/for-loop-bug.js @@ -0,0 +1,5 @@ +// For loop was missing initializer +for (let i = 0; i < 100; i++) { + console.log("hi"); + console.log("hey"); +} |