From 7547ed04fb3040182ffe24d03cea0812fc0935b2 Mon Sep 17 00:00:00 2001 From: Ben Grant Date: Thu, 20 Mar 2025 17:19:23 -0700 Subject: [PATCH] Enable non-null VMHolder vm assertion in release --- src/bun.js/bindings/JSGlobalObject.zig | 30 ++++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/bun.js/bindings/JSGlobalObject.zig b/src/bun.js/bindings/JSGlobalObject.zig index 78552c1647..09c8027941 100644 --- a/src/bun.js/bindings/JSGlobalObject.zig +++ b/src/bun.js/bindings/JSGlobalObject.zig @@ -486,21 +486,23 @@ pub const JSGlobalObject = opaque { } pub fn bunVM(this: *JSGlobalObject) *JSC.VirtualMachine { - if (comptime bun.Environment.allow_assert) { - if (JSC.VirtualMachine.VMHolder.vm) |vm_holder_vm| { - bun.assertf( - this.bunVMUnsafe() == @as(*anyopaque, @ptrCast(vm_holder_vm)), - \\expected bunVMUnsafe() to be {x} but got {x}. - \\VMHolder and JSC__JSGlobalObject__bunVM disagree on the Bun VM for global object {x}. - \\either there is an inconsistency with the bindings, or bunVM() was called on the wrong thread. - , - .{ @intFromPtr(vm_holder_vm), @intFromPtr(this.bunVMUnsafe()), @intFromPtr(this) }, - ); - } else { - @panic("This thread lacks a Bun VM"); - } + const vm_holder_vm = JSC.VirtualMachine.VMHolder.vm orelse + @panic("internal assertion failure: bunVM() called on thread with no VM"); + const global_object_vm = this.bunVMConcurrently(); + if (bun.Environment.allow_assert) { + bun.assertf(global_object_vm == vm_holder_vm, + \\Bun VM for global object {x} mismatched: + \\{x} in VMHolder + \\{x} from JSC__JSGlobalObject__bunVM + \\either there is an inconsistency with the bindings, or bunVM() was called on the wrong thread. + , .{ + @intFromPtr(this), + @intFromPtr(vm_holder_vm), + @intFromPtr(global_object_vm), + }); } - return @ptrCast(@alignCast(this.bunVMUnsafe())); + + return global_object_vm; } pub const TryBunVMResult = union(enum) {