1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 07:55:07 +00:00

LibJS: Use regular stack for VM call frames instead of Vector storage

Keeping the VM call frames in a Vector could cause them to move around
underneath us due to Vector resizing. Avoid this issue by allocating
CallFrame objects on the stack and having the VM simply keep a list
of pointers to each CallFrame, instead of the CallFrames themselves.

Fixes #3830.
Fixes #3951.
This commit is contained in:
Andreas Kling 2020-11-07 11:07:17 +01:00
parent a950d3dd5f
commit 43ff2ea8d8
6 changed files with 36 additions and 27 deletions

View file

@ -76,8 +76,8 @@ Value Interpreter::run(GlobalObject& global_object, const Program& program)
global_call_frame.is_strict_mode = program.is_strict_mode();
if (vm().exception())
return {};
vm().call_stack().append(move(global_call_frame));
vm().push_call_frame(global_call_frame);
auto result = program.execute(*this, global_object);
vm().pop_call_frame();
return result;
@ -128,7 +128,7 @@ void Interpreter::enter_scope(const ScopeNode& scope_node, ArgumentVector argume
if (!scope_variables_with_declaration_kind.is_empty()) {
auto* block_lexical_environment = heap().allocate<LexicalEnvironment>(global_object, move(scope_variables_with_declaration_kind), current_environment());
vm().call_stack().last().environment = block_lexical_environment;
vm().call_frame().environment = block_lexical_environment;
pushed_lexical_environment = true;
}