1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2026-01-13 00:50:59 +00:00
serenity/Userland
Gunnar Beutner 67cc31a74f LibJS: Implement bytecode generation for try..catch..finally
EnterUnwindContext pushes an unwind context (exception handler and/or
finalizer) onto a stack.

LeaveUnwindContext pops the unwind context from that stack.

Upon return to the interpreter loop we check whether the VM has an
exception pending. If no unwind context is available we return from the
loop. If an exception handler is available we clear the VM's exception,
put the exception value into the accumulator register, clear the unwind
context's handler and jump to the handler. If no handler is available
but a finalizer is available we save the exception value + metadata (for
 later use by ContinuePendingUnwind), clear the VM's exception, pop the
unwind context and jump to the finalizer.

ContinuePendingUnwind checks whether a saved exception is available. If
no saved exception is available it jumps to the resume label. Otherwise
it stores the exception into the VM.

The Jump after LeaveUnwindContext could be integrated into the
LeaveUnwindContext instruction. I've kept them separate for now to make
the bytecode more readable.

> try { 1; throw "x" } catch (e) { 2 } finally { 3 }; 4
1:
[   0] EnterScope
[  10] EnterUnwindContext handler:@4 finalizer:@3
[  38] EnterScope
[  48] LoadImmediate 1
[  60] NewString 1 ("x")
[  70] Throw
<for non-terminated blocks: insert LeaveUnwindContext + Jump @3 here>
2:
[   0] LoadImmediate 4
3:
[   0] EnterScope
[  10] LoadImmediate 3
[  28] ContinuePendingUnwind resume:@2
4:
[   0] SetVariable 0 (e)
[  10] EnterScope
[  20] LoadImmediate 2
[  38] LeaveUnwindContext
[  3c] Jump @3

String Table:
0: e
1: x
2021-06-10 21:59:46 +02:00
..
Applets Applets/Network: Replace fprintf(stderr) with dbgln() 2021-05-31 17:44:01 +01:00
Applications FileManager: Save maximized window state on exit 2021-06-09 22:58:10 +02:00
Demos CatDog: Enhance the speech bubble artificial intelligence 2021-06-07 21:52:16 +02:00
DevTools LibCpp: Support non-field class members 2021-06-09 22:26:46 +02:00
DynamicLoader Userland: Port UBSAN implementation to userspace 2021-05-27 15:18:03 +02:00
Games AK+Everywhere: Disallow constructing Functions from incompatible types 2021-06-06 00:27:30 +04:30
Libraries LibJS: Implement bytecode generation for try..catch..finally 2021-06-10 21:59:46 +02:00
Services LibGUI/WindowServer: Add set_maximized IPC call 2021-06-09 22:58:10 +02:00
Shell Shell: Make time stop parsing options on first non-option 2021-06-08 11:30:58 +02:00
Utilities LibJS: Show the VM's last value after executing bytecode programs 2021-06-10 21:47:25 +02:00
CMakeLists.txt Tests: Establish root Tests directory, move Userland/Tests there 2021-05-06 17:54:28 +02:00