summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-08-22 19:00:49 +0100
committerLinus Groh <mail@linusgroh.de>2022-08-23 13:58:30 +0100
commitb345a0acca725d1b4e4d6df26fc602d69e97f073 (patch)
treec1a1b7936505373fc3be8cb7b6f0ced444d05d63 /Userland/Libraries
parente3895e6c808d4606f02b26b1eaad3a3a803bba12 (diff)
downloadserenity-b345a0acca725d1b4e4d6df26fc602d69e97f073.zip
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
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/AST.cpp53
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Op.cpp9
-rw-r--r--Userland/Libraries/LibJS/Console.cpp3
-rw-r--r--Userland/Libraries/LibJS/CyclicModule.cpp9
-rw-r--r--Userland/Libraries/LibJS/Interpreter.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/DatePrototype.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp9
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp7
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp5
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/Segmenter.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/JSONObject.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Object.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp5
-rw-r--r--Userland/Libraries/LibJS/Runtime/Promise.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp16
-rw-r--r--Userland/Libraries/LibJS/Runtime/ProxyObject.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/Reference.cpp7
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringConstructor.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDay.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/TypedArray.cpp12
-rw-r--r--Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp3
-rw-r--r--Userland/Libraries/LibTest/JavaScriptTestRunner.h6
-rw-r--r--Userland/Libraries/LibWeb/Bindings/LocationObject.cpp18
-rw-r--r--Userland/Libraries/LibWeb/Bindings/WindowProxy.cpp6
-rw-r--r--Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp6
-rw-r--r--Userland/Libraries/LibWeb/Fetch/Headers.cpp3
-rw-r--r--Userland/Libraries/LibWeb/Fetch/HeadersIterator.cpp5
-rw-r--r--Userland/Libraries/LibWeb/FileAPI/Blob.cpp10
-rw-r--r--Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp3
-rw-r--r--Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp2
-rw-r--r--Userland/Libraries/LibWeb/URL/URLSearchParamsIterator.cpp5
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp3
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp3
-rw-r--r--Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp4
-rw-r--r--Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp6
54 files changed, 128 insertions, 195 deletions
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<ClassElement::ClassValue> 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<ECMAScriptFunctionObject> initializer {};
@@ -1713,8 +1711,8 @@ Optional<FlyString> ClassMethod::private_bound_identifier() const
// 15.7.11 Runtime Semantics: ClassStaticBlockDefinitionEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-classstaticblockdefinitionevaluation
ThrowCompletionOr<ClassElement::ClassValue> 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<ECMAScriptFunctionObject*> 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<Value> 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<void> 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<void> NewString::execute_impl(Bytecode::Interpreter& interpret
ThrowCompletionOr<void> 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<void> NewRegExp::execute_impl(Bytecode::Interpreter& interpret
ThrowCompletionOr<void> 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<Value, ValueTraits> 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<Value> ConsoleClient::logger(Console::LogLevel log_level, MarkedVector<Value> const& args)
{
- auto& global_object = this->global_object();
auto& vm = this->vm();
// 1. If args is empty, return.
@@ -515,7 +514,7 @@ ThrowCompletionOr<Value> ConsoleClient::logger(Console::LogLevel log_level, Mark
// 4. If rest is empty, perform Printer(logLevel, Ā« first Ā») and return.
if (rest_size == 0) {
- MarkedVector<Value> first_as_vector { global_object.heap() };
+ MarkedVector<Value> 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<Promise*> CyclicModule::evaluate(VM& vm)
// 5. Let stack be a new empty List.
Vector<Module*> 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<void> CyclicModule::execute_module(VM&, Optional<PromiseCapabi
// 16.2.1.5.2.2 ExecuteAsyncModule ( module ), https://tc39.es/ecma262/#sec-execute-async-module
void CyclicModule::execute_async_module(VM& vm)
{
- auto& global_object = realm().global_object();
- auto& realm = *global_object.associated_realm();
+ auto& realm = *vm.current_realm();
dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] executing async module {}", filename());
// 1. Assert: module.[[Status]] is evaluating or evaluating-async.
@@ -443,7 +442,7 @@ void CyclicModule::execute_async_module(VM& vm)
VERIFY(m_has_top_level_await);
// 3. Let capability be ! NewPromiseCapability(%Promise%).
- auto capability = MUST(new_promise_capability(vm, global_object.promise_constructor()));
+ auto capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor()));
// 4. Let fulfilledClosure be a new Abstract Closure with no parameters that captures module and performs the following steps when called:
auto fulfilled_closure = [&](VM& vm) -> ThrowCompletionOr<Value> {
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> 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<Value> AggregateErrorConstructor::call()
ThrowCompletionOr<Object*> 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<AggregateError>(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<Value> ArrayConstructor::call()
ThrowCompletionOr<Object*> 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<Value> {
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<Intl::DateTimeFormat*> 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<Intl::DateTimeFormat*>(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<void> 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<Statement> 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<void> GlobalEnvironment::create_global_var_binding(FlyString c
// 1. Let ObjRec be envRec.[[ObjectRecord]].
// 2. Let globalObject be ObjRec.[[BindingObject]].
- auto& global_object = verify_cast<GlobalObject>(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<StringView> resolve_day_period(StringView locale, StringView cal
ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(VM& vm, DateTimeFormat& date_time_format, Vector<PatternPartition> 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<Vector<PatternPartition>> format_date_time_pattern(VM& vm, Dat
auto const& data_locale = date_time_format.data_locale();
auto construct_number_format = [&](auto* options) -> ThrowCompletionOr<NumberFormat*> {
- 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<NumberFormat*>(number_format);
};
@@ -849,7 +848,6 @@ ThrowCompletionOr<String> format_date_time(VM& vm, DateTimeFormat& date_time_for
ThrowCompletionOr<Array*> 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<Array*> 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<String> format_date_time_range(VM& vm, DateTimeFormat& date_ti
ThrowCompletionOr<Array*> 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<Array*> 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<Value> 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<Value> 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<Vector<PatternPartition>> 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<PatternPartition> result;
@@ -403,7 +402,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
}
// o. Let nf be ? Construct(%NumberFormat%, Ā« durationFormat.[[Locale]], nfOpts Ā»).
- auto* number_format = static_cast<Intl::NumberFormat*>(TRY(construct(vm, *global_object.intl_number_format_constructor(), js_string(vm, duration_format.locale()), number_format_options)));
+ auto* number_format = static_cast<Intl::NumberFormat*>(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<Vector<PatternPartition>> 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<PluralRules&>(*plural_rules), value);
@@ -480,7 +479,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
}
// 3. Let lf be ? Construct(%ListFormat%, Ā« durationFormat.[[Locale]] Ā»).
- auto* list_format = static_cast<Intl::ListFormat*>(TRY(construct(vm, *global_object.intl_list_format_constructor(), js_string(vm, duration_format.locale()))));
+ auto* list_format = static_cast<Intl::ListFormat*>(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<String> const& list)
Array* format_list_to_parts(VM& vm, ListFormat const& list_format, Vector<String> 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, Vector<String
// 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/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<String> format_numeric_range(VM& vm, NumberFormat& number_form
ThrowCompletionOr<Array*> 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<Array*> 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<String> format_relative_time(VM& vm, RelativeTimeFormat& relat
ThrowCompletionOr<Array*> 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<Array*> 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<RelativeTimeFormat*> 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<RelativeTimeFormat*> 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<NumberFormat*>(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<PluralRules*>(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<String> 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<String> 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<MarkedVector<Value>> 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<Value> ObjectConstructor::call()
ThrowCompletionOr<Object*> 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<Object>(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<AlreadyResolved>();
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<Value> 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<Value> 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<Value> 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<Value> 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<MarkedVector<Value>> ProxyObject::internal_own_property_keys()
ThrowCompletionOr<Value> ProxyObject::internal_call(Value this_argument, MarkedVector<Value> 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<Object*> ProxyObject::internal_construct(MarkedVector<Value> 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<Value> 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<Value> 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<Value> StringConstructor::call()
ThrowCompletionOr<Object*> 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<StringView const> available_calendars()
ThrowCompletionOr<Calendar*> 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<Object*> 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<PartialDurationRecord> to_temporal_partial_duration_record(VM&
ThrowCompletionOr<Duration*> 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<Duration*> 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<Instant*> 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<Instant*> 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<PlainDate*> 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<PlainDate*> 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<PlainDateTime*> 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<PlainDateTime*> 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<PlainMonthDay*> to_temporal_month_day(VM& vm, Value item, Obje
ThrowCompletionOr<PlainMonthDay*> 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<PlainMonthDay*> 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<PlainTime*> 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<PlainTime*> 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<PlainYearMonth*> 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<PlainYearMonth*> 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<TimeZone*> 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<TimeZone>(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<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item
ThrowCompletionOr<ZonedDateTime*> 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<typename T>
static ThrowCompletionOr<void> initialize_typed_array_from_typed_array(VM& vm, TypedArray<T>& 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<void> 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<typename T>
static ThrowCompletionOr<void> allocate_typed_array_buffer(VM& vm, TypedArray<T>& typed_array, size_t length)
{
auto& realm = *vm.current_realm();
- auto& global_object = realm.global_object();
// Enforce 2GB "Excessive Length" limit
if (length > NumericLimits<i32>::max() / sizeof(T))
@@ -242,7 +240,7 @@ static ThrowCompletionOr<void> allocate_typed_array_buffer(VM& vm, TypedArray<T>
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<TypedArrayBase*> typed_array_create(VM& vm, FunctionObject& co
ThrowCompletionOr<TypedArrayBase*> typed_array_create_same_type(VM& vm, TypedArrayBase const& exemplar, MarkedVector<Value> 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<Object*> 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<void> for_each_item_from_last(VM& vm, String const& nam
static ThrowCompletionOr<TypedArrayBase*> typed_array_species_create(VM& vm, TypedArrayBase const& exemplar, MarkedVector<Value> 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<NonnullRefPtr<JS::SourceTextModule>, ParserError> parse_module
inline ErrorOr<JsonValue> 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<WindowObject&>(global_object);
+ auto& window = static_cast<WindowObject&>(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<WindowObject&>(global_object);
+ auto& window = static_cast<WindowObject&>(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<WindowObject&>(global_object);
+ auto& window = static_cast<WindowObject&>(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<Optional<JS::PropertyDescriptor>> LocationObject::internal
// 7.10.5.6 [[DefineOwnProperty]] ( P, Desc ), https://html.spec.whatwg.org/multipage/history.html#location-defineownproperty
JS::ThrowCompletionOr<bool> 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<bool> LocationObject::internal_set(JS::PropertyKey const&
// 7.10.5.9 [[Delete]] ( P ), https://html.spec.whatwg.org/multipage/history.html#location-delete
JS::ThrowCompletionOr<bool> 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<Optional<JS::PropertyDescriptor>> WindowProxy::internal_ge
// 7.4.6 [[DefineOwnProperty]] ( P, Desc ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-defineownproperty
JS::ThrowCompletionOr<bool> 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<bool> 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<bool> 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 <linusg@serenityos.org>
+ * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
*
* 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<void> Headers::set(String const& name_string, String const& val
// https://webidl.spec.whatwg.org/#es-iterable, Step 4
JS::ThrowCompletionOr<void> 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<Vector<Fetch::Infrastructure::Header>> {
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<JS::Object*> 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<Vector<Fetch::Infrastructure::Header>> {
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<NonnullRefPtr<Blob>> Blob::slice(Optional<i64> 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> 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<JS::Value> WebAssemblyMemoryConstructor::call()
JS::ThrowCompletionOr<JS::Object*> 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<JS::Value> WebAssemblyTableConstructor::call()
JS::ThrowCompletionOr<JS::Object*> 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<String> XMLHttpRequest::response_text() const
// https://xhr.spec.whatwg.org/#response
DOM::ExceptionOr<JS::Value> XMLHttpRequest::response()
{
- auto& global_object = wrapper()->global_object();
auto& vm = wrapper()->vm();
auto& realm = *vm.current_realm();
@@ -144,7 +143,7 @@ DOM::ExceptionOr<JS::Value> 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<void> 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<Bindings::WindowObject>(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.