From b345a0acca725d1b4e4d6df26fc602d69e97f073 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 22 Aug 2022 19:00:49 +0100 Subject: [PATCH] LibJS+LibWeb: Reduce use of GlobalObject as an intermediary - Prefer VM::current_realm() over GlobalObject::associated_realm() - Prefer VM::heap() over GlobalObject::heap() - Prefer Cell::vm() over Cell::global_object() - Prefer Wrapper::vm() over Wrapper::global_object() - Inline Realm::global_object() calls used to access intrinsics as they will later perform a direct lookup without going through the global object --- .../LibWeb/WrapperGenerator/IDLGenerators.cpp | 39 ++++++-------- .../Applications/Spreadsheet/Spreadsheet.cpp | 8 +-- Userland/Libraries/LibJS/AST.cpp | 53 ++++++++----------- Userland/Libraries/LibJS/Bytecode/Op.cpp | 9 +++- Userland/Libraries/LibJS/Console.cpp | 3 +- Userland/Libraries/LibJS/CyclicModule.cpp | 9 ++-- Userland/Libraries/LibJS/Interpreter.cpp | 8 +-- .../Runtime/AggregateErrorConstructor.cpp | 3 +- .../LibJS/Runtime/ArrayConstructor.cpp | 3 +- .../AsyncFromSyncIteratorPrototype.cpp | 3 +- .../Libraries/LibJS/Runtime/DatePrototype.cpp | 3 +- .../Runtime/ECMAScriptFunctionObject.cpp | 8 ++- .../LibJS/Runtime/GlobalEnvironment.cpp | 2 +- .../LibJS/Runtime/Intl/DateTimeFormat.cpp | 9 ++-- .../Runtime/Intl/DateTimeFormatFunction.cpp | 6 +-- .../LibJS/Runtime/Intl/DurationFormat.cpp | 7 ++- .../LibJS/Runtime/Intl/ListFormat.cpp | 3 +- .../LibJS/Runtime/Intl/NumberFormat.cpp | 6 +-- .../LibJS/Runtime/Intl/RelativeTimeFormat.cpp | 3 +- .../Intl/RelativeTimeFormatConstructor.cpp | 5 +- .../LibJS/Runtime/Intl/Segmenter.cpp | 3 +- .../LibJS/Runtime/IteratorOperations.cpp | 3 +- .../Libraries/LibJS/Runtime/JSONObject.cpp | 3 +- Userland/Libraries/LibJS/Runtime/Object.cpp | 3 +- .../LibJS/Runtime/ObjectConstructor.cpp | 5 +- Userland/Libraries/LibJS/Runtime/Promise.cpp | 3 +- .../PromiseResolvingElementFunctions.cpp | 16 +++--- .../Libraries/LibJS/Runtime/ProxyObject.cpp | 6 +-- .../Libraries/LibJS/Runtime/Reference.cpp | 7 ++- .../LibJS/Runtime/StringConstructor.cpp | 3 +- .../LibJS/Runtime/Temporal/Calendar.cpp | 6 +-- .../LibJS/Runtime/Temporal/Duration.cpp | 3 +- .../LibJS/Runtime/Temporal/Instant.cpp | 3 +- .../LibJS/Runtime/Temporal/PlainDate.cpp | 3 +- .../LibJS/Runtime/Temporal/PlainDateTime.cpp | 3 +- .../LibJS/Runtime/Temporal/PlainMonthDay.cpp | 3 +- .../LibJS/Runtime/Temporal/PlainTime.cpp | 3 +- .../LibJS/Runtime/Temporal/PlainYearMonth.cpp | 3 +- .../LibJS/Runtime/Temporal/TimeZone.cpp | 3 +- .../LibJS/Runtime/Temporal/ZonedDateTime.cpp | 3 +- .../Libraries/LibJS/Runtime/TypedArray.cpp | 12 ++--- .../LibJS/Runtime/TypedArrayPrototype.cpp | 3 +- .../Libraries/LibTest/JavaScriptTestRunner.h | 6 +-- .../LibWeb/Bindings/LocationObject.cpp | 18 ++----- .../Libraries/LibWeb/Bindings/WindowProxy.cpp | 6 +-- .../Libraries/LibWeb/Encoding/TextEncoder.cpp | 6 +-- Userland/Libraries/LibWeb/Fetch/Headers.cpp | 3 +- .../LibWeb/Fetch/HeadersIterator.cpp | 5 +- Userland/Libraries/LibWeb/FileAPI/Blob.cpp | 10 ++-- .../LibWeb/HTML/Scripting/ClassicScript.cpp | 3 +- .../LibWeb/HTML/Scripting/Environments.cpp | 2 +- .../LibWeb/URL/URLSearchParamsIterator.cpp | 5 +- .../WebAssemblyMemoryConstructor.cpp | 3 +- .../WebAssemblyTableConstructor.cpp | 3 +- .../Libraries/LibWeb/WebSockets/WebSocket.cpp | 4 +- .../Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 6 +-- .../WebContent/WebContentConsoleClient.cpp | 6 +-- Userland/Utilities/js.cpp | 12 ++--- 58 files changed, 157 insertions(+), 231 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp index 0df31f3129..6b3ff0fe32 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp @@ -891,7 +891,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter // The lambda must take the JS::Value to convert as a parameter instead of capturing it in order to support union types being variadic. dictionary_generator.append(R"~~~( - auto @js_name@@js_suffix@_to_dictionary = [&global_object, &vm](JS::Value @js_name@@js_suffix@) -> JS::ThrowCompletionOr<@dictionary.type@> { + auto @js_name@@js_suffix@_to_dictionary = [&vm](JS::Value @js_name@@js_suffix@) -> JS::ThrowCompletionOr<@dictionary.type@> { )~~~"); IDL::Parameter dictionary_parameter { .type = *dictionary_type, .name = acceptable_cpp_name, .optional_default_value = {}, .extended_attributes = {} }; @@ -913,7 +913,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter // The lambda must take the JS::Value to convert as a parameter instead of capturing it in order to support union types being variadic. StringBuilder to_variant_captures; - to_variant_captures.append("&global_object, &vm, &realm"sv); + to_variant_captures.append("&vm, &realm"sv); if (dictionary_type) to_variant_captures.append(String::formatted(", &{}{}_to_dictionary", js_name, js_suffix)); @@ -923,7 +923,6 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter union_generator.append(R"~~~( auto @js_name@@js_suffix@_to_variant = [@to_variant_captures@](JS::Value @js_name@@js_suffix@) -> JS::ThrowCompletionOr<@union_type@> { // These might be unused. - (void)global_object; (void)vm; (void)realm; )~~~"); @@ -1371,7 +1370,7 @@ void IDL::ParameterizedType::generate_sequence_from_iterable(SourceGenerator& ge )~~~"); } else { sequence_generator.append(R"~~~( - @sequence.storage_type@ @cpp_name@ { global_object.heap() }; + @sequence.storage_type@ @cpp_name@ { vm.heap() }; )~~~"); } @@ -1508,10 +1507,9 @@ static void generate_wrap_statement(SourceGenerator& generator, String const& va auto cpp_type = IDL::idl_type_name_to_cpp_type(current_union_type, interface); union_generator.set("current_type", cpp_type.name); union_generator.append(R"~~~( - [&vm, &global_object, &realm](@current_type@ const& visited_union_value@recursion_depth@) -> JS::Value { + [&vm, &realm](@current_type@ const& visited_union_value@recursion_depth@) -> JS::Value { // These may be unused. (void)vm; - (void)global_object; (void) realm; )~~~"); @@ -1574,7 +1572,7 @@ static void generate_wrap_statement(SourceGenerator& generator, String const& va auto dictionary_generator = scoped_generator.fork(); dictionary_generator.append(R"~~~( - auto* dictionary_object@recursion_depth@ = JS::Object::create(realm, global_object.object_prototype()); + auto* dictionary_object@recursion_depth@ = JS::Object::create(realm, realm.global_object().object_prototype()); )~~~"); auto* current_dictionary = &interface.dictionaries.find(type.name)->value; @@ -2166,9 +2164,8 @@ JS::ThrowCompletionOr> @class_name@::legacy_pla )~~~"); get_own_property_generator.append(R"~~~( - [[maybe_unused]] auto& global_object = this->global_object(); - [[maybe_unused]] auto& vm = this->vm(); - [[maybe_unused]] auto& realm = *global_object.associated_realm(); + auto& vm = this->vm(); + [[maybe_unused]] auto& realm = *vm.current_realm(); )~~~"); // 1. If O supports indexed properties... @@ -2436,9 +2433,8 @@ JS::ThrowCompletionOr> @class_name@::internal_g scoped_generator.append(R"~~~( JS::ThrowCompletionOr @class_name@::internal_set(JS::PropertyKey const& property_name, JS::Value value, JS::Value receiver) { - [[maybe_unused]] auto& global_object = this->global_object(); - [[maybe_unused]] auto& vm = this->vm(); - [[maybe_unused]] auto& realm = *global_object.associated_realm(); + auto& vm = this->vm(); + [[maybe_unused]] auto& realm = *vm.current_realm(); )~~~"); // The step 1 if statement will be empty if the interface has no setters, so don't generate the if statement if there's no setters. @@ -2496,9 +2492,8 @@ JS::ThrowCompletionOr @class_name@::internal_set(JS::PropertyKey const& pr scoped_generator.append(R"~~~( JS::ThrowCompletionOr @class_name@::internal_define_own_property(JS::PropertyKey const& property_name, JS::PropertyDescriptor const& property_descriptor) { - [[maybe_unused]] auto& vm = this->vm(); - [[maybe_unused]] auto& global_object = this->global_object(); - [[maybe_unused]] auto& realm = *global_object.associated_realm(); + auto& vm = this->vm(); + [[maybe_unused]] auto& realm = *vm.current_realm(); )~~~"); // 1. If O supports indexed properties... @@ -2617,9 +2612,8 @@ JS::ThrowCompletionOr @class_name@::internal_define_own_property(JS::Prope scoped_generator.append(R"~~~( JS::ThrowCompletionOr @class_name@::internal_delete(JS::PropertyKey const& property_name) { - [[maybe_unused]] auto& global_object = this->global_object(); - [[maybe_unused]] auto& vm = this->vm(); - [[maybe_unused]] auto& realm = *global_object.associated_realm(); + auto& vm = this->vm(); + [[maybe_unused]] auto& realm = *vm.current_realm(); )~~~"); // 1. If O supports indexed properties... @@ -2969,11 +2963,10 @@ JS::ThrowCompletionOr @constructor_class@::construct(FunctionObject generator.set("constructor.length", String::number(constructor.length())); generator.append(R"~~~( - [[maybe_unused]] auto& vm = this->vm(); - [[maybe_unused]] auto& global_object = this->global_object(); - [[maybe_unused]] auto& realm = *global_object.associated_realm(); + auto& vm = this->vm(); + [[maybe_unused]] auto& realm = *vm.current_realm(); - auto& window = static_cast(global_object); + auto& window = static_cast(realm.global_object()); )~~~"); if (!constructor.parameters.is_empty()) { diff --git a/Userland/Applications/Spreadsheet/Spreadsheet.cpp b/Userland/Applications/Spreadsheet/Spreadsheet.cpp index da8fbc3b6e..e5da87ac9b 100644 --- a/Userland/Applications/Spreadsheet/Spreadsheet.cpp +++ b/Userland/Applications/Spreadsheet/Spreadsheet.cpp @@ -399,7 +399,7 @@ RefPtr Sheet::from_json(JsonObject const& object, Workbook& workbook) sheet->add_column(); } - auto json = sheet->interpreter().global_object().get_without_side_effects("JSON"); + auto json = sheet->global_object().get_without_side_effects("JSON"); auto& parse_function = json.as_object().get_without_side_effects("parse").as_function(); auto read_format = [](auto& format, auto const& obj) { @@ -559,7 +559,7 @@ JsonObject Sheet::to_json() const if (it.value->kind() == Cell::Formula) { auto& vm = interpreter().vm(); data.set("source", it.value->data()); - auto json = interpreter().global_object().get_without_side_effects("JSON"); + auto json = interpreter().realm().global_object().get_without_side_effects("JSON"); auto stringified_or_error = JS::call(vm, json.as_object().get_without_side_effects("stringify").as_function(), json, it.value->evaluated_data()); VERIFY(!stringified_or_error.is_error()); data.set("value", stringified_or_error.release_value().to_string_without_side_effects()); @@ -702,8 +702,8 @@ JsonObject Sheet::gather_documentation() const dbgln("Sheet::gather_documentation(): Failed to parse the documentation for '{}'!", it.key.to_display_string()); }; - for (auto& it : interpreter().global_object().shape().property_table()) - add_docs_from(it, interpreter().global_object()); + for (auto& it : interpreter().realm().global_object().shape().property_table()) + add_docs_from(it, interpreter().realm().global_object()); for (auto& it : global_object().shape().property_table()) add_docs_from(it, global_object()); diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 6eabb15219..ee6e5f07ae 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -288,9 +288,8 @@ Completion FunctionExpression::execute(Interpreter& interpreter) const // 15.2.5 Runtime Semantics: InstantiateOrdinaryFunctionExpression, https://tc39.es/ecma262/#sec-runtime-semantics-instantiateordinaryfunctionexpression Value FunctionExpression::instantiate_ordinary_function_expression(Interpreter& interpreter, FlyString given_name) const { - auto& global_object = interpreter.global_object(); auto& vm = interpreter.vm(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); if (given_name.is_empty()) given_name = ""; @@ -426,8 +425,8 @@ Completion CallExpression::throw_type_error_for_callee(Interpreter& interpreter, Completion CallExpression::execute(Interpreter& interpreter) const { InterpreterNodeScope node_scope { interpreter, *this }; - auto& global_object = interpreter.global_object(); auto& vm = interpreter.vm(); + auto& realm = *vm.current_realm(); auto callee_reference = TRY(m_callee->to_reference(interpreter)); @@ -443,7 +442,7 @@ Completion CallExpression::execute(Interpreter& interpreter) const auto& function = callee.as_function(); - if (&function == global_object.eval_function() + if (&function == realm.global_object().eval_function() && callee_reference.is_environment_reference() && callee_reference.name().is_string() && callee_reference.name().as_string() == vm.names.eval.as_string()) { @@ -594,8 +593,7 @@ Completion IfStatement::execute(Interpreter& interpreter) const Completion WithStatement::execute(Interpreter& interpreter) const { InterpreterNodeScope node_scope { interpreter, *this }; - auto& global_object = interpreter.global_object(); - auto& vm = global_object.vm(); + auto& vm = interpreter.vm(); // 1. Let value be the result of evaluating Expression. auto value = TRY(m_object->execute(interpreter)).release_value(); @@ -1664,8 +1662,8 @@ private: // 15.7.10 Runtime Semantics: ClassFieldDefinitionEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-classfielddefinitionevaluation ThrowCompletionOr ClassField::class_element_evaluation(Interpreter& interpreter, Object& target) const { - auto& global_object = interpreter.global_object(); - auto& realm = *global_object.associated_realm(); + auto& vm = interpreter.vm(); + auto& realm = *vm.current_realm(); auto property_key_or_private_name = TRY(class_key_to_property_name(interpreter, *m_key)); Handle initializer {}; @@ -1713,8 +1711,8 @@ Optional ClassMethod::private_bound_identifier() const // 15.7.11 Runtime Semantics: ClassStaticBlockDefinitionEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-classstaticblockdefinitionevaluation ThrowCompletionOr StaticInitializer::class_element_evaluation(Interpreter& interpreter, Object& home_object) const { - auto& global_object = interpreter.global_object(); - auto& realm = *global_object.associated_realm(); + auto& vm = interpreter.vm(); + auto& realm = *vm.current_realm(); // 1. Let lex be the running execution context's LexicalEnvironment. auto* lexical_environment = interpreter.vm().running_execution_context().lexical_environment; @@ -1807,9 +1805,8 @@ Completion ClassDeclaration::execute(Interpreter& interpreter) const // 15.7.14 Runtime Semantics: ClassDefinitionEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-classdefinitionevaluation ThrowCompletionOr ClassExpression::class_definition_evaluation(Interpreter& interpreter, FlyString const& binding_name, FlyString const& class_name) const { - auto& global_object = interpreter.global_object(); auto& vm = interpreter.vm(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* environment = vm.lexical_environment(); VERIFY(environment); @@ -3035,12 +3032,11 @@ Completion ObjectProperty::execute(Interpreter& interpreter) const Completion ObjectExpression::execute(Interpreter& interpreter) const { InterpreterNodeScope node_scope { interpreter, *this }; - auto& global_object = interpreter.global_object(); auto& vm = interpreter.vm(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let obj be OrdinaryObjectCreate(%Object.prototype%). - auto* object = Object::create(realm, global_object.object_prototype()); + auto* object = Object::create(realm, realm.global_object().object_prototype()); // 2. Perform ? PropertyDefinitionEvaluation of PropertyDefinitionList with argument obj. for (auto& property : m_properties) { @@ -3252,8 +3248,8 @@ void MetaProperty::dump(int indent) const Completion MetaProperty::execute(Interpreter& interpreter) const { InterpreterNodeScope node_scope { interpreter, *this }; - auto& global_object = interpreter.global_object(); - auto& realm = *global_object.associated_realm(); + auto& vm = interpreter.vm(); + auto& realm = *vm.current_realm(); // NewTarget : new . target if (m_type == MetaProperty::Type::NewTarget) { @@ -3328,9 +3324,8 @@ void ImportCall::dump(int indent) const Completion ImportCall::execute(Interpreter& interpreter) const { InterpreterNodeScope node_scope { interpreter, *this }; - auto& global_object = interpreter.global_object(); auto& vm = interpreter.vm(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] ), https://tc39.es/proposal-import-assertions/#sec-evaluate-import-call // 1. Let referencingScriptOrModule be GetActiveScriptOrModule(). @@ -3352,7 +3347,7 @@ Completion ImportCall::execute(Interpreter& interpreter) const // Note: options_value is undefined by default. // 6. Let promiseCapability be ! NewPromiseCapability(%Promise%). - auto promise_capability = MUST(new_promise_capability(vm, global_object.promise_constructor())); + auto promise_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor())); // 7. Let specifierString be Completion(ToString(specifier)). // 8. IfAbruptRejectPromise(specifierString, promiseCapability). @@ -3501,8 +3496,8 @@ void RegExpLiteral::dump(int indent) const Completion RegExpLiteral::execute(Interpreter& interpreter) const { InterpreterNodeScope node_scope { interpreter, *this }; - auto& global_object = interpreter.global_object(); - auto& realm = *global_object.associated_realm(); + auto& vm = interpreter.vm(); + auto& realm = *vm.current_realm(); // 1. Let pattern be CodePointsToString(BodyText of RegularExpressionLiteral). auto pattern = this->pattern(); @@ -3532,9 +3527,8 @@ void ArrayExpression::dump(int indent) const Completion ArrayExpression::execute(Interpreter& interpreter) const { InterpreterNodeScope node_scope { interpreter, *this }; - auto& global_object = interpreter.global_object(); auto& vm = interpreter.vm(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let array be ! ArrayCreate(0). auto* array = MUST(Array::create(realm, 0)); @@ -3651,9 +3645,10 @@ Completion TaggedTemplateLiteral::execute(Interpreter& interpreter) const // 13.2.8.3 GetTemplateObject ( templateLiteral ), https://tc39.es/ecma262/#sec-gettemplateobject ThrowCompletionOr TaggedTemplateLiteral::get_template_object(Interpreter& interpreter) const { + auto& vm = interpreter.vm(); + // 1. Let realm be the current Realm Record. - auto& global_object = interpreter.global_object(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 2. Let templateRegistry be realm.[[TemplateMap]]. // 3. For each element e of templateRegistry, do @@ -4518,9 +4513,8 @@ bool ImportStatement::has_bound_name(FlyString const& name) const void ScopeNode::block_declaration_instantiation(Interpreter& interpreter, Environment* environment) const { // See also B.3.2.6 Changes to BlockDeclarationInstantiation, https://tc39.es/ecma262/#sec-web-compat-blockdeclarationinstantiation - auto& global_object = interpreter.global_object(); auto& vm = interpreter.vm(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); VERIFY(environment); auto* private_environment = vm.running_execution_context().private_environment; @@ -4548,9 +4542,8 @@ void ScopeNode::block_declaration_instantiation(Interpreter& interpreter, Enviro // 16.1.7 GlobalDeclarationInstantiation ( script, env ), https://tc39.es/ecma262/#sec-globaldeclarationinstantiation ThrowCompletionOr Program::global_declaration_instantiation(Interpreter& interpreter, GlobalEnvironment& global_environment) const { - auto& global_object = interpreter.global_object(); auto& vm = interpreter.vm(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let lexNames be the LexicallyDeclaredNames of script. // 2. Let varNames be the VarDeclaredNames of script. diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index 267bb43f24..0e08621fd6 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -237,7 +237,10 @@ ThrowCompletionOr NewString::execute_impl(Bytecode::Interpreter& interpret ThrowCompletionOr NewObject::execute_impl(Bytecode::Interpreter& interpreter) const { - interpreter.accumulator() = Object::create(interpreter.realm(), interpreter.global_object().object_prototype()); + auto& vm = interpreter.vm(); + auto& realm = *vm.current_realm(); + + interpreter.accumulator() = Object::create(realm, realm.global_object().object_prototype()); return {}; } @@ -255,9 +258,11 @@ ThrowCompletionOr NewRegExp::execute_impl(Bytecode::Interpreter& interpret ThrowCompletionOr CopyObjectExcludingProperties::execute_impl(Bytecode::Interpreter& interpreter) const { auto& vm = interpreter.vm(); + auto& realm = *vm.current_realm(); + auto* from_object = TRY(interpreter.reg(m_from_object).to_object(vm)); - auto* to_object = Object::create(interpreter.realm(), interpreter.global_object().object_prototype()); + auto* to_object = Object::create(realm, realm.global_object().object_prototype()); HashTable excluded_names; for (size_t i = 0; i < m_excluded_names_count; ++i) diff --git a/Userland/Libraries/LibJS/Console.cpp b/Userland/Libraries/LibJS/Console.cpp index 74544e19c7..95847eb636 100644 --- a/Userland/Libraries/LibJS/Console.cpp +++ b/Userland/Libraries/LibJS/Console.cpp @@ -500,7 +500,6 @@ VM& ConsoleClient::vm() // 2.1. Logger(logLevel, args), https://console.spec.whatwg.org/#logger ThrowCompletionOr ConsoleClient::logger(Console::LogLevel log_level, MarkedVector const& args) { - auto& global_object = this->global_object(); auto& vm = this->vm(); // 1. If args is empty, return. @@ -515,7 +514,7 @@ ThrowCompletionOr ConsoleClient::logger(Console::LogLevel log_level, Mark // 4. If rest is empty, perform Printer(logLevel, « first ») and return. if (rest_size == 0) { - MarkedVector first_as_vector { global_object.heap() }; + MarkedVector first_as_vector { vm.heap() }; first_as_vector.append(first); return printer(log_level, move(first_as_vector)); } diff --git a/Userland/Libraries/LibJS/CyclicModule.cpp b/Userland/Libraries/LibJS/CyclicModule.cpp index 029ada9857..0101873085 100644 --- a/Userland/Libraries/LibJS/CyclicModule.cpp +++ b/Userland/Libraries/LibJS/CyclicModule.cpp @@ -197,11 +197,11 @@ ThrowCompletionOr CyclicModule::evaluate(VM& vm) // 5. Let stack be a new empty List. Vector stack; - auto& global_object = realm().global_object(); + auto& realm = *vm.current_realm(); // 6. Let capability be ! NewPromiseCapability(%Promise%). // 7. Set module.[[TopLevelCapability]] to capability. - m_top_level_capability = MUST(new_promise_capability(vm, global_object.promise_constructor())); + m_top_level_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor())); // 8. Let result be Completion(InnerModuleEvaluation(module, stack, 0)). auto result = inner_module_evaluation(vm, stack, 0); @@ -433,8 +433,7 @@ ThrowCompletionOr CyclicModule::execute_module(VM&, Optional ThrowCompletionOr { diff --git a/Userland/Libraries/LibJS/Interpreter.cpp b/Userland/Libraries/LibJS/Interpreter.cpp index b3b7f022af..9439662269 100644 --- a/Userland/Libraries/LibJS/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Interpreter.cpp @@ -22,10 +22,10 @@ namespace JS { NonnullOwnPtr Interpreter::create_with_existing_realm(Realm& realm) { - auto& global_object = realm.global_object(); - DeferGC defer_gc(global_object.heap()); - auto interpreter = adopt_own(*new Interpreter(global_object.vm())); - interpreter->m_global_object = make_handle(&global_object); + auto& vm = realm.vm(); + DeferGC defer_gc(vm.heap()); + auto interpreter = adopt_own(*new Interpreter(vm)); + interpreter->m_global_object = make_handle(&realm.global_object()); interpreter->m_realm = make_handle(&realm); return interpreter; } diff --git a/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp b/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp index e914af42b8..868efa57ba 100644 --- a/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp @@ -40,8 +40,7 @@ ThrowCompletionOr AggregateErrorConstructor::call() ThrowCompletionOr AggregateErrorConstructor::construct(FunctionObject& new_target) { auto& vm = this->vm(); - auto& global_object = this->global_object(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* aggregate_error = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::aggregate_error_prototype)); diff --git a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp index c025cf0a88..562d7126ec 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp @@ -50,8 +50,7 @@ ThrowCompletionOr ArrayConstructor::call() ThrowCompletionOr ArrayConstructor::construct(FunctionObject& new_target) { auto& vm = this->vm(); - auto& global_object = this->global_object(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* proto = TRY(get_prototype_from_constructor(vm, new_target, &GlobalObject::array_prototype)); diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp index 99f10dabfe..84f09708ad 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp @@ -34,7 +34,6 @@ void AsyncFromSyncIteratorPrototype::initialize(Realm& realm) static Object* async_from_sync_iterator_continuation(VM& vm, Object& result, PromiseCapability& promise_capability) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. NOTE: Because promiseCapability is derived from the intrinsic %Promise%, the calls to promiseCapability.[[Reject]] entailed by the use IfAbruptRejectPromise below are guaranteed not to throw. // 2. Let done be Completion(IteratorComplete(result)). @@ -47,7 +46,7 @@ static Object* async_from_sync_iterator_continuation(VM& vm, Object& result, Pro // 6. Let valueWrapper be PromiseResolve(%Promise%, value). // 7. IfAbruptRejectPromise(valueWrapper, promiseCapability). - auto value_wrapper = TRY_OR_MUST_REJECT(vm, promise_capability, promise_resolve(vm, *global_object.promise_constructor(), value)); + auto value_wrapper = TRY_OR_MUST_REJECT(vm, promise_capability, promise_resolve(vm, *realm.global_object().promise_constructor(), value)); // 8. Let unwrap be a new Abstract Closure with parameters (value) that captures done and performs the following steps when called: auto unwrap = [done](VM& vm) -> ThrowCompletionOr { diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp index c49512fab7..7ab96f1f37 100644 --- a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp @@ -986,8 +986,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_json) static ThrowCompletionOr construct_date_time_format(VM& vm, Value locales, Value options) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); - auto* date_time_format = TRY(construct(vm, *global_object.intl_date_time_format_constructor(), locales, options)); + auto* date_time_format = TRY(construct(vm, *realm.global_object().intl_date_time_format_constructor(), locales, options)); return static_cast(date_time_format); } diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp index 8874d385a9..4385719a43 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp @@ -318,8 +318,7 @@ void ECMAScriptFunctionObject::make_method(Object& home_object) ThrowCompletionOr ECMAScriptFunctionObject::function_declaration_instantiation(Interpreter* interpreter) { auto& vm = this->vm(); - auto& global_object = this->global_object(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto& callee_context = vm.running_execution_context(); @@ -780,8 +779,7 @@ void async_block_start(VM& vm, NonnullRefPtr const& async_body, Promi Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body() { auto& vm = this->vm(); - auto& global_object = this->global_object(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* bytecode_interpreter = Bytecode::Interpreter::current(); if (m_kind == FunctionKind::AsyncGenerator) @@ -865,7 +863,7 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body() // AsyncFunctionBody : FunctionBody else if (m_kind == FunctionKind::Async) { // 1. Let promiseCapability be ! NewPromiseCapability(%Promise%). - auto promise_capability = MUST(new_promise_capability(vm, global_object.promise_constructor())); + auto promise_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor())); // 2. Let declResult be Completion(FunctionDeclarationInstantiation(functionObject, argumentsList)). auto declaration_result = function_declaration_instantiation(ast_interpreter); diff --git a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp index 797c252f2d..c25e16efac 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp +++ b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp @@ -247,7 +247,7 @@ ThrowCompletionOr GlobalEnvironment::create_global_var_binding(FlyString c // 1. Let ObjRec be envRec.[[ObjectRecord]]. // 2. Let globalObject be ObjRec.[[BindingObject]]. - auto& global_object = verify_cast(m_object_record->binding_object()); + auto& global_object = m_object_record->binding_object(); // 3. Let hasProperty be ? HasOwnProperty(globalObject, N). auto has_property = TRY(global_object.has_own_property(name)); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp index 83da04cc0f..b5ebf23dca 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp @@ -532,7 +532,6 @@ static Optional resolve_day_period(StringView locale, StringView cal ThrowCompletionOr> format_date_time_pattern(VM& vm, DateTimeFormat& date_time_format, Vector pattern_parts, double time, Unicode::CalendarPattern const* range_format_options) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Let x be TimeClip(x). time = time_clip(time); @@ -546,7 +545,7 @@ ThrowCompletionOr> format_date_time_pattern(VM& vm, Dat auto const& data_locale = date_time_format.data_locale(); auto construct_number_format = [&](auto* options) -> ThrowCompletionOr { - auto* number_format = TRY(construct(vm, *global_object.intl_number_format_constructor(), js_string(vm, locale), options)); + auto* number_format = TRY(construct(vm, *realm.global_object().intl_number_format_constructor(), js_string(vm, locale), options)); return static_cast(number_format); }; @@ -849,7 +848,6 @@ ThrowCompletionOr format_date_time(VM& vm, DateTimeFormat& date_time_for ThrowCompletionOr format_date_time_to_parts(VM& vm, DateTimeFormat& date_time_format, double time) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Let parts be ? PartitionDateTimePattern(dateTimeFormat, x). auto parts = TRY(partition_date_time_pattern(vm, date_time_format, time)); @@ -863,7 +861,7 @@ ThrowCompletionOr format_date_time_to_parts(VM& vm, DateTimeFormat& date // 4. For each Record { [[Type]], [[Value]] } part in parts, do for (auto& part : parts) { // a. Let O be OrdinaryObjectCreate(%Object.prototype%). - auto* object = Object::create(realm, global_object.object_prototype()); + auto* object = Object::create(realm, realm.global_object().object_prototype()); // b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]). MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type))); @@ -1164,7 +1162,6 @@ ThrowCompletionOr format_date_time_range(VM& vm, DateTimeFormat& date_ti ThrowCompletionOr format_date_time_range_to_parts(VM& vm, DateTimeFormat& date_time_format, double start, double end) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Let parts be ? PartitionDateTimeRangePattern(dateTimeFormat, x, y). auto parts = TRY(partition_date_time_range_pattern(vm, date_time_format, start, end)); @@ -1178,7 +1175,7 @@ ThrowCompletionOr format_date_time_range_to_parts(VM& vm, DateTimeFormat // 4. For each Record { [[Type]], [[Value]], [[Source]] } part in parts, do for (auto& part : parts) { // a. Let O be OrdinaryObjectCreate(%ObjectPrototype%). - auto* object = Object::create(realm, global_object.object_prototype()); + auto* object = Object::create(realm, realm.global_object().object_prototype()); // b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]). MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type))); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp index eafb39dfa6..e796859c76 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp @@ -36,8 +36,8 @@ void DateTimeFormatFunction::initialize(Realm& realm) ThrowCompletionOr DateTimeFormatFunction::call() { - auto& global_object = this->global_object(); - auto& vm = global_object.vm(); + auto& vm = this->vm(); + auto& realm = *vm.current_realm(); auto date = vm.argument(0); @@ -49,7 +49,7 @@ ThrowCompletionOr DateTimeFormatFunction::call() // 3. If date is not provided or is undefined, then if (date.is_undefined()) { // a. Let x be ! Call(%Date.now%, undefined). - date_value = MUST(JS::call(vm, global_object.date_constructor_now_function(), js_undefined())).as_double(); + date_value = MUST(JS::call(vm, realm.global_object().date_constructor_now_function(), js_undefined())).as_double(); } // 4. Else, else { diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp index df6d4451d4..aa87496f48 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp @@ -307,7 +307,6 @@ static String convert_number_format_pattern_to_duration_format_template(Unicode: ThrowCompletionOr> partition_duration_format_pattern(VM& vm, DurationFormat const& duration_format, Temporal::DurationRecord const& duration) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Let result be a new empty List. Vector result; @@ -403,7 +402,7 @@ ThrowCompletionOr> partition_duration_format_pattern(VM } // o. Let nf be ? Construct(%NumberFormat%, « durationFormat.[[Locale]], nfOpts »). - auto* number_format = static_cast(TRY(construct(vm, *global_object.intl_number_format_constructor(), js_string(vm, duration_format.locale()), number_format_options))); + auto* number_format = static_cast(TRY(construct(vm, *realm.global_object().intl_number_format_constructor(), js_string(vm, duration_format.locale()), number_format_options))); // FIXME: durationFormat.[[NumberFormat]] is not a thing, the spec likely means 'nf' in this case // p. Let num be ! FormatNumeric(durationFormat.[[NumberFormat]], value). @@ -432,7 +431,7 @@ ThrowCompletionOr> partition_duration_format_pattern(VM // t. Else, else { // i. Let pr be ? Construct(%PluralRules%, « durationFormat.[[Locale]] »). - auto* plural_rules = TRY(construct(vm, *global_object.intl_plural_rules_constructor(), js_string(vm, duration_format.locale()))); + auto* plural_rules = TRY(construct(vm, *realm.global_object().intl_plural_rules_constructor(), js_string(vm, duration_format.locale()))); // ii. Let prv be ! ResolvePlural(pr, value). auto plurality = resolve_plural(static_cast(*plural_rules), value); @@ -480,7 +479,7 @@ ThrowCompletionOr> partition_duration_format_pattern(VM } // 3. Let lf be ? Construct(%ListFormat%, « durationFormat.[[Locale]] »). - auto* list_format = static_cast(TRY(construct(vm, *global_object.intl_list_format_constructor(), js_string(vm, duration_format.locale())))); + auto* list_format = static_cast(TRY(construct(vm, *realm.global_object().intl_list_format_constructor(), js_string(vm, duration_format.locale())))); // FIXME: CreatePartsFromList expects a list of strings and creates a list of Pattern Partition records, but we already created a list of Pattern Partition records // so we try to hack something together from it that looks mostly right diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp index 17ac661e8d..5401ebd3fc 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp @@ -204,7 +204,6 @@ String format_list(ListFormat const& list_format, Vector const& list) Array* format_list_to_parts(VM& vm, ListFormat const& list_format, Vector const& list) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Let parts be ! CreatePartsFromList(listFormat, list). auto parts = create_parts_from_list(list_format, list); @@ -218,7 +217,7 @@ Array* format_list_to_parts(VM& vm, ListFormat const& list_format, Vectorcreate_data_property_or_throw(vm.names.type, js_string(vm, part.type))); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp index c0e09e69fd..23ad1c2be2 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp @@ -908,7 +908,6 @@ String format_numeric(VM& vm, NumberFormat& number_format, MathematicalValue num Array* format_numeric_to_parts(VM& vm, NumberFormat& number_format, MathematicalValue number) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Let parts be ? PartitionNumberPattern(numberFormat, x). // Note: Our implementation of PartitionNumberPattern does not throw. @@ -923,7 +922,7 @@ Array* format_numeric_to_parts(VM& vm, NumberFormat& number_format, Mathematical // 4. For each Record { [[Type]], [[Value]] } part in parts, do for (auto& part : parts) { // a. Let O be OrdinaryObjectCreate(%Object.prototype%). - auto* object = Object::create(realm, global_object.object_prototype()); + auto* object = Object::create(realm, realm.global_object().object_prototype()); // b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]). MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type))); @@ -1825,7 +1824,6 @@ ThrowCompletionOr format_numeric_range(VM& vm, NumberFormat& number_form ThrowCompletionOr format_numeric_range_to_parts(VM& vm, NumberFormat& number_format, MathematicalValue start, MathematicalValue end) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Let parts be ? PartitionNumberRangePattern(numberFormat, x, y). auto parts = TRY(partition_number_range_pattern(vm, number_format, move(start), move(end))); @@ -1839,7 +1837,7 @@ ThrowCompletionOr format_numeric_range_to_parts(VM& vm, NumberFormat& nu // 4. For each Record { [[Type]], [[Value]] } part in parts, do for (auto& part : parts) { // a. Let O be OrdinaryObjectCreate(%Object.prototype%). - auto* object = Object::create(realm, global_object.object_prototype()); + auto* object = Object::create(realm, realm.global_object().object_prototype()); // b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]). MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type))); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp index a72c017549..96fac8169a 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp @@ -244,7 +244,6 @@ ThrowCompletionOr format_relative_time(VM& vm, RelativeTimeFormat& relat ThrowCompletionOr format_relative_time_to_parts(VM& vm, RelativeTimeFormat& relative_time_format, double value, StringView unit) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Let parts be ? PartitionRelativeTimePattern(relativeTimeFormat, value, unit). auto parts = TRY(partition_relative_time_pattern(vm, relative_time_format, value, unit)); @@ -258,7 +257,7 @@ ThrowCompletionOr format_relative_time_to_parts(VM& vm, RelativeTimeForm // 4. For each Record { [[Type]], [[Value]], [[Unit]] } part in parts, do for (auto& part : parts) { // a. Let O be OrdinaryObjectCreate(%Object.prototype%). - auto* object = Object::create(realm, global_object.object_prototype()); + auto* object = Object::create(realm, realm.global_object().object_prototype()); // b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]). MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type))); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp index d985b6c13f..9896a1b62a 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp @@ -79,7 +79,6 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatConstructor::supported_locales_of) ThrowCompletionOr initialize_relative_time_format(VM& vm, RelativeTimeFormat& relative_time_format, Value locales_value, Value options_value) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Let requestedLocales be ? CanonicalizeLocaleList(locales). auto requested_locales = TRY(canonicalize_locale_list(vm, locales_value)); @@ -139,11 +138,11 @@ ThrowCompletionOr initialize_relative_time_format(VM& vm, R relative_time_format.set_numeric(numeric.as_string().string()); // 19. Let relativeTimeFormat.[[NumberFormat]] be ! Construct(%NumberFormat%, « locale »). - auto* number_format = MUST(construct(vm, *global_object.intl_number_format_constructor(), js_string(vm, locale))); + auto* number_format = MUST(construct(vm, *realm.global_object().intl_number_format_constructor(), js_string(vm, locale))); relative_time_format.set_number_format(static_cast(number_format)); // 20. Let relativeTimeFormat.[[PluralRules]] be ! Construct(%PluralRules%, « locale »). - auto* plural_rules = MUST(construct(vm, *global_object.intl_plural_rules_constructor(), js_string(vm, locale))); + auto* plural_rules = MUST(construct(vm, *realm.global_object().intl_plural_rules_constructor(), js_string(vm, locale))); relative_time_format.set_plural_rules(static_cast(plural_rules)); // 21. Return relativeTimeFormat. diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Segmenter.cpp b/Userland/Libraries/LibJS/Runtime/Intl/Segmenter.cpp index d5049b8970..6bfaa33655 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/Segmenter.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/Segmenter.cpp @@ -48,7 +48,6 @@ StringView Segmenter::segmenter_granularity_string() const Object* create_segment_data_object(VM& vm, Segmenter const& segmenter, Utf16View const& string, double start_index, double end_index) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Let len be the length of string. auto length = string.length_in_code_units(); @@ -63,7 +62,7 @@ Object* create_segment_data_object(VM& vm, Segmenter const& segmenter, Utf16View VERIFY(start_index < end_index); // 5. Let result be OrdinaryObjectCreate(%Object.prototype%). - auto* result = Object::create(realm, global_object.object_prototype()); + auto* result = Object::create(realm, realm.global_object().object_prototype()); // 6. Let segment be the substring of string from startIndex to endIndex. auto segment = string.substring_view(start_index, end_index - start_index); diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp index 9de508fb0a..c57de9bd7a 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp @@ -187,10 +187,9 @@ Completion async_iterator_close(VM& vm, Iterator const& iterator_record, Complet Object* create_iterator_result_object(VM& vm, Value value, bool done) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Let obj be OrdinaryObjectCreate(%Object.prototype%). - auto* object = Object::create(realm, global_object.object_prototype()); + auto* object = Object::create(realm, realm.global_object().object_prototype()); // 2. Perform ! CreateDataPropertyOrThrow(obj, "value", value). MUST(object->create_data_property_or_throw(vm.names.value, value)); diff --git a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp index d471bff14a..7f5991ddd3 100644 --- a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp @@ -46,7 +46,6 @@ void JSONObject::initialize(Realm& realm) ThrowCompletionOr JSONObject::stringify_impl(VM& vm, Value value, Value replacer, Value space) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); StringifyState state; @@ -102,7 +101,7 @@ ThrowCompletionOr JSONObject::stringify_impl(VM& vm, Value value, Value state.gap = String::empty(); } - auto* wrapper = Object::create(realm, global_object.object_prototype()); + auto* wrapper = Object::create(realm, realm.global_object().object_prototype()); MUST(wrapper->create_data_property_or_throw(String::empty(), value)); return serialize_json_property(vm, state, String::empty(), wrapper); } diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index 638b676725..7eeefde661 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -369,9 +369,8 @@ ThrowCompletionOr> Object::enumerable_own_property_names(Pro // NOTE: This has been flattened for readability, so some `else` branches in the // spec text have been replaced with `continue`s in the loop below. - auto& global_object = this->global_object(); auto& vm = this->vm(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let ownKeys be ? O.[[OwnPropertyKeys]](). auto own_keys = TRY(internal_own_property_keys()); diff --git a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp index 3b4671d884..9f3ccf6ec5 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp @@ -67,14 +67,13 @@ ThrowCompletionOr ObjectConstructor::call() ThrowCompletionOr ObjectConstructor::construct(FunctionObject& new_target) { auto& vm = this->vm(); - auto& global_object = this->global_object(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); if (&new_target != this) return TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::object_prototype)); auto value = vm.argument(0); if (value.is_nullish()) - return Object::create(realm, global_object.object_prototype()); + return Object::create(realm, realm.global_object().object_prototype()); return value.to_object(vm); } diff --git a/Userland/Libraries/LibJS/Runtime/Promise.cpp b/Userland/Libraries/LibJS/Runtime/Promise.cpp index c80f0df565..e36b9195eb 100644 --- a/Userland/Libraries/LibJS/Runtime/Promise.cpp +++ b/Userland/Libraries/LibJS/Runtime/Promise.cpp @@ -58,8 +58,7 @@ Promise::ResolvingFunctions Promise::create_resolving_functions() dbgln_if(PROMISE_DEBUG, "[Promise @ {} / create_resolving_functions()]", this); auto& vm = this->vm(); - auto& global_object = this->global_object(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let alreadyResolved be the Record { [[Value]]: false }. auto* already_resolved = vm.heap().allocate_without_realm(); diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp index a1c205fce9..c80b9d7cd6 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp @@ -68,8 +68,7 @@ PromiseAllResolveElementFunction::PromiseAllResolveElementFunction(size_t index, ThrowCompletionOr PromiseAllResolveElementFunction::resolve_element() { auto& vm = this->vm(); - auto& global_object = this->global_object(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 8. Set values[index] to x. m_values.values()[m_index] = vm.argument(0); @@ -101,11 +100,10 @@ PromiseAllSettledResolveElementFunction::PromiseAllSettledResolveElementFunction ThrowCompletionOr PromiseAllSettledResolveElementFunction::resolve_element() { auto& vm = this->vm(); - auto& global_object = this->global_object(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 9. Let obj be OrdinaryObjectCreate(%Object.prototype%). - auto* object = Object::create(realm, global_object.object_prototype()); + auto* object = Object::create(realm, realm.global_object().object_prototype()); // 10. Perform ! CreateDataPropertyOrThrow(obj, "status", "fulfilled"). MUST(object->create_data_property_or_throw(vm.names.status, js_string(vm, "fulfilled"sv))); @@ -143,11 +141,10 @@ PromiseAllSettledRejectElementFunction::PromiseAllSettledRejectElementFunction(s ThrowCompletionOr PromiseAllSettledRejectElementFunction::resolve_element() { auto& vm = this->vm(); - auto& global_object = this->global_object(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 9. Let obj be OrdinaryObjectCreate(%Object.prototype%). - auto* object = Object::create(realm, global_object.object_prototype()); + auto* object = Object::create(realm, realm.global_object().object_prototype()); // 10. Perform ! CreateDataPropertyOrThrow(obj, "status", "rejected"). MUST(object->create_data_property_or_throw(vm.names.status, js_string(vm, "rejected"sv))); @@ -185,8 +182,7 @@ PromiseAnyRejectElementFunction::PromiseAnyRejectElementFunction(size_t index, P ThrowCompletionOr PromiseAnyRejectElementFunction::resolve_element() { auto& vm = this->vm(); - auto& global_object = this->global_object(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 8. Set errors[index] to x. m_values.values()[m_index] = vm.argument(0); diff --git a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp index 9ccfbd548b..648e00c526 100644 --- a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp @@ -743,8 +743,7 @@ ThrowCompletionOr> ProxyObject::internal_own_property_keys() ThrowCompletionOr ProxyObject::internal_call(Value this_argument, MarkedVector arguments_list) { auto& vm = this->vm(); - auto& global_object = this->global_object(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // A Proxy exotic object only has a [[Call]] internal method if the initial value of its [[ProxyTarget]] internal slot is an object that has a [[Call]] internal method. // TODO: We should be able to turn this into a VERIFY(), this must be checked at the call site. @@ -792,8 +791,7 @@ bool ProxyObject::has_constructor() const ThrowCompletionOr ProxyObject::internal_construct(MarkedVector arguments_list, FunctionObject& new_target) { auto& vm = this->vm(); - auto& global_object = this->global_object(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // A Proxy exotic object only has a [[Construct]] internal method if the initial value of its [[ProxyTarget]] internal slot is an object that has a [[Construct]] internal method. // TODO: We should be able to turn this into a VERIFY(), this must be checked at the call site. diff --git a/Userland/Libraries/LibJS/Runtime/Reference.cpp b/Userland/Libraries/LibJS/Runtime/Reference.cpp index d94148398c..dbf23f5419 100644 --- a/Userland/Libraries/LibJS/Runtime/Reference.cpp +++ b/Userland/Libraries/LibJS/Runtime/Reference.cpp @@ -86,7 +86,6 @@ Completion Reference::throw_reference_error(VM& vm) const ThrowCompletionOr Reference::get_value(VM& vm) const { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. ReturnIfAbrupt(V). // 2. If V is not a Reference Record, return V. @@ -119,11 +118,11 @@ ThrowCompletionOr Reference::get_value(VM& vm) const auto string_value = m_base_value.as_string().get(vm, m_name); if (string_value.has_value()) return *string_value; - base_obj = global_object.string_prototype(); + base_obj = realm.global_object().string_prototype(); } else if (m_base_value.is_number()) - base_obj = global_object.number_prototype(); + base_obj = realm.global_object().number_prototype(); else if (m_base_value.is_boolean()) - base_obj = global_object.boolean_prototype(); + base_obj = realm.global_object().boolean_prototype(); else base_obj = TRY(m_base_value.to_object(vm)); diff --git a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp index 06bc2bb193..fa07dcd9cd 100644 --- a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp @@ -53,8 +53,7 @@ ThrowCompletionOr StringConstructor::call() ThrowCompletionOr StringConstructor::construct(FunctionObject& new_target) { auto& vm = this->vm(); - auto& global_object = this->global_object(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); PrimitiveString* primitive_string; if (!vm.argument_count()) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp index ea23baf105..4693f07ae5 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp @@ -64,14 +64,13 @@ Span available_calendars() ThrowCompletionOr create_temporal_calendar(VM& vm, String const& identifier, FunctionObject const* new_target) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Assert: IsBuiltinCalendar(identifier) is true. VERIFY(is_builtin_calendar(identifier)); // 2. If newTarget is not provided, set newTarget to %Temporal.Calendar%. if (!new_target) - new_target = global_object.temporal_calendar_constructor(); + new_target = realm.global_object().temporal_calendar_constructor(); // 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Calendar.prototype%", « [[InitializedTemporalCalendar]], [[Identifier]] »). // 4. Set object.[[Identifier]] to identifier. @@ -886,10 +885,9 @@ u8 iso_day(Object& temporal_object) ThrowCompletionOr default_merge_calendar_fields(VM& vm, Object const& fields, Object const& additional_fields) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Let merged be OrdinaryObjectCreate(%Object.prototype%). - auto* merged = Object::create(realm, global_object.object_prototype()); + auto* merged = Object::create(realm, realm.global_object().object_prototype()); // 2. Let fieldsKeys be ? EnumerableOwnPropertyNames(fields, key). auto fields_keys = TRY(fields.enumerable_own_property_names(Object::PropertyKind::Key)); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp index 8a2843470b..f675af1074 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp @@ -327,7 +327,6 @@ ThrowCompletionOr to_temporal_partial_duration_record(VM& ThrowCompletionOr create_temporal_duration(VM& vm, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, FunctionObject const* new_target) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. If ! IsValidDuration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds) is false, throw a RangeError exception. if (!is_valid_duration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds)) @@ -335,7 +334,7 @@ ThrowCompletionOr create_temporal_duration(VM& vm, double years, doub // 2. If newTarget is not present, set newTarget to %Temporal.Duration%. if (!new_target) - new_target = global_object.temporal_duration_constructor(); + new_target = realm.global_object().temporal_duration_constructor(); // 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Duration.prototype%", « [[InitializedTemporalDuration]], [[Years]], [[Months]], [[Weeks]], [[Days]], [[Hours]], [[Minutes]], [[Seconds]], [[Milliseconds]], [[Microseconds]], [[Nanoseconds]] »). // 4. Set object.[[Years]] to ℝ(𝔽(years)). diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp index cec11631e8..b404177453 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp @@ -53,7 +53,6 @@ bool is_valid_epoch_nanoseconds(BigInt const& epoch_nanoseconds) ThrowCompletionOr create_temporal_instant(VM& vm, BigInt const& epoch_nanoseconds, FunctionObject const* new_target) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Assert: Type(epochNanoseconds) is BigInt. @@ -62,7 +61,7 @@ ThrowCompletionOr create_temporal_instant(VM& vm, BigInt const& epoch_ // 3. If newTarget is not present, set newTarget to %Temporal.Instant%. if (!new_target) - new_target = global_object.temporal_instant_constructor(); + new_target = realm.global_object().temporal_instant_constructor(); // 4. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Instant.prototype%", « [[InitializedTemporalInstant]], [[Nanoseconds]] »). // 5. Set object.[[Nanoseconds]] to epochNanoseconds. diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp index bf82afdbf5..946690dc4e 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp @@ -51,7 +51,6 @@ ISODateRecord create_iso_date_record(i32 year, u8 month, u8 day) ThrowCompletionOr create_temporal_date(VM& vm, i32 iso_year, u8 iso_month, u8 iso_day, Object& calendar, FunctionObject const* new_target) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Assert: isoYear is an integer. // 2. Assert: isoMonth is an integer. @@ -68,7 +67,7 @@ ThrowCompletionOr create_temporal_date(VM& vm, i32 iso_year, u8 iso_ // 7. If newTarget is not present, set newTarget to %Temporal.PlainDate%. if (!new_target) - new_target = global_object.temporal_plain_date_constructor(); + new_target = realm.global_object().temporal_plain_date_constructor(); // 8. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainDate.prototype%", « [[InitializedTemporalDate]], [[ISOYear]], [[ISOMonth]], [[ISODay]], [[Calendar]] »). // 9. Set object.[[ISOYear]] to isoYear. diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp index 3c1f0469a2..ae43066cc8 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp @@ -228,7 +228,6 @@ ISODateTime balance_iso_date_time(i32 year, u8 month, u8 day, u8 hour, u8 minute ThrowCompletionOr create_temporal_date_time(VM& vm, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Object& calendar, FunctionObject const* new_target) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Assert: isoYear, isoMonth, isoDay, hour, minute, second, millisecond, microsecond, and nanosecond are integers. // 2. Assert: Type(calendar) is Object. @@ -249,7 +248,7 @@ ThrowCompletionOr create_temporal_date_time(VM& vm, i32 iso_year // 6. If newTarget is not present, set newTarget to %Temporal.PlainDateTime%. if (!new_target) - new_target = global_object.temporal_plain_date_time_constructor(); + new_target = realm.global_object().temporal_plain_date_time_constructor(); // 7. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainDateTime.prototype%", « [[InitializedTemporalDateTime]], [[ISOYear]], [[ISOMonth]], [[ISODay]], [[ISOHour]], [[ISOMinute]], [[ISOSecond]], [[ISOMillisecond]], [[ISOMicrosecond]], [[ISONanosecond]], [[Calendar]] »). // 8. Set object.[[ISOYear]] to isoYear. diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDay.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDay.cpp index 3aa6a6bdb9..ecbc433553 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDay.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDay.cpp @@ -145,7 +145,6 @@ ThrowCompletionOr to_temporal_month_day(VM& vm, Value item, Obje ThrowCompletionOr create_temporal_month_day(VM& vm, u8 iso_month, u8 iso_day, Object& calendar, i32 reference_iso_year, FunctionObject const* new_target) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Assert: isoMonth, isoDay, and referenceISOYear are integers. // 2. Assert: Type(calendar) is Object. @@ -160,7 +159,7 @@ ThrowCompletionOr create_temporal_month_day(VM& vm, u8 iso_month // 5. If newTarget is not present, set newTarget to %Temporal.PlainMonthDay%. if (!new_target) - new_target = global_object.temporal_plain_month_day_constructor(); + new_target = realm.global_object().temporal_plain_month_day_constructor(); // 6. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainMonthDay.prototype%", « [[InitializedTemporalMonthDay]], [[ISOMonth]], [[ISODay]], [[ISOYear]], [[Calendar]] »). // 7. Set object.[[ISOMonth]] to isoMonth. diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp index 4fc39906b0..ddcb234cfb 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp @@ -311,7 +311,6 @@ TemporalTime constrain_time(double hour, double minute, double second, double mi ThrowCompletionOr create_temporal_time(VM& vm, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, FunctionObject const* new_target) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Assert: hour, minute, second, millisecond, microsecond and nanosecond are integers. @@ -321,7 +320,7 @@ ThrowCompletionOr create_temporal_time(VM& vm, u8 hour, u8 minute, u // 3. If newTarget is not present, set newTarget to %Temporal.PlainTime%. if (!new_target) - new_target = global_object.temporal_plain_time_constructor(); + new_target = realm.global_object().temporal_plain_time_constructor(); // 4. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainTime.prototype%", « [[InitializedTemporalTime]], [[ISOHour]], [[ISOMinute]], [[ISOSecond]], [[ISOMillisecond]], [[ISOMicrosecond]], [[ISONanosecond]], [[Calendar]] »). // 5. Set object.[[ISOHour]] to hour. diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp index f9ee7ba2b3..093b65774a 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp @@ -186,7 +186,6 @@ ISOYearMonth balance_iso_year_month(double year, double month) ThrowCompletionOr create_temporal_year_month(VM& vm, i32 iso_year, u8 iso_month, Object& calendar, u8 reference_iso_day, FunctionObject const* new_target) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Assert: isoYear, isoMonth, and referenceISODay are integers. // 2. Assert: Type(calendar) is Object. @@ -201,7 +200,7 @@ ThrowCompletionOr create_temporal_year_month(VM& vm, i32 iso_ye // 5. If newTarget is not present, set newTarget to %Temporal.PlainYearMonth%. if (!new_target) - new_target = global_object.temporal_plain_year_month_constructor(); + new_target = realm.global_object().temporal_plain_year_month_constructor(); // 6. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainYearMonth.prototype%", « [[InitializedTemporalYearMonth]], [[ISOYear]], [[ISOMonth]], [[ISODay]], [[Calendar]] »). // 7. Set object.[[ISOYear]] to isoYear. diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp index cc836fa52c..d6dfe07b8b 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp @@ -66,11 +66,10 @@ String default_time_zone() ThrowCompletionOr create_temporal_time_zone(VM& vm, String const& identifier, FunctionObject const* new_target) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. If newTarget is not present, set newTarget to %Temporal.TimeZone%. if (!new_target) - new_target = global_object.temporal_time_zone_constructor(); + new_target = realm.global_object().temporal_time_zone_constructor(); // 2. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.TimeZone.prototype%", « [[InitializedTemporalTimeZone]], [[Identifier]], [[OffsetNanoseconds]] »). auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &GlobalObject::temporal_time_zone_prototype)); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp index 35da023777..96a9acd1bf 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp @@ -268,14 +268,13 @@ ThrowCompletionOr to_temporal_zoned_date_time(VM& vm, Value item ThrowCompletionOr create_temporal_zoned_date_time(VM& vm, BigInt const& epoch_nanoseconds, Object& time_zone, Object& calendar, FunctionObject const* new_target) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Assert: ! IsValidEpochNanoseconds(epochNanoseconds) is true. VERIFY(is_valid_epoch_nanoseconds(epoch_nanoseconds)); // 2. If newTarget is not present, set newTarget to %Temporal.ZonedDateTime%. if (!new_target) - new_target = global_object.temporal_zoned_date_time_constructor(); + new_target = realm.global_object().temporal_zoned_date_time_constructor(); // 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.ZonedDateTime.prototype%", « [[InitializedTemporalZonedDateTime]], [[Nanoseconds]], [[TimeZone]], [[Calendar]] »). // 4. Set object.[[Nanoseconds]] to epochNanoseconds. diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp index 4fb9f73ed6..35e20e2007 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp @@ -129,7 +129,6 @@ template static ThrowCompletionOr initialize_typed_array_from_typed_array(VM& vm, TypedArray& dest_array, TypedArrayBase& src_array) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Let srcData be srcArray.[[ViewedArrayBuffer]]. auto* src_data = src_array.viewed_array_buffer(); @@ -169,7 +168,7 @@ static ThrowCompletionOr initialize_typed_array_from_typed_array(VM& vm, T // 11. Else, else { // a. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength). - data = TRY(allocate_array_buffer(vm, *global_object.array_buffer_constructor(), byte_length.value())); + data = TRY(allocate_array_buffer(vm, *realm.global_object().array_buffer_constructor(), byte_length.value())); // b. If IsDetachedBuffer(srcData) is true, throw a TypeError exception. if (src_data->is_detached()) @@ -225,7 +224,6 @@ template static ThrowCompletionOr allocate_typed_array_buffer(VM& vm, TypedArray& typed_array, size_t length) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // Enforce 2GB "Excessive Length" limit if (length > NumericLimits::max() / sizeof(T)) @@ -242,7 +240,7 @@ static ThrowCompletionOr allocate_typed_array_buffer(VM& vm, TypedArray auto byte_length = element_size * length; // 4. Let data be ? AllocateArrayBuffer(%ArrayBuffer%, byteLength). - auto* data = TRY(allocate_array_buffer(vm, *global_object.array_buffer_constructor(), byte_length)); + auto* data = TRY(allocate_array_buffer(vm, *realm.global_object().array_buffer_constructor(), byte_length)); // 5. Set O.[[ViewedArrayBuffer]] to data. typed_array.set_viewed_array_buffer(data); @@ -345,11 +343,10 @@ ThrowCompletionOr typed_array_create(VM& vm, FunctionObject& co ThrowCompletionOr typed_array_create_same_type(VM& vm, TypedArrayBase const& exemplar, MarkedVector arguments) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Assert: exemplar is an Object that has [[TypedArrayName]] and [[ContentType]] internal slots. // 2. Let constructor be the intrinsic object listed in column one of Table 63 (points to Table 72) for exemplar.[[TypedArrayName]]. - auto* constructor = (global_object.*exemplar.intrinsic_constructor())(); + auto* constructor = (realm.global_object().*exemplar.intrinsic_constructor())(); // 3. Let result be ? TypedArrayCreate(constructor, argumentList). auto* result = TRY(typed_array_create(vm, *constructor, move(arguments))); @@ -514,8 +511,7 @@ void TypedArrayBase::visit_edges(Visitor& visitor) ThrowCompletionOr ConstructorName::construct(FunctionObject& new_target) \ { \ auto& vm = this->vm(); \ - auto& global_object = this->global_object(); \ - auto& realm = *global_object.associated_realm(); \ + auto& realm = *vm.current_realm(); \ \ if (vm.argument_count() == 0) \ return TRY(ClassName::create(realm, 0, new_target)); \ diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp index f410547197..a391a9f45b 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp @@ -144,10 +144,9 @@ static ThrowCompletionOr for_each_item_from_last(VM& vm, String const& nam static ThrowCompletionOr typed_array_species_create(VM& vm, TypedArrayBase const& exemplar, MarkedVector arguments) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Let defaultConstructor be the intrinsic object listed in column one of Table 72 for exemplar.[[TypedArrayName]]. - auto* default_constructor = (global_object.*exemplar.intrinsic_constructor())(); + auto* default_constructor = (realm.global_object().*exemplar.intrinsic_constructor())(); // 2. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). auto* constructor = TRY(species_constructor(vm, exemplar, *default_constructor)); diff --git a/Userland/Libraries/LibTest/JavaScriptTestRunner.h b/Userland/Libraries/LibTest/JavaScriptTestRunner.h index 4982f8294d..be8719fb2d 100644 --- a/Userland/Libraries/LibTest/JavaScriptTestRunner.h +++ b/Userland/Libraries/LibTest/JavaScriptTestRunner.h @@ -260,7 +260,7 @@ inline AK::Result, ParserError> parse_module inline ErrorOr get_test_results(JS::Interpreter& interpreter) { - auto results = MUST(interpreter.global_object().get("__TestResults__")); + auto results = MUST(interpreter.realm().global_object().get("__TestResults__")); auto json_string = MUST(JS::JSONObject::stringify_impl(*g_vm, results, JS::js_undefined(), JS::js_undefined())); return JsonValue::from_string(json_string); @@ -383,7 +383,7 @@ inline JSFileResult TestRunner::run_file_test(String const& test_path) executable->name = test_path; if (JS::Bytecode::g_dump_bytecode) executable->dump(); - JS::Bytecode::Interpreter bytecode_interpreter(interpreter->global_object(), interpreter->realm()); + JS::Bytecode::Interpreter bytecode_interpreter(interpreter->realm().global_object(), interpreter->realm()); (void)bytecode_interpreter.run(*executable); } } else { @@ -403,7 +403,7 @@ inline JSFileResult TestRunner::run_file_test(String const& test_path) JSFileResult file_result { test_path.substring(m_test_root.length() + 1, test_path.length() - m_test_root.length() - 1) }; // Collect logged messages - auto user_output = MUST(interpreter->global_object().get("__UserOutput__")); + auto user_output = MUST(interpreter->realm().global_object().get("__UserOutput__")); auto& arr = user_output.as_array(); for (auto& entry : arr.indexed_properties()) { diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp index 2b4f3b4ece..f063bb7ece 100644 --- a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp @@ -95,9 +95,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_getter) // https://html.spec.whatwg.org/multipage/history.html#the-location-interface:dom-location-href-2 JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_setter) { - auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); - auto& window = static_cast(global_object); + auto& window = static_cast(HTML::current_global_object()); // FIXME: 1. If this's relevant Document is null, then return. @@ -220,9 +218,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::port_getter) // https://html.spec.whatwg.org/multipage/history.html#dom-location-reload JS_DEFINE_NATIVE_FUNCTION(LocationObject::reload) { - auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); - auto& window = static_cast(global_object); + auto& window = static_cast(HTML::current_global_object()); window.impl().did_call_location_reload({}); return JS::js_undefined(); } @@ -230,9 +226,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::reload) // https://html.spec.whatwg.org/multipage/history.html#dom-location-replace JS_DEFINE_NATIVE_FUNCTION(LocationObject::replace) { - auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); - auto& window = static_cast(global_object); + auto& window = static_cast(HTML::current_global_object()); auto url = TRY(vm.argument(0).to_string(vm)); // FIXME: This needs spec compliance work. window.impl().did_call_location_replace({}, move(url)); @@ -306,8 +300,7 @@ JS::ThrowCompletionOr> LocationObject::internal // 7.10.5.6 [[DefineOwnProperty]] ( P, Desc ), https://html.spec.whatwg.org/multipage/history.html#location-defineownproperty JS::ThrowCompletionOr LocationObject::internal_define_own_property(JS::PropertyKey const& property_key, JS::PropertyDescriptor const& descriptor) { - auto& global_object = HTML::current_global_object(); - auto& vm = global_object.vm(); + auto& vm = this->vm(); // 1. If IsPlatformObjectSameOrigin(this) is true, then: if (is_platform_object_same_origin(*this)) { @@ -349,8 +342,7 @@ JS::ThrowCompletionOr LocationObject::internal_set(JS::PropertyKey const& // 7.10.5.9 [[Delete]] ( P ), https://html.spec.whatwg.org/multipage/history.html#location-delete JS::ThrowCompletionOr LocationObject::internal_delete(JS::PropertyKey const& property_key) { - auto& global_object = HTML::current_global_object(); - auto& vm = global_object.vm(); + auto& vm = this->vm(); // 1. If IsPlatformObjectSameOrigin(this) is true, then return ? OrdinaryDelete(this, P). if (is_platform_object_same_origin(*this)) diff --git a/Userland/Libraries/LibWeb/Bindings/WindowProxy.cpp b/Userland/Libraries/LibWeb/Bindings/WindowProxy.cpp index e77e175fac..04fffa57cd 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowProxy.cpp +++ b/Userland/Libraries/LibWeb/Bindings/WindowProxy.cpp @@ -128,8 +128,7 @@ JS::ThrowCompletionOr> WindowProxy::internal_ge // 7.4.6 [[DefineOwnProperty]] ( P, Desc ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-defineownproperty JS::ThrowCompletionOr WindowProxy::internal_define_own_property(JS::PropertyKey const& property_key, JS::PropertyDescriptor const& descriptor) { - auto& global_object = HTML::current_global_object(); - auto& vm = global_object.vm(); + auto& vm = this->vm(); // 1. Let W be the value of the [[Window]] internal slot of this. @@ -196,8 +195,7 @@ JS::ThrowCompletionOr WindowProxy::internal_set(JS::PropertyKey const& pro // 7.4.9 [[Delete]] ( P ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-delete JS::ThrowCompletionOr WindowProxy::internal_delete(JS::PropertyKey const& property_key) { - auto& global_object = HTML::current_global_object(); - auto& vm = global_object.vm(); + auto& vm = this->vm(); // 1. Let W be the value of the [[Window]] internal slot of this. diff --git a/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp b/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp index 7a71b0ad6b..bf2b1e5139 100644 --- a/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp +++ b/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Linus Groh + * Copyright (c) 2021-2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -14,8 +14,8 @@ namespace Web::Encoding { // https://encoding.spec.whatwg.org/#dom-textencoder-encode JS::Uint8Array* TextEncoder::encode(String const& input) const { - auto& global_object = wrapper()->global_object(); - auto& realm = *global_object.associated_realm(); + auto& vm = wrapper()->vm(); + auto& realm = *vm.current_realm(); // NOTE: The AK::String returned from PrimitiveString::string() is always UTF-8, regardless of the internal string type, so most of these steps are no-ops. diff --git a/Userland/Libraries/LibWeb/Fetch/Headers.cpp b/Userland/Libraries/LibWeb/Fetch/Headers.cpp index 24a754e31b..50af058fb8 100644 --- a/Userland/Libraries/LibWeb/Fetch/Headers.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Headers.cpp @@ -158,8 +158,7 @@ DOM::ExceptionOr Headers::set(String const& name_string, String const& val // https://webidl.spec.whatwg.org/#es-iterable, Step 4 JS::ThrowCompletionOr Headers::for_each(ForEachCallback callback) { - auto& global_object = wrapper()->global_object(); - auto& vm = global_object.vm(); + auto& vm = wrapper()->vm(); // The value pairs to iterate over are the return value of running sort and combine with this’s header list. auto value_pairs_to_iterate_over = [&]() -> JS::ThrowCompletionOr> { diff --git a/Userland/Libraries/LibWeb/Fetch/HeadersIterator.cpp b/Userland/Libraries/LibWeb/Fetch/HeadersIterator.cpp index dd9397d5eb..d5981ad0cb 100644 --- a/Userland/Libraries/LibWeb/Fetch/HeadersIterator.cpp +++ b/Userland/Libraries/LibWeb/Fetch/HeadersIterator.cpp @@ -15,9 +15,8 @@ namespace Web::Fetch { // https://webidl.spec.whatwg.org/#es-iterable, Step 2 JS::ThrowCompletionOr HeadersIterator::next() { - auto& global_object = wrapper()->global_object(); - auto& vm = global_object.vm(); - auto& realm = *global_object.associated_realm(); + auto& vm = wrapper()->vm(); + auto& realm = *vm.current_realm(); // The value pairs to iterate over are the return value of running sort and combine with this’s header list. auto value_pairs_to_iterate_over = [&]() -> JS::ThrowCompletionOr> { diff --git a/Userland/Libraries/LibWeb/FileAPI/Blob.cpp b/Userland/Libraries/LibWeb/FileAPI/Blob.cpp index 23c713f7f4..573330e83b 100644 --- a/Userland/Libraries/LibWeb/FileAPI/Blob.cpp +++ b/Userland/Libraries/LibWeb/FileAPI/Blob.cpp @@ -221,8 +221,8 @@ DOM::ExceptionOr> Blob::slice(Optional start, Optional< // https://w3c.github.io/FileAPI/#dom-blob-text JS::Promise* Blob::text() { - auto& global_object = wrapper()->global_object(); - auto& realm = *global_object.associated_realm(); + auto& vm = wrapper()->vm(); + auto& realm = *vm.current_realm(); // FIXME: 1. Let stream be the result of calling get stream on this. // FIXME: 2. Let reader be the result of getting a reader from stream. If that threw an exception, return a new promise rejected with that exception. @@ -230,7 +230,7 @@ JS::Promise* Blob::text() // FIXME: We still need to implement ReadableStream for this step to be fully valid. // 3. Let promise be the result of reading all bytes from stream with reader auto* promise = JS::Promise::create(realm); - auto* result = JS::js_string(global_object.heap(), String { m_byte_buffer.bytes() }); + auto* result = JS::js_string(vm, String { m_byte_buffer.bytes() }); // 4. Return the result of transforming promise by a fulfillment handler that returns the result of running UTF-8 decode on its first argument. promise->fulfill(result); @@ -240,8 +240,8 @@ JS::Promise* Blob::text() // https://w3c.github.io/FileAPI/#dom-blob-arraybuffer JS::Promise* Blob::array_buffer() { - auto& global_object = wrapper()->global_object(); - auto& realm = *global_object.associated_realm(); + auto& vm = wrapper()->vm(); + auto& realm = *vm.current_realm(); // FIXME: 1. Let stream be the result of calling get stream on this. // FIXME: 2. Let reader be the result of getting a reader from stream. If that threw an exception, return a new promise rejected with that exception. diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp index ea469eb2f1..9fad10b186 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp @@ -71,8 +71,7 @@ NonnullRefPtr ClassicScript::create(String filename, StringView s // https://html.spec.whatwg.org/multipage/webappapis.html#run-a-classic-script JS::Completion ClassicScript::run(RethrowErrors rethrow_errors) { - auto& global_object = settings_object().global_object(); - auto& vm = global_object.vm(); + auto& vm = settings_object().realm().vm(); // 1. Let settings be the settings object of script. auto& settings = settings_object(); diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp index c709889376..d554d91526 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp @@ -324,7 +324,7 @@ JS::GlobalObject& current_global_object() JS::Realm& relevant_realm(JS::Object const& object) { // The relevant Realm for a platform object is the value of its [[Realm]] field. - return *object.global_object().associated_realm(); + return object.shape().realm(); } // https://html.spec.whatwg.org/multipage/webappapis.html#relevant-settings-object diff --git a/Userland/Libraries/LibWeb/URL/URLSearchParamsIterator.cpp b/Userland/Libraries/LibWeb/URL/URLSearchParamsIterator.cpp index b32ffe406d..bf21003141 100644 --- a/Userland/Libraries/LibWeb/URL/URLSearchParamsIterator.cpp +++ b/Userland/Libraries/LibWeb/URL/URLSearchParamsIterator.cpp @@ -14,9 +14,8 @@ namespace Web::URL { JS::Object* URLSearchParamsIterator::next() { - auto& global_object = wrapper()->global_object(); - auto& vm = global_object.vm(); - auto& realm = *global_object.associated_realm(); + auto& vm = wrapper()->vm(); + auto& realm = *vm.current_realm(); if (m_index >= m_url_search_params.m_list.size()) return create_iterator_result_object(vm, JS::js_undefined(), true); diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp index e5ad7168c0..ea8698c57a 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp @@ -27,8 +27,7 @@ JS::ThrowCompletionOr WebAssemblyMemoryConstructor::call() JS::ThrowCompletionOr WebAssemblyMemoryConstructor::construct(FunctionObject&) { auto& vm = this->vm(); - auto& global_object = this->global_object(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto descriptor = TRY(vm.argument(0).to_object(vm)); auto initial_value = TRY(descriptor->get("initial")); diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp index 951099eddd..a9a7bef0fe 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp @@ -29,8 +29,7 @@ JS::ThrowCompletionOr WebAssemblyTableConstructor::call() JS::ThrowCompletionOr WebAssemblyTableConstructor::construct(FunctionObject&) { auto& vm = this->vm(); - auto& global_object = this->global_object(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto descriptor = TRY(vm.argument(0).to_object(vm)); auto element_value = TRY(descriptor->get("element")); diff --git a/Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp b/Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp index 1d67485d1b..ca1197f25e 100644 --- a/Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp +++ b/Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp @@ -213,8 +213,8 @@ void WebSocket::on_message(ByteBuffer message, bool is_text) TODO(); } else if (m_binary_type == "arraybuffer") { // type indicates that the data is Binary and binaryType is "arraybuffer" - auto& global_object = wrapper()->global_object(); - auto& realm = *global_object.associated_realm(); + auto& vm = wrapper()->vm(); + auto& realm = *vm.current_realm(); HTML::MessageEventInit event_init; event_init.data = JS::ArrayBuffer::create(realm, message); event_init.origin = url(); diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index f1ef2b1c8d..b08020d917 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -82,7 +82,6 @@ DOM::ExceptionOr XMLHttpRequest::response_text() const // https://xhr.spec.whatwg.org/#response DOM::ExceptionOr XMLHttpRequest::response() { - auto& global_object = wrapper()->global_object(); auto& vm = wrapper()->vm(); auto& realm = *vm.current_realm(); @@ -144,7 +143,7 @@ DOM::ExceptionOr XMLHttpRequest::response() // 3. Let jsonObject be the result of running parse JSON from bytes on this’s received bytes. If that threw an exception, then return null. TextCodec::UTF8Decoder decoder; - auto json_object_result = JS::call(vm, global_object.json_parse_function(), JS::js_undefined(), JS::js_string(global_object.heap(), decoder.to_utf8({ m_received_bytes.data(), m_received_bytes.size() }))); + auto json_object_result = JS::call(vm, realm.global_object().json_parse_function(), JS::js_undefined(), JS::js_string(vm, decoder.to_utf8({ m_received_bytes.data(), m_received_bytes.size() }))); if (json_object_result.is_error()) return JS::Value(JS::js_null()); @@ -623,8 +622,7 @@ DOM::ExceptionOr XMLHttpRequest::set_timeout(u32 timeout) { // 1. If the current global object is a Window object and this’s synchronous flag is set, // then throw an "InvalidAccessError" DOMException. - auto& global_object = wrapper()->global_object(); - if (global_object.class_name() == "WindowObject" && m_synchronous) + if (is(HTML::current_global_object()) && m_synchronous) return DOM::InvalidAccessError::create("Use of XMLHttpRequest's timeout attribute is not supported in the synchronous mode in window context."); // 2. Set this’s timeout to the given value. diff --git a/Userland/Services/WebContent/WebContentConsoleClient.cpp b/Userland/Services/WebContent/WebContentConsoleClient.cpp index 9e3922e97a..a94c1ff774 100644 --- a/Userland/Services/WebContent/WebContentConsoleClient.cpp +++ b/Userland/Services/WebContent/WebContentConsoleClient.cpp @@ -25,13 +25,13 @@ WebContentConsoleClient::WebContentConsoleClient(JS::Console& console, WeakPtrvm(); auto& realm = m_interpreter->realm(); - auto& global_object = realm.global_object(); + auto& window = static_cast(realm.global_object()); - auto console_global_object = m_interpreter->heap().allocate_without_realm(m_interpreter->realm(), static_cast(global_object)); + auto console_global_object = m_interpreter->heap().allocate_without_realm(realm, window); // NOTE: We need to push an execution context here for NativeFunction::create() to succeed during global object initialization. // It gets removed immediately after creating the interpreter in Document::interpreter(). - auto& eso = verify_cast(*m_interpreter->realm().host_defined()); + auto& eso = verify_cast(*realm.host_defined()); vm.push_execution_context(eso.realm_execution_context()); console_global_object->set_associated_realm(realm); console_global_object->initialize_global_object(realm); diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index 0727d242ec..84dffb5e12 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -1170,7 +1170,7 @@ static bool parse_and_run(JS::Interpreter& interpreter, StringView source, Strin executable->dump(); if (s_run_bytecode) { - JS::Bytecode::Interpreter bytecode_interpreter(interpreter.global_object(), interpreter.realm()); + JS::Bytecode::Interpreter bytecode_interpreter(interpreter.realm().global_object(), interpreter.realm()); auto result_or_error = bytecode_interpreter.run_and_return_frame(*executable, nullptr); if (result_or_error.value.is_error()) result = result_or_error.value.release_error(); @@ -1556,8 +1556,8 @@ ErrorOr serenity_main(Main::Arguments arguments) if (evaluate_script.is_empty() && script_paths.is_empty()) { s_print_last_result = true; interpreter = JS::Interpreter::create(*g_vm); - ReplConsoleClient console_client(interpreter->global_object().console()); - interpreter->global_object().console().set_client(console_client); + ReplConsoleClient console_client(interpreter->realm().global_object().console()); + interpreter->realm().global_object().console().set_client(console_client); interpreter->heap().set_should_collect_on_every_allocation(gc_on_every_allocation); auto& global_environment = interpreter->realm().global_environment(); @@ -1743,7 +1743,7 @@ ErrorOr serenity_main(Main::Arguments arguments) break; } case CompleteVariable: { - auto const& variable = interpreter->global_object(); + auto const& variable = interpreter->realm().global_object(); list_all_properties(variable.shape(), variable_name); for (auto const& name : global_environment.declarative_record().bindings()) { @@ -1766,8 +1766,8 @@ ErrorOr serenity_main(Main::Arguments arguments) s_editor->save_history(s_history_path); } else { interpreter = JS::Interpreter::create(*g_vm); - ReplConsoleClient console_client(interpreter->global_object().console()); - interpreter->global_object().console().set_client(console_client); + ReplConsoleClient console_client(interpreter->realm().global_object().console()); + interpreter->realm().global_object().console().set_client(console_client); interpreter->heap().set_should_collect_on_every_allocation(gc_on_every_allocation); signal(SIGINT, [](int) {