/* * Copyright (c) 2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include #include #include #include #include #include #include #include namespace JS::Bytecode { static bool s_bytecode_interpreter_enabled = false; bool Interpreter::enabled() { return s_bytecode_interpreter_enabled; } void Interpreter::set_enabled(bool enabled) { s_bytecode_interpreter_enabled = enabled; } static bool s_optimizations_enabled = false; void Interpreter::set_optimizations_enabled(bool enabled) { s_optimizations_enabled = enabled; } bool g_dump_bytecode = false; Interpreter::Interpreter(VM& vm) : m_vm(vm) { } Interpreter::~Interpreter() { } void Interpreter::visit_edges(Cell::Visitor& visitor) { if (m_return_value.has_value()) visitor.visit(*m_return_value); if (m_saved_return_value.has_value()) visitor.visit(*m_saved_return_value); if (m_saved_exception.has_value()) visitor.visit(*m_saved_exception); for (auto& window : m_register_windows) { window.visit([&](auto& value) { value->visit_edges(visitor); }); } } // 16.1.6 ScriptEvaluation ( scriptRecord ), https://tc39.es/ecma262/#sec-runtime-semantics-scriptevaluation ThrowCompletionOr Interpreter::run(Script& script_record, JS::GCPtr lexical_environment_override) { auto& vm = this->vm(); // 1. Let globalEnv be scriptRecord.[[Realm]].[[GlobalEnv]]. auto& global_environment = script_record.realm().global_environment(); // 2. Let scriptContext be a new ECMAScript code execution context. ExecutionContext script_context(vm.heap()); // 3. Set the Function of scriptContext to null. // NOTE: This was done during execution context construction. // 4. Set the Realm of scriptContext to scriptRecord.[[Realm]]. script_context.realm = &script_record.realm(); // 5. Set the ScriptOrModule of scriptContext to scriptRecord. script_context.script_or_module = NonnullGCPtr