/* * 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 Interpreter* s_current; bool g_dump_bytecode = false; Interpreter* Interpreter::current() { return s_current; } Interpreter::Interpreter(Realm& realm) : m_vm(realm.vm()) , m_realm(realm) { VERIFY(!s_current); s_current = this; } Interpreter::~Interpreter() { VERIFY(s_current == this); s_current = nullptr; } // 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