Skip to content

Commit

Permalink
Consolidate event loop initialization before VM
Browse files Browse the repository at this point in the history
  • Loading branch information
190n committed Jan 24, 2025
1 parent 46921ef commit ea53a88
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/bun.js/bindings/exports.zig
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ pub const ZigGlobalObject = extern struct {
pub const Interface: type = NewGlobalObject(JS.VirtualMachine);

pub fn create(
vm: *JSC.VirtualMachine,
console: *anyopaque,
context_id: i32,
mini_mode: bool,
eval_mode: bool,
worker_ptr: ?*anyopaque,
) *JSGlobalObject {
vm.eventLoop().ensureWaker();
const global = shim.cppFn("create", .{ console, context_id, mini_mode, eval_mode, worker_ptr });

// JSC might mess with the stack size.
Expand Down
6 changes: 3 additions & 3 deletions src/bun.js/javascript.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,6 @@ pub const VirtualMachine = struct {
vm.regular_event_loop.tasks.ensureUnusedCapacity(64) catch unreachable;
vm.regular_event_loop.concurrent_tasks = .{};
vm.event_loop = &vm.regular_event_loop;
vm.eventLoop().ensureWaker();

vm.transpiler.macro_context = null;
vm.transpiler.resolver.store_fd = false;
Expand All @@ -1957,6 +1956,7 @@ pub const VirtualMachine = struct {
VMHolder.main_thread_vm = vm;
}
vm.global = ZigGlobalObject.create(
vm,
vm.console,
if (opts.is_main_thread) -1 else std.math.maxInt(i32),
false,
Expand Down Expand Up @@ -2057,7 +2057,6 @@ pub const VirtualMachine = struct {
vm.regular_event_loop.tasks.ensureUnusedCapacity(64) catch unreachable;
vm.regular_event_loop.concurrent_tasks = .{};
vm.event_loop = &vm.regular_event_loop;
vm.eventLoop().ensureWaker();

vm.transpiler.macro_context = null;
vm.transpiler.resolver.store_fd = opts.store_fd;
Expand All @@ -2074,6 +2073,7 @@ pub const VirtualMachine = struct {
vm.transpiler.macro_context = js_ast.Macro.MacroContext.init(&vm.transpiler);

vm.global = ZigGlobalObject.create(
vm,
vm.console,
if (opts.is_main_thread) -1 else std.math.maxInt(i32),
opts.smol,
Expand Down Expand Up @@ -2218,7 +2218,6 @@ pub const VirtualMachine = struct {
vm.regular_event_loop.tasks.ensureUnusedCapacity(64) catch unreachable;
vm.regular_event_loop.concurrent_tasks = .{};
vm.event_loop = &vm.regular_event_loop;
vm.eventLoop().ensureWaker();
vm.hot_reload = worker.parent.hot_reload;
vm.transpiler.macro_context = null;
vm.transpiler.resolver.store_fd = opts.store_fd;
Expand All @@ -2240,6 +2239,7 @@ pub const VirtualMachine = struct {
vm.transpiler.macro_context = js_ast.Macro.MacroContext.init(&vm.transpiler);

vm.global = ZigGlobalObject.create(
vm,
vm.console,
@as(i32, @intCast(worker.execution_context_id)),
worker.mini,
Expand Down

0 comments on commit ea53a88

Please sign in to comment.