aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/javascript.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-08-29 21:17:56 -0700
committerGravatar GitHub <noreply@github.com> 2023-08-29 21:17:56 -0700
commitc028b206bce3f9b5c3cba7899c6bf34856efe43f (patch)
treec5248e13572ad76ebff5952308f01b788cde71ed /src/bun.js/javascript.zig
parenta846852818278641cf33413ce784adf2fc0e2e52 (diff)
downloadbun-c028b206bce3f9b5c3cba7899c6bf34856efe43f.tar.gz
bun-c028b206bce3f9b5c3cba7899c6bf34856efe43f.tar.zst
bun-c028b206bce3f9b5c3cba7899c6bf34856efe43f.zip
Fix assertion failure in spawn-related tests (#4400)
* Clean up some of the event loop code * Support timeouts * Defer freeing FilePoll --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/javascript.zig')
-rw-r--r--src/bun.js/javascript.zig25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig
index 59b10a75a..90a3bbc66 100644
--- a/src/bun.js/javascript.zig
+++ b/src/bun.js/javascript.zig
@@ -449,6 +449,9 @@ pub const VirtualMachine = struct {
transpiler_store: JSC.RuntimeTranspilerStore,
+ after_event_loop_callback_ctx: ?*anyopaque = null,
+ after_event_loop_callback: ?OpaqueCallback = null,
+
/// The arguments used to launch the process _after_ the script name and bun and any flags applied to Bun
/// "bun run foo --bar"
/// ["--bar"]
@@ -479,7 +482,6 @@ pub const VirtualMachine = struct {
active_tasks: usize = 0,
rare_data: ?*JSC.RareData = null,
- us_loop_reference_count: usize = 0,
is_us_loop_entered: bool = false,
pending_internal_promise: *JSC.JSInternalPromise = undefined,
auto_install_dependencies: bool = false,
@@ -533,6 +535,21 @@ pub const VirtualMachine = struct {
return this.rareData().mimeTypeFromString(this.allocator, str);
}
+ pub fn onAfterEventLoop(this: *VirtualMachine) void {
+ if (this.after_event_loop_callback) |cb| {
+ var ctx = this.after_event_loop_callback_ctx;
+ this.after_event_loop_callback = null;
+ this.after_event_loop_callback_ctx = null;
+ cb(ctx);
+ }
+ }
+
+ pub fn isEventLoopAlive(vm: *const VirtualMachine) bool {
+ return vm.active_tasks > 0 or
+ vm.event_loop_handle.?.active > 0 or
+ vm.event_loop.tasks.count > 0;
+ }
+
const SourceMapHandlerGetter = struct {
vm: *VirtualMachine,
printer: *js_printer.BufferPrinter,
@@ -732,7 +749,7 @@ pub const VirtualMachine = struct {
this.exit_handler.dispatchOnBeforeExit();
var dispatch = false;
while (true) {
- while (this.eventLoop().tasks.count > 0 or this.active_tasks > 0 or this.event_loop_handle.?.active > 0) : (dispatch = true) {
+ while (this.isEventLoopAlive()) : (dispatch = true) {
this.tick();
this.eventLoop().autoTickActive();
}
@@ -741,7 +758,7 @@ pub const VirtualMachine = struct {
this.exit_handler.dispatchOnBeforeExit();
dispatch = false;
- if (this.eventLoop().tasks.count > 0 or this.active_tasks > 0 or this.event_loop_handle.?.active > 0) continue;
+ if (this.isEventLoopAlive()) continue;
}
break;
@@ -884,7 +901,7 @@ pub const VirtualMachine = struct {
this.eventLoop().tick();
while (true) {
- while (this.eventLoop().tasks.count > 0 or this.active_tasks > 0 or this.event_loop_handle.?.active > 0) {
+ while (this.isEventLoopAlive()) {
this.tick();
this.eventLoop().autoTickActive();
}