Skip to content

Commit 2cf93c5

Browse files
committed
add: js/ipc: react to goodbye-packets
The JavaScript process now reacts to `feGoodbye` packets. The cleanup sequence needs some work. (It currently segfaults as soon as it's about to exit, most likely due to some problem in Bali!)
1 parent 8e9f064 commit 2cf93c5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/components/js/process.nim

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type JSProcess* = object
1515
ipc*: IPCClient
1616
parser*: Parser
1717
runtime*: Runtime
18+
running*: bool = true
1819

1920
document*: HTMLDocument
2021

@@ -72,6 +73,14 @@ proc talk(js: var JSProcess, process: FerusProcess) =
7273

7374
debug "Got document for this tab - passing it to JS land."
7475
js.document = packet.document
76+
of feGoodbye:
77+
info "js: got goodbye packet, cleaning up."
78+
# TODO: make it so that we always respond to goodbye(s), even when in an unreachable/expensive VM loop
79+
# there's two ways to do this:
80+
# a) either add a way for a hook function to constantly monitor for this packet (bad performance)
81+
# b) shift the VM to another thread (good performance but harder to work with)
82+
js.runtime.vm.halt = true
83+
js.running = false
7584
else:
7685
discard
7786

@@ -87,5 +96,5 @@ proc jsProcessLogic*(client: var IPCClient, process: FerusProcess) {.inline.} =
8796
else:
8897
setLogFilter(lvlNone)
8998

90-
while true:
99+
while js.running:
91100
js.talk(process)

0 commit comments

Comments
 (0)