/* * Copyright (c) 2020, Andreas Kling * Copyright (c) 2020-2022, Linus Groh * Copyright (c) 2022, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include #include #include #include #include #include namespace JS { NonnullOwnPtr Interpreter::create_with_existing_realm(Realm& realm) { auto& vm = realm.vm(); DeferGC defer_gc(vm.heap()); auto interpreter = adopt_own(*new Interpreter(vm)); interpreter->m_realm = make_handle(&realm); return interpreter; } Interpreter::Interpreter(VM& vm) : m_vm(vm) { } // 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(); VM::InterpreterExecutionScope scope(*this); // 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