Spreadsheet: Replace hacky JS VM configuration with a more correct one

Now we give each sheet its own interpreter and realm, and only make them
share the VM.
This is to prepare for the next commit, which will be refactoring a
bunch of things to propagate exceptions via ThrowCompletionOr<T>.
This commit is contained in:
Ali Mohammad Pur 2021-11-21 05:04:55 +03:30 committed by Ali Mohammad Pur
commit 235eb0b1ad
Notes: sideshowbarker 2024-07-17 22:53:55 +09:00
5 changed files with 27 additions and 26 deletions

View file

@ -17,21 +17,24 @@
namespace Spreadsheet {
static JS::VM& global_vm()
{
static RefPtr<JS::VM> vm;
if (!vm)
vm = JS::VM::create();
return *vm;
}
Workbook::Workbook(NonnullRefPtrVector<Sheet>&& sheets)
: m_sheets(move(sheets))
, m_interpreter(JS::Interpreter::create<JS::GlobalObject>(global_vm()))
, m_interpreter_scope(JS::VM::InterpreterExecutionScope(interpreter()))
, m_vm(JS::VM::create())
, m_interpreter(JS::Interpreter::create<JS::GlobalObject>(m_vm))
, m_interpreter_scope(*m_interpreter)
, m_main_execution_context(m_vm->heap())
{
m_workbook_object = interpreter().heap().allocate<WorkbookObject>(global_object(), *this);
global_object().define_direct_property("workbook", workbook_object(), JS::default_attributes);
m_workbook_object = m_vm->heap().allocate<WorkbookObject>(m_interpreter->global_object(), *this);
m_interpreter->global_object().define_direct_property("workbook", workbook_object(), JS::default_attributes);
m_main_execution_context.current_node = nullptr;
m_main_execution_context.this_value = &m_interpreter->global_object();
m_main_execution_context.function_name = "(global execution context)"sv;
m_main_execution_context.lexical_environment = &m_interpreter->realm().global_environment();
m_main_execution_context.variable_environment = &m_interpreter->realm().global_environment();
m_main_execution_context.realm = &m_interpreter->realm();
m_main_execution_context.is_strict_mode = true;
MUST(m_vm->push_execution_context(m_main_execution_context, m_interpreter->global_object()));
}
bool Workbook::set_filename(const String& filename)