js: fix async macros on windows (#20903)

This commit is contained in:
Meghan Denny
2025-07-08 20:23:25 -08:00
committed by GitHub
parent a63f09784e
commit 36bedb0bbc
4 changed files with 19 additions and 1 deletions

View File

@@ -118,6 +118,7 @@ pub const MacroContext = struct {
}
macro.vm.enableMacroMode();
defer macro.vm.disableMacroMode();
macro.vm.eventLoop().ensureWaker();
const Wrapper = struct {
args: std.meta.ArgsTuple(@TypeOf(Macro.Runner.run)),
@@ -193,6 +194,7 @@ pub fn init(
};
vm.enableMacroMode();
vm.eventLoop().ensureWaker();
const loaded_result = try vm.loadMacroEntryPoint(input_specifier, function_name, specifier, hash);

View File

@@ -314,7 +314,7 @@ pub fn tickConcurrentWithCount(this: *EventLoop) usize {
return this.tasks.count - start_count;
}
pub inline fn usocketsLoop(this: *const EventLoop) *uws.Loop {
pub fn usocketsLoop(this: *const EventLoop) *uws.Loop {
if (comptime Environment.isWindows) {
return this.uws_loop.?;
}
@@ -553,6 +553,11 @@ pub fn ensureWaker(this: *EventLoop) void {
// _ = actual.addPostHandler(*JSC.EventLoop, this, JSC.EventLoop.afterUSocketsTick);
// _ = actual.addPreHandler(*JSC.VM, this.virtual_machine.jsc, JSC.VM.drainMicrotasks);
}
if (comptime Environment.isWindows) {
if (this.uws_loop == null) {
this.uws_loop = bun.uws.Loop.get();
}
}
bun.uws.Loop.get().internal_loop_data.setParentEventLoop(bun.JSC.EventLoopHandle.init(this));
}

View File

@@ -8,6 +8,7 @@ import defaultMacro, {
identity,
identity as identity1,
identity as identity2,
ireturnapromise,
} from "./macro.ts" assert { type: "macro" };
import * as macros from "./macro.ts" assert { type: "macro" };
@@ -124,3 +125,7 @@ test("namespace import", () => {
// test("template string latin1", () => {
// expect(identity(`©${""}`)).toBe("©");
// });
test("ireturnapromise", async () => {
expect(await ireturnapromise()).toEqual("aaa");
});

View File

@@ -17,3 +17,9 @@ export function addStringsUTF16(arg: string) {
export default function() {
return "defaultdefaultdefault";
}
export async function ireturnapromise() {
const { promise, resolve } = Promise.withResolvers();
setTimeout(() => resolve("aaa"), 100);
return promise;
}