serenity/Userland/Libraries/LibJS
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
..
Bytecode LibJS: Implement bytecode generation for try..catch..finally 2021-06-10 21:59:46 +02:00
Heap LibJS: Notify WeakSets when heap cells are sweeped 2021-06-09 21:52:25 +01:00
Runtime LibJS: Let the bytecode interpreter set the VM's last value 2021-06-10 21:47:25 +02:00
Tests LibJS: Pass in actual_delete_count to removed array creation in splice 2021-06-10 10:04:06 +01:00
AST.cpp LibJS: Handle Proxy with Array target in IsArray() abstract operation 2021-06-08 23:53:13 +02:00
AST.h LibJS: Implement bytecode generation for try..catch..finally 2021-06-10 21:59:46 +02:00
CMakeLists.txt LibJS: Add the WeakSet built-in object 2021-06-09 21:52:25 +01:00
Console.cpp Everywhere: Use linusg@serenityos.org for my copyright headers 2021-04-22 22:51:19 +02:00
Console.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Forward.h LibJS: Implement the CreateListFromArrayLike() abstract operation 2021-06-09 23:46:37 +01:00
Interpreter.cpp LibJS: Let the bytecode interpreter set the VM's last value 2021-06-10 21:47:25 +02:00
Interpreter.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Lexer.cpp Everywhere: Use s.unverwerth@serenityos.org :^) 2021-05-29 12:30:08 +01:00
Lexer.h Everywhere: Use s.unverwerth@serenityos.org :^) 2021-05-29 12:30:08 +01:00
MarkupGenerator.cpp LibJS: Handle Proxy with Array target in IsArray() abstract operation 2021-06-08 23:53:13 +02:00
MarkupGenerator.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Parser.cpp AK+LibWasm+LibJS: Disallow Variant.has() on types that aren't contained 2021-06-02 18:02:47 +02:00
Parser.h LibJS: Implement destructuring assignments and function parameters 2021-05-29 23:02:23 +04:30
SourceRange.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
SyntaxHighlighter.cpp LibWeb+LibSyntax: Implement nested syntax highlighters 2021-06-07 14:45:49 +04:30
SyntaxHighlighter.h LibWeb+LibSyntax: Implement nested syntax highlighters 2021-06-07 14:45:49 +04:30
Token.cpp Everywhere: Use s.unverwerth@serenityos.org :^) 2021-05-29 12:30:08 +01:00
Token.h Everywhere: Use s.unverwerth@serenityos.org :^) 2021-05-29 12:30:08 +01:00