1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:38:12 +00:00

LibJS/Bytecode: Store unwind contexts inside RegisterWindow

Unwind contexts need to be preserved as we exit and re-enter a
generator.

For example, this would previously crash when returning from the try
statement after yielding as we lost the unwind context when yielding,
but still have a LeaveUnwindContext instruction from running
`perform_needed_unwinds` when generating the return statement.
```js
function* a() {
    try {
        return (yield 1);
    } catch {}
}

iter = a();
iter.next();
iter.next();
```
This commit is contained in:
Luke Wilde 2022-11-25 23:15:44 +00:00 committed by Andreas Kling
parent b914680f0c
commit 277132f70d
2 changed files with 9 additions and 8 deletions

View file

@ -22,6 +22,7 @@ struct RegisterWindow {
MarkedVector<Value> registers;
MarkedVector<Environment*> saved_lexical_environments;
MarkedVector<Environment*> saved_variable_environments;
Vector<UnwindInfo> unwind_contexts;
};
class Interpreter {
@ -52,6 +53,7 @@ public:
auto& saved_lexical_environment_stack() { return window().saved_lexical_environments; }
auto& saved_variable_environment_stack() { return window().saved_variable_environments; }
auto& unwind_contexts() { return window().unwind_contexts; }
void jump(Label const& label)
{
@ -98,7 +100,6 @@ private:
Optional<BasicBlock const*> m_pending_jump;
Value m_return_value;
Executable const* m_current_executable { nullptr };
Vector<UnwindInfo> m_unwind_contexts;
Handle<Value> m_saved_exception;
OwnPtr<JS::Interpreter> m_ast_interpreter;
BasicBlock const* m_current_block { nullptr };