mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:47:44 +00:00
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:
parent
82dde46a30
commit
235eb0b1ad
5 changed files with 27 additions and 26 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue