mirror of
https://github.com/oven-sh/bun
synced 2026-02-16 05:42:43 +00:00
js: fix async macros on windows (#20903)
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user