summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/Spreadsheet/JSIntegration.cpp8
-rw-r--r--Userland/Libraries/LibJS/AST.cpp59
-rw-r--r--Userland/Libraries/LibJS/AST.h4
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Op.cpp20
-rw-r--r--Userland/Libraries/LibJS/CyclicModule.cpp9
-rw-r--r--Userland/Libraries/LibJS/Heap/Heap.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/AbstractOperations.h3
-rw-r--r--Userland/Libraries/LibJS/Runtime/AggregateError.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/AggregateError.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Array.cpp14
-rw-r--r--Userland/Libraries/LibJS/Runtime/Array.h10
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp14
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayBuffer.h6
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp22
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayIterator.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayIterator.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp47
-rw-r--r--Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.cpp5
-rw-r--r--Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp15
-rw-r--r--Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp17
-rw-r--r--Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/BigIntObject.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/BigIntObject.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/BooleanObject.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/BooleanObject.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/BoundFunction.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/BoundFunction.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Completion.cpp5
-rw-r--r--Userland/Libraries/LibJS/Runtime/DataView.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/DataView.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Date.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Date.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp92
-rw-r--r--Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Error.cpp21
-rw-r--r--Userland/Libraries/LibJS/Runtime/Error.h8
-rw-r--r--Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp12
-rw-r--r--Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp16
-rw-r--r--Userland/Libraries/LibJS/Runtime/GeneratorObject.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/GlobalObject.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp10
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp5
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/CollatorPrototype.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp20
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatPrototype.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp10
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp5
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp10
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/Locale.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp18
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp10
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/PluralRulesPrototype.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp5
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatPrototype.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp5
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/Segmenter.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/SegmenterPrototype.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp5
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/Segments.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/JSONObject.cpp14
-rw-r--r--Userland/Libraries/LibJS/Runtime/Map.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Map.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/MapIterator.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/MapIterator.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/MapPrototype.cpp12
-rw-r--r--Userland/Libraries/LibJS/Runtime/NativeFunction.cpp11
-rw-r--r--Userland/Libraries/LibJS/Runtime/NativeFunction.h4
-rw-r--r--Userland/Libraries/LibJS/Runtime/NumberObject.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/NumberObject.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Object.cpp21
-rw-r--r--Userland/Libraries/LibJS/Runtime/Object.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp34
-rw-r--r--Userland/Libraries/LibJS/Runtime/Promise.cpp21
-rw-r--r--Userland/Libraries/LibJS/Runtime/Promise.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp19
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp12
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp34
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.h8
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/PropertyDescriptor.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp9
-rw-r--r--Userland/Libraries/LibJS/Runtime/ProxyObject.cpp10
-rw-r--r--Userland/Libraries/LibJS/Runtime/ProxyObject.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/ReflectObject.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/RegExpObject.cpp11
-rw-r--r--Userland/Libraries/LibJS/Runtime/RegExpObject.h4
-rw-r--r--Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp26
-rw-r--r--Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/RegExpStringIterator.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Set.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Set.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/SetIterator.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/SetIterator.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/SetPrototype.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringConstructor.cpp10
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringIterator.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringIterator.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringObject.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringObject.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringPrototype.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/SymbolObject.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/SymbolObject.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp12
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp16
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimePrototype.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/TypedArray.cpp49
-rw-r--r--Userland/Libraries/LibJS/Runtime/TypedArray.h6
-rw-r--r--Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp12
-rw-r--r--Userland/Libraries/LibJS/Runtime/VM.cpp29
-rw-r--r--Userland/Libraries/LibJS/Runtime/VM.h3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.cpp11
-rw-r--r--Userland/Libraries/LibJS/Runtime/WeakMap.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/WeakMap.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/WeakRef.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/WeakRef.h4
-rw-r--r--Userland/Libraries/LibJS/Runtime/WeakSet.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/WeakSet.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp10
-rw-r--r--Userland/Libraries/LibJS/Runtime/WrappedFunction.h2
-rw-r--r--Userland/Libraries/LibJS/SourceTextModule.cpp2
-rw-r--r--Userland/Libraries/LibJS/SyntheticModule.cpp2
-rw-r--r--Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.cpp8
-rw-r--r--Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp4
-rw-r--r--Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp2
-rw-r--r--Userland/Libraries/LibWeb/Bindings/WindowObject.cpp6
-rw-r--r--Userland/Libraries/LibWeb/Bindings/Wrappable.h2
-rw-r--r--Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp9
-rw-r--r--Userland/Libraries/LibWeb/DOM/EventTarget.cpp42
-rw-r--r--Userland/Libraries/LibWeb/DOM/EventTarget.h7
-rw-r--r--Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp5
-rw-r--r--Userland/Libraries/LibWeb/Fetch/HeadersIterator.cpp3
-rw-r--r--Userland/Libraries/LibWeb/FileAPI/Blob.cpp8
-rw-r--r--Userland/Libraries/LibWeb/HTML/ImageData.cpp4
-rw-r--r--Userland/Libraries/LibWeb/URL/URLSearchParamsIterator.cpp3
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp2
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp4
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp14
-rw-r--r--Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp3
-rw-r--r--Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp3
-rw-r--r--Userland/Utilities/js.cpp6
176 files changed, 853 insertions, 590 deletions
diff --git a/Userland/Applications/Spreadsheet/JSIntegration.cpp b/Userland/Applications/Spreadsheet/JSIntegration.cpp
index 1ab581712c..9d5958b663 100644
--- a/Userland/Applications/Spreadsheet/JSIntegration.cpp
+++ b/Userland/Applications/Spreadsheet/JSIntegration.cpp
@@ -240,6 +240,8 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::set_real_cell_contents)
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::parse_cell_name)
{
+ auto& realm = *global_object.associated_realm();
+
auto* this_object = TRY(vm.this_value(global_object).to_object(global_object));
if (!is<SheetGlobalObject>(this_object))
@@ -256,7 +258,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::parse_cell_name)
if (!position.has_value())
return JS::js_undefined();
- auto object = JS::Object::create(global_object, global_object.object_prototype());
+ auto object = JS::Object::create(realm, global_object.object_prototype());
object->define_direct_property("column", JS::js_string(vm, sheet_object->m_sheet.column(position.value().column)), JS::default_attributes);
object->define_direct_property("row", JS::Value((unsigned)position.value().row), JS::default_attributes);
@@ -265,6 +267,8 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::parse_cell_name)
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::current_cell_position)
{
+ auto& realm = *global_object.associated_realm();
+
if (vm.argument_count() != 0)
return vm.throw_completion<JS::TypeError>(global_object, "Expected no arguments to current_cell_position()");
@@ -280,7 +284,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::current_cell_position)
auto position = current_cell->position();
- auto object = JS::Object::create(global_object, global_object.object_prototype());
+ auto object = JS::Object::create(realm, global_object.object_prototype());
object->define_direct_property("column", JS::js_string(vm, sheet_object->m_sheet.column(position.column)), JS::default_attributes);
object->define_direct_property("row", JS::Value((unsigned)position.row), JS::default_attributes);
diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp
index 82406f3107..db1b8faeba 100644
--- a/Userland/Libraries/LibJS/AST.cpp
+++ b/Userland/Libraries/LibJS/AST.cpp
@@ -231,7 +231,7 @@ Completion BlockStatement::execute(Interpreter& interpreter, GlobalObject& globa
if (has_lexical_declarations()) {
old_environment = vm.running_execution_context().lexical_environment;
auto* block_environment = new_declarative_environment(*old_environment);
- block_declaration_instantiation(global_object, block_environment);
+ block_declaration_instantiation(interpreter, global_object, block_environment);
vm.running_execution_context().lexical_environment = block_environment;
} else {
restore_environment.disarm();
@@ -287,6 +287,8 @@ Completion FunctionExpression::execute(Interpreter& interpreter, GlobalObject& g
// 15.2.5 Runtime Semantics: InstantiateOrdinaryFunctionExpression, https://tc39.es/ecma262/#sec-runtime-semantics-instantiateordinaryfunctionexpression
Value FunctionExpression::instantiate_ordinary_function_expression(Interpreter& interpreter, GlobalObject& global_object, FlyString given_name) const
{
+ auto& realm = *global_object.associated_realm();
+
if (given_name.is_empty())
given_name = "";
auto has_own_name = !name().is_empty();
@@ -301,7 +303,7 @@ Value FunctionExpression::instantiate_ordinary_function_expression(Interpreter&
auto* private_environment = interpreter.vm().running_execution_context().private_environment;
- auto closure = ECMAScriptFunctionObject::create(global_object, used_name, source_text(), body(), parameters(), function_length(), environment, private_environment, kind(), is_strict_mode(), might_need_arguments_object(), contains_direct_call_to_eval(), is_arrow_function());
+ auto closure = ECMAScriptFunctionObject::create(realm, used_name, source_text(), body(), parameters(), function_length(), environment, private_environment, kind(), is_strict_mode(), might_need_arguments_object(), contains_direct_call_to_eval(), is_arrow_function());
// FIXME: 6. Perform SetFunctionName(closure, name).
// FIXME: 7. Perform MakeConstructor(closure).
@@ -1639,6 +1641,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, GlobalObject& global_object, Object& target) const
{
+ auto& realm = *global_object.associated_realm();
+
auto property_key_or_private_name = TRY(class_key_to_property_name(interpreter, global_object, *m_key));
Handle<ECMAScriptFunctionObject> initializer {};
if (m_initializer) {
@@ -1653,7 +1657,7 @@ ThrowCompletionOr<ClassElement::ClassValue> ClassField::class_element_evaluation
// FIXME: A potential optimization is not creating the functions here since these are never directly accessible.
auto function_code = create_ast_node<ClassFieldInitializerStatement>(m_initializer->source_range(), copy_initializer.release_nonnull(), name);
- initializer = make_handle(ECMAScriptFunctionObject::create(interpreter.global_object(), String::empty(), String::empty(), *function_code, {}, 0, interpreter.lexical_environment(), interpreter.vm().running_execution_context().private_environment, FunctionKind::Normal, true, false, m_contains_direct_call_to_eval, false, property_key_or_private_name));
+ initializer = make_handle(ECMAScriptFunctionObject::create(realm, String::empty(), String::empty(), *function_code, {}, 0, interpreter.lexical_environment(), interpreter.vm().running_execution_context().private_environment, FunctionKind::Normal, true, false, m_contains_direct_call_to_eval, false, property_key_or_private_name));
initializer->make_method(target);
}
@@ -1685,6 +1689,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, GlobalObject& global_object, Object& home_object) const
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let lex be the running execution context's LexicalEnvironment.
auto* lexical_environment = interpreter.vm().running_execution_context().lexical_environment;
@@ -1695,7 +1701,7 @@ ThrowCompletionOr<ClassElement::ClassValue> StaticInitializer::class_element_eva
// 4. Let formalParameters be an instance of the production FormalParameters : [empty] .
// 5. Let bodyFunction be OrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParameters, ClassStaticBlockBody, non-lexical-this, lex, privateEnv).
// Note: The function bodyFunction is never directly accessible to ECMAScript code.
- auto* body_function = ECMAScriptFunctionObject::create(global_object, String::empty(), String::empty(), *m_function_body, {}, 0, lexical_environment, private_environment, FunctionKind::Normal, true, false, m_contains_direct_call_to_eval, false);
+ auto* body_function = ECMAScriptFunctionObject::create(realm, String::empty(), String::empty(), *m_function_body, {}, 0, lexical_environment, private_environment, FunctionKind::Normal, true, false, m_contains_direct_call_to_eval, false);
// 6. Perform MakeMethod(bodyFunction, homeObject).
body_function->make_method(home_object);
@@ -1775,6 +1781,8 @@ Completion ClassDeclaration::execute(Interpreter& interpreter, GlobalObject& glo
ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::class_definition_evaluation(Interpreter& interpreter, GlobalObject& global_object, FlyString const& binding_name, FlyString const& class_name) const
{
auto& vm = interpreter.vm();
+ auto& realm = *global_object.associated_realm();
+
auto* environment = vm.lexical_environment();
VERIFY(environment);
auto* class_environment = new_declarative_environment(*environment);
@@ -1833,7 +1841,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::class_definition_e
}
}
- auto* prototype = Object::create(global_object, proto_parent);
+ auto* prototype = Object::create(realm, proto_parent);
VERIFY(prototype);
vm.running_execution_context().lexical_environment = class_environment;
@@ -2994,9 +3002,10 @@ Completion ObjectProperty::execute(Interpreter& interpreter, GlobalObject&) cons
Completion ObjectExpression::execute(Interpreter& interpreter, GlobalObject& global_object) const
{
InterpreterNodeScope node_scope { interpreter, *this };
+ auto& realm = *global_object.associated_realm();
// 1. Let obj be OrdinaryObjectCreate(%Object.prototype%).
- auto* object = Object::create(global_object, global_object.object_prototype());
+ auto* object = Object::create(realm, global_object.object_prototype());
// 2. Perform ? PropertyDefinitionEvaluation of PropertyDefinitionList with argument obj.
for (auto& property : m_properties) {
@@ -3205,6 +3214,7 @@ void MetaProperty::dump(int indent) const
Completion MetaProperty::execute(Interpreter& interpreter, GlobalObject& global_object) const
{
InterpreterNodeScope node_scope { interpreter, *this };
+ auto& realm = *global_object.associated_realm();
// NewTarget : new . target
if (m_type == MetaProperty::Type::NewTarget) {
@@ -3229,7 +3239,7 @@ Completion MetaProperty::execute(Interpreter& interpreter, GlobalObject& global_
// 4. If importMeta is empty, then
if (import_meta == nullptr) {
// a. Set importMeta to OrdinaryObjectCreate(null).
- import_meta = Object::create(global_object, nullptr);
+ import_meta = Object::create(realm, nullptr);
// b. Let importMetaValues be HostGetImportMetaProperties(module).
auto import_meta_values = interpreter.vm().host_get_import_meta_properties(module);
@@ -3279,6 +3289,7 @@ void ImportCall::dump(int indent) const
Completion ImportCall::execute(Interpreter& interpreter, GlobalObject& global_object) const
{
InterpreterNodeScope node_scope { interpreter, *this };
+ auto& realm = *global_object.associated_realm();
// 2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] ), https://tc39.es/proposal-import-assertions/#sec-evaluate-import-call
// 1. Let referencingScriptOrModule be GetActiveScriptOrModule().
@@ -3313,7 +3324,7 @@ Completion ImportCall::execute(Interpreter& interpreter, GlobalObject& global_ob
if (!options_value.is_undefined()) {
// a. If Type(options) is not Object,
if (!options_value.is_object()) {
- auto* error = TypeError::create(global_object, String::formatted(ErrorType::NotAnObject.message(), "ImportOptions"));
+ auto* error = TypeError::create(realm, String::formatted(ErrorType::NotAnObject.message(), "ImportOptions"));
// i. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
MUST(call(global_object, *promise_capability.reject, js_undefined(), error));
@@ -3329,7 +3340,7 @@ Completion ImportCall::execute(Interpreter& interpreter, GlobalObject& global_ob
if (!assertion_object.is_undefined()) {
// i. If Type(assertionsObj) is not Object,
if (!assertion_object.is_object()) {
- auto* error = TypeError::create(global_object, String::formatted(ErrorType::NotAnObject.message(), "ImportOptionsAssertions"));
+ auto* error = TypeError::create(realm, String::formatted(ErrorType::NotAnObject.message(), "ImportOptionsAssertions"));
// 1. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
MUST(call(global_object, *promise_capability.reject, js_undefined(), error));
@@ -3354,7 +3365,7 @@ Completion ImportCall::execute(Interpreter& interpreter, GlobalObject& global_ob
// 3. If Type(value) is not String, then
if (!value.is_string()) {
- auto* error = TypeError::create(global_object, String::formatted(ErrorType::NotAString.message(), "Import Assertion option value"));
+ auto* error = TypeError::create(realm, String::formatted(ErrorType::NotAString.message(), "Import Assertion option value"));
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
MUST(call(global_object, *promise_capability.reject, js_undefined(), error));
@@ -3449,6 +3460,7 @@ void RegExpLiteral::dump(int indent) const
Completion RegExpLiteral::execute(Interpreter& interpreter, GlobalObject& global_object) const
{
InterpreterNodeScope node_scope { interpreter, *this };
+ auto& realm = *global_object.associated_realm();
// 1. Let pattern be CodePointsToString(BodyText of RegularExpressionLiteral).
auto pattern = this->pattern();
@@ -3458,7 +3470,7 @@ Completion RegExpLiteral::execute(Interpreter& interpreter, GlobalObject& global
// 3. Return ! RegExpCreate(pattern, flags).
Regex<ECMA262> regex(parsed_regex(), parsed_pattern(), parsed_flags());
- return Value { RegExpObject::create(global_object, move(regex), move(pattern), move(flags)) };
+ return Value { RegExpObject::create(realm, move(regex), move(pattern), move(flags)) };
}
void ArrayExpression::dump(int indent) const
@@ -3478,9 +3490,10 @@ void ArrayExpression::dump(int indent) const
Completion ArrayExpression::execute(Interpreter& interpreter, GlobalObject& global_object) const
{
InterpreterNodeScope node_scope { interpreter, *this };
+ auto& realm = *global_object.associated_realm();
// 1. Let array be ! ArrayCreate(0).
- auto* array = MUST(Array::create(global_object, 0));
+ auto* array = MUST(Array::create(realm, 0));
// 2. Perform ? ArrayAccumulation of ElementList with arguments array and 0.
@@ -3593,7 +3606,7 @@ Completion TaggedTemplateLiteral::execute(Interpreter& interpreter, GlobalObject
ThrowCompletionOr<Value> TaggedTemplateLiteral::get_template_object(Interpreter& interpreter, GlobalObject& global_object) const
{
// 1. Let realm be the current Realm Record.
- auto* realm = global_object.associated_realm();
+ auto& realm = *global_object.associated_realm();
// 2. Let templateRegistry be realm.[[TemplateMap]].
// 3. For each element e of templateRegistry, do
@@ -3601,7 +3614,7 @@ ThrowCompletionOr<Value> TaggedTemplateLiteral::get_template_object(Interpreter&
// i. Return e.[[Array]].
// NOTE: Instead of caching on the realm we cache on the Parse Node side as
// this makes it easier to track whether it is the same parse node.
- if (auto cached_value_or_end = m_cached_values.find(realm); cached_value_or_end != m_cached_values.end())
+ if (auto cached_value_or_end = m_cached_values.find(&realm); cached_value_or_end != m_cached_values.end())
return Value { cached_value_or_end->value.cell() };
// 4. Let rawStrings be TemplateStrings of templateLiteral with argument true.
@@ -3622,10 +3635,10 @@ ThrowCompletionOr<Value> TaggedTemplateLiteral::get_template_object(Interpreter&
// 8. Let template be ! ArrayCreate(count).
// NOTE: We don't set count since we push the values using append which
// would then append after count. Same for 9.
- auto* template_ = MUST(Array::create(global_object, 0));
+ auto* template_ = MUST(Array::create(realm, 0));
// 9. Let rawObj be ! ArrayCreate(count).
- auto* raw_obj = MUST(Array::create(global_object, 0));
+ auto* raw_obj = MUST(Array::create(realm, 0));
// 10. Let index be 0.
// 11. Repeat, while index < count,
@@ -3661,7 +3674,7 @@ ThrowCompletionOr<Value> TaggedTemplateLiteral::get_template_object(Interpreter&
MUST(template_->set_integrity_level(Object::IntegrityLevel::Frozen));
// 15. Append the Record { [[Site]]: templateLiteral, [[Array]]: template } to templateRegistry.
- m_cached_values.set(realm, make_handle(template_));
+ m_cached_values.set(&realm, make_handle(template_));
// 16. Return template.
return template_;
@@ -4047,7 +4060,7 @@ Completion SwitchStatement::execute_impl(Interpreter& interpreter, GlobalObject&
auto* block_environment = new_declarative_environment(*old_environment);
// 5. Perform BlockDeclarationInstantiation(CaseBlock, blockEnv).
- block_declaration_instantiation(global_object, block_environment);
+ block_declaration_instantiation(interpreter, global_object, block_environment);
// 6. Set the running execution context's LexicalEnvironment to blockEnv.
vm.running_execution_context().lexical_environment = block_environment;
@@ -4455,9 +4468,11 @@ bool ImportStatement::has_bound_name(FlyString const& name) const
}
// 14.2.3 BlockDeclarationInstantiation ( code, env ), https://tc39.es/ecma262/#sec-blockdeclarationinstantiation
-void ScopeNode::block_declaration_instantiation(GlobalObject& global_object, Environment* environment) const
+void ScopeNode::block_declaration_instantiation(Interpreter&, GlobalObject& global_object, Environment* environment) const
{
// See also B.3.2.6 Changes to BlockDeclarationInstantiation, https://tc39.es/ecma262/#sec-web-compat-blockdeclarationinstantiation
+ auto& realm = *global_object.associated_realm();
+
VERIFY(environment);
auto* private_environment = global_object.vm().running_execution_context().private_environment;
// Note: All the calls here are ! and thus we do not need to TRY this callback.
@@ -4474,7 +4489,7 @@ void ScopeNode::block_declaration_instantiation(GlobalObject& global_object, Env
if (is<FunctionDeclaration>(declaration)) {
auto& function_declaration = static_cast<FunctionDeclaration const&>(declaration);
- auto* function = ECMAScriptFunctionObject::create(global_object, function_declaration.name(), function_declaration.source_text(), function_declaration.body(), function_declaration.parameters(), function_declaration.function_length(), environment, private_environment, function_declaration.kind(), function_declaration.is_strict_mode(), function_declaration.might_need_arguments_object(), function_declaration.contains_direct_call_to_eval());
+ auto* function = ECMAScriptFunctionObject::create(realm, function_declaration.name(), function_declaration.source_text(), function_declaration.body(), function_declaration.parameters(), function_declaration.function_length(), environment, private_environment, function_declaration.kind(), function_declaration.is_strict_mode(), function_declaration.might_need_arguments_object(), function_declaration.contains_direct_call_to_eval());
VERIFY(is<DeclarativeEnvironment>(*environment));
static_cast<DeclarativeEnvironment&>(*environment).initialize_or_set_mutable_binding({}, global_object, function_declaration.name(), function);
}
@@ -4484,6 +4499,8 @@ void ScopeNode::block_declaration_instantiation(GlobalObject& global_object, Env
// 16.1.7 GlobalDeclarationInstantiation ( script, env ), https://tc39.es/ecma262/#sec-globaldeclarationinstantiation
ThrowCompletionOr<void> Program::global_declaration_instantiation(Interpreter& interpreter, GlobalObject& global_object, GlobalEnvironment& global_environment) const
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let lexNames be the LexicallyDeclaredNames of script.
// 2. Let varNames be the VarDeclaredNames of script.
// 3. For each element name of lexNames, do
@@ -4661,7 +4678,7 @@ ThrowCompletionOr<void> Program::global_declaration_instantiation(Interpreter& i
for (auto& declaration : functions_to_initialize) {
// a. Let fn be the sole element of the BoundNames of f.
// b. Let fo be InstantiateFunctionObject of f with arguments env and privateEnv.
- auto* function = ECMAScriptFunctionObject::create(global_object, declaration.name(), declaration.source_text(), declaration.body(), declaration.parameters(), declaration.function_length(), &global_environment, private_environment, declaration.kind(), declaration.is_strict_mode(), declaration.might_need_arguments_object(), declaration.contains_direct_call_to_eval());
+ auto* function = ECMAScriptFunctionObject::create(realm, declaration.name(), declaration.source_text(), declaration.body(), declaration.parameters(), declaration.function_length(), &global_environment, private_environment, declaration.kind(), declaration.is_strict_mode(), declaration.might_need_arguments_object(), declaration.contains_direct_call_to_eval());
// c. Perform ? env.CreateGlobalFunctionBinding(fn, fo, false).
TRY(global_environment.create_global_function_binding(declaration.name(), function, false));
diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h
index 1c6c7886ef..815f18ab62 100644
--- a/Userland/Libraries/LibJS/AST.h
+++ b/Userland/Libraries/LibJS/AST.h
@@ -255,7 +255,7 @@ public:
ThrowCompletionOr<void> for_each_var_function_declaration_in_reverse_order(ThrowCompletionOrVoidCallback<FunctionDeclaration const&>&& callback) const;
ThrowCompletionOr<void> for_each_var_scoped_variable_declaration(ThrowCompletionOrVoidCallback<VariableDeclaration const&>&& callback) const;
- void block_declaration_instantiation(GlobalObject& global_object, Environment* environment) const;
+ void block_declaration_instantiation(Interpreter&, GlobalObject&, Environment*) const;
ThrowCompletionOr<void> for_each_function_hoistable_with_annexB_extension(ThrowCompletionOrVoidCallback<FunctionDeclaration&>&& callback) const;
@@ -495,7 +495,7 @@ public:
bool has_top_level_await() const { return m_has_top_level_await; }
void set_has_top_level_await() { m_has_top_level_await = true; }
- ThrowCompletionOr<void> global_declaration_instantiation(Interpreter& interpreter, GlobalObject& global_object, GlobalEnvironment& global_environment) const;
+ ThrowCompletionOr<void> global_declaration_instantiation(Interpreter&, GlobalObject&, GlobalEnvironment&) const;
private:
virtual bool is_program() const override { return true; }
diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp
index c5d1497d74..86d86d61a8 100644
--- a/Userland/Libraries/LibJS/Bytecode/Op.cpp
+++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp
@@ -168,7 +168,7 @@ ThrowCompletionOr<void> NewBigInt::execute_impl(Bytecode::Interpreter& interpret
ThrowCompletionOr<void> NewArray::execute_impl(Bytecode::Interpreter& interpreter) const
{
- auto* array = MUST(Array::create(interpreter.global_object(), 0));
+ auto* array = MUST(Array::create(interpreter.realm(), 0));
for (size_t i = 0; i < m_element_count; i++) {
auto& value = interpreter.reg(Register(m_elements[0].index() + i));
array->indexed_properties().put(i, value, default_attributes);
@@ -182,7 +182,8 @@ ThrowCompletionOr<void> NewArray::execute_impl(Bytecode::Interpreter& interprete
static Object* iterator_to_object(GlobalObject& global_object, Iterator iterator)
{
auto& vm = global_object.vm();
- auto* object = Object::create(global_object, nullptr);
+ auto& realm = *global_object.associated_realm();
+ auto* object = Object::create(realm, nullptr);
object->define_direct_property(vm.names.iterator, iterator.iterator, 0);
object->define_direct_property(vm.names.next, iterator.next_method, 0);
object->define_direct_property(vm.names.done, Value(iterator.done), 0);
@@ -205,7 +206,7 @@ ThrowCompletionOr<void> IteratorToArray::execute_impl(Bytecode::Interpreter& int
auto iterator_object = TRY(interpreter.accumulator().to_object(global_object));
auto iterator = object_to_iterator(global_object, *iterator_object);
- auto* array = MUST(Array::create(global_object, 0));
+ auto* array = MUST(Array::create(interpreter.realm(), 0));
size_t index = 0;
while (true) {
@@ -234,7 +235,7 @@ ThrowCompletionOr<void> NewString::execute_impl(Bytecode::Interpreter& interpret
ThrowCompletionOr<void> NewObject::execute_impl(Bytecode::Interpreter& interpreter) const
{
- interpreter.accumulator() = Object::create(interpreter.global_object(), interpreter.global_object().object_prototype());
+ interpreter.accumulator() = Object::create(interpreter.realm(), interpreter.global_object().object_prototype());
return {};
}
@@ -251,7 +252,7 @@ ThrowCompletionOr<void> CopyObjectExcludingProperties::execute_impl(Bytecode::In
{
auto* from_object = TRY(interpreter.reg(m_from_object).to_object(interpreter.global_object()));
- auto* to_object = Object::create(interpreter.global_object(), interpreter.global_object().object_prototype());
+ auto* to_object = Object::create(interpreter.realm(), interpreter.global_object().object_prototype());
HashTable<Value, ValueTraits> excluded_names;
for (size_t i = 0; i < m_excluded_names_count; ++i)
@@ -506,7 +507,7 @@ ThrowCompletionOr<void> Call::execute_impl(Bytecode::Interpreter& interpreter) c
ThrowCompletionOr<void> NewFunction::execute_impl(Bytecode::Interpreter& interpreter) const
{
auto& vm = interpreter.vm();
- interpreter.accumulator() = ECMAScriptFunctionObject::create(interpreter.global_object(), m_function_node.name(), m_function_node.source_text(), m_function_node.body(), m_function_node.parameters(), m_function_node.function_length(), vm.lexical_environment(), vm.running_execution_context().private_environment, m_function_node.kind(), m_function_node.is_strict_mode(), m_function_node.might_need_arguments_object(), m_function_node.contains_direct_call_to_eval(), m_function_node.is_arrow_function());
+ interpreter.accumulator() = ECMAScriptFunctionObject::create(interpreter.realm(), m_function_node.name(), m_function_node.source_text(), m_function_node.body(), m_function_node.parameters(), m_function_node.function_length(), vm.lexical_environment(), vm.running_execution_context().private_environment, m_function_node.kind(), m_function_node.is_strict_mode(), m_function_node.might_need_arguments_object(), m_function_node.contains_direct_call_to_eval(), m_function_node.is_arrow_function());
return {};
}
@@ -610,7 +611,7 @@ ThrowCompletionOr<void> PushDeclarativeEnvironment::execute_impl(Bytecode::Inter
ThrowCompletionOr<void> Yield::execute_impl(Bytecode::Interpreter& interpreter) const
{
auto yielded_value = interpreter.accumulator().value_or(js_undefined());
- auto object = JS::Object::create(interpreter.global_object(), nullptr);
+ auto object = Object::create(interpreter.realm(), nullptr);
object->define_direct_property("result", yielded_value, JS::default_attributes);
if (m_continuation_label.has_value())
object->define_direct_property("continuation", Value(static_cast<double>(reinterpret_cast<u64>(&m_continuation_label->block()))), JS::default_attributes);
@@ -693,14 +694,15 @@ ThrowCompletionOr<void> GetObjectPropertyIterator::execute_impl(Bytecode::Interp
Iterator iterator {
.iterator = object,
.next_method = NativeFunction::create(
- interpreter.global_object(),
+ interpreter.realm(),
[seen_items = HashTable<PropertyKey>(), items = move(properties)](VM& vm, GlobalObject& global_object) mutable -> ThrowCompletionOr<Value> {
+ auto& realm = *global_object.associated_realm();
auto iterated_object_value = vm.this_value(global_object);
if (!iterated_object_value.is_object())
return vm.throw_completion<InternalError>(global_object, "Invalid state for GetObjectPropertyIterator.next");
auto& iterated_object = iterated_object_value.as_object();
- auto* result_object = Object::create(global_object, nullptr);
+ auto* result_object = Object::create(realm, nullptr);
while (true) {
if (items.is_empty()) {
result_object->define_direct_property(vm.names.done, JS::Value(true), default_attributes);
diff --git a/Userland/Libraries/LibJS/CyclicModule.cpp b/Userland/Libraries/LibJS/CyclicModule.cpp
index 55515c16e0..63c6f534f4 100644
--- a/Userland/Libraries/LibJS/CyclicModule.cpp
+++ b/Userland/Libraries/LibJS/CyclicModule.cpp
@@ -433,14 +433,15 @@ 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();
+
dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] executing async module {}", filename());
// 1. Assert: module.[[Status]] is evaluating or evaluating-async.
VERIFY(m_status == ModuleStatus::Evaluating || m_status == ModuleStatus::EvaluatingAsync);
// 2. Assert: module.[[HasTLA]] is true.
VERIFY(m_has_top_level_await);
- auto& global_object = realm().global_object();
-
// 3. Let capability be ! NewPromiseCapability(%Promise%).
auto capability = MUST(new_promise_capability(global_object, global_object.promise_constructor()));
@@ -454,7 +455,7 @@ void CyclicModule::execute_async_module(VM& vm)
};
// 5. Let onFulfilled be CreateBuiltinFunction(fulfilledClosure, 0, "", « »).
- auto* on_fulfilled = NativeFunction::create(global_object, move(fulfilled_closure), 0, "");
+ auto* on_fulfilled = NativeFunction::create(realm, move(fulfilled_closure), 0, "");
// 6. Let rejectedClosure be a new Abstract Closure with parameters (error) that captures module and performs the following steps when called:
auto rejected_closure = [&](VM& vm, GlobalObject&) -> ThrowCompletionOr<Value> {
@@ -468,7 +469,7 @@ void CyclicModule::execute_async_module(VM& vm)
};
// 7. Let onRejected be CreateBuiltinFunction(rejectedClosure, 0, "", « »).
- auto* on_rejected = NativeFunction::create(global_object, move(rejected_closure), 0, "");
+ auto* on_rejected = NativeFunction::create(realm, move(rejected_closure), 0, "");
VERIFY(is<Promise>(*capability.promise));
diff --git a/Userland/Libraries/LibJS/Heap/Heap.cpp b/Userland/Libraries/LibJS/Heap/Heap.cpp
index 53bcc1de4b..8c60e20cce 100644
--- a/Userland/Libraries/LibJS/Heap/Heap.cpp
+++ b/Userland/Libraries/LibJS/Heap/Heap.cpp
@@ -349,8 +349,8 @@ void Heap::uproot_cell(Cell* cell)
m_uprooted_cells.append(cell);
}
-// Temporary helper function as we can't pass a realm directly until Heap::allocate<T>() receives one.
-// Heap.h only has a forward declaration of the GlobalObject, so no inlined member access possible.
+// Temporary helper function as we can't pass a realm directly until Heap::allocate<T>() and VM::throw_completion<T>() receive one.
+// Heap.h and VM.h only have a forward declaration of the GlobalObject, so no inlined member access possible.
Realm& realm_from_global_object(GlobalObject& global_object)
{
return *global_object.associated_realm();
diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
index a26fe25f39..f0c817b44f 100644
--- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
@@ -726,6 +726,7 @@ ThrowCompletionOr<Value> perform_eval(GlobalObject& global_object, Value x, Call
// 19.2.1.3 EvalDeclarationInstantiation ( body, varEnv, lexEnv, privateEnv, strict ), https://tc39.es/ecma262/#sec-evaldeclarationinstantiation
ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, GlobalObject& global_object, Program const& program, Environment* variable_environment, Environment* lexical_environment, PrivateEnvironment* private_environment, bool strict)
{
+ auto& realm = *global_object.associated_realm();
GlobalEnvironment* global_var_environment = variable_environment->is_global_environment() ? static_cast<GlobalEnvironment*>(variable_environment) : nullptr;
// 1. Let varNames be the VarDeclaredNames of body.
@@ -974,7 +975,7 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, GlobalObject& glo
for (auto& declaration : functions_to_initialize) {
// a. Let fn be the sole element of the BoundNames of f.
// b. Let fo be InstantiateFunctionObject of f with arguments lexEnv and privateEnv.
- auto* function = ECMAScriptFunctionObject::create(global_object, declaration.name(), declaration.source_text(), declaration.body(), declaration.parameters(), declaration.function_length(), lexical_environment, private_environment, declaration.kind(), declaration.is_strict_mode(), declaration.might_need_arguments_object());
+ auto* function = ECMAScriptFunctionObject::create(realm, declaration.name(), declaration.source_text(), declaration.body(), declaration.parameters(), declaration.function_length(), lexical_environment, private_environment, declaration.kind(), declaration.is_strict_mode(), declaration.might_need_arguments_object());
// c. If varEnv is a global Environment Record, then
if (global_var_environment) {
@@ -1036,13 +1037,14 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, GlobalObject& glo
Object* create_unmapped_arguments_object(GlobalObject& global_object, Span<Value> arguments)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let len be the number of elements in argumentsList.
auto length = arguments.size();
// 2. Let obj be OrdinaryObjectCreate(%Object.prototype%, « [[ParameterMap]] »).
// 3. Set obj.[[ParameterMap]] to undefined.
- auto* object = Object::create(global_object, global_object.object_prototype());
+ auto* object = Object::create(realm, global_object.object_prototype());
object->set_has_parameter_map();
// 4. Perform ! DefinePropertyOrThrow(obj, "length", PropertyDescriptor { [[Value]]: 𝔽(len), [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }).
diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h
index 3a0162fbb7..795d85c77f 100644
--- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h
+++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h
@@ -133,8 +133,9 @@ ALWAYS_INLINE ThrowCompletionOr<Object*> construct(GlobalObject& global_object,
template<typename T, typename... Args>
ThrowCompletionOr<T*> ordinary_create_from_constructor(GlobalObject& global_object, FunctionObject const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)(), Args&&... args)
{
+ auto& realm = *global_object.associated_realm();
auto* prototype = TRY(get_prototype_from_constructor(global_object, constructor, intrinsic_default_prototype));
- return global_object.heap().allocate<T>(global_object, forward<Args>(args)..., *prototype);
+ return realm.heap().allocate<T>(realm.global_object(), forward<Args>(args)..., *prototype);
}
// 14.1 MergeLists ( a, b ), https://tc39.es/proposal-temporal/#sec-temporal-mergelists
diff --git a/Userland/Libraries/LibJS/Runtime/AggregateError.cpp b/Userland/Libraries/LibJS/Runtime/AggregateError.cpp
index 3048d5262e..eb530ae04b 100644
--- a/Userland/Libraries/LibJS/Runtime/AggregateError.cpp
+++ b/Userland/Libraries/LibJS/Runtime/AggregateError.cpp
@@ -10,9 +10,9 @@
namespace JS {
-AggregateError* AggregateError::create(GlobalObject& global_object)
+AggregateError* AggregateError::create(Realm& realm)
{
- return global_object.heap().allocate<AggregateError>(global_object, *global_object.aggregate_error_prototype());
+ return realm.heap().allocate<AggregateError>(realm.global_object(), *realm.global_object().aggregate_error_prototype());
}
AggregateError::AggregateError(Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/AggregateError.h b/Userland/Libraries/LibJS/Runtime/AggregateError.h
index 85133fdede..23e74be65f 100644
--- a/Userland/Libraries/LibJS/Runtime/AggregateError.h
+++ b/Userland/Libraries/LibJS/Runtime/AggregateError.h
@@ -15,7 +15,7 @@ class AggregateError : public Error {
JS_OBJECT(AggregateError, Error);
public:
- static AggregateError* create(GlobalObject&);
+ static AggregateError* create(Realm&);
explicit AggregateError(Object& prototype);
virtual ~AggregateError() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp b/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp
index 58a055b9fc..2707059977 100644
--- a/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp
@@ -41,6 +41,7 @@ ThrowCompletionOr<Object*> AggregateErrorConstructor::construct(FunctionObject&
{
auto& vm = this->vm();
auto& global_object = this->global_object();
+ auto& realm = *global_object.associated_realm();
auto* aggregate_error = TRY(ordinary_create_from_constructor<AggregateError>(global_object, new_target, &GlobalObject::aggregate_error_prototype));
@@ -53,7 +54,7 @@ ThrowCompletionOr<Object*> AggregateErrorConstructor::construct(FunctionObject&
auto errors_list = TRY(iterable_to_list(global_object, vm.argument(0)));
- MUST(aggregate_error->define_property_or_throw(vm.names.errors, { .value = Array::create_from(global_object, errors_list), .writable = true, .enumerable = false, .configurable = true }));
+ MUST(aggregate_error->define_property_or_throw(vm.names.errors, { .value = Array::create_from(realm, errors_list), .writable = true, .enumerable = false, .configurable = true }));
return aggregate_error;
}
diff --git a/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp b/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp
index 84956b5fc0..924ba893ca 100644
--- a/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp
@@ -20,7 +20,7 @@ void ArgumentsObject::initialize(Realm& realm)
{
Base::initialize(realm);
set_has_parameter_map();
- m_parameter_map = Object::create(realm.global_object(), nullptr);
+ m_parameter_map = Object::create(realm, nullptr);
}
void ArgumentsObject::visit_edges(Cell::Visitor& visitor)
diff --git a/Userland/Libraries/LibJS/Runtime/Array.cpp b/Userland/Libraries/LibJS/Runtime/Array.cpp
index 79d983df90..c03e665dd4 100644
--- a/Userland/Libraries/LibJS/Runtime/Array.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Array.cpp
@@ -17,22 +17,22 @@
namespace JS {
// 10.4.2.2 ArrayCreate ( length [ , proto ] ), https://tc39.es/ecma262/#sec-arraycreate
-ThrowCompletionOr<Array*> Array::create(GlobalObject& global_object, u64 length, Object* prototype)
+ThrowCompletionOr<Array*> Array::create(Realm& realm, u64 length, Object* prototype)
{
- auto& vm = global_object.vm();
+ auto& vm = realm.vm();
// 1. If length > 2^32 - 1, throw a RangeError exception.
if (length > NumericLimits<u32>::max())
- return vm.throw_completion<RangeError>(global_object, ErrorType::InvalidLength, "array");
+ return vm.throw_completion<RangeError>(realm.global_object(), ErrorType::InvalidLength, "array");
// 2. If proto is not present, set proto to %Array.prototype%.
if (!prototype)
- prototype = global_object.array_prototype();
+ prototype = realm.global_object().array_prototype();
// 3. Let A be MakeBasicObject(« [[Prototype]], [[Extensible]] »).
// 4. Set A.[[Prototype]] to proto.
// 5. Set A.[[DefineOwnProperty]] as specified in 10.4.2.1.
- auto* array = global_object.heap().allocate<Array>(global_object, *prototype);
+ auto* array = realm.heap().allocate<Array>(realm.global_object(), *prototype);
// 6. Perform ! OrdinaryDefineOwnProperty(A, "length", PropertyDescriptor { [[Value]]: 𝔽(length), [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
MUST(array->internal_define_own_property(vm.names.length, { .value = Value(length), .writable = true, .enumerable = false, .configurable = false }));
@@ -42,10 +42,10 @@ ThrowCompletionOr<Array*> Array::create(GlobalObject& global_object, u64 length,
}
// 7.3.18 CreateArrayFromList ( elements ), https://tc39.es/ecma262/#sec-createarrayfromlist
-Array* Array::create_from(GlobalObject& global_object, Vector<Value> const& elements)
+Array* Array::create_from(Realm& realm, Vector<Value> const& elements)
{
// 1. Let array be ! ArrayCreate(0).
- auto* array = MUST(Array::create(global_object, 0));
+ auto* array = MUST(Array::create(realm, 0));
// 2. Let n be 0.
// 3. For each element e of elements, do
diff --git a/Userland/Libraries/LibJS/Runtime/Array.h b/Userland/Libraries/LibJS/Runtime/Array.h
index 7886ac3c83..d1a9291123 100644
--- a/Userland/Libraries/LibJS/Runtime/Array.h
+++ b/Userland/Libraries/LibJS/Runtime/Array.h
@@ -21,18 +21,18 @@ class Array : public Object {
JS_OBJECT(Array, Object);
public:
- static ThrowCompletionOr<Array*> create(GlobalObject&, u64 length, Object* prototype = nullptr);
- static Array* create_from(GlobalObject&, Vector<Value> const&);
+ static ThrowCompletionOr<Array*> create(Realm&, u64 length, Object* prototype = nullptr);
+ static Array* create_from(Realm&, Vector<Value> const&);
// Non-standard but equivalent to CreateArrayFromList.
template<typename T>
- static Array* create_from(GlobalObject& global_object, Span<T const> elements, Function<Value(T const&)> map_fn)
+ static Array* create_from(Realm& realm, Span<T const> elements, Function<Value(T const&)> map_fn)
{
- auto values = MarkedVector<Value> { global_object.heap() };
+ auto values = MarkedVector<Value> { realm.heap() };
values.ensure_capacity(elements.size());
for (auto const& element : elements)
values.append(map_fn(element));
- return Array::create_from(global_object, values);
+ return Array::create_from(realm, values);
}
explicit Array(Object& prototype);
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp
index a8bc823207..3a820084c3 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp
@@ -11,23 +11,23 @@
namespace JS {
-ThrowCompletionOr<ArrayBuffer*> ArrayBuffer::create(GlobalObject& global_object, size_t byte_length)
+ThrowCompletionOr<ArrayBuffer*> ArrayBuffer::create(Realm& realm, size_t byte_length)
{
auto buffer = ByteBuffer::create_zeroed(byte_length);
if (buffer.is_error())
- return global_object.vm().throw_completion<RangeError>(global_object, ErrorType::NotEnoughMemoryToAllocate, byte_length);
+ return realm.vm().throw_completion<RangeError>(realm.global_object(), ErrorType::NotEnoughMemoryToAllocate, byte_length);
- return global_object.heap().allocate<ArrayBuffer>(global_object, buffer.release_value(), *global_object.array_buffer_prototype());
+ return realm.heap().allocate<ArrayBuffer>(realm.global_object(), buffer.release_value(), *realm.global_object().array_buffer_prototype());
}
-ArrayBuffer* ArrayBuffer::create(GlobalObject& global_object, ByteBuffer buffer)
+ArrayBuffer* ArrayBuffer::create(Realm& realm, ByteBuffer buffer)
{
- return global_object.heap().allocate<ArrayBuffer>(global_object, move(buffer), *global_object.array_buffer_prototype());
+ return realm.heap().allocate<ArrayBuffer>(realm.global_object(), move(buffer), *realm.global_object().array_buffer_prototype());
}
-ArrayBuffer* ArrayBuffer::create(GlobalObject& global_object, ByteBuffer* buffer)
+ArrayBuffer* ArrayBuffer::create(Realm& realm, ByteBuffer* buffer)
{
- return global_object.heap().allocate<ArrayBuffer>(global_object, buffer, *global_object.array_buffer_prototype());
+ return realm.heap().allocate<ArrayBuffer>(realm.global_object(), buffer, *realm.global_object().array_buffer_prototype());
}
ArrayBuffer::ArrayBuffer(ByteBuffer buffer, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h
index e8d17c3240..1be0de1c1c 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h
+++ b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h
@@ -25,9 +25,9 @@ class ArrayBuffer : public Object {
JS_OBJECT(ArrayBuffer, Object);
public:
- static ThrowCompletionOr<ArrayBuffer*> create(GlobalObject&, size_t);
- static ArrayBuffer* create(GlobalObject&, ByteBuffer);
- static ArrayBuffer* create(GlobalObject&, ByteBuffer*);
+ static ThrowCompletionOr<ArrayBuffer*> create(Realm&, size_t);
+ static ArrayBuffer* create(Realm&, ByteBuffer);
+ static ArrayBuffer* create(Realm&, ByteBuffer*);
ArrayBuffer(ByteBuffer buffer, Object& prototype);
ArrayBuffer(ByteBuffer* buffer, Object& prototype);
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp
index 2d1c9b9a92..2fc769b1ee 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp
@@ -50,29 +50,31 @@ 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* proto = TRY(get_prototype_from_constructor(global_object(), new_target, &GlobalObject::array_prototype));
+ auto* proto = TRY(get_prototype_from_constructor(global_object, new_target, &GlobalObject::array_prototype));
if (vm.argument_count() == 0)
- return MUST(Array::create(global_object(), 0, proto));
+ return MUST(Array::create(realm, 0, proto));
if (vm.argument_count() == 1) {
auto length = vm.argument(0);
- auto* array = MUST(Array::create(global_object(), 0, proto));
+ auto* array = MUST(Array::create(realm, 0, proto));
size_t int_length;
if (!length.is_number()) {
MUST(array->create_data_property_or_throw(0, length));
int_length = 1;
} else {
- int_length = MUST(length.to_u32(global_object()));
+ int_length = MUST(length.to_u32(global_object));
if (int_length != length.as_double())
- return vm.throw_completion<RangeError>(global_object(), ErrorType::InvalidLength, "array");
+ return vm.throw_completion<RangeError>(global_object, ErrorType::InvalidLength, "array");
}
TRY(array->set(vm.names.length, Value(int_length), Object::ShouldThrowExceptions::Yes));
return array;
}
- auto* array = TRY(Array::create(global_object(), vm.argument_count(), proto));
+ auto* array = TRY(Array::create(realm, vm.argument_count(), proto));
for (size_t k = 0; k < vm.argument_count(); ++k)
MUST(array->create_data_property_or_throw(k, vm.argument(k)));
@@ -83,6 +85,7 @@ ThrowCompletionOr<Object*> ArrayConstructor::construct(FunctionObject& new_targe
// 23.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] ), https://tc39.es/ecma262/#sec-array.from
JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
{
+ auto& realm = *global_object.associated_realm();
auto constructor = vm.this_value(global_object);
FunctionObject* map_fn = nullptr;
@@ -102,7 +105,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
if (constructor.is_constructor())
array = TRY(JS::construct(global_object, constructor.as_function(), {}));
else
- array = MUST(Array::create(global_object, 0));
+ array = MUST(Array::create(realm, 0));
auto iterator = TRY(get_iterator(global_object, items, IteratorHint::Sync, using_iterator));
@@ -147,7 +150,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
if (constructor.is_constructor())
array = TRY(JS::construct(global_object, constructor.as_function(), Value(length)));
else
- array = TRY(Array::create(global_object, length));
+ array = TRY(Array::create(realm, length));
for (size_t k = 0; k < length; ++k) {
auto k_value = TRY(array_like->get(k));
@@ -174,12 +177,13 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::is_array)
// 23.1.2.3 Array.of ( ...items ), https://tc39.es/ecma262/#sec-array.of
JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::of)
{
+ auto& realm = *global_object.associated_realm();
auto this_value = vm.this_value(global_object);
Object* array;
if (this_value.is_constructor())
array = TRY(JS::construct(global_object, this_value.as_function(), Value(vm.argument_count())));
else
- array = TRY(Array::create(global_object, vm.argument_count()));
+ array = TRY(Array::create(realm, vm.argument_count()));
for (size_t k = 0; k < vm.argument_count(); ++k)
TRY(array->create_data_property_or_throw(k, vm.argument(k)));
TRY(array->set(vm.names.length, Value(vm.argument_count()), Object::ShouldThrowExceptions::Yes));
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayIterator.cpp b/Userland/Libraries/LibJS/Runtime/ArrayIterator.cpp
index 2a8b84aab1..340ff7db2c 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayIterator.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ArrayIterator.cpp
@@ -9,9 +9,9 @@
namespace JS {
-ArrayIterator* ArrayIterator::create(GlobalObject& global_object, Value array, Object::PropertyKind iteration_kind)
+ArrayIterator* ArrayIterator::create(Realm& realm, Value array, Object::PropertyKind iteration_kind)
{
- return global_object.heap().allocate<ArrayIterator>(global_object, array, iteration_kind, *global_object.array_iterator_prototype());
+ return realm.heap().allocate<ArrayIterator>(realm.global_object(), array, iteration_kind, *realm.global_object().array_iterator_prototype());
}
ArrayIterator::ArrayIterator(Value array, Object::PropertyKind iteration_kind, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayIterator.h b/Userland/Libraries/LibJS/Runtime/ArrayIterator.h
index 47e115f4c1..fca149fb16 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayIterator.h
+++ b/Userland/Libraries/LibJS/Runtime/ArrayIterator.h
@@ -14,7 +14,7 @@ class ArrayIterator final : public Object {
JS_OBJECT(ArrayIterator, Object);
public:
- static ArrayIterator* create(GlobalObject&, Value array, Object::PropertyKind iteration_kind);
+ static ArrayIterator* create(Realm&, Value array, Object::PropertyKind iteration_kind);
explicit ArrayIterator(Value array, Object::PropertyKind iteration_kind, Object& prototype);
virtual ~ArrayIterator() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp
index aaa3e8b97e..ffaa276bb4 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp
@@ -34,6 +34,8 @@ void ArrayIteratorPrototype::initialize(Realm& realm)
// FIXME: This seems to be CreateArrayIterator (https://tc39.es/ecma262/#sec-createarrayiterator) instead of %ArrayIteratorPrototype%.next.
JS_DEFINE_NATIVE_FUNCTION(ArrayIteratorPrototype::next)
{
+ auto& realm = *global_object.associated_realm();
+
auto* iterator = TRY(typed_this_value(global_object));
auto target_array = iterator->array();
if (target_array.is_undefined())
@@ -71,7 +73,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayIteratorPrototype::next)
if (iteration_kind == Object::PropertyKind::Value)
return create_iterator_result_object(global_object, value, false);
- return create_iterator_result_object(global_object, Array::create_from(global_object, { Value(static_cast<i32>(index)), value }), false);
+ return create_iterator_result_object(global_object, Array::create_from(realm, { Value(static_cast<i32>(index)), value }), false);
}
}
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp
index c749a1c575..a38874d0ad 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp
@@ -89,7 +89,7 @@ void ArrayPrototype::initialize(Realm& realm)
// 23.1.3.37 Array.prototype [ @@unscopables ], https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
// With array grouping proposal, https://tc39.es/proposal-array-grouping/#sec-array.prototype-@@unscopables
// With change array by copy proposal, https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype-@@unscopables
- auto* unscopable_list = Object::create(realm.global_object(), nullptr);
+ auto* unscopable_list = Object::create(realm, nullptr);
MUST(unscopable_list->create_data_property_or_throw(vm.names.at, Value(true)));
MUST(unscopable_list->create_data_property_or_throw(vm.names.copyWithin, Value(true)));
MUST(unscopable_list->create_data_property_or_throw(vm.names.entries, Value(true)));
@@ -116,11 +116,12 @@ void ArrayPrototype::initialize(Realm& realm)
static ThrowCompletionOr<Object*> array_species_create(GlobalObject& global_object, Object& original_array, size_t length)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
auto is_array = TRY(Value(&original_array).is_array(global_object));
if (!is_array)
- return TRY(Array::create(global_object, length));
+ return TRY(Array::create(realm, length));
auto constructor = TRY(original_array.get(vm.names.constructor));
if (constructor.is_constructor()) {
@@ -140,7 +141,7 @@ static ThrowCompletionOr<Object*> array_species_create(GlobalObject& global_obje
}
if (constructor.is_undefined())
- return TRY(Array::create(global_object, length));
+ return TRY(Array::create(realm, length));
if (!constructor.is_constructor())
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAConstructor, constructor.to_string_without_side_effects());
@@ -295,9 +296,11 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::copy_within)
// 23.1.3.5 Array.prototype.entries ( ), https://tc39.es/ecma262/#sec-array.prototype.entries
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::entries)
{
+ auto& realm = *global_object.associated_realm();
+
auto* this_object = TRY(vm.this_value(global_object).to_object(global_object));
- return ArrayIterator::create(global_object, this_object, Object::PropertyKind::KeyAndValue);
+ return ArrayIterator::create(realm, this_object, Object::PropertyKind::KeyAndValue);
}
// 23.1.3.6 Array.prototype.every ( callbackfn [ , thisArg ] ), https://tc39.es/ecma262/#sec-array.prototype.every
@@ -752,6 +755,8 @@ static void add_value_to_keyed_group(GlobalObject& global_object, GroupsType& gr
// 2.1 Array.prototype.group ( callbackfn [ , thisArg ] ), https://tc39.es/proposal-array-grouping/#sec-array.prototype.group
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group)
{
+ auto& realm = *global_object.associated_realm();
+
auto callback_function = vm.argument(0);
auto this_arg = vm.argument(1);
@@ -788,12 +793,12 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group)
}
// 7. Let obj be OrdinaryObjectCreate(null).
- auto* object = Object::create(global_object, nullptr);
+ auto* object = Object::create(realm, nullptr);
// 8. For each Record { [[Key]], [[Elements]] } g of groups, do
for (auto& group : groups) {
// a. Let elements be CreateArrayFromList(g.[[Elements]]).
- auto* elements = Array::create_from(global_object, group.value);
+ auto* elements = Array::create_from(realm, group.value);
// b. Perform ! CreateDataPropertyOrThrow(obj, g.[[Key]], elements).
MUST(object->create_data_property_or_throw(group.key, elements));
@@ -806,6 +811,8 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group)
// 2.2 Array.prototype.groupToMap ( callbackfn [ , thisArg ] ), https://tc39.es/proposal-array-grouping/#sec-array.prototype.grouptomap
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group_to_map)
{
+ auto& realm = *global_object.associated_realm();
+
auto callback_function = vm.argument(0);
auto this_arg = vm.argument(1);
@@ -858,12 +865,12 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group_to_map)
}
// 7. Let map be ! Construct(%Map%).
- auto* map = Map::create(global_object);
+ auto* map = Map::create(realm);
// 8. For each Record { [[Key]], [[Elements]] } g of groups, do
for (auto& group : groups) {
// a. Let elements be CreateArrayFromList(g.[[Elements]]).
- auto* elements = Array::create_from(global_object, group.value);
+ auto* elements = Array::create_from(realm, group.value);
// b. Let entry be the Record { [[Key]]: g.[[Key]], [[Value]]: elements }.
// c. Append entry as the last element of map.[[MapData]].
@@ -1013,9 +1020,11 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::join)
// 23.1.3.19 Array.prototype.keys ( ), https://tc39.es/ecma262/#sec-array.prototype.keys
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::keys)
{
+ auto& realm = *global_object.associated_realm();
+
auto* this_object = TRY(vm.this_value(global_object).to_object(global_object));
- return ArrayIterator::create(global_object, this_object, Object::PropertyKind::Key);
+ return ArrayIterator::create(realm, this_object, Object::PropertyKind::Key);
}
// 23.1.3.20 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ), https://tc39.es/ecma262/#sec-array.prototype.lastindexof
@@ -1744,6 +1753,8 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_locale_string)
// 1.1.1.4 Array.prototype.toReversed ( ), https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toReversed
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_reversed)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let O be ? ToObject(this value).
auto* object = TRY(vm.this_value(global_object).to_object(global_object));
@@ -1751,7 +1762,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_reversed)
auto length = TRY(length_of_array_like(global_object, *object));
// 3. Let A be ? ArrayCreate(𝔽(len)).
- auto* array = TRY(Array::create(global_object, length));
+ auto* array = TRY(Array::create(realm, length));
// 4. Let k be 0.
// 5. Repeat, while k < len,
@@ -1778,6 +1789,8 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_reversed)
// 1.1.1.5 Array.prototype.toSorted ( comparefn ), https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toSorted
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_sorted)
{
+ auto& realm = *global_object.associated_realm();
+
auto comparefn = vm.argument(0);
// 1. If comparefn is not undefined and IsCallable(comparefn) is false, throw a TypeError exception.
@@ -1791,7 +1804,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_sorted)
auto length = TRY(length_of_array_like(global_object, *object));
// 4. Let A be ? ArrayCreate(𝔽(len)).
- auto* array = TRY(Array::create(global_object, length));
+ auto* array = TRY(Array::create(realm, length));
// 5. Let SortCompare be a new Abstract Closure with parameters (x, y) that captures comparefn and performs the following steps when called:
Function<ThrowCompletionOr<double>(Value, Value)> sort_compare = [&](auto x, auto y) -> ThrowCompletionOr<double> {
@@ -1818,6 +1831,8 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_sorted)
// 1.1.1.6 Array.prototype.toSpliced ( start, deleteCount, ...items ), https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toSpliced
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_spliced)
{
+ auto& realm = *global_object.associated_realm();
+
auto start = vm.argument(0);
auto delete_count = vm.argument(1);
@@ -1882,7 +1897,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_spliced)
auto new_length = static_cast<u64>(new_length_double);
// 13. Let A be ? ArrayCreate(𝔽(newLen)).
- auto* array = TRY(Array::create(global_object, new_length));
+ auto* array = TRY(Array::create(realm, new_length));
// 14. Let i be 0.
size_t i = 0;
@@ -1996,14 +2011,18 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::unshift)
// 23.1.3.35 Array.prototype.values ( ), https://tc39.es/ecma262/#sec-array.prototype.values
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::values)
{
+ auto& realm = *global_object.associated_realm();
+
auto* this_object = TRY(vm.this_value(global_object).to_object(global_object));
- return ArrayIterator::create(global_object, this_object, Object::PropertyKind::Value);
+ return ArrayIterator::create(realm, this_object, Object::PropertyKind::Value);
}
// 1.1.1.7 Array.prototype.with ( index, value ), https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.with
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::with)
{
+ auto& realm = *global_object.associated_realm();
+
auto index = vm.argument(0);
auto value = vm.argument(1);
@@ -2030,7 +2049,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::with)
return vm.throw_completion<RangeError>(global_object, ErrorType::IndexOutOfRange, actual_index, length);
// 7. Let A be ? ArrayCreate(𝔽(len)).
- auto* array = TRY(Array::create(global_object, length));
+ auto* array = TRY(Array::create(realm, length));
// 8. Let k be 0.
// 9. Repeat, while k < len,
diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.cpp
index 0925f31577..1747e6c800 100644
--- a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.cpp
+++ b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.cpp
@@ -11,10 +11,9 @@
namespace JS {
-AsyncFromSyncIterator* AsyncFromSyncIterator::create(GlobalObject& global_object, Iterator sync_iterator_record)
+AsyncFromSyncIterator* AsyncFromSyncIterator::create(Realm& realm, Iterator sync_iterator_record)
{
- auto& realm = *global_object.associated_realm();
- return global_object.heap().allocate<AsyncFromSyncIterator>(global_object, realm, sync_iterator_record);
+ return realm.heap().allocate<AsyncFromSyncIterator>(realm.global_object(), realm, sync_iterator_record);
}
AsyncFromSyncIterator::AsyncFromSyncIterator(Realm& realm, Iterator sync_iterator_record)
diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.h b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.h
index 8ce4d06043..89dc61663d 100644
--- a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.h
+++ b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.h
@@ -17,7 +17,7 @@ class AsyncFromSyncIterator final : public Object {
JS_OBJECT(AsyncFromSyncIterator, Object);
public:
- static AsyncFromSyncIterator* create(GlobalObject&, Iterator sync_iterator_record);
+ static AsyncFromSyncIterator* create(Realm&, Iterator sync_iterator_record);
explicit AsyncFromSyncIterator(Realm&, Iterator sync_iterator_record);
virtual void initialize(Realm&) override;
diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp
index 31d8c63756..1fb8f8ef48 100644
--- a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp
@@ -33,6 +33,8 @@ void AsyncFromSyncIteratorPrototype::initialize(Realm& realm)
// 27.1.4.4 AsyncFromSyncIteratorContinuation ( result, promiseCapability ), https://tc39.es/ecma262/#sec-asyncfromsynciteratorcontinuation
static Object* async_from_sync_iterator_continuation(GlobalObject& global_object, Object& result, PromiseCapability& promise_capability)
{
+ auto& realm = *global_object.associated_realm();
+
// 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)).
// 3. IfAbruptRejectPromise(done, promiseCapability).
@@ -54,7 +56,7 @@ static Object* async_from_sync_iterator_continuation(GlobalObject& global_object
// 9. Let onFulfilled be CreateBuiltinFunction(unwrap, 1, "", « »).
// 10. NOTE: onFulfilled is used when processing the "value" property of an IteratorResult object in order to wait for its value if it is a promise and re-package the result in a new "unwrapped" IteratorResult object.
- auto* on_fulfilled = NativeFunction::create(global_object, move(unwrap), 1, "");
+ auto* on_fulfilled = NativeFunction::create(realm, move(unwrap), 1, "");
// 11. Perform PerformPromiseThen(valueWrapper, onFulfilled, undefined, promiseCapability).
verify_cast<Promise>(value_wrapper)->perform_then(move(on_fulfilled), js_undefined(), promise_capability);
@@ -92,6 +94,8 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::next)
// 27.1.4.2.2 %AsyncFromSyncIteratorPrototype%.return ( [ value ] ), https://tc39.es/ecma262/#sec-%asyncfromsynciteratorprototype%.return
JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let O be the this value.
// 2. Assert: O is an Object that has a [[SyncIteratorRecord]] internal slot.
auto* this_object = MUST(typed_this_object(global_object));
@@ -129,7 +133,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_)
// 11. If Type(result) is not Object, then
if (!result.is_object()) {
- auto* error = TypeError::create(global_object, String::formatted(ErrorType::NotAnObject.message(), "SyncIteratorReturnResult"));
+ auto* error = TypeError::create(realm, String::formatted(ErrorType::NotAnObject.message(), "SyncIteratorReturnResult"));
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
MUST(call(global_object, *promise_capability.reject, js_undefined(), error));
// b. Return promiseCapability.[[Promise]].
@@ -143,6 +147,8 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_)
// 27.1.4.2.3 %AsyncFromSyncIteratorPrototype%.throw ( [ value ] ), https://tc39.es/ecma262/#sec-%asyncfromsynciteratorprototype%.throw
JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::throw_)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let O be the this value.
// 2. Assert: O is an Object that has a [[SyncIteratorRecord]] internal slot.
auto* this_object = MUST(typed_this_object(global_object));
@@ -175,7 +181,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::throw_)
// 11. If Type(result) is not Object, then
if (!result.is_object()) {
- auto* error = TypeError::create(global_object, String::formatted(ErrorType::NotAnObject.message(), "SyncIteratorThrowResult"));
+ auto* error = TypeError::create(realm, String::formatted(ErrorType::NotAnObject.message(), "SyncIteratorThrowResult"));
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
MUST(call(global_object, *promise_capability.reject, js_undefined(), error));
@@ -191,10 +197,11 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::throw_)
Iterator create_async_from_sync_iterator(GlobalObject& global_object, Iterator sync_iterator_record)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let asyncIterator be OrdinaryObjectCreate(%AsyncFromSyncIteratorPrototype%, « [[SyncIteratorRecord]] »).
// 2. Set asyncIterator.[[SyncIteratorRecord]] to syncIteratorRecord.
- auto* async_iterator = AsyncFromSyncIterator::create(global_object, sync_iterator_record);
+ auto* async_iterator = AsyncFromSyncIterator::create(realm, sync_iterator_record);
// 3. Let nextMethod be ! Get(asyncIterator, "next").
auto next_method = MUST(async_iterator->get(vm.names.next));
diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp
index 72300237e2..731f3f23bb 100644
--- a/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp
+++ b/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp
@@ -12,20 +12,19 @@
namespace JS {
-ThrowCompletionOr<Value> AsyncFunctionDriverWrapper::create(GlobalObject& global_object, GeneratorObject* generator_object)
+ThrowCompletionOr<Value> AsyncFunctionDriverWrapper::create(Realm& realm, GeneratorObject* generator_object)
{
- auto& realm = *global_object.associated_realm();
- auto wrapper = global_object.heap().allocate<AsyncFunctionDriverWrapper>(global_object, realm, generator_object);
- return wrapper->react_to_async_task_completion(global_object.vm(), global_object, js_undefined(), true);
+ auto wrapper = realm.heap().allocate<AsyncFunctionDriverWrapper>(realm.global_object(), realm, generator_object);
+ return wrapper->react_to_async_task_completion(realm.vm(), realm.global_object(), js_undefined(), true);
}
AsyncFunctionDriverWrapper::AsyncFunctionDriverWrapper(Realm& realm, GeneratorObject* generator_object)
: Promise(*realm.global_object().promise_prototype())
, m_generator_object(generator_object)
- , m_on_fulfillment(NativeFunction::create(realm.global_object(), "async.on_fulfillment"sv, [this](VM& vm, GlobalObject& global_object) {
+ , m_on_fulfillment(NativeFunction::create(realm, "async.on_fulfillment"sv, [this](VM& vm, GlobalObject& global_object) {
return react_to_async_task_completion(vm, global_object, vm.argument(0), true);
}))
- , m_on_rejection(NativeFunction::create(realm.global_object(), "async.on_rejection"sv, [this](VM& vm, GlobalObject& global_object) {
+ , m_on_rejection(NativeFunction::create(realm, "async.on_rejection"sv, [this](VM& vm, GlobalObject& global_object) {
return react_to_async_task_completion(vm, global_object, vm.argument(0), false);
}))
{
@@ -33,13 +32,15 @@ AsyncFunctionDriverWrapper::AsyncFunctionDriverWrapper(Realm& realm, GeneratorOb
ThrowCompletionOr<Value> AsyncFunctionDriverWrapper::react_to_async_task_completion(VM& vm, GlobalObject& global_object, Value value, bool is_successful)
{
+ auto& realm = *global_object.associated_realm();
+
auto generator_result = is_successful
? m_generator_object->next_impl(vm, global_object, value, {})
: m_generator_object->next_impl(vm, global_object, {}, value);
if (generator_result.is_throw_completion()) {
VERIFY(generator_result.throw_completion().type() == Completion::Type::Throw);
- auto promise = Promise::create(global_object);
+ auto promise = Promise::create(realm);
promise->reject(*generator_result.throw_completion().value());
return promise;
}
@@ -49,7 +50,7 @@ ThrowCompletionOr<Value> AsyncFunctionDriverWrapper::react_to_async_task_complet
auto promise_value = TRY(result.get(global_object, vm.names.value));
if (!promise_value.is_object() || !is<Promise>(promise_value.as_object())) {
- auto promise = Promise::create(global_object);
+ auto promise = Promise::create(realm);
promise->fulfill(promise_value);
return promise;
}
diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.h b/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.h
index 27e533858f..4942ed2e31 100644
--- a/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.h
+++ b/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.h
@@ -18,7 +18,7 @@ class AsyncFunctionDriverWrapper final : public Promise {
JS_OBJECT(AsyncFunctionDriverWrapper, Promise);
public:
- static ThrowCompletionOr<Value> create(GlobalObject&, GeneratorObject*);
+ static ThrowCompletionOr<Value> create(Realm&, GeneratorObject*);
explicit AsyncFunctionDriverWrapper(Realm&, GeneratorObject*);
virtual ~AsyncFunctionDriverWrapper() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp b/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp
index b2935e35bf..ce1f048941 100644
--- a/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp
@@ -9,9 +9,9 @@
namespace JS {
-BigIntObject* BigIntObject::create(GlobalObject& global_object, BigInt& bigint)
+BigIntObject* BigIntObject::create(Realm& realm, BigInt& bigint)
{
- return global_object.heap().allocate<BigIntObject>(global_object, bigint, *global_object.bigint_prototype());
+ return realm.heap().allocate<BigIntObject>(realm.global_object(), bigint, *realm.global_object().bigint_prototype());
}
BigIntObject::BigIntObject(BigInt& bigint, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/BigIntObject.h b/Userland/Libraries/LibJS/Runtime/BigIntObject.h
index 5570a4ef75..2eb03f5c90 100644
--- a/Userland/Libraries/LibJS/Runtime/BigIntObject.h
+++ b/Userland/Libraries/LibJS/Runtime/BigIntObject.h
@@ -15,7 +15,7 @@ class BigIntObject final : public Object {
JS_OBJECT(BigIntObject, Object);
public:
- static BigIntObject* create(GlobalObject&, BigInt&);
+ static BigIntObject* create(Realm&, BigInt&);
BigIntObject(BigInt&, Object& prototype);
virtual ~BigIntObject() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/BooleanObject.cpp b/Userland/Libraries/LibJS/Runtime/BooleanObject.cpp
index 948016f9f7..af0dd4f16f 100644
--- a/Userland/Libraries/LibJS/Runtime/BooleanObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/BooleanObject.cpp
@@ -9,9 +9,9 @@
namespace JS {
-BooleanObject* BooleanObject::create(GlobalObject& global_object, bool value)
+BooleanObject* BooleanObject::create(Realm& realm, bool value)
{
- return global_object.heap().allocate<BooleanObject>(global_object, value, *global_object.boolean_prototype());
+ return realm.heap().allocate<BooleanObject>(realm.global_object(), value, *realm.global_object().boolean_prototype());
}
BooleanObject::BooleanObject(bool value, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/BooleanObject.h b/Userland/Libraries/LibJS/Runtime/BooleanObject.h
index a1ed7f6752..4be928dcd7 100644
--- a/Userland/Libraries/LibJS/Runtime/BooleanObject.h
+++ b/Userland/Libraries/LibJS/Runtime/BooleanObject.h
@@ -14,7 +14,7 @@ class BooleanObject : public Object {
JS_OBJECT(BooleanObject, Object);
public:
- static BooleanObject* create(GlobalObject&, bool);
+ static BooleanObject* create(Realm&, bool);
BooleanObject(bool, Object& prototype);
virtual ~BooleanObject() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/BoundFunction.cpp b/Userland/Libraries/LibJS/Runtime/BoundFunction.cpp
index a9fa182217..89b44f4129 100644
--- a/Userland/Libraries/LibJS/Runtime/BoundFunction.cpp
+++ b/Userland/Libraries/LibJS/Runtime/BoundFunction.cpp
@@ -12,10 +12,8 @@
namespace JS {
// 10.4.1.3 BoundFunctionCreate ( targetFunction, boundThis, boundArgs ), https://tc39.es/ecma262/#sec-boundfunctioncreate
-ThrowCompletionOr<BoundFunction*> BoundFunction::create(GlobalObject& global_object, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments)
+ThrowCompletionOr<BoundFunction*> BoundFunction::create(Realm& realm, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments)
{
- auto& realm = *global_object.associated_realm();
-
// 1. Let proto be ? targetFunction.[[GetPrototypeOf]]().
auto* prototype = TRY(target_function.internal_get_prototype_of());
@@ -28,7 +26,7 @@ ThrowCompletionOr<BoundFunction*> BoundFunction::create(GlobalObject& global_obj
// 7. Set obj.[[BoundTargetFunction]] to targetFunction.
// 8. Set obj.[[BoundThis]] to boundThis.
// 9. Set obj.[[BoundArguments]] to boundArgs.
- auto* object = global_object.heap().allocate<BoundFunction>(global_object, realm, target_function, bound_this, move(bound_arguments), prototype);
+ auto* object = realm.heap().allocate<BoundFunction>(realm.global_object(), realm, target_function, bound_this, move(bound_arguments), prototype);
// 10. Return obj.
return object;
diff --git a/Userland/Libraries/LibJS/Runtime/BoundFunction.h b/Userland/Libraries/LibJS/Runtime/BoundFunction.h
index b7dabe66f5..85425be94a 100644
--- a/Userland/Libraries/LibJS/Runtime/BoundFunction.h
+++ b/Userland/Libraries/LibJS/Runtime/BoundFunction.h
@@ -15,7 +15,7 @@ class BoundFunction final : public FunctionObject {
JS_OBJECT(BoundFunction, FunctionObject);
public:
- static ThrowCompletionOr<BoundFunction*> create(GlobalObject&, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments);
+ static ThrowCompletionOr<BoundFunction*> create(Realm&, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments);
BoundFunction(Realm&, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments, Object* prototype);
virtual ~BoundFunction() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/Completion.cpp b/Userland/Libraries/LibJS/Runtime/Completion.cpp
index 3683391d47..303d33adbe 100644
--- a/Userland/Libraries/LibJS/Runtime/Completion.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Completion.cpp
@@ -32,6 +32,7 @@ Completion::Completion(ThrowCompletionOr<Value> const& throw_completion_or_value
ThrowCompletionOr<Value> await(GlobalObject& global_object, Value value)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let asyncContext be the running execution context.
// NOTE: This is not needed, as we don't suspend anything.
@@ -63,7 +64,7 @@ ThrowCompletionOr<Value> await(GlobalObject& global_object, Value value)
};
// 4. Let onFulfilled be CreateBuiltinFunction(fulfilledClosure, 1, "", « »).
- auto* on_fulfilled = NativeFunction::create(global_object, move(fulfilled_closure), 1, "");
+ auto* on_fulfilled = NativeFunction::create(realm, move(fulfilled_closure), 1, "");
// 5. Let rejectedClosure be a new Abstract Closure with parameters (reason) that captures asyncContext and performs the following steps when called:
auto rejected_closure = [&success, &result](VM& vm, GlobalObject&) -> ThrowCompletionOr<Value> {
@@ -87,7 +88,7 @@ ThrowCompletionOr<Value> await(GlobalObject& global_object, Value value)
};
// 6. Let onRejected be CreateBuiltinFunction(rejectedClosure, 1, "", « »).
- auto* on_rejected = NativeFunction::create(global_object, move(rejected_closure), 1, "");
+ auto* on_rejected = NativeFunction::create(realm, move(rejected_closure), 1, "");
// 7. Perform PerformPromiseThen(promise, onFulfilled, onRejected).
auto* promise = verify_cast<Promise>(promise_object);
diff --git a/Userland/Libraries/LibJS/Runtime/DataView.cpp b/Userland/Libraries/LibJS/Runtime/DataView.cpp
index 44ebab6319..f8f247afc9 100644
--- a/Userland/Libraries/LibJS/Runtime/DataView.cpp
+++ b/Userland/Libraries/LibJS/Runtime/DataView.cpp
@@ -8,9 +8,9 @@
namespace JS {
-DataView* DataView::create(GlobalObject& global_object, ArrayBuffer* viewed_buffer, size_t byte_length, size_t byte_offset)
+DataView* DataView::create(Realm& realm, ArrayBuffer* viewed_buffer, size_t byte_length, size_t byte_offset)
{
- return global_object.heap().allocate<DataView>(global_object, viewed_buffer, byte_length, byte_offset, *global_object.data_view_prototype());
+ return realm.heap().allocate<DataView>(realm.global_object(), viewed_buffer, byte_length, byte_offset, *realm.global_object().data_view_prototype());
}
DataView::DataView(ArrayBuffer* viewed_buffer, size_t byte_length, size_t byte_offset, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/DataView.h b/Userland/Libraries/LibJS/Runtime/DataView.h
index 45dc66c7d8..4edb44cc88 100644
--- a/Userland/Libraries/LibJS/Runtime/DataView.h
+++ b/Userland/Libraries/LibJS/Runtime/DataView.h
@@ -16,7 +16,7 @@ class DataView : public Object {
JS_OBJECT(DataView, Object);
public:
- static DataView* create(GlobalObject&, ArrayBuffer*, size_t byte_length, size_t byte_offset);
+ static DataView* create(Realm&, ArrayBuffer*, size_t byte_length, size_t byte_offset);
explicit DataView(ArrayBuffer*, size_t byte_length, size_t byte_offset, Object& prototype);
virtual ~DataView() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp
index 9d68e369b1..bc8bb5c87b 100644
--- a/Userland/Libraries/LibJS/Runtime/Date.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Date.cpp
@@ -16,9 +16,9 @@
namespace JS {
-Date* Date::create(GlobalObject& global_object, double date_value)
+Date* Date::create(Realm& realm, double date_value)
{
- return global_object.heap().allocate<Date>(global_object, date_value, *global_object.date_prototype());
+ return realm.heap().allocate<Date>(realm.global_object(), date_value, *realm.global_object().date_prototype());
}
Date::Date(double date_value, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/Date.h b/Userland/Libraries/LibJS/Runtime/Date.h
index b3923a2d8b..e7271a8e3d 100644
--- a/Userland/Libraries/LibJS/Runtime/Date.h
+++ b/Userland/Libraries/LibJS/Runtime/Date.h
@@ -15,7 +15,7 @@ class Date final : public Object {
JS_OBJECT(Date, Object);
public:
- static Date* create(GlobalObject&, double date_value);
+ static Date* create(Realm&, double date_value);
static Date* now(GlobalObject&);
Date(double date_value, Object& prototype);
diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
index 33cb8cff38..7828d128dd 100644
--- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
@@ -28,29 +28,29 @@
namespace JS {
-ECMAScriptFunctionObject* ECMAScriptFunctionObject::create(GlobalObject& global_object, FlyString name, String source_text, Statement const& ecmascript_code, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind kind, bool is_strict, bool might_need_arguments_object, bool contains_direct_call_to_eval, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
+ECMAScriptFunctionObject* ECMAScriptFunctionObject::create(Realm& realm, FlyString name, String source_text, Statement const& ecmascript_code, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind kind, bool is_strict, bool might_need_arguments_object, bool contains_direct_call_to_eval, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
{
Object* prototype = nullptr;
switch (kind) {
case FunctionKind::Normal:
- prototype = global_object.function_prototype();
+ prototype = realm.global_object().function_prototype();
break;
case FunctionKind::Generator:
- prototype = global_object.generator_function_prototype();
+ prototype = realm.global_object().generator_function_prototype();
break;
case FunctionKind::Async:
- prototype = global_object.async_function_prototype();
+ prototype = realm.global_object().async_function_prototype();
break;
case FunctionKind::AsyncGenerator:
- prototype = global_object.async_generator_function_prototype();
+ prototype = realm.global_object().async_generator_function_prototype();
break;
}
- return global_object.heap().allocate<ECMAScriptFunctionObject>(global_object, move(name), move(source_text), ecmascript_code, move(parameters), m_function_length, parent_environment, private_environment, *prototype, kind, is_strict, might_need_arguments_object, contains_direct_call_to_eval, is_arrow_function, move(class_field_initializer_name));
+ return realm.heap().allocate<ECMAScriptFunctionObject>(realm.global_object(), move(name), move(source_text), ecmascript_code, move(parameters), m_function_length, parent_environment, private_environment, *prototype, kind, is_strict, might_need_arguments_object, contains_direct_call_to_eval, is_arrow_function, move(class_field_initializer_name));
}
-ECMAScriptFunctionObject* ECMAScriptFunctionObject::create(GlobalObject& global_object, FlyString name, Object& prototype, String source_text, Statement const& ecmascript_code, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind kind, bool is_strict, bool might_need_arguments_object, bool contains_direct_call_to_eval, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
+ECMAScriptFunctionObject* ECMAScriptFunctionObject::create(Realm& realm, FlyString name, Object& prototype, String source_text, Statement const& ecmascript_code, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind kind, bool is_strict, bool might_need_arguments_object, bool contains_direct_call_to_eval, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
{
- return global_object.heap().allocate<ECMAScriptFunctionObject>(global_object, move(name), move(source_text), ecmascript_code, move(parameters), m_function_length, parent_environment, private_environment, prototype, kind, is_strict, might_need_arguments_object, contains_direct_call_to_eval, is_arrow_function, move(class_field_initializer_name));
+ return realm.heap().allocate<ECMAScriptFunctionObject>(realm.global_object(), move(name), move(source_text), ecmascript_code, move(parameters), m_function_length, parent_environment, private_environment, prototype, kind, is_strict, might_need_arguments_object, contains_direct_call_to_eval, is_arrow_function, move(class_field_initializer_name));
}
ECMAScriptFunctionObject::ECMAScriptFunctionObject(FlyString name, String source_text, Statement const& ecmascript_code, Vector<FunctionNode::Parameter> formal_parameters, i32 function_length, Environment* parent_environment, PrivateEnvironment* private_environment, Object& prototype, FunctionKind kind, bool strict, bool might_need_arguments_object, bool contains_direct_call_to_eval, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
@@ -119,12 +119,12 @@ void ECMAScriptFunctionObject::initialize(Realm& realm)
break;
case FunctionKind::Generator:
// prototype is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png)
- prototype = Object::create(realm.global_object(), realm.global_object().generator_function_prototype_prototype());
+ prototype = Object::create(realm, realm.global_object().generator_function_prototype_prototype());
break;
case FunctionKind::Async:
break;
case FunctionKind::AsyncGenerator:
- prototype = Object::create(realm.global_object(), realm.global_object().async_generator_function_prototype_prototype());
+ prototype = Object::create(realm, realm.global_object().async_generator_function_prototype_prototype());
break;
}
// 27.7.4 AsyncFunction Instances, https://tc39.es/ecma262/#sec-async-function-instances
@@ -319,6 +319,8 @@ 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& callee_context = vm.running_execution_context();
@@ -399,24 +401,24 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
if (MUST(environment->has_binding(parameter_name)))
continue;
- MUST(environment->create_mutable_binding(global_object(), parameter_name, false));
+ MUST(environment->create_mutable_binding(global_object, parameter_name, false));
if (has_duplicates)
- MUST(environment->initialize_binding(global_object(), parameter_name, js_undefined()));
+ MUST(environment->initialize_binding(global_object, parameter_name, js_undefined()));
}
if (arguments_object_needed) {
Object* arguments_object;
if (is_strict_mode() || !has_simple_parameter_list())
- arguments_object = create_unmapped_arguments_object(global_object(), vm.running_execution_context().arguments);
+ arguments_object = create_unmapped_arguments_object(global_object, vm.running_execution_context().arguments);
else
- arguments_object = create_mapped_arguments_object(global_object(), *this, formal_parameters(), vm.running_execution_context().arguments, *environment);
+ arguments_object = create_mapped_arguments_object(global_object, *this, formal_parameters(), vm.running_execution_context().arguments, *environment);
if (is_strict_mode())
- MUST(environment->create_immutable_binding(global_object(), vm.names.arguments.as_string(), false));
+ MUST(environment->create_immutable_binding(global_object, vm.names.arguments.as_string(), false));
else
- MUST(environment->create_mutable_binding(global_object(), vm.names.arguments.as_string(), false));
+ MUST(environment->create_mutable_binding(global_object, vm.names.arguments.as_string(), false));
- MUST(environment->initialize_binding(global_object(), vm.names.arguments.as_string(), arguments_object));
+ MUST(environment->initialize_binding(global_object, vm.names.arguments.as_string(), arguments_object));
parameter_names.set(vm.names.arguments.as_string());
}
@@ -435,7 +437,7 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
[&](auto const& param) -> ThrowCompletionOr<void> {
Value argument_value;
if (parameter.is_rest) {
- auto* array = MUST(Array::create(global_object(), 0));
+ auto* array = MUST(Array::create(realm, 0));
for (size_t rest_index = i; rest_index < execution_context_arguments.size(); ++rest_index)
array->indexed_properties().append(execution_context_arguments[rest_index]);
argument_value = array;
@@ -449,7 +451,7 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
// Resulting value is in the accumulator.
argument_value = value_and_frame.frame->registers.at(0);
} else if (interpreter) {
- argument_value = TRY(parameter.default_value->execute(*interpreter, global_object())).release_value();
+ argument_value = TRY(parameter.default_value->execute(*interpreter, global_object)).release_value();
}
} else {
argument_value = js_undefined();
@@ -461,12 +463,12 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
Reference reference = TRY(vm.resolve_binding(param, used_environment));
// Here the difference from hasDuplicates is important
if (has_duplicates)
- return reference.put_value(global_object(), argument_value);
+ return reference.put_value(global_object, argument_value);
else
- return reference.initialize_referenced_binding(global_object(), argument_value);
+ return reference.initialize_referenced_binding(global_object, argument_value);
} else if (IsSame<NonnullRefPtr<BindingPattern> const&, decltype(param)>) {
// Here the difference from hasDuplicates is important
- return vm.binding_initialization(param, argument_value, used_environment, global_object());
+ return vm.binding_initialization(param, argument_value, used_environment, global_object);
}
}));
}
@@ -481,8 +483,8 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
if (scope_body) {
scope_body->for_each_var_declared_name([&](auto const& name) {
if (!parameter_names.contains(name) && instantiated_var_names.set(name) == AK::HashSetResult::InsertedNewEntry) {
- MUST(environment->create_mutable_binding(global_object(), name, false));
- MUST(environment->initialize_binding(global_object(), name, js_undefined()));
+ MUST(environment->create_mutable_binding(global_object, name, false));
+ MUST(environment->initialize_binding(global_object, name, js_undefined()));
}
});
}
@@ -495,15 +497,15 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
scope_body->for_each_var_declared_name([&](auto const& name) {
if (instantiated_var_names.set(name) != AK::HashSetResult::InsertedNewEntry)
return;
- MUST(var_environment->create_mutable_binding(global_object(), name, false));
+ MUST(var_environment->create_mutable_binding(global_object, name, false));
Value initial_value;
if (!parameter_names.contains(name) || function_names.contains(name))
initial_value = js_undefined();
else
- initial_value = MUST(environment->get_binding_value(global_object(), name, false));
+ initial_value = MUST(environment->get_binding_value(global_object, name, false));
- MUST(var_environment->initialize_binding(global_object(), name, initial_value));
+ MUST(var_environment->initialize_binding(global_object, name, initial_value));
});
}
}
@@ -516,8 +518,8 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
return;
// The spec says 'initializedBindings' here but that does not exist and it then adds it to 'instantiatedVarNames' so it probably means 'instantiatedVarNames'.
if (!instantiated_var_names.contains(function_name) && function_name != vm.names.arguments.as_string()) {
- MUST(var_environment->create_mutable_binding(global_object(), function_name, false));
- MUST(var_environment->initialize_binding(global_object(), function_name, js_undefined()));
+ MUST(var_environment->create_mutable_binding(global_object, function_name, false));
+ MUST(var_environment->initialize_binding(global_object, function_name, js_undefined()));
instantiated_var_names.set(function_name);
}
@@ -558,17 +560,17 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
scope_body->for_each_lexically_scoped_declaration([&](Declaration const& declaration) {
declaration.for_each_bound_name([&](auto const& name) {
if (declaration.is_constant_declaration())
- MUST(lex_environment->create_immutable_binding(global_object(), name, true));
+ MUST(lex_environment->create_immutable_binding(global_object, name, true));
else
- MUST(lex_environment->create_mutable_binding(global_object(), name, false));
+ MUST(lex_environment->create_mutable_binding(global_object, name, false));
});
});
}
auto* private_environment = callee_context.private_environment;
for (auto& declaration : functions_to_initialize) {
- auto* function = ECMAScriptFunctionObject::create(global_object(), declaration.name(), declaration.source_text(), declaration.body(), declaration.parameters(), declaration.function_length(), lex_environment, private_environment, declaration.kind(), declaration.is_strict_mode(), declaration.might_need_arguments_object(), declaration.contains_direct_call_to_eval());
- MUST(var_environment->set_mutable_binding(global_object(), declaration.name(), function, false));
+ auto* function = ECMAScriptFunctionObject::create(realm, declaration.name(), declaration.source_text(), declaration.body(), declaration.parameters(), declaration.function_length(), lex_environment, private_environment, declaration.kind(), declaration.is_strict_mode(), declaration.might_need_arguments_object(), declaration.contains_direct_call_to_eval());
+ MUST(var_environment->set_mutable_binding(global_object, declaration.name(), function, false));
}
return {};
@@ -717,14 +719,16 @@ void ECMAScriptFunctionObject::async_function_start(PromiseCapability const& pro
// 27.7.5.2 AsyncBlockStart ( promiseCapability, asyncBody, asyncContext ), https://tc39.es/ecma262/#sec-asyncblockstart
void async_block_start(VM& vm, NonnullRefPtr<Statement> const& async_body, PromiseCapability const& promise_capability, ExecutionContext& async_context)
{
- auto& global_object = vm.current_realm()->global_object();
+ auto& realm = *vm.current_realm();
+ auto& global_object = realm.global_object();
+
// 1. Assert: promiseCapability is a PromiseCapability Record.
// 2. Let runningContext be the running execution context.
auto& running_context = vm.running_execution_context();
// 3. Set the code evaluation state of asyncContext such that when evaluation is resumed for that execution context the following steps will be performed:
- auto* execution_steps = NativeFunction::create(global_object, "", [&async_body, &promise_capability](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
+ auto* execution_steps = NativeFunction::create(realm, "", [&async_body, &promise_capability](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
// a. Let result be the result of evaluating asyncBody.
auto result = async_body->execute(vm.interpreter(), global_object);
@@ -778,10 +782,12 @@ 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* bytecode_interpreter = Bytecode::Interpreter::current();
if (m_kind == FunctionKind::AsyncGenerator)
- return vm.throw_completion<InternalError>(global_object(), ErrorType::NotImplemented, "Async Generator function execution");
+ return vm.throw_completion<InternalError>(global_object, ErrorType::NotImplemented, "Async Generator function execution");
if (bytecode_interpreter) {
if (!m_bytecode_executable) {
@@ -828,23 +834,23 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
if (m_kind == FunctionKind::Normal)
return { Completion::Type::Return, result.value_or(js_undefined()), {} };
- auto generator_object = TRY(GeneratorObject::create(global_object(), result, this, vm.running_execution_context().copy(), move(*result_and_frame.frame)));
+ auto generator_object = TRY(GeneratorObject::create(realm, result, this, vm.running_execution_context().copy(), move(*result_and_frame.frame)));
// NOTE: Async functions are entirely transformed to generator functions, and wrapped in a custom driver that returns a promise
// See AwaitExpression::generate_bytecode() for the transformation.
if (m_kind == FunctionKind::Async)
- return { Completion::Type::Return, TRY(AsyncFunctionDriverWrapper::create(global_object(), generator_object)), {} };
+ return { Completion::Type::Return, TRY(AsyncFunctionDriverWrapper::create(realm, generator_object)), {} };
VERIFY(m_kind == FunctionKind::Generator);
return { Completion::Type::Return, generator_object, {} };
} else {
if (m_kind == FunctionKind::Generator)
- return vm.throw_completion<InternalError>(global_object(), ErrorType::NotImplemented, "Generator function execution in AST interpreter");
+ return vm.throw_completion<InternalError>(global_object, ErrorType::NotImplemented, "Generator function execution in AST interpreter");
OwnPtr<Interpreter> local_interpreter;
Interpreter* ast_interpreter = vm.interpreter_if_exists();
if (!ast_interpreter) {
- local_interpreter = Interpreter::create_with_existing_realm(*realm());
+ local_interpreter = Interpreter::create_with_existing_realm(realm);
ast_interpreter = local_interpreter.ptr();
}
@@ -856,12 +862,12 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
TRY(function_declaration_instantiation(ast_interpreter));
// 2. Return the result of evaluating FunctionStatementList.
- return m_ecmascript_code->execute(*ast_interpreter, global_object());
+ return m_ecmascript_code->execute(*ast_interpreter, global_object);
}
// AsyncFunctionBody : FunctionBody
else if (m_kind == FunctionKind::Async) {
// 1. Let promiseCapability be ! NewPromiseCapability(%Promise%).
- auto promise_capability = MUST(new_promise_capability(global_object(), global_object().promise_constructor()));
+ auto promise_capability = MUST(new_promise_capability(global_object, global_object.promise_constructor()));
// 2. Let declResult be Completion(FunctionDeclarationInstantiation(functionObject, argumentsList)).
auto declaration_result = function_declaration_instantiation(ast_interpreter);
@@ -869,7 +875,7 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
// 3. If declResult is an abrupt completion, then
if (declaration_result.is_throw_completion()) {
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « declResult.[[Value]] »).
- MUST(call(global_object(), promise_capability.reject, js_undefined(), *declaration_result.throw_completion().value()));
+ MUST(call(global_object, promise_capability.reject, js_undefined(), *declaration_result.throw_completion().value()));
}
// 4. Else,
else {
diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h
index 710d0f1098..29d7fcc5a7 100644
--- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h
+++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h
@@ -32,8 +32,8 @@ public:
Global,
};
- static ECMAScriptFunctionObject* create(GlobalObject&, FlyString name, String source_text, Statement const& ecmascript_code, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind, bool is_strict, bool might_need_arguments_object = true, bool contains_direct_call_to_eval = true, bool is_arrow_function = false, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name = {});
- static ECMAScriptFunctionObject* create(GlobalObject&, FlyString name, Object& prototype, String source_text, Statement const& ecmascript_code, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind, bool is_strict, bool might_need_arguments_object = true, bool contains_direct_call_to_eval = true, bool is_arrow_function = false, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name = {});
+ static ECMAScriptFunctionObject* create(Realm&, FlyString name, String source_text, Statement const& ecmascript_code, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind, bool is_strict, bool might_need_arguments_object = true, bool contains_direct_call_to_eval = true, bool is_arrow_function = false, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name = {});
+ static ECMAScriptFunctionObject* create(Realm&, FlyString name, Object& prototype, String source_text, Statement const& ecmascript_code, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind, bool is_strict, bool might_need_arguments_object = true, bool contains_direct_call_to_eval = true, bool is_arrow_function = false, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name = {});
ECMAScriptFunctionObject(FlyString name, String source_text, Statement const& ecmascript_code, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, Environment* parent_environment, PrivateEnvironment* private_environment, Object& prototype, FunctionKind, bool is_strict, bool might_need_arguments_object, bool contains_direct_call_to_eval, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name);
virtual void initialize(Realm&) override;
diff --git a/Userland/Libraries/LibJS/Runtime/Error.cpp b/Userland/Libraries/LibJS/Runtime/Error.cpp
index 362ce994e9..e7dbade620 100644
--- a/Userland/Libraries/LibJS/Runtime/Error.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Error.cpp
@@ -14,15 +14,15 @@
namespace JS {
-Error* Error::create(GlobalObject& global_object)
+Error* Error::create(Realm& realm)
{
- return global_object.heap().allocate<Error>(global_object, *global_object.error_prototype());
+ return realm.heap().allocate<Error>(realm.global_object(), *realm.global_object().error_prototype());
}
-Error* Error::create(GlobalObject& global_object, String const& message)
+Error* Error::create(Realm& realm, String const& message)
{
- auto& vm = global_object.vm();
- auto* error = Error::create(global_object);
+ auto& vm = realm.vm();
+ auto* error = Error::create(realm);
u8 attr = Attribute::Writable | Attribute::Configurable;
error->define_direct_property(vm.names.message, js_string(vm, message), attr);
return error;
@@ -97,15 +97,16 @@ String Error::stack_string() const
}
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
- ClassName* ClassName::create(GlobalObject& global_object) \
+ ClassName* ClassName::create(Realm& realm) \
{ \
- return global_object.heap().allocate<ClassName>(global_object, *global_object.snake_name##_prototype()); \
+ return realm.heap().allocate<ClassName>( \
+ realm.global_object(), *realm.global_object().snake_name##_prototype()); /* */ \
} \
\
- ClassName* ClassName::create(GlobalObject& global_object, String const& message) \
+ ClassName* ClassName::create(Realm& realm, String const& message) \
{ \
- auto& vm = global_object.vm(); \
- auto* error = ClassName::create(global_object); \
+ auto& vm = realm.vm(); \
+ auto* error = ClassName::create(realm); \
u8 attr = Attribute::Writable | Attribute::Configurable; \
error->define_direct_property(vm.names.message, js_string(vm, message), attr); \
return error; \
diff --git a/Userland/Libraries/LibJS/Runtime/Error.h b/Userland/Libraries/LibJS/Runtime/Error.h
index a7967320de..761dee42d4 100644
--- a/Userland/Libraries/LibJS/Runtime/Error.h
+++ b/Userland/Libraries/LibJS/Runtime/Error.h
@@ -23,8 +23,8 @@ class Error : public Object {
JS_OBJECT(Error, Object);
public:
- static Error* create(GlobalObject&);
- static Error* create(GlobalObject&, String const& message);
+ static Error* create(Realm&);
+ static Error* create(Realm&, String const& message);
explicit Error(Object& prototype);
virtual ~Error() override = default;
@@ -48,8 +48,8 @@ private:
JS_OBJECT(ClassName, Error); \
\
public: \
- static ClassName* create(GlobalObject&); \
- static ClassName* create(GlobalObject&, String const& message); \
+ static ClassName* create(Realm&); \
+ static ClassName* create(Realm&, String const& message); \
\
explicit ClassName(Object& prototype); \
virtual ~ClassName() override = default; \
diff --git a/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp b/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp
index c7e1c0a1da..6332d9c180 100644
--- a/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp
@@ -217,16 +217,16 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic
auto* prototype = TRY(get_prototype_from_constructor(global_object, *new_target, fallback_prototype));
// 25. Let realmF be the current Realm Record.
- auto* realm = vm.current_realm();
+ auto& realm = *vm.current_realm();
// 26. Let env be realmF.[[GlobalEnv]].
- auto* environment = &realm->global_environment();
+ auto& environment = realm.global_environment();
// 27. Let privateEnv be null.
PrivateEnvironment* private_environment = nullptr;
// 28. Let F be OrdinaryFunctionCreate(proto, sourceText, parameters, body, non-lexical-this, env, privateEnv).
- auto* function = ECMAScriptFunctionObject::create(global_object, "anonymous", *prototype, move(source_text), expr->body(), expr->parameters(), expr->function_length(), environment, private_environment, expr->kind(), expr->is_strict_mode(), expr->might_need_arguments_object(), contains_direct_call_to_eval);
+ auto* function = ECMAScriptFunctionObject::create(realm, "anonymous", *prototype, move(source_text), expr->body(), expr->parameters(), expr->function_length(), &environment, private_environment, expr->kind(), expr->is_strict_mode(), expr->might_need_arguments_object(), contains_direct_call_to_eval);
// FIXME: Remove the name argument from create() and do this instead.
// 29. Perform SetFunctionName(F, "anonymous").
@@ -234,7 +234,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic
// 30. If kind is generator, then
if (kind == FunctionKind::Generator) {
// a. Let prototype be OrdinaryObjectCreate(%GeneratorFunction.prototype.prototype%).
- prototype = Object::create(global_object, global_object.generator_function_prototype_prototype());
+ prototype = Object::create(realm, global_object.generator_function_prototype_prototype());
// b. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
function->define_direct_property(vm.names.prototype, prototype, Attribute::Writable);
@@ -242,7 +242,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic
// 31. Else if kind is asyncGenerator, then
else if (kind == FunctionKind::AsyncGenerator) {
// a. Let prototype be OrdinaryObjectCreate(%AsyncGeneratorFunction.prototype.prototype%).
- prototype = Object::create(global_object, global_object.async_generator_function_prototype_prototype());
+ prototype = Object::create(realm, global_object.async_generator_function_prototype_prototype());
// b. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
function->define_direct_property(vm.names.prototype, prototype, Attribute::Writable);
@@ -250,7 +250,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic
// 32. Else if kind is normal, perform MakeConstructor(F).
else if (kind == FunctionKind::Normal) {
// FIXME: Implement MakeConstructor
- prototype = Object::create(global_object, global_object.object_prototype());
+ prototype = Object::create(realm, global_object.object_prototype());
prototype->define_direct_property(vm.names.constructor, function, Attribute::Writable | Attribute::Configurable);
function->define_direct_property(vm.names.prototype, prototype, Attribute::Writable);
}
diff --git a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp
index 64b46d649f..d401128c41 100644
--- a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp
@@ -82,6 +82,8 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::apply)
// 3.1.2.1 Function.prototype.bind ( thisArg, ...args ), https://tc39.es/proposal-shadowrealm/#sec-function.prototype.bind
JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::bind)
{
+ auto& realm = *global_object.associated_realm();
+
auto this_argument = vm.argument(0);
// 1. Let Target be the this value.
@@ -100,7 +102,7 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::bind)
}
// 3. Let F be ? BoundFunctionCreate(Target, thisArg, args).
- auto* function = TRY(BoundFunction::create(global_object, target, this_argument, move(arguments)));
+ auto* function = TRY(BoundFunction::create(realm, target, this_argument, move(arguments)));
// 4. Let argCount be the number of elements in args.
auto arg_count = vm.argument_count() > 0 ? vm.argument_count() - 1 : 0;
diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp
index 2249e54071..f9e1d03e90 100644
--- a/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp
@@ -13,22 +13,21 @@
namespace JS {
-ThrowCompletionOr<GeneratorObject*> GeneratorObject::create(GlobalObject& global_object, Value initial_value, ECMAScriptFunctionObject* generating_function, ExecutionContext execution_context, Bytecode::RegisterWindow frame)
+ThrowCompletionOr<GeneratorObject*> GeneratorObject::create(Realm& realm, Value initial_value, ECMAScriptFunctionObject* generating_function, ExecutionContext execution_context, Bytecode::RegisterWindow frame)
{
- auto& realm = *global_object.associated_realm();
-
+ auto& vm = realm.vm();
// This is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png)
Value generating_function_prototype;
if (generating_function->kind() == FunctionKind::Async) {
// We implement async functions by transforming them to generator function in the bytecode
// interpreter. However an async function does not have a prototype and should not be
// changed thus we hardcode the prototype.
- generating_function_prototype = global_object.generator_prototype();
+ generating_function_prototype = realm.global_object().generator_prototype();
} else {
- generating_function_prototype = TRY(generating_function->get(global_object.vm().names.prototype));
+ generating_function_prototype = TRY(generating_function->get(vm.names.prototype));
}
- auto* generating_function_prototype_object = TRY(generating_function_prototype.to_object(global_object));
- auto object = global_object.heap().allocate<GeneratorObject>(global_object, realm, *generating_function_prototype_object, move(execution_context));
+ auto* generating_function_prototype_object = TRY(generating_function_prototype.to_object(realm.global_object()));
+ auto object = realm.heap().allocate<GeneratorObject>(realm.global_object(), realm, *generating_function_prototype_object, move(execution_context));
object->m_generating_function = generating_function;
object->m_frame = move(frame);
object->m_previous_value = initial_value;
@@ -54,6 +53,7 @@ void GeneratorObject::visit_edges(Cell::Visitor& visitor)
ThrowCompletionOr<Value> GeneratorObject::next_impl(VM& vm, GlobalObject& global_object, Optional<Value> next_argument, Optional<Value> value_to_throw)
{
+ auto& realm = *global_object.associated_realm();
auto bytecode_interpreter = Bytecode::Interpreter::current();
VERIFY(bytecode_interpreter);
@@ -73,7 +73,7 @@ ThrowCompletionOr<Value> GeneratorObject::next_impl(VM& vm, GlobalObject& global
auto previous_generated_value = TRY(generated_value(m_previous_value));
- auto result = Object::create(global_object, global_object.object_prototype());
+ auto result = Object::create(realm, global_object.object_prototype());
result->define_direct_property("value", previous_generated_value, default_attributes);
if (m_done) {
diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorObject.h b/Userland/Libraries/LibJS/Runtime/GeneratorObject.h
index c205417164..963367d274 100644
--- a/Userland/Libraries/LibJS/Runtime/GeneratorObject.h
+++ b/Userland/Libraries/LibJS/Runtime/GeneratorObject.h
@@ -16,7 +16,7 @@ class GeneratorObject final : public Object {
JS_OBJECT(GeneratorObject, Object);
public:
- static ThrowCompletionOr<GeneratorObject*> create(GlobalObject&, Value, ECMAScriptFunctionObject*, ExecutionContext, Bytecode::RegisterWindow);
+ static ThrowCompletionOr<GeneratorObject*> create(Realm&, Value, ECMAScriptFunctionObject*, ExecutionContext, Bytecode::RegisterWindow);
GeneratorObject(Realm&, Object& prototype, ExecutionContext);
virtual void initialize(Realm&) override;
virtual ~GeneratorObject() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
index aeabf3cedc..e00b22ded7 100644
--- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
@@ -225,9 +225,11 @@ void GlobalObject::initialize_global_object()
define_native_function(vm.names.eval, eval, 1, attr);
// 10.2.4.1 %ThrowTypeError% ( ), https://tc39.es/ecma262/#sec-%throwtypeerror%
- m_throw_type_error_function = NativeFunction::create(global_object(), {}, [](VM& vm, GlobalObject& global_object) {
- return vm.throw_completion<TypeError>(global_object, ErrorType::RestrictedFunctionPropertiesAccess);
- });
+ m_throw_type_error_function = NativeFunction::create(
+ realm, [](VM& vm, GlobalObject& global_object) {
+ return vm.throw_completion<TypeError>(global_object, ErrorType::RestrictedFunctionPropertiesAccess);
+ },
+ 0, "", &realm);
m_throw_type_error_function->define_direct_property(vm.names.length, Value(0), 0);
m_throw_type_error_function->define_direct_property(vm.names.name, js_string(vm, ""), 0);
MUST(m_throw_type_error_function->internal_prevent_extensions());
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp
index de552b5f7e..595c8686f9 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp
@@ -186,6 +186,7 @@ bool is_well_formed_unit_identifier(StringView unit_identifier)
ThrowCompletionOr<Vector<String>> canonicalize_locale_list(GlobalObject& global_object, Value locales)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. If locales is undefined, then
if (locales.is_undefined()) {
@@ -200,7 +201,7 @@ ThrowCompletionOr<Vector<String>> canonicalize_locale_list(GlobalObject& global_
// 3. If Type(locales) is String or Type(locales) is Object and locales has an [[InitializedLocale]] internal slot, then
if (locales.is_string() || (locales.is_object() && is<Locale>(locales.as_object()))) {
// a. Let O be CreateArrayFromList(« locales »).
- object = Array::create_from(global_object, { locales });
+ object = Array::create_from(realm, { locales });
}
// 4. Else,
else {
@@ -568,6 +569,7 @@ Vector<String> best_fit_supported_locales(Vector<String> const& requested_locale
ThrowCompletionOr<Array*> supported_locales(GlobalObject& global_object, Vector<String> const& requested_locales, Value options)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Set options to ? CoerceOptionsToObject(options).
auto* options_object = TRY(coerce_options_to_object(global_object, options));
@@ -589,16 +591,18 @@ ThrowCompletionOr<Array*> supported_locales(GlobalObject& global_object, Vector<
}
// 5. Return CreateArrayFromList(supportedLocales).
- return Array::create_from<String>(global_object, supported_locales, [&vm](auto& locale) { return js_string(vm, locale); });
+ return Array::create_from<String>(realm, supported_locales, [&vm](auto& locale) { return js_string(vm, locale); });
}
// 9.2.12 CoerceOptionsToObject ( options ), https://tc39.es/ecma402/#sec-coerceoptionstoobject
ThrowCompletionOr<Object*> coerce_options_to_object(GlobalObject& global_object, Value options)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. If options is undefined, then
if (options.is_undefined()) {
// a. Return OrdinaryObjectCreate(null).
- return Object::create(global_object, nullptr);
+ return Object::create(realm, nullptr);
}
// 2. Return ? ToObject(options).
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp b/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp
index fa945f3034..0c77d01bf4 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp
@@ -11,10 +11,9 @@
namespace JS::Intl {
-CollatorCompareFunction* CollatorCompareFunction::create(GlobalObject& global_object, Collator& collator)
+CollatorCompareFunction* CollatorCompareFunction::create(Realm& realm, Collator& collator)
{
- auto& realm = *global_object.associated_realm();
- return global_object.heap().allocate<CollatorCompareFunction>(global_object, realm, collator);
+ return realm.heap().allocate<CollatorCompareFunction>(realm.global_object(), realm, collator);
}
CollatorCompareFunction::CollatorCompareFunction(Realm& realm, Collator& collator)
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.h b/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.h
index 98a39b7a91..0bab632a37 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.h
+++ b/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.h
@@ -14,7 +14,7 @@ class CollatorCompareFunction : public NativeFunction {
JS_OBJECT(CollatorCompareFunction, NativeFunction);
public:
- static CollatorCompareFunction* create(GlobalObject&, Collator&);
+ static CollatorCompareFunction* create(Realm&, Collator&);
CollatorCompareFunction(Realm&, Collator&);
virtual void initialize(Realm&) override;
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/CollatorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/CollatorPrototype.cpp
index 4d575a3378..499269b1af 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/CollatorPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/CollatorPrototype.cpp
@@ -34,6 +34,8 @@ void CollatorPrototype::initialize(Realm& realm)
// 10.3.3 get Intl.Collator.prototype.compare, https://tc39.es/ecma402/#sec-intl.collator.prototype.compare
JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::compare_getter)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let collator be the this value.
// 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]).
auto* collator = TRY(typed_this_object(global_object));
@@ -42,7 +44,7 @@ JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::compare_getter)
if (!collator->bound_compare()) {
// a. Let F be a new built-in function object as defined in 10.3.3.1.
// b. Set F.[[Collator]] to collator.
- auto* function = CollatorCompareFunction::create(global_object, *collator);
+ auto* function = CollatorCompareFunction::create(realm, *collator);
// c. Set collator.[[BoundCompare]] to F.
collator->set_bound_compare(function);
@@ -55,12 +57,14 @@ JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::compare_getter)
// 10.3.4 Intl.Collator.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.collator.prototype.resolvedoptions
JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::resolved_options)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let collator be the this value.
// 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]).
auto* collator = TRY(typed_this_object(global_object));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
- auto* options = Object::create(global_object, global_object.object_prototype());
+ auto* options = Object::create(realm, global_object.object_prototype());
// 4. For each row of Table 3, except the header row, in table order, do
// a. Let p be the Property value of the current row.
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp
index 20a17cafb6..0d4b0cd844 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp
@@ -67,6 +67,7 @@ StringView DateTimeFormat::style_to_string(Style style)
ThrowCompletionOr<Object*> to_date_time_options(GlobalObject& global_object, Value options_value, OptionRequired required, OptionDefaults defaults)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. If options is undefined, let options be null; otherwise let options be ? ToObject(options).
Object* options = nullptr;
@@ -74,7 +75,7 @@ ThrowCompletionOr<Object*> to_date_time_options(GlobalObject& global_object, Val
options = TRY(options_value.to_object(global_object));
// 2. Let options be OrdinaryObjectCreate(options).
- options = Object::create(global_object, options);
+ options = Object::create(realm, options);
// 3. Let needDefaults be true.
bool needs_defaults = true;
@@ -532,6 +533,7 @@ static Optional<StringView> resolve_day_period(StringView locale, StringView cal
ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(GlobalObject& global_object, DateTimeFormat& date_time_format, Vector<PatternPartition> pattern_parts, double time, Unicode::CalendarPattern const* range_format_options)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let x be TimeClip(x).
time = time_clip(time);
@@ -550,7 +552,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(GlobalObjec
};
// 4. Let nfOptions be OrdinaryObjectCreate(null).
- auto* number_format_options = Object::create(global_object, nullptr);
+ auto* number_format_options = Object::create(realm, nullptr);
// 5. Perform ! CreateDataPropertyOrThrow(nfOptions, "useGrouping", false).
MUST(number_format_options->create_data_property_or_throw(vm.names.useGrouping, Value(false)));
@@ -559,7 +561,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(GlobalObjec
auto* number_format = TRY(construct_number_format(number_format_options));
// 7. Let nf2Options be OrdinaryObjectCreate(null).
- auto* number_format_options2 = Object::create(global_object, nullptr);
+ auto* number_format_options2 = Object::create(realm, nullptr);
// 8. Perform ! CreateDataPropertyOrThrow(nf2Options, "minimumIntegerDigits", 2).
MUST(number_format_options2->create_data_property_or_throw(vm.names.minimumIntegerDigits, Value(2)));
@@ -579,7 +581,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(GlobalObjec
fractional_second_digits = date_time_format.fractional_second_digits();
// a. Let nf3Options be OrdinaryObjectCreate(null).
- auto* number_format_options3 = Object::create(global_object, nullptr);
+ auto* number_format_options3 = Object::create(realm, nullptr);
// b. Perform ! CreateDataPropertyOrThrow(nf3Options, "minimumIntegerDigits", fractionalSecondDigits).
MUST(number_format_options3->create_data_property_or_throw(vm.names.minimumIntegerDigits, Value(*fractional_second_digits)));
@@ -848,12 +850,13 @@ ThrowCompletionOr<String> format_date_time(GlobalObject& global_object, DateTime
ThrowCompletionOr<Array*> format_date_time_to_parts(GlobalObject& global_object, DateTimeFormat& date_time_format, double time)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let parts be ? PartitionDateTimePattern(dateTimeFormat, x).
auto parts = TRY(partition_date_time_pattern(global_object, date_time_format, time));
// 2. Let result be ! ArrayCreate(0).
- auto* result = MUST(Array::create(global_object, 0));
+ auto* result = MUST(Array::create(realm, 0));
// 3. Let n be 0.
size_t n = 0;
@@ -861,7 +864,7 @@ ThrowCompletionOr<Array*> format_date_time_to_parts(GlobalObject& global_object,
// 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(global_object, global_object.object_prototype());
+ auto* object = Object::create(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,12 +1167,13 @@ ThrowCompletionOr<String> format_date_time_range(GlobalObject& global_object, Da
ThrowCompletionOr<Array*> format_date_time_range_to_parts(GlobalObject& global_object, DateTimeFormat& date_time_format, double start, double end)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let parts be ? PartitionDateTimeRangePattern(dateTimeFormat, x, y).
auto parts = TRY(partition_date_time_range_pattern(global_object, date_time_format, start, end));
// 2. Let result be ! ArrayCreate(0).
- auto* result = MUST(Array::create(global_object, 0));
+ auto* result = MUST(Array::create(realm, 0));
// 3. Let n be 0.
size_t n = 0;
@@ -1177,7 +1181,7 @@ ThrowCompletionOr<Array*> format_date_time_range_to_parts(GlobalObject& global_o
// 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(global_object, global_object.object_prototype());
+ auto* object = Object::create(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 1d285b1844..d78d110f5e 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp
@@ -14,9 +14,9 @@
namespace JS::Intl {
// 11.5.5 DateTime Format Functions, https://tc39.es/ecma402/#sec-datetime-format-functions
-DateTimeFormatFunction* DateTimeFormatFunction::create(GlobalObject& global_object, DateTimeFormat& date_time_format)
+DateTimeFormatFunction* DateTimeFormatFunction::create(Realm& realm, DateTimeFormat& date_time_format)
{
- return global_object.heap().allocate<DateTimeFormatFunction>(global_object, date_time_format, *global_object.function_prototype());
+ return realm.heap().allocate<DateTimeFormatFunction>(realm.global_object(), date_time_format, *realm.global_object().function_prototype());
}
DateTimeFormatFunction::DateTimeFormatFunction(DateTimeFormat& date_time_format, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.h b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.h
index ab7f4be5ef..ece66beeec 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.h
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.h
@@ -16,7 +16,7 @@ class DateTimeFormatFunction final : public NativeFunction {
JS_OBJECT(DateTimeFormatFunction, NativeFunction);
public:
- static DateTimeFormatFunction* create(GlobalObject&, DateTimeFormat&);
+ static DateTimeFormatFunction* create(Realm&, DateTimeFormat&);
explicit DateTimeFormatFunction(DateTimeFormat&, Object& prototype);
virtual ~DateTimeFormatFunction() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatPrototype.cpp
index 6e1e3e14e1..afd5ab026f 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatPrototype.cpp
@@ -40,6 +40,8 @@ void DateTimeFormatPrototype::initialize(Realm& realm)
// 11.3.3 get Intl.DateTimeFormat.prototype.format, https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype.format
JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let dtf be the this value.
// 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
// a. Set dtf to ? UnwrapDateTimeFormat(dtf).
@@ -50,7 +52,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format)
if (!date_time_format->bound_format()) {
// a. Let F be a new built-in function object as defined in DateTime Format Functions (11.1.6).
// b. Set F.[[DateTimeFormat]] to dtf.
- auto* bound_format = DateTimeFormatFunction::create(global_object, *date_time_format);
+ auto* bound_format = DateTimeFormatFunction::create(realm, *date_time_format);
// c. Set dtf.[[BoundFormat]] to F.
date_time_format->set_bound_format(bound_format);
@@ -142,6 +144,8 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_range_to_parts)
// 11.3.7 Intl.DateTimeFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype.resolvedoptions
JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let dtf be the this value.
// 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
// a. Set dtf to ? UnwrapDateTimeFormat(dtf).
@@ -149,7 +153,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options)
auto* date_time_format = TRY(typed_this_object(global_object));
// 4. Let options be OrdinaryObjectCreate(%Object.prototype%).
- auto* options = Object::create(global_object, global_object.object_prototype());
+ auto* options = Object::create(realm, global_object.object_prototype());
// 5. For each row of Table 5, except the header row, in table order, do
// a. Let p be the Property value of the current row.
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp
index 2db9146d7c..b845cf9cfd 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp
@@ -124,12 +124,14 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
// 12.3.4 Intl.DisplayNames.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-Intl.DisplayNames.prototype.resolvedOptions
JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::resolved_options)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let displayNames be this value.
// 2. Perform ? RequireInternalSlot(displayNames, [[InitializedDisplayNames]]).
auto* display_names = TRY(typed_this_object(global_object));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
- auto* options = Object::create(global_object, global_object.object_prototype());
+ auto* options = Object::create(realm, global_object.object_prototype());
// 4. For each row of Table 8, except the header row, in table order, do
// a. Let p be the Property value of the current row.
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp
index 7cfa919050..d552a28b39 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp
@@ -311,6 +311,7 @@ static String convert_number_format_pattern_to_duration_format_template(Unicode:
ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(GlobalObject& global_object, DurationFormat const& duration_format, Temporal::DurationRecord const& duration)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let result be a new empty List.
Vector<PatternPartition> result;
@@ -349,7 +350,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(Gl
}
// h. Let nfOpts be ! OrdinaryObjectCreate(null).
- auto* number_format_options = Object::create(global_object, nullptr);
+ auto* number_format_options = Object::create(realm, nullptr);
// i. Let value be 0.
auto value = Value(0);
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp
index 917504ca48..9c180474a3 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp
@@ -64,6 +64,8 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format)
// 1.4.4 Intl.DurationFormat.prototype.formatToParts ( duration ), https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype.formatToParts
JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let df be this value.
// 2. Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]).
auto* duration_format = TRY(typed_this_object(global_object));
@@ -79,7 +81,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
auto formatted = TRY(partition_duration_format_pattern(global_object, *duration_format, record));
// 6. Let result be ! ArrayCreate(0).
- auto* result = MUST(Array::create(global_object, 0));
+ auto* result = MUST(Array::create(realm, 0));
// 7. Let n be 0.
// 8. For each element part in formatted, in List order, do
@@ -87,7 +89,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
auto const& part = formatted[n];
// a. Let obj be ! OrdinaryObjectCreate(%ObjectPrototype%).
- auto* object = Object::create(global_object, global_object.object_prototype());
+ auto* object = Object::create(realm, global_object.object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(obj, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
@@ -108,12 +110,14 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
// 1.4.5 Intl.DurationFormat.prototype.resolvedOptions ( ), https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype.resolvedOptions
JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::resolved_options)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let df be the this value.
// 2. Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]).
auto* duration_format = TRY(typed_this_object(global_object));
// 3. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
- auto* options = Object::create(global_object, global_object.object_prototype());
+ auto* options = Object::create(realm, global_object.object_prototype());
// 4. For each row of Table 2, except the header row, in table order, do
// a. Let p be the Property value of the current row.
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp b/Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp
index fd10e5f021..8e829afbb6 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp
@@ -61,6 +61,8 @@ void Intl::initialize(Realm& realm)
// 8.3.1 Intl.getCanonicalLocales ( locales ), https://tc39.es/ecma402/#sec-intl.getcanonicallocales
JS_DEFINE_NATIVE_FUNCTION(Intl::get_canonical_locales)
{
+ auto& realm = *global_object.associated_realm();
+
auto locales = vm.argument(0);
// 1. Let ll be ? CanonicalizeLocaleList(locales).
@@ -72,7 +74,7 @@ JS_DEFINE_NATIVE_FUNCTION(Intl::get_canonical_locales)
marked_locale_list.append(js_string(vm, move(locale)));
// 2. Return CreateArrayFromList(ll).
- return Array::create_from(global_object, marked_locale_list);
+ return Array::create_from(realm, marked_locale_list);
}
// 1.4.4 AvailableTimeZones (), https://tc39.es/proposal-intl-enumeration/#sec-availablecurrencies
@@ -107,6 +109,8 @@ static Vector<StringView> available_time_zones()
// 2.2.2 Intl.supportedValuesOf ( key ), https://tc39.es/proposal-intl-enumeration/#sec-intl.supportedvaluesof
JS_DEFINE_NATIVE_FUNCTION(Intl::supported_values_of)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let key be ? ToString(key).
auto key = TRY(vm.argument(0).to_string(global_object));
@@ -151,7 +155,7 @@ JS_DEFINE_NATIVE_FUNCTION(Intl::supported_values_of)
}
// 9. Return CreateArrayFromList( list ).
- return Array::create_from<StringView>(global_object, list, [&](auto value) { return js_string(vm, value); });
+ return Array::create_from<StringView>(realm, list, [&](auto value) { return js_string(vm, value); });
}
}
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp
index 794e703eca..48991142c2 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp
@@ -204,12 +204,13 @@ String format_list(ListFormat const& list_format, Vector<String> const& list)
Array* format_list_to_parts(GlobalObject& global_object, ListFormat const& list_format, Vector<String> const& list)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let parts be ! CreatePartsFromList(listFormat, list).
auto parts = create_parts_from_list(list_format, list);
// 2. Let result be ! ArrayCreate(0).
- auto* result = MUST(Array::create(global_object, 0));
+ auto* result = MUST(Array::create(realm, 0));
// 3. Let n be 0.
size_t n = 0;
@@ -217,7 +218,7 @@ Array* format_list_to_parts(GlobalObject& global_object, ListFormat const& list_
// 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(global_object, global_object.object_prototype());
+ auto* object = Object::create(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/ListFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp
index e6776a6486..c08abda4ac 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp
@@ -69,12 +69,14 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::format_to_parts)
// 13.3.5 Intl.ListFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-Intl.ListFormat.prototype.resolvedoptions
JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::resolved_options)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let lf be the this value.
// 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]).
auto* list_format = TRY(typed_this_object(global_object));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
- auto* options = Object::create(global_object, global_object.object_prototype());
+ auto* options = Object::create(realm, global_object.object_prototype());
// 4. For each row of Table 10, except the header row, in table order, do
// a. Let p be the Property value of the current row.
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp b/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp
index 1d26a62edd..d5bb9c6e6b 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp
@@ -14,9 +14,9 @@
namespace JS::Intl {
-Locale* Locale::create(GlobalObject& global_object, Unicode::LocaleID const& locale_id)
+Locale* Locale::create(Realm& realm, Unicode::LocaleID const& locale_id)
{
- return global_object.heap().allocate<Locale>(global_object, locale_id, *global_object.intl_locale_prototype());
+ return realm.heap().allocate<Locale>(realm.global_object(), locale_id, *realm.global_object().intl_locale_prototype());
}
// 14 Locale Objects, https://tc39.es/ecma402/#locale-objects
@@ -58,6 +58,7 @@ Locale::Locale(Unicode::LocaleID const& locale_id, Object& prototype)
static Array* create_array_from_list_or_restricted(GlobalObject& global_object, Vector<StringView> list, Optional<String> restricted)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. If restricted is not undefined, then
if (restricted.has_value()) {
@@ -66,7 +67,7 @@ static Array* create_array_from_list_or_restricted(GlobalObject& global_object,
}
// 2. Return ! CreateArrayFromList( list ).
- return Array::create_from<StringView>(global_object, list, [&vm](auto value) {
+ return Array::create_from<StringView>(realm, list, [&vm](auto value) {
return js_string(vm, value);
});
}
@@ -152,6 +153,7 @@ Array* numbering_systems_of_locale(GlobalObject& global_object, Locale const& lo
Array* time_zones_of_locale(GlobalObject& global_object, StringView region)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let locale be loc.[[Locale]].
// 2. Assert: locale matches the unicode_locale_id production.
@@ -162,7 +164,7 @@ Array* time_zones_of_locale(GlobalObject& global_object, StringView region)
quick_sort(list);
// 5. Return ! CreateArrayFromList( list ).
- return Array::create_from<StringView>(global_object, list, [&vm](auto value) {
+ return Array::create_from<StringView>(realm, list, [&vm](auto value) {
return js_string(vm, value);
});
}
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Locale.h b/Userland/Libraries/LibJS/Runtime/Intl/Locale.h
index 70017ae1ce..32d230e439 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/Locale.h
+++ b/Userland/Libraries/LibJS/Runtime/Intl/Locale.h
@@ -21,7 +21,7 @@ class Locale final : public Object {
JS_OBJECT(Locale, Object);
public:
- static Locale* create(GlobalObject&, Unicode::LocaleID const&);
+ static Locale* create(Realm&, Unicode::LocaleID const&);
static constexpr auto relevant_extension_keys()
{
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp
index da3420463b..8686c4141b 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp
@@ -55,6 +55,8 @@ void LocalePrototype::initialize(Realm& realm)
// 14.3.3 Intl.Locale.prototype.maximize ( ), https://tc39.es/ecma402/#sec-Intl.Locale.prototype.maximize
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::maximize)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = TRY(typed_this_object(global_object));
@@ -67,12 +69,14 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::maximize)
locale->language_id = maximal.release_value();
// 4. Return ! Construct(%Locale%, maximal).
- return Locale::create(global_object, *locale);
+ return Locale::create(realm, *locale);
}
// 14.3.4 Intl.Locale.prototype.minimize ( ), https://tc39.es/ecma402/#sec-Intl.Locale.prototype.minimize
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::minimize)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = TRY(typed_this_object(global_object));
@@ -85,7 +89,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::minimize)
locale->language_id = minimal.release_value();
// 4. Return ! Construct(%Locale%, minimal).
- return Locale::create(global_object, *locale);
+ return Locale::create(realm, *locale);
}
// 14.3.5 Intl.Locale.prototype.toString ( ), https://tc39.es/ecma402/#sec-Intl.Locale.prototype.toString
@@ -247,12 +251,14 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::time_zones)
// 1.4.21 get Intl.Locale.prototype.textInfo, https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.textInfo
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::text_info)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = TRY(typed_this_object(global_object));
// 3. Let info be ! ObjectCreate(%Object.prototype%).
- auto* info = Object::create(global_object, global_object.object_prototype());
+ auto* info = Object::create(realm, global_object.object_prototype());
// 4. Let dir be ! CharacterDirectionOfLocale(loc).
auto direction = character_direction_of_locale(*locale_object);
@@ -267,18 +273,20 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::text_info)
// 1.4.22 get Intl.Locale.prototype.weekInfo, https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.weekInfo
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::week_info)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
[[maybe_unused]] auto* locale_object = TRY(typed_this_object(global_object));
// 3. Let info be ! ObjectCreate(%Object.prototype%).
- auto* info = Object::create(global_object, global_object.object_prototype());
+ auto* info = Object::create(realm, global_object.object_prototype());
// 4. Let wi be ! WeekInfoOfLocale(loc).
auto week_info = week_info_of_locale(*locale_object);
// 5. Let we be ! CreateArrayFromList( wi.[[Weekend]] ).
- auto weekend = Array::create_from<u8>(global_object, week_info.weekend, [](auto day) { return Value(day); });
+ auto weekend = Array::create_from<u8>(realm, week_info.weekend, [](auto day) { return Value(day); });
// 6. Perform ! CreateDataPropertyOrThrow(info, "firstDay", wi.[[FirstDay]]).
MUST(info->create_data_property_or_throw(vm.names.firstDay, Value(week_info.first_day)));
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp
index f407b91cd3..71d0a4210d 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp
@@ -910,13 +910,14 @@ String format_numeric(GlobalObject& global_object, NumberFormat& number_format,
Array* format_numeric_to_parts(GlobalObject& global_object, NumberFormat& number_format, MathematicalValue number)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let parts be ? PartitionNumberPattern(numberFormat, x).
// Note: Our implementation of PartitionNumberPattern does not throw.
auto parts = partition_number_pattern(global_object, number_format, move(number));
// 2. Let result be ! ArrayCreate(0).
- auto* result = MUST(Array::create(global_object, 0));
+ auto* result = MUST(Array::create(realm, 0));
// 3. Let n be 0.
size_t n = 0;
@@ -924,7 +925,7 @@ Array* format_numeric_to_parts(GlobalObject& global_object, NumberFormat& number
// 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(global_object, global_object.object_prototype());
+ auto* object = Object::create(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)));
@@ -1827,12 +1828,13 @@ ThrowCompletionOr<String> format_numeric_range(GlobalObject& global_object, Numb
ThrowCompletionOr<Array*> format_numeric_range_to_parts(GlobalObject& global_object, NumberFormat& number_format, MathematicalValue start, MathematicalValue end)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let parts be ? PartitionNumberRangePattern(numberFormat, x, y).
auto parts = TRY(partition_number_range_pattern(global_object, number_format, move(start), move(end)));
// 2. Let result be ! ArrayCreate(0).
- auto* result = MUST(Array::create(global_object, 0));
+ auto* result = MUST(Array::create(realm, 0));
// 3. Let n be 0.
size_t n = 0;
@@ -1840,7 +1842,7 @@ ThrowCompletionOr<Array*> format_numeric_range_to_parts(GlobalObject& global_obj
// 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(global_object, global_object.object_prototype());
+ auto* object = Object::create(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/NumberFormatFunction.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.cpp
index f19a60cd23..01d758ea1b 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.cpp
@@ -12,9 +12,9 @@ namespace JS::Intl {
// 15.5.2 Number Format Functions, https://tc39.es/ecma402/#sec-number-format-functions
// 1.1.4 Number Format Functions, https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/proposed.html#sec-number-format-functions
-NumberFormatFunction* NumberFormatFunction::create(GlobalObject& global_object, NumberFormat& number_format)
+NumberFormatFunction* NumberFormatFunction::create(Realm& realm, NumberFormat& number_format)
{
- return global_object.heap().allocate<NumberFormatFunction>(global_object, number_format, *global_object.function_prototype());
+ return realm.heap().allocate<NumberFormatFunction>(realm.global_object(), number_format, *realm.global_object().function_prototype());
}
NumberFormatFunction::NumberFormatFunction(NumberFormat& number_format, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.h b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.h
index 80971c8d6f..d562ca5c07 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.h
+++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.h
@@ -16,7 +16,7 @@ class NumberFormatFunction final : public NativeFunction {
JS_OBJECT(NumberFormatFunction, NativeFunction);
public:
- static NumberFormatFunction* create(GlobalObject&, NumberFormat&);
+ static NumberFormatFunction* create(Realm&, NumberFormat&);
explicit NumberFormatFunction(NumberFormat&, Object& prototype);
virtual ~NumberFormatFunction() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.cpp
index 34b4e15032..70b8cdef48 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.cpp
@@ -40,6 +40,8 @@ void NumberFormatPrototype::initialize(Realm& realm)
// 15.3.3 get Intl.NumberFormat.prototype.format, https://tc39.es/ecma402/#sec-intl.numberformat.prototype.format
JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::format)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let nf be the this value.
// 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
// a. Set nf to ? UnwrapNumberFormat(nf).
@@ -50,7 +52,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::format)
if (!number_format->bound_format()) {
// a. Let F be a new built-in function object as defined in Number Format Functions (15.1.4).
// b. Set F.[[NumberFormat]] to nf.
- auto* bound_format = NumberFormatFunction::create(global_object, *number_format);
+ auto* bound_format = NumberFormatFunction::create(realm, *number_format);
// c. Set nf.[[BoundFormat]] to F.
number_format->set_bound_format(bound_format);
@@ -134,6 +136,8 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::format_range_to_parts)
// 15.3.5 Intl.NumberFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.numberformat.prototype.resolvedoptions
JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::resolved_options)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let nf be the this value.
// 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
// a. Set nf to ? UnwrapNumberFormat(nf).
@@ -141,7 +145,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::resolved_options)
auto* number_format = TRY(typed_this_object(global_object));
// 4. Let options be OrdinaryObjectCreate(%Object.prototype%).
- auto* options = Object::create(global_object, global_object.object_prototype());
+ auto* options = Object::create(realm, global_object.object_prototype());
// 5. For each row of Table 11, except the header row, in table order, do
// a. Let p be the Property value of the current row.
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesPrototype.cpp
index 2b1e306440..25b556027f 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesPrototype.cpp
@@ -79,12 +79,14 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::select_range)
// 1.4.5 Intl.PluralRules.prototype.resolvedOptions ( ), https://tc39.es/proposal-intl-numberformat-v3/out/pluralrules/proposed.html#sec-intl.pluralrules.prototype.resolvedoptions
JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let pr be the this value.
// 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]).
auto* plural_rules = TRY(typed_this_object(global_object));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
- auto* options = Object::create(global_object, global_object.object_prototype());
+ auto* options = Object::create(realm, global_object.object_prototype());
// 4. For each row of Table 13, except the header row, in table order, do
// a. Let p be the Property value of the current row.
@@ -106,7 +108,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
// 5. Let pluralCategories be a List of Strings containing all possible results of PluralRuleSelect for the selected locale pr.[[Locale]].
auto available_categories = Unicode::available_plural_categories(plural_rules->locale(), plural_rules->type());
- auto* plural_categories = Array::create_from<Unicode::PluralCategory>(global_object, available_categories, [&](auto category) {
+ auto* plural_categories = Array::create_from<Unicode::PluralCategory>(realm, available_categories, [&](auto category) {
return js_string(vm, Unicode::plural_category_to_string(category));
});
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp
index 61d88f587c..cf0e50d88f 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp
@@ -248,12 +248,13 @@ ThrowCompletionOr<String> format_relative_time(GlobalObject& global_object, Rela
ThrowCompletionOr<Array*> format_relative_time_to_parts(GlobalObject& global_object, RelativeTimeFormat& relative_time_format, double value, StringView unit)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let parts be ? PartitionRelativeTimePattern(relativeTimeFormat, value, unit).
auto parts = TRY(partition_relative_time_pattern(global_object, relative_time_format, value, unit));
// 2. Let result be ! ArrayCreate(0).
- auto* result = MUST(Array::create(global_object, 0));
+ auto* result = MUST(Array::create(realm, 0));
// 3. Let n be 0.
size_t n = 0;
@@ -261,7 +262,7 @@ ThrowCompletionOr<Array*> format_relative_time_to_parts(GlobalObject& global_obj
// 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(global_object, global_object.object_prototype());
+ auto* object = Object::create(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/RelativeTimeFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatPrototype.cpp
index abf43ee9f9..2b3c1a6bcc 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatPrototype.cpp
@@ -69,12 +69,14 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::format_to_parts)
// 17.3.5 Intl.RelativeTimeFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.relativetimeformat.prototype.resolvedoptions
JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::resolved_options)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let relativeTimeFormat be the this value.
// 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]).
auto* relative_time_format = TRY(typed_this_object(global_object));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
- auto* options = Object::create(global_object, global_object.object_prototype());
+ auto* options = Object::create(realm, global_object.object_prototype());
// 4. For each row of Table 15, except the header row, in table order, do
// a. Let p be the Property value of the current row.
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp b/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp
index 2089b5dcdc..1095226566 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp
@@ -11,16 +11,15 @@
namespace JS::Intl {
// 18.6.1 CreateSegmentIterator ( segmenter, string ), https://tc39.es/ecma402/#sec-createsegmentsobject
-SegmentIterator* SegmentIterator::create(GlobalObject& global_object, Segmenter& segmenter, Utf16View const& string, Segments const& segments)
+SegmentIterator* SegmentIterator::create(Realm& realm, Segmenter& segmenter, Utf16View const& string, Segments const& segments)
{
- auto& realm = *global_object.associated_realm();
// 1. Let internalSlotsList be « [[IteratingSegmenter]], [[IteratedString]], [[IteratedStringNextSegmentCodeUnitIndex]] ».
// 2. Let iterator be OrdinaryObjectCreate(%SegmentIteratorPrototype%, internalSlotsList).
// 3. Set iterator.[[IteratingSegmenter]] to segmenter.
// 4. Set iterator.[[IteratedString]] to string.
// 5. Set iterator.[[IteratedStringNextSegmentCodeUnitIndex]] to 0.
// 6. Return iterator.
- return global_object.heap().allocate<SegmentIterator>(global_object, realm, segmenter, move(string), segments);
+ return realm.heap().allocate<SegmentIterator>(realm.global_object(), realm, segmenter, move(string), segments);
}
// 18.6 Segment Iterator Objects, https://tc39.es/ecma402/#sec-segment-iterator-objects
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.h b/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.h
index 1a4aee5d14..02906050cd 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.h
+++ b/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.h
@@ -16,7 +16,7 @@ class SegmentIterator final : public Object {
JS_OBJECT(SegmentIterator, Object);
public:
- static SegmentIterator* create(GlobalObject&, Segmenter&, Utf16View const&, Segments const&);
+ static SegmentIterator* create(Realm&, Segmenter&, Utf16View const&, Segments const&);
SegmentIterator(Realm&, Segmenter&, Utf16View const&, Segments const&);
virtual ~SegmentIterator() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Segmenter.cpp b/Userland/Libraries/LibJS/Runtime/Intl/Segmenter.cpp
index 5acd0e6dfd..f2db15fa0a 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/Segmenter.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/Segmenter.cpp
@@ -48,6 +48,7 @@ StringView Segmenter::segmenter_granularity_string() const
Object* create_segment_data_object(GlobalObject& global_object, Segmenter const& segmenter, Utf16View const& string, double start_index, double end_index)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let len be the length of string.
auto length = string.length_in_code_units();
@@ -62,7 +63,7 @@ Object* create_segment_data_object(GlobalObject& global_object, Segmenter const&
VERIFY(start_index < end_index);
// 5. Let result be OrdinaryObjectCreate(%Object.prototype%).
- auto* result = Object::create(global_object, global_object.object_prototype());
+ auto* result = Object::create(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/Intl/SegmenterPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/SegmenterPrototype.cpp
index f13448445f..b42733cb01 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/SegmenterPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/SegmenterPrototype.cpp
@@ -34,12 +34,14 @@ void SegmenterPrototype::initialize(Realm& realm)
// 18.3.4 Intl.Segmenter.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.segmenter.prototype.resolvedoptions
JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::resolved_options)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let segmenter be the this value.
// 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]).
auto* segmenter = TRY(typed_this_object(global_object));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
- auto* options = Object::create(global_object, global_object.object_prototype());
+ auto* options = Object::create(realm, global_object.object_prototype());
// 4. For each row of Table 16, except the header row, in table order, do
// a. Let p be the Property value of the current row.
@@ -56,6 +58,8 @@ JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::resolved_options)
// 18.3.3 Intl.Segmenter.prototype.segment ( string ), https://tc39.es/ecma402/#sec-intl.segmenter.prototype.segment
JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::segment)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let segmenter be the this value.
// 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]).
auto* segmenter = TRY(typed_this_object(global_object));
@@ -64,7 +68,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::segment)
auto string = TRY(vm.argument(0).to_utf16_string(global_object));
// 4. Return ! CreateSegmentsObject(segmenter, string).
- return Segments::create(global_object, *segmenter, move(string));
+ return Segments::create(realm, *segmenter, move(string));
}
}
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp b/Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp
index 1eab2f191b..ce3590ab5a 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp
@@ -11,15 +11,14 @@
namespace JS::Intl {
// 18.5.1 CreateSegmentsObject ( segmenter, string ), https://tc39.es/ecma402/#sec-createsegmentsobject
-Segments* Segments::create(GlobalObject& global_object, Segmenter& segmenter, Utf16String string)
+Segments* Segments::create(Realm& realm, Segmenter& segmenter, Utf16String string)
{
- auto& realm = *global_object.associated_realm();
// 1. Let internalSlotsList be « [[SegmentsSegmenter]], [[SegmentsString]] ».
// 2. Let segments be OrdinaryObjectCreate(%SegmentsPrototype%, internalSlotsList).
// 3. Set segments.[[SegmentsSegmenter]] to segmenter.
// 4. Set segments.[[SegmentsString]] to string.
// 5. Return segments.
- return global_object.heap().allocate<Segments>(global_object, realm, segmenter, move(string));
+ return realm.heap().allocate<Segments>(realm.global_object(), realm, segmenter, move(string));
}
// 18.5 Segments Objects, https://tc39.es/ecma402/#sec-segments-objects
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Segments.h b/Userland/Libraries/LibJS/Runtime/Intl/Segments.h
index 5696d3089a..251d132ad4 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/Segments.h
+++ b/Userland/Libraries/LibJS/Runtime/Intl/Segments.h
@@ -16,7 +16,7 @@ class Segments final : public Object {
JS_OBJECT(Segments, Object);
public:
- static Segments* create(GlobalObject&, Segmenter&, Utf16String);
+ static Segments* create(Realm&, Segmenter&, Utf16String);
Segments(Realm&, Segmenter&, Utf16String);
virtual ~Segments() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp
index 8d1353601d..117ef331ff 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp
@@ -64,6 +64,8 @@ JS_DEFINE_NATIVE_FUNCTION(SegmentsPrototype::containing)
// 18.5.2.2 %SegmentsPrototype% [ @@iterator ] ( ), https://tc39.es/ecma402/#sec-%segmentsprototype%-@@iterator
JS_DEFINE_NATIVE_FUNCTION(SegmentsPrototype::symbol_iterator)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let segments be the this value.
// 2. Perform ? RequireInternalSlot(segments, [[SegmentsSegmenter]]).
auto* segments = TRY(typed_this_object(global_object));
@@ -75,7 +77,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmentsPrototype::symbol_iterator)
auto string = segments->segments_string();
// 5. Return ! CreateSegmentIterator(segmenter, string).
- return SegmentIterator::create(global_object, segmenter, string, *segments);
+ return SegmentIterator::create(realm, segmenter, string, *segments);
}
}
diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp
index aacc2edf4c..9d14a77bde 100644
--- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp
@@ -197,9 +197,10 @@ Completion async_iterator_close(GlobalObject& global_object, Iterator const& ite
Object* create_iterator_result_object(GlobalObject& global_object, Value value, bool done)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let obj be OrdinaryObjectCreate(%Object.prototype%).
- auto* object = Object::create(global_object, global_object.object_prototype());
+ auto* object = Object::create(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 4818ffb8d1..e11291d05f 100644
--- a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp
@@ -45,6 +45,8 @@ void JSONObject::initialize(Realm& realm)
// 25.5.2 JSON.stringify ( value [ , replacer [ , space ] ] ), https://tc39.es/ecma262/#sec-json.stringify
ThrowCompletionOr<String> JSONObject::stringify_impl(GlobalObject& global_object, Value value, Value replacer, Value space)
{
+ auto& realm = *global_object.associated_realm();
+
StringifyState state;
if (replacer.is_object()) {
@@ -99,7 +101,7 @@ ThrowCompletionOr<String> JSONObject::stringify_impl(GlobalObject& global_object
state.gap = String::empty();
}
- auto* wrapper = Object::create(global_object, global_object.object_prototype());
+ auto* wrapper = Object::create(realm, global_object.object_prototype());
MUST(wrapper->create_data_property_or_throw(String::empty(), value));
return serialize_json_property(global_object, state, String::empty(), wrapper);
}
@@ -392,6 +394,8 @@ String JSONObject::quote_json_string(String string)
// 25.5.1 JSON.parse ( text [ , reviver ] ), https://tc39.es/ecma262/#sec-json.parse
JS_DEFINE_NATIVE_FUNCTION(JSONObject::parse)
{
+ auto& realm = *global_object.associated_realm();
+
auto string = TRY(vm.argument(0).to_string(global_object));
auto reviver = vm.argument(1);
@@ -400,7 +404,7 @@ JS_DEFINE_NATIVE_FUNCTION(JSONObject::parse)
return vm.throw_completion<SyntaxError>(global_object, ErrorType::JsonMalformed);
Value unfiltered = parse_json_value(global_object, json.value());
if (reviver.is_function()) {
- auto* root = Object::create(global_object, global_object.object_prototype());
+ auto* root = Object::create(realm, global_object.object_prototype());
auto root_name = String::empty();
MUST(root->create_data_property_or_throw(root_name, unfiltered));
return internalize_json_property(global_object, root, root_name, reviver.as_function());
@@ -429,7 +433,8 @@ Value JSONObject::parse_json_value(GlobalObject& global_object, JsonValue const&
Object* JSONObject::parse_json_object(GlobalObject& global_object, JsonObject const& json_object)
{
- auto* object = Object::create(global_object, global_object.object_prototype());
+ auto& realm = *global_object.associated_realm();
+ auto* object = Object::create(realm, global_object.object_prototype());
json_object.for_each_member([&](auto& key, auto& value) {
object->define_direct_property(key, parse_json_value(global_object, value), default_attributes);
});
@@ -438,7 +443,8 @@ Object* JSONObject::parse_json_object(GlobalObject& global_object, JsonObject co
Array* JSONObject::parse_json_array(GlobalObject& global_object, JsonArray const& json_array)
{
- auto* array = MUST(Array::create(global_object, 0));
+ auto& realm = *global_object.associated_realm();
+ auto* array = MUST(Array::create(realm, 0));
size_t index = 0;
json_array.for_each([&](auto& value) {
array->define_direct_property(index++, parse_json_value(global_object, value), default_attributes);
diff --git a/Userland/Libraries/LibJS/Runtime/Map.cpp b/Userland/Libraries/LibJS/Runtime/Map.cpp
index a0b4f38579..75e8b206b3 100644
--- a/Userland/Libraries/LibJS/Runtime/Map.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Map.cpp
@@ -8,9 +8,9 @@
namespace JS {
-Map* Map::create(GlobalObject& global_object)
+Map* Map::create(Realm& realm)
{
- return global_object.heap().allocate<Map>(global_object, *global_object.map_prototype());
+ return realm.heap().allocate<Map>(realm.global_object(), *realm.global_object().map_prototype());
}
Map::Map(Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/Map.h b/Userland/Libraries/LibJS/Runtime/Map.h
index bfc8ffc7bc..6cdef237b1 100644
--- a/Userland/Libraries/LibJS/Runtime/Map.h
+++ b/Userland/Libraries/LibJS/Runtime/Map.h
@@ -20,7 +20,7 @@ class Map : public Object {
JS_OBJECT(Map, Object);
public:
- static Map* create(GlobalObject&);
+ static Map* create(Realm&);
explicit Map(Object& prototype);
virtual ~Map() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/MapIterator.cpp b/Userland/Libraries/LibJS/Runtime/MapIterator.cpp
index 2bf4f20a0f..4a3f75b4a0 100644
--- a/Userland/Libraries/LibJS/Runtime/MapIterator.cpp
+++ b/Userland/Libraries/LibJS/Runtime/MapIterator.cpp
@@ -9,9 +9,9 @@
namespace JS {
-MapIterator* MapIterator::create(GlobalObject& global_object, Map& map, Object::PropertyKind iteration_kind)
+MapIterator* MapIterator::create(Realm& realm, Map& map, Object::PropertyKind iteration_kind)
{
- return global_object.heap().allocate<MapIterator>(global_object, map, iteration_kind, *global_object.map_iterator_prototype());
+ return realm.heap().allocate<MapIterator>(realm.global_object(), map, iteration_kind, *realm.global_object().map_iterator_prototype());
}
MapIterator::MapIterator(Map& map, Object::PropertyKind iteration_kind, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/MapIterator.h b/Userland/Libraries/LibJS/Runtime/MapIterator.h
index c7a57bab09..676f46c7d3 100644
--- a/Userland/Libraries/LibJS/Runtime/MapIterator.h
+++ b/Userland/Libraries/LibJS/Runtime/MapIterator.h
@@ -16,7 +16,7 @@ class MapIterator final : public Object {
JS_OBJECT(MapIterator, Object);
public:
- static MapIterator* create(GlobalObject&, Map& map, Object::PropertyKind iteration_kind);
+ static MapIterator* create(Realm&, Map& map, Object::PropertyKind iteration_kind);
explicit MapIterator(Map& map, Object::PropertyKind iteration_kind, Object& prototype);
virtual ~MapIterator() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp
index 76515fcbd8..eacfd846b8 100644
--- a/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp
@@ -30,6 +30,8 @@ void MapIteratorPrototype::initialize(Realm& realm)
// 24.1.5.2.1 %MapIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%mapiteratorprototype%.next
JS_DEFINE_NATIVE_FUNCTION(MapIteratorPrototype::next)
{
+ auto& realm = *global_object.associated_realm();
+
auto* map_iterator = TRY(typed_this_value(global_object));
if (map_iterator->done())
return create_iterator_result_object(global_object, js_undefined(), true);
@@ -48,7 +50,7 @@ JS_DEFINE_NATIVE_FUNCTION(MapIteratorPrototype::next)
if (iteration_kind == Object::PropertyKind::Value)
return create_iterator_result_object(global_object, entry.value, false);
- return create_iterator_result_object(global_object, Array::create_from(global_object, { entry.key, entry.value }), false);
+ return create_iterator_result_object(global_object, Array::create_from(realm, { entry.key, entry.value }), false);
}
}
diff --git a/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp b/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp
index c06d6b2625..50dc9a17f2 100644
--- a/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp
@@ -57,9 +57,11 @@ JS_DEFINE_NATIVE_FUNCTION(MapPrototype::delete_)
// 24.1.3.4 Map.prototype.entries ( ), https://tc39.es/ecma262/#sec-map.prototype.entries
JS_DEFINE_NATIVE_FUNCTION(MapPrototype::entries)
{
+ auto& realm = *global_object.associated_realm();
+
auto* map = TRY(typed_this_object(global_object));
- return MapIterator::create(global_object, *map, Object::PropertyKind::KeyAndValue);
+ return MapIterator::create(realm, *map, Object::PropertyKind::KeyAndValue);
}
// 24.1.3.5 Map.prototype.forEach ( callbackfn [ , thisArg ] ), https://tc39.es/ecma262/#sec-map.prototype.foreach
@@ -94,9 +96,11 @@ JS_DEFINE_NATIVE_FUNCTION(MapPrototype::has)
// 24.1.3.8 Map.prototype.keys ( ), https://tc39.es/ecma262/#sec-map.prototype.keys
JS_DEFINE_NATIVE_FUNCTION(MapPrototype::keys)
{
+ auto& realm = *global_object.associated_realm();
+
auto* map = TRY(typed_this_object(global_object));
- return MapIterator::create(global_object, *map, Object::PropertyKind::Key);
+ return MapIterator::create(realm, *map, Object::PropertyKind::Key);
}
// 24.1.3.9 Map.prototype.set ( key, value ), https://tc39.es/ecma262/#sec-map.prototype.set
@@ -113,9 +117,11 @@ JS_DEFINE_NATIVE_FUNCTION(MapPrototype::set)
// 24.1.3.11 Map.prototype.values ( ), https://tc39.es/ecma262/#sec-map.prototype.values
JS_DEFINE_NATIVE_FUNCTION(MapPrototype::values)
{
+ auto& realm = *global_object.associated_realm();
+
auto* map = TRY(typed_this_object(global_object));
- return MapIterator::create(global_object, *map, Object::PropertyKind::Value);
+ return MapIterator::create(realm, *map, Object::PropertyKind::Value);
}
// 24.1.3.10 get Map.prototype.size, https://tc39.es/ecma262/#sec-get-map.prototype.size
diff --git a/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp b/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp
index 342330a163..93b1e58f45 100644
--- a/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp
+++ b/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp
@@ -16,9 +16,9 @@ namespace JS {
// 10.3.3 CreateBuiltinFunction ( behaviour, length, name, additionalInternalSlotsList [ , realm [ , prototype [ , prefix ] ] ] ), https://tc39.es/ecma262/#sec-createbuiltinfunction
// NOTE: This doesn't consider additionalInternalSlotsList, which is rarely used, and can either be implemented using only the `function` lambda, or needs a NativeFunction subclass.
-NativeFunction* NativeFunction::create(GlobalObject& global_object, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> behaviour, i32 length, PropertyKey const& name, Optional<Realm*> realm, Optional<Object*> prototype, Optional<StringView> const& prefix)
+NativeFunction* NativeFunction::create(Realm& allocating_realm, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> behaviour, i32 length, PropertyKey const& name, Optional<Realm*> realm, Optional<Object*> prototype, Optional<StringView> const& prefix)
{
- auto& vm = global_object.vm();
+ auto& vm = allocating_realm.vm();
// 1. If realm is not present, set realm to the current Realm Record.
if (!realm.has_value())
@@ -36,7 +36,7 @@ NativeFunction* NativeFunction::create(GlobalObject& global_object, Function<Thr
// 7. Set func.[[Extensible]] to true.
// 8. Set func.[[Realm]] to realm.
// 9. Set func.[[InitialName]] to null.
- auto* function = global_object.heap().allocate<NativeFunction>(global_object, move(behaviour), prototype.value(), *realm.value());
+ auto* function = allocating_realm.heap().allocate<NativeFunction>(allocating_realm.global_object(), move(behaviour), prototype.value(), *realm.value());
// 10. Perform SetFunctionLength(func, length).
function->set_function_length(length);
@@ -51,10 +51,9 @@ NativeFunction* NativeFunction::create(GlobalObject& global_object, Function<Thr
return function;
}
-NativeFunction* NativeFunction::create(GlobalObject& global_object, FlyString const& name, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> function)
+NativeFunction* NativeFunction::create(Realm& realm, FlyString const& name, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> function)
{
- auto& realm = *global_object.associated_realm();
- return global_object.heap().allocate<NativeFunction>(global_object, name, move(function), *realm.global_object().function_prototype());
+ return realm.heap().allocate<NativeFunction>(realm.global_object(), name, move(function), *realm.global_object().function_prototype());
}
NativeFunction::NativeFunction(Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> native_function, Object* prototype, Realm& realm)
diff --git a/Userland/Libraries/LibJS/Runtime/NativeFunction.h b/Userland/Libraries/LibJS/Runtime/NativeFunction.h
index d129236a0d..05ac7f567c 100644
--- a/Userland/Libraries/LibJS/Runtime/NativeFunction.h
+++ b/Userland/Libraries/LibJS/Runtime/NativeFunction.h
@@ -20,8 +20,8 @@ class NativeFunction : public FunctionObject {
JS_OBJECT(NativeFunction, FunctionObject);
public:
- static NativeFunction* create(GlobalObject&, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> behaviour, i32 length, PropertyKey const& name, Optional<Realm*> = {}, Optional<Object*> prototype = {}, Optional<StringView> const& prefix = {});
- static NativeFunction* create(GlobalObject&, FlyString const& name, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)>);
+ static NativeFunction* create(Realm&, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> behaviour, i32 length, PropertyKey const& name, Optional<Realm*> = {}, Optional<Object*> prototype = {}, Optional<StringView> const& prefix = {});
+ static NativeFunction* create(Realm&, FlyString const& name, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)>);
NativeFunction(Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)>, Object* prototype, Realm& realm);
NativeFunction(FlyString name, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)>, Object& prototype);
diff --git a/Userland/Libraries/LibJS/Runtime/NumberObject.cpp b/Userland/Libraries/LibJS/Runtime/NumberObject.cpp
index 8a4313706e..1e02d8a4f1 100644
--- a/Userland/Libraries/LibJS/Runtime/NumberObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/NumberObject.cpp
@@ -9,9 +9,9 @@
namespace JS {
-NumberObject* NumberObject::create(GlobalObject& global_object, double value)
+NumberObject* NumberObject::create(Realm& realm, double value)
{
- return global_object.heap().allocate<NumberObject>(global_object, value, *global_object.number_prototype());
+ return realm.heap().allocate<NumberObject>(realm.global_object(), value, *realm.global_object().number_prototype());
}
NumberObject::NumberObject(double value, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/NumberObject.h b/Userland/Libraries/LibJS/Runtime/NumberObject.h
index 6208bde0e6..16fd7fd2d9 100644
--- a/Userland/Libraries/LibJS/Runtime/NumberObject.h
+++ b/Userland/Libraries/LibJS/Runtime/NumberObject.h
@@ -14,7 +14,7 @@ class NumberObject : public Object {
JS_OBJECT(NumberObject, Object);
public:
- static NumberObject* create(GlobalObject&, double);
+ static NumberObject* create(Realm&, double);
NumberObject(double, Object& prototype);
virtual ~NumberObject() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp
index 015c2f0a21..36a39156b8 100644
--- a/Userland/Libraries/LibJS/Runtime/Object.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Object.cpp
@@ -24,14 +24,14 @@
namespace JS {
// 10.1.12 OrdinaryObjectCreate ( proto [ , additionalInternalSlotsList ] ), https://tc39.es/ecma262/#sec-ordinaryobjectcreate
-Object* Object::create(GlobalObject& global_object, Object* prototype)
+Object* Object::create(Realm& realm, Object* prototype)
{
if (!prototype)
- return global_object.heap().allocate<Object>(global_object, *global_object.empty_object_shape());
- else if (prototype == global_object.object_prototype())
- return global_object.heap().allocate<Object>(global_object, *global_object.new_object_shape());
+ return realm.heap().allocate<Object>(realm.global_object(), *realm.global_object().empty_object_shape());
+ else if (prototype == realm.global_object().object_prototype())
+ return realm.heap().allocate<Object>(realm.global_object(), *realm.global_object().new_object_shape());
else
- return global_object.heap().allocate<Object>(global_object, *prototype);
+ return realm.heap().allocate<Object>(realm.global_object(), *prototype);
}
GlobalObject& Object::global_object() const
@@ -368,6 +368,7 @@ ThrowCompletionOr<MarkedVector<Value>> Object::enumerable_own_property_names(Pro
// spec text have been replaced with `continue`s in the loop below.
auto& global_object = this->global_object();
+ auto& realm = *global_object.associated_realm();
// 1. Let ownKeys be ? O.[[OwnPropertyKeys]]().
auto own_keys = TRY(internal_own_property_keys());
@@ -408,7 +409,7 @@ ThrowCompletionOr<MarkedVector<Value>> Object::enumerable_own_property_names(Pro
VERIFY(kind == PropertyKind::KeyAndValue);
// ii. Let entry be CreateArrayFromList(« key, value »).
- auto entry = Array::create_from(global_object, { key, value });
+ auto entry = Array::create_from(realm, { key, value });
// iii. Append entry to properties.
properties.append(entry);
@@ -1057,12 +1058,13 @@ void Object::set_prototype(Object* new_prototype)
void Object::define_native_accessor(PropertyKey const& property_key, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> getter, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> setter, PropertyAttributes attribute)
{
+ auto& realm = *global_object().associated_realm();
FunctionObject* getter_function = nullptr;
if (getter)
- getter_function = NativeFunction::create(global_object(), move(getter), 0, property_key, {}, {}, "get"sv);
+ getter_function = NativeFunction::create(realm, move(getter), 0, property_key, &realm, {}, "get"sv);
FunctionObject* setter_function = nullptr;
if (setter)
- setter_function = NativeFunction::create(global_object(), move(setter), 1, property_key, {}, {}, "set"sv);
+ setter_function = NativeFunction::create(realm, move(setter), 1, property_key, &realm, {}, "set"sv);
return define_direct_accessor(property_key, getter_function, setter_function, attribute);
}
@@ -1106,7 +1108,8 @@ Value Object::get_without_side_effects(PropertyKey const& property_key) const
void Object::define_native_function(PropertyKey const& property_key, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> native_function, i32 length, PropertyAttributes attribute)
{
- auto* function = NativeFunction::create(global_object(), move(native_function), length, property_key);
+ auto& realm = *global_object().associated_realm();
+ auto* function = NativeFunction::create(realm, move(native_function), length, property_key, &realm);
define_direct_property(property_key, function, attribute);
}
diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h
index 4937c91760..bf9b422aa1 100644
--- a/Userland/Libraries/LibJS/Runtime/Object.h
+++ b/Userland/Libraries/LibJS/Runtime/Object.h
@@ -47,7 +47,7 @@ struct PrivateElement {
class Object : public Cell {
public:
- static Object* create(GlobalObject&, Object* prototype);
+ static Object* create(Realm&, Object* prototype);
Object(Realm&, Object* prototype);
explicit Object(Object& prototype);
diff --git a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp
index 1014a42156..2f0bf8d90a 100644
--- a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp
@@ -68,12 +68,13 @@ ThrowCompletionOr<Object*> ObjectConstructor::construct(FunctionObject& new_targ
{
auto& vm = this->vm();
auto& global_object = this->global_object();
+ auto& realm = *global_object.associated_realm();
if (&new_target != this)
return TRY(ordinary_create_from_constructor<Object>(global_object, new_target, &GlobalObject::object_prototype));
auto value = vm.argument(0);
if (value.is_nullish())
- return Object::create(global_object, global_object.object_prototype());
+ return Object::create(realm, global_object.object_prototype());
return value.to_object(global_object);
}
@@ -112,15 +113,19 @@ static ThrowCompletionOr<MarkedVector<Value>> get_own_property_keys(GlobalObject
// 20.1.2.10 Object.getOwnPropertyNames ( O ), https://tc39.es/ecma262/#sec-object.getownpropertynames
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_names)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Return CreateArrayFromList(? GetOwnPropertyKeys(O, string)).
- return Array::create_from(global_object, TRY(get_own_property_keys(global_object, vm.argument(0), GetOwnPropertyKeysType::String)));
+ return Array::create_from(realm, TRY(get_own_property_keys(global_object, vm.argument(0), GetOwnPropertyKeysType::String)));
}
// 20.1.2.11 Object.getOwnPropertySymbols ( O ), https://tc39.es/ecma262/#sec-object.getownpropertysymbols
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_symbols)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Return CreateArrayFromList(? GetOwnPropertyKeys(O, symbol)).
- return Array::create_from(global_object, TRY(get_own_property_keys(global_object, vm.argument(0), GetOwnPropertyKeysType::Symbol)));
+ return Array::create_from(realm, TRY(get_own_property_keys(global_object, vm.argument(0), GetOwnPropertyKeysType::Symbol)));
}
// 20.1.2.12 Object.getPrototypeOf ( O ), https://tc39.es/ecma262/#sec-object.getprototypeof
@@ -218,9 +223,10 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::freeze)
// 20.1.2.7 Object.fromEntries ( iterable ), https://tc39.es/ecma262/#sec-object.fromentries
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::from_entries)
{
+ auto& realm = *global_object.associated_realm();
auto iterable = TRY(require_object_coercible(global_object, vm.argument(0)));
- auto* object = Object::create(global_object, global_object.object_prototype());
+ auto* object = Object::create(realm, global_object.object_prototype());
(void)TRY(get_iterator_values(global_object, iterable, [&](Value iterator_value) -> Optional<Completion> {
if (!iterator_value.is_object())
@@ -262,6 +268,8 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptor)
// 20.1.2.9 Object.getOwnPropertyDescriptors ( O ), https://tc39.es/ecma262/#sec-object.getownpropertydescriptors
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptors)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let obj be ? ToObject(O).
auto* object = TRY(vm.argument(0).to_object(global_object));
@@ -269,7 +277,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptors)
auto own_keys = TRY(object->internal_own_property_keys());
// 3. Let descriptors be OrdinaryObjectCreate(%Object.prototype%).
- auto* descriptors = Object::create(global_object, global_object.object_prototype());
+ auto* descriptors = Object::create(realm, global_object.object_prototype());
// 4. For each element key of ownKeys, do
for (auto& key : own_keys) {
@@ -324,30 +332,38 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is)
// 20.1.2.18 Object.keys ( O ), https://tc39.es/ecma262/#sec-object.keys
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::keys)
{
+ auto& realm = *global_object.associated_realm();
+
auto* object = TRY(vm.argument(0).to_object(global_object));
auto name_list = TRY(object->enumerable_own_property_names(PropertyKind::Key));
- return Array::create_from(global_object, name_list);
+ return Array::create_from(realm, name_list);
}
// 20.1.2.23 Object.values ( O ), https://tc39.es/ecma262/#sec-object.values
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values)
{
+ auto& realm = *global_object.associated_realm();
+
auto* object = TRY(vm.argument(0).to_object(global_object));
auto name_list = TRY(object->enumerable_own_property_names(PropertyKind::Value));
- return Array::create_from(global_object, name_list);
+ return Array::create_from(realm, name_list);
}
// 20.1.2.5 Object.entries ( O ), https://tc39.es/ecma262/#sec-object.entries
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::entries)
{
+ auto& realm = *global_object.associated_realm();
+
auto* object = TRY(vm.argument(0).to_object(global_object));
auto name_list = TRY(object->enumerable_own_property_names(PropertyKind::KeyAndValue));
- return Array::create_from(global_object, name_list);
+ return Array::create_from(realm, name_list);
}
// 20.1.2.2 Object.create ( O, Properties ), https://tc39.es/ecma262/#sec-object.create
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::create)
{
+ auto& realm = *global_object.associated_realm();
+
auto proto = vm.argument(0);
auto properties = vm.argument(1);
@@ -356,7 +372,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::create)
return vm.throw_completion<TypeError>(global_object, ErrorType::ObjectPrototypeWrongType);
// 2. Let obj be OrdinaryObjectCreate(O).
- auto* object = Object::create(global_object, proto.is_null() ? nullptr : &proto.as_object());
+ auto* object = Object::create(realm, proto.is_null() ? nullptr : &proto.as_object());
// 3. If Properties is not undefined, then
if (!properties.is_undefined()) {
diff --git a/Userland/Libraries/LibJS/Runtime/Promise.cpp b/Userland/Libraries/LibJS/Runtime/Promise.cpp
index c6a5a9fcaa..7367b37bd3 100644
--- a/Userland/Libraries/LibJS/Runtime/Promise.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Promise.cpp
@@ -43,9 +43,9 @@ ThrowCompletionOr<Object*> promise_resolve(GlobalObject& global_object, Object&
return promise_capability.promise;
}
-Promise* Promise::create(GlobalObject& global_object)
+Promise* Promise::create(Realm& realm)
{
- return global_object.heap().allocate<Promise>(global_object, *global_object.promise_prototype());
+ return realm.heap().allocate<Promise>(realm.global_object(), *realm.global_object().promise_prototype());
}
// 27.2 Promise Objects, https://tc39.es/ecma262/#sec-promise-objects
@@ -58,7 +58,10 @@ Promise::Promise(Object& prototype)
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();
// 1. Let alreadyResolved be the Record { [[Value]]: false }.
auto* already_resolved = vm.heap().allocate_without_global_object<AlreadyResolved>();
@@ -70,9 +73,11 @@ Promise::ResolvingFunctions Promise::create_resolving_functions()
// 6. Set resolve.[[AlreadyResolved]] to alreadyResolved.
// 27.2.1.3.2 Promise Resolve Functions, https://tc39.es/ecma262/#sec-promise-resolve-functions
- auto* resolve_function = PromiseResolvingFunction::create(global_object(), *this, *already_resolved, [](auto& vm, auto& global_object, auto& promise, auto& already_resolved) {
+ auto* resolve_function = PromiseResolvingFunction::create(realm, *this, *already_resolved, [](auto& vm, auto& global_object, auto& promise, auto& already_resolved) {
dbgln_if(PROMISE_DEBUG, "[Promise @ {} / PromiseResolvingFunction]: Resolve function was called", &promise);
+ auto& realm = *global_object.associated_realm();
+
auto resolution = vm.argument(0);
// 1. Let F be the active function object.
@@ -94,7 +99,7 @@ Promise::ResolvingFunctions Promise::create_resolving_functions()
dbgln_if(PROMISE_DEBUG, "[Promise @ {} / PromiseResolvingFunction]: Promise can't be resolved with itself, rejecting with error", &promise);
// a. Let selfResolutionError be a newly created TypeError object.
- auto* self_resolution_error = TypeError::create(global_object, "Cannot resolve promise with itself");
+ auto* self_resolution_error = TypeError::create(realm, "Cannot resolve promise with itself");
// b. Perform RejectPromise(promise, selfResolutionError).
promise.reject(self_resolution_error);
@@ -145,11 +150,11 @@ Promise::ResolvingFunctions Promise::create_resolving_functions()
// 14. Let job be NewPromiseResolveThenableJob(promise, resolution, thenJobCallback).
dbgln_if(PROMISE_DEBUG, "[Promise @ {} / PromiseResolvingFunction]: Creating PromiseResolveThenableJob for thenable {}", &promise, resolution);
- auto [job, realm] = create_promise_resolve_thenable_job(global_object, promise, resolution, move(then_job_callback));
+ auto job = create_promise_resolve_thenable_job(global_object, promise, resolution, move(then_job_callback));
// 15. Perform HostEnqueuePromiseJob(job.[[Job]], job.[[Realm]]).
- dbgln_if(PROMISE_DEBUG, "[Promise @ {} / PromiseResolvingFunction]: Enqueuing job @ {} in realm {}", &promise, &job, realm);
- vm.host_enqueue_promise_job(move(job), realm);
+ dbgln_if(PROMISE_DEBUG, "[Promise @ {} / PromiseResolvingFunction]: Enqueuing job @ {} in realm {}", &promise, &job.job, job.realm);
+ vm.host_enqueue_promise_job(move(job.job), job.realm);
// 16. Return undefined.
return js_undefined();
@@ -163,7 +168,7 @@ Promise::ResolvingFunctions Promise::create_resolving_functions()
// 11. Set reject.[[AlreadyResolved]] to alreadyResolved.
// 27.2.1.3.1 Promise Reject Functions, https://tc39.es/ecma262/#sec-promise-reject-functions
- auto* reject_function = PromiseResolvingFunction::create(global_object(), *this, *already_resolved, [](auto& vm, auto&, auto& promise, auto& already_resolved) {
+ auto* reject_function = PromiseResolvingFunction::create(realm, *this, *already_resolved, [](auto& vm, auto&, auto& promise, auto& already_resolved) {
dbgln_if(PROMISE_DEBUG, "[Promise @ {} / PromiseResolvingFunction]: Reject function was called", &promise);
auto reason = vm.argument(0);
diff --git a/Userland/Libraries/LibJS/Runtime/Promise.h b/Userland/Libraries/LibJS/Runtime/Promise.h
index 3bc704cf4d..fe3b62ae5a 100644
--- a/Userland/Libraries/LibJS/Runtime/Promise.h
+++ b/Userland/Libraries/LibJS/Runtime/Promise.h
@@ -27,7 +27,7 @@ public:
Handle,
};
- static Promise* create(GlobalObject&);
+ static Promise* create(Realm&);
explicit Promise(Object& prototype);
virtual ~Promise() = default;
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp
index f9e9e727ae..4e9c2bc099 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp
@@ -119,12 +119,13 @@ static ThrowCompletionOr<Value> perform_promise_common(GlobalObject& global_obje
static ThrowCompletionOr<Value> perform_promise_all(GlobalObject& global_object, Iterator& iterator_record, Value constructor, PromiseCapability result_capability, Value promise_resolve)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
return perform_promise_common(
global_object, iterator_record, constructor, result_capability, promise_resolve,
[&](PromiseValueList& values) -> ThrowCompletionOr<Value> {
// 1. Let valuesArray be CreateArrayFromList(values).
- auto* values_array = Array::create_from(global_object, values.values());
+ auto* values_array = Array::create_from(realm, values.values());
// 2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »).
TRY(call(global_object, *result_capability.resolve, js_undefined(), values_array));
@@ -141,7 +142,7 @@ static ThrowCompletionOr<Value> perform_promise_all(GlobalObject& global_object,
// o. Set onFulfilled.[[Values]] to values.
// p. Set onFulfilled.[[Capability]] to resultCapability.
// q. Set onFulfilled.[[RemainingElements]] to remainingElementsCount.
- auto* on_fulfilled = PromiseAllResolveElementFunction::create(global_object, index, values, result_capability, remaining_elements_count);
+ auto* on_fulfilled = PromiseAllResolveElementFunction::create(realm, index, values, result_capability, remaining_elements_count);
on_fulfilled->define_direct_property(vm.names.name, js_string(vm, String::empty()), Attribute::Configurable);
// s. Perform ? Invoke(nextPromise, "then", « onFulfilled, resultCapability.[[Reject]] »).
@@ -153,11 +154,12 @@ static ThrowCompletionOr<Value> perform_promise_all(GlobalObject& global_object,
static ThrowCompletionOr<Value> perform_promise_all_settled(GlobalObject& global_object, Iterator& iterator_record, Value constructor, PromiseCapability result_capability, Value promise_resolve)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
return perform_promise_common(
global_object, iterator_record, constructor, result_capability, promise_resolve,
[&](PromiseValueList& values) -> ThrowCompletionOr<Value> {
- auto* values_array = Array::create_from(global_object, values.values());
+ auto* values_array = Array::create_from(realm, values.values());
TRY(call(global_object, *result_capability.resolve, js_undefined(), values_array));
@@ -173,7 +175,7 @@ static ThrowCompletionOr<Value> perform_promise_all_settled(GlobalObject& global
// p. Set onFulfilled.[[Values]] to values.
// q. Set onFulfilled.[[Capability]] to resultCapability.
// r. Set onFulfilled.[[RemainingElements]] to remainingElementsCount.
- auto* on_fulfilled = PromiseAllSettledResolveElementFunction::create(global_object, index, values, result_capability, remaining_elements_count);
+ auto* on_fulfilled = PromiseAllSettledResolveElementFunction::create(realm, index, values, result_capability, remaining_elements_count);
on_fulfilled->define_direct_property(vm.names.name, js_string(vm, String::empty()), Attribute::Configurable);
// s. Let stepsRejected be the algorithm steps defined in Promise.allSettled Reject Element Functions.
@@ -184,7 +186,7 @@ static ThrowCompletionOr<Value> perform_promise_all_settled(GlobalObject& global
// x. Set onRejected.[[Values]] to values.
// y. Set onRejected.[[Capability]] to resultCapability.
// z. Set onRejected.[[RemainingElements]] to remainingElementsCount.
- auto* on_rejected = PromiseAllSettledRejectElementFunction::create(global_object, index, values, result_capability, remaining_elements_count);
+ auto* on_rejected = PromiseAllSettledRejectElementFunction::create(realm, index, values, result_capability, remaining_elements_count);
on_rejected->define_direct_property(vm.names.name, js_string(vm, String::empty()), Attribute::Configurable);
// ab. Perform ? Invoke(nextPromise, "then", « onFulfilled, onRejected »).
@@ -196,15 +198,16 @@ static ThrowCompletionOr<Value> perform_promise_all_settled(GlobalObject& global
static ThrowCompletionOr<Value> perform_promise_any(GlobalObject& global_object, Iterator& iterator_record, Value constructor, PromiseCapability result_capability, Value promise_resolve)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
return perform_promise_common(
global_object, iterator_record, constructor, result_capability, promise_resolve,
[&](PromiseValueList& errors) -> ThrowCompletionOr<Value> {
// 1. Let error be a newly created AggregateError object.
- auto* error = AggregateError::create(global_object);
+ auto* error = AggregateError::create(realm);
// 2. Perform ! DefinePropertyOrThrow(error, "errors", PropertyDescriptor { [[Configurable]]: true, [[Enumerable]]: false, [[Writable]]: true, [[Value]]: CreateArrayFromList(errors) }).
- auto* errors_array = Array::create_from(global_object, errors.values());
+ auto* errors_array = Array::create_from(realm, errors.values());
MUST(error->define_property_or_throw(vm.names.errors, { .value = errors_array, .writable = true, .enumerable = false, .configurable = true }));
// 3. Return ThrowCompletion(error).
@@ -219,7 +222,7 @@ static ThrowCompletionOr<Value> perform_promise_any(GlobalObject& global_object,
// o. Set onRejected.[[Errors]] to errors.
// p. Set onRejected.[[Capability]] to resultCapability.
// q. Set onRejected.[[RemainingElements]] to remainingElementsCount.
- auto* on_rejected = PromiseAnyRejectElementFunction::create(global_object, index, errors, result_capability, remaining_elements_count);
+ auto* on_rejected = PromiseAnyRejectElementFunction::create(realm, index, errors, result_capability, remaining_elements_count);
on_rejected->define_direct_property(vm.names.name, js_string(vm, String::empty()), Attribute::Configurable);
// s. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], onRejected »).
diff --git a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp
index 5beb86e457..68a29b0f3e 100644
--- a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp
@@ -70,6 +70,8 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::catch_)
// 27.2.5.3 Promise.prototype.finally ( onFinally ), https://tc39.es/ecma262/#sec-promise.prototype.finally
JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
{
+ auto& realm = *global_object.associated_realm();
+
auto on_finally = vm.argument(0);
// 1. Let promise be the this value.
@@ -100,6 +102,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
else {
// a. Let thenFinallyClosure be a new Abstract Closure with parameters (value) that captures onFinally and C and performs the following steps when called:
auto then_finally_closure = [constructor_handle = make_handle(constructor), on_finally_handle = make_handle(&on_finally.as_function())](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
+ auto& realm = *global_object.associated_realm();
auto& constructor = const_cast<FunctionObject&>(*constructor_handle.cell());
auto& on_finally = const_cast<FunctionObject&>(*on_finally_handle.cell());
auto value = vm.argument(0);
@@ -117,17 +120,18 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
};
// iv. Let valueThunk be CreateBuiltinFunction(returnValue, 0, "", « »).
- auto* value_thunk = NativeFunction::create(global_object, move(return_value), 0, "");
+ auto* value_thunk = NativeFunction::create(realm, move(return_value), 0, "");
// v. Return ? Invoke(promise, "then", « valueThunk »).
return TRY(Value(promise).invoke(global_object, vm.names.then, value_thunk));
};
// b. Let thenFinally be CreateBuiltinFunction(thenFinallyClosure, 1, "", « »).
- then_finally = NativeFunction::create(global_object, move(then_finally_closure), 1, "");
+ then_finally = NativeFunction::create(realm, move(then_finally_closure), 1, "");
// c. Let catchFinallyClosure be a new Abstract Closure with parameters (reason) that captures onFinally and C and performs the following steps when called:
auto catch_finally_closure = [constructor_handle = make_handle(constructor), on_finally_handle = make_handle(&on_finally.as_function())](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
+ auto& realm = *global_object.associated_realm();
auto& constructor = const_cast<FunctionObject&>(*constructor_handle.cell());
auto& on_finally = const_cast<FunctionObject&>(*on_finally_handle.cell());
auto reason = vm.argument(0);
@@ -145,14 +149,14 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
};
// iv. Let thrower be CreateBuiltinFunction(throwReason, 0, "", « »).
- auto* thrower = NativeFunction::create(global_object, move(throw_reason), 0, "");
+ auto* thrower = NativeFunction::create(realm, move(throw_reason), 0, "");
// v. Return ? Invoke(promise, "then", « thrower »).
return TRY(Value(promise).invoke(global_object, vm.names.then, thrower));
};
// d. Let catchFinally be CreateBuiltinFunction(catchFinallyClosure, 1, "", « »).
- catch_finally = NativeFunction::create(global_object, move(catch_finally_closure), 1, "");
+ catch_finally = NativeFunction::create(realm, move(catch_finally_closure), 1, "");
}
// 7. Return ? Invoke(promise, "then", « thenFinally, catchFinally »).
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp b/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp
index 6d6d2d51af..beadbce5b8 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp
@@ -15,6 +15,7 @@ namespace JS {
ThrowCompletionOr<PromiseCapability> new_promise_capability(GlobalObject& global_object, Value constructor)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. If IsConstructor(C) is false, throw a TypeError exception.
if (!constructor.is_constructor())
@@ -55,7 +56,7 @@ ThrowCompletionOr<PromiseCapability> new_promise_capability(GlobalObject& global
};
// 5. Let executor be CreateBuiltinFunction(executorClosure, 2, "", « »).
- auto* executor = NativeFunction::create(global_object, move(executor_closure), 2, "");
+ auto* executor = NativeFunction::create(realm, move(executor_closure), 2, "");
// 6. Let promise be ? Construct(C, « executor »).
auto* promise = TRY(construct(global_object, constructor.as_function(), executor));
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp
index b475f4b9ee..aa21e6a5e3 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp
@@ -55,9 +55,9 @@ void PromiseResolvingElementFunction::visit_edges(Cell::Visitor& visitor)
visitor.visit(&m_remaining_elements);
}
-PromiseAllResolveElementFunction* PromiseAllResolveElementFunction::create(GlobalObject& global_object, size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements)
+PromiseAllResolveElementFunction* PromiseAllResolveElementFunction::create(Realm& realm, size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements)
{
- return global_object.heap().allocate<PromiseAllResolveElementFunction>(global_object, index, values, capability, remaining_elements, *global_object.function_prototype());
+ return realm.heap().allocate<PromiseAllResolveElementFunction>(realm.global_object(), index, values, capability, remaining_elements, *realm.global_object().function_prototype());
}
PromiseAllResolveElementFunction::PromiseAllResolveElementFunction(size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements, Object& prototype)
@@ -69,6 +69,7 @@ ThrowCompletionOr<Value> PromiseAllResolveElementFunction::resolve_element()
{
auto& vm = this->vm();
auto& global_object = this->global_object();
+ auto& realm = *global_object.associated_realm();
// 8. Set values[index] to x.
m_values.values()[m_index] = vm.argument(0);
@@ -77,7 +78,7 @@ ThrowCompletionOr<Value> PromiseAllResolveElementFunction::resolve_element()
// 10. If remainingElementsCount.[[Value]] is 0, then
if (--m_remaining_elements.value == 0) {
// a. Let valuesArray be CreateArrayFromList(values).
- auto* values_array = Array::create_from(global_object, m_values.values());
+ auto* values_array = Array::create_from(realm, m_values.values());
// b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).
return JS::call(global_object, *m_capability.resolve, js_undefined(), values_array);
@@ -87,9 +88,9 @@ ThrowCompletionOr<Value> PromiseAllResolveElementFunction::resolve_element()
return js_undefined();
}
-PromiseAllSettledResolveElementFunction* PromiseAllSettledResolveElementFunction::create(GlobalObject& global_object, size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements)
+PromiseAllSettledResolveElementFunction* PromiseAllSettledResolveElementFunction::create(Realm& realm, size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements)
{
- return global_object.heap().allocate<PromiseAllSettledResolveElementFunction>(global_object, index, values, capability, remaining_elements, *global_object.function_prototype());
+ return realm.heap().allocate<PromiseAllSettledResolveElementFunction>(realm.global_object(), index, values, capability, remaining_elements, *realm.global_object().function_prototype());
}
PromiseAllSettledResolveElementFunction::PromiseAllSettledResolveElementFunction(size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements, Object& prototype)
@@ -101,9 +102,10 @@ ThrowCompletionOr<Value> PromiseAllSettledResolveElementFunction::resolve_elemen
{
auto& vm = this->vm();
auto& global_object = this->global_object();
+ auto& realm = *global_object.associated_realm();
// 9. Let obj be OrdinaryObjectCreate(%Object.prototype%).
- auto* object = Object::create(global_object, global_object.object_prototype());
+ auto* object = Object::create(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)));
@@ -118,7 +120,7 @@ ThrowCompletionOr<Value> PromiseAllSettledResolveElementFunction::resolve_elemen
// 14. If remainingElementsCount.[[Value]] is 0, then
if (--m_remaining_elements.value == 0) {
// a. Let valuesArray be CreateArrayFromList(values).
- auto* values_array = Array::create_from(global_object, m_values.values());
+ auto* values_array = Array::create_from(realm, m_values.values());
// b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).
return JS::call(global_object, *m_capability.resolve, js_undefined(), values_array);
@@ -128,9 +130,9 @@ ThrowCompletionOr<Value> PromiseAllSettledResolveElementFunction::resolve_elemen
return js_undefined();
}
-PromiseAllSettledRejectElementFunction* PromiseAllSettledRejectElementFunction::create(GlobalObject& global_object, size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements)
+PromiseAllSettledRejectElementFunction* PromiseAllSettledRejectElementFunction::create(Realm& realm, size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements)
{
- return global_object.heap().allocate<PromiseAllSettledRejectElementFunction>(global_object, index, values, capability, remaining_elements, *global_object.function_prototype());
+ return realm.heap().allocate<PromiseAllSettledRejectElementFunction>(realm.global_object(), index, values, capability, remaining_elements, *realm.global_object().function_prototype());
}
PromiseAllSettledRejectElementFunction::PromiseAllSettledRejectElementFunction(size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements, Object& prototype)
@@ -142,9 +144,10 @@ ThrowCompletionOr<Value> PromiseAllSettledRejectElementFunction::resolve_element
{
auto& vm = this->vm();
auto& global_object = this->global_object();
+ auto& realm = *global_object.associated_realm();
// 9. Let obj be OrdinaryObjectCreate(%Object.prototype%).
- auto* object = Object::create(global_object, global_object.object_prototype());
+ auto* object = Object::create(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)));
@@ -159,7 +162,7 @@ ThrowCompletionOr<Value> PromiseAllSettledRejectElementFunction::resolve_element
// 14. If remainingElementsCount.[[Value]] is 0, then
if (--m_remaining_elements.value == 0) {
// a. Let valuesArray be CreateArrayFromList(values).
- auto* values_array = Array::create_from(global_object, m_values.values());
+ auto* values_array = Array::create_from(realm, m_values.values());
// b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).
return JS::call(global_object, *m_capability.resolve, js_undefined(), values_array);
@@ -169,9 +172,9 @@ ThrowCompletionOr<Value> PromiseAllSettledRejectElementFunction::resolve_element
return js_undefined();
}
-PromiseAnyRejectElementFunction* PromiseAnyRejectElementFunction::create(GlobalObject& global_object, size_t index, PromiseValueList& errors, PromiseCapability capability, RemainingElements& remaining_elements)
+PromiseAnyRejectElementFunction* PromiseAnyRejectElementFunction::create(Realm& realm, size_t index, PromiseValueList& errors, PromiseCapability capability, RemainingElements& remaining_elements)
{
- return global_object.heap().allocate<PromiseAnyRejectElementFunction>(global_object, index, errors, capability, remaining_elements, *global_object.function_prototype());
+ return realm.heap().allocate<PromiseAnyRejectElementFunction>(realm.global_object(), index, errors, capability, remaining_elements, *realm.global_object().function_prototype());
}
PromiseAnyRejectElementFunction::PromiseAnyRejectElementFunction(size_t index, PromiseValueList& errors, PromiseCapability capability, RemainingElements& remaining_elements, Object& prototype)
@@ -183,6 +186,7 @@ ThrowCompletionOr<Value> PromiseAnyRejectElementFunction::resolve_element()
{
auto& vm = this->vm();
auto& global_object = this->global_object();
+ auto& realm = *global_object.associated_realm();
// 8. Set errors[index] to x.
m_values.values()[m_index] = vm.argument(0);
@@ -191,10 +195,10 @@ ThrowCompletionOr<Value> PromiseAnyRejectElementFunction::resolve_element()
// 10. If remainingElementsCount.[[Value]] is 0, then
if (--m_remaining_elements.value == 0) {
// a. Let error be a newly created AggregateError object.
- auto* error = AggregateError::create(global_object);
+ auto* error = AggregateError::create(realm);
// b. Perform ! DefinePropertyOrThrow(error, "errors", PropertyDescriptor { [[Configurable]]: true, [[Enumerable]]: false, [[Writable]]: true, [[Value]]: CreateArrayFromList(errors) }).
- auto* errors_array = Array::create_from(global_object, m_values.values());
+ auto* errors_array = Array::create_from(realm, m_values.values());
MUST(error->define_property_or_throw(vm.names.errors, { .value = errors_array, .writable = true, .enumerable = false, .configurable = true }));
// c. Return ? Call(promiseCapability.[[Reject]], undefined, « error »).
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.h b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.h
index 3e2cc4f6cf..8f7113347d 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.h
+++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.h
@@ -71,7 +71,7 @@ class PromiseAllResolveElementFunction final : public PromiseResolvingElementFun
JS_OBJECT(PromiseResolvingFunction, NativeFunction);
public:
- static PromiseAllResolveElementFunction* create(GlobalObject&, size_t, PromiseValueList&, PromiseCapability, RemainingElements&);
+ static PromiseAllResolveElementFunction* create(Realm&, size_t, PromiseValueList&, PromiseCapability, RemainingElements&);
explicit PromiseAllResolveElementFunction(size_t, PromiseValueList&, PromiseCapability, RemainingElements&, Object& prototype);
virtual ~PromiseAllResolveElementFunction() override = default;
@@ -85,7 +85,7 @@ class PromiseAllSettledResolveElementFunction final : public PromiseResolvingEle
JS_OBJECT(PromiseResolvingFunction, NativeFunction);
public:
- static PromiseAllSettledResolveElementFunction* create(GlobalObject&, size_t, PromiseValueList&, PromiseCapability, RemainingElements&);
+ static PromiseAllSettledResolveElementFunction* create(Realm&, size_t, PromiseValueList&, PromiseCapability, RemainingElements&);
explicit PromiseAllSettledResolveElementFunction(size_t, PromiseValueList&, PromiseCapability, RemainingElements&, Object& prototype);
virtual ~PromiseAllSettledResolveElementFunction() override = default;
@@ -99,7 +99,7 @@ class PromiseAllSettledRejectElementFunction final : public PromiseResolvingElem
JS_OBJECT(PromiseResolvingFunction, PromiseResolvingElementFunction);
public:
- static PromiseAllSettledRejectElementFunction* create(GlobalObject&, size_t, PromiseValueList&, PromiseCapability, RemainingElements&);
+ static PromiseAllSettledRejectElementFunction* create(Realm&, size_t, PromiseValueList&, PromiseCapability, RemainingElements&);
explicit PromiseAllSettledRejectElementFunction(size_t, PromiseValueList&, PromiseCapability, RemainingElements&, Object& prototype);
virtual ~PromiseAllSettledRejectElementFunction() override = default;
@@ -113,7 +113,7 @@ class PromiseAnyRejectElementFunction final : public PromiseResolvingElementFunc
JS_OBJECT(PromiseResolvingFunction, PromiseResolvingElementFunction);
public:
- static PromiseAnyRejectElementFunction* create(GlobalObject&, size_t, PromiseValueList&, PromiseCapability, RemainingElements&);
+ static PromiseAnyRejectElementFunction* create(Realm&, size_t, PromiseValueList&, PromiseCapability, RemainingElements&);
explicit PromiseAnyRejectElementFunction(size_t, PromiseValueList&, PromiseCapability, RemainingElements&, Object& prototype);
virtual ~PromiseAnyRejectElementFunction() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp
index 8dfa505b2a..b556ab154a 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp
@@ -11,9 +11,9 @@
namespace JS {
-PromiseResolvingFunction* PromiseResolvingFunction::create(GlobalObject& global_object, Promise& promise, AlreadyResolved& already_resolved, FunctionType function)
+PromiseResolvingFunction* PromiseResolvingFunction::create(Realm& realm, Promise& promise, AlreadyResolved& already_resolved, FunctionType function)
{
- return global_object.heap().allocate<PromiseResolvingFunction>(global_object, promise, already_resolved, move(function), *global_object.function_prototype());
+ return realm.heap().allocate<PromiseResolvingFunction>(realm.global_object(), promise, already_resolved, move(function), *realm.global_object().function_prototype());
}
PromiseResolvingFunction::PromiseResolvingFunction(Promise& promise, AlreadyResolved& already_resolved, FunctionType native_function, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.h b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.h
index 66f7c27b63..fede9b09b5 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.h
+++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.h
@@ -28,7 +28,7 @@ class PromiseResolvingFunction final : public NativeFunction {
public:
using FunctionType = Function<ThrowCompletionOr<Value>(VM&, GlobalObject&, Promise&, AlreadyResolved&)>;
- static PromiseResolvingFunction* create(GlobalObject&, Promise&, AlreadyResolved&, FunctionType);
+ static PromiseResolvingFunction* create(Realm&, Promise&, AlreadyResolved&, FunctionType);
explicit PromiseResolvingFunction(Promise&, AlreadyResolved&, FunctionType, Object& prototype);
virtual void initialize(Realm&) override;
diff --git a/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.cpp b/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.cpp
index fcdbb36b59..e5130e90b0 100644
--- a/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.cpp
@@ -67,10 +67,11 @@ bool PropertyDescriptor::is_generic_descriptor() const
// 6.2.5.4 FromPropertyDescriptor ( Desc ), https://tc39.es/ecma262/#sec-frompropertydescriptor
Value from_property_descriptor(GlobalObject& global_object, Optional<PropertyDescriptor> const& property_descriptor)
{
+ auto& realm = *global_object.associated_realm();
if (!property_descriptor.has_value())
return js_undefined();
auto& vm = global_object.vm();
- auto* object = Object::create(global_object, global_object.object_prototype());
+ auto* object = Object::create(realm, global_object.object_prototype());
if (property_descriptor->value.has_value())
MUST(object->create_data_property_or_throw(vm.names.value, *property_descriptor->value));
if (property_descriptor->writable.has_value())
diff --git a/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp
index 50db1a1a85..2d4f75927c 100644
--- a/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp
@@ -17,11 +17,12 @@ namespace JS {
static ThrowCompletionOr<ProxyObject*> proxy_create(GlobalObject& global_object, Value target, Value handler)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
if (!target.is_object())
return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyConstructorBadType, "target", target.to_string_without_side_effects());
if (!handler.is_object())
return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyConstructorBadType, "handler", handler.to_string_without_side_effects());
- return ProxyObject::create(global_object, target.as_object(), handler.as_object());
+ return ProxyObject::create(realm, target.as_object(), handler.as_object());
}
ProxyConstructor::ProxyConstructor(Realm& realm)
@@ -56,6 +57,8 @@ ThrowCompletionOr<Object*> ProxyConstructor::construct(FunctionObject&)
// 28.2.2.1 Proxy.revocable ( target, handler ), https://tc39.es/ecma262/#sec-proxy.revocable
JS_DEFINE_NATIVE_FUNCTION(ProxyConstructor::revocable)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let p be ? ProxyCreate(target, handler).
auto* proxy = TRY(proxy_create(global_object, vm.argument(0), vm.argument(1)));
@@ -82,10 +85,10 @@ JS_DEFINE_NATIVE_FUNCTION(ProxyConstructor::revocable)
// 3. Let revoker be CreateBuiltinFunction(revokerClosure, 0, "", « [[RevocableProxy]] »).
// 4. Set revoker.[[RevocableProxy]] to p.
- auto* revoker = NativeFunction::create(global_object, move(revoker_closure), 0, "");
+ auto* revoker = NativeFunction::create(realm, move(revoker_closure), 0, "");
// 5. Let result be OrdinaryObjectCreate(%Object.prototype%).
- auto* result = Object::create(global_object, global_object.object_prototype());
+ auto* result = Object::create(realm, global_object.object_prototype());
// 6. Perform ! CreateDataPropertyOrThrow(result, "proxy", p).
MUST(result->create_data_property_or_throw(vm.names.proxy, proxy));
diff --git a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
index b000b35ed5..2ff103201c 100644
--- a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
@@ -15,9 +15,9 @@
namespace JS {
-ProxyObject* ProxyObject::create(GlobalObject& global_object, Object& target, Object& handler)
+ProxyObject* ProxyObject::create(Realm& realm, Object& target, Object& handler)
{
- return global_object.heap().allocate<ProxyObject>(global_object, target, handler, *global_object.object_prototype());
+ return realm.heap().allocate<ProxyObject>(realm.global_object(), target, handler, *realm.global_object().object_prototype());
}
ProxyObject::ProxyObject(Object& target, Object& handler, Object& prototype)
@@ -756,6 +756,7 @@ ThrowCompletionOr<Value> ProxyObject::internal_call(Value this_argument, MarkedV
{
auto& vm = this->vm();
auto& global_object = this->global_object();
+ auto& realm = *global_object.associated_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.
@@ -783,7 +784,7 @@ ThrowCompletionOr<Value> ProxyObject::internal_call(Value this_argument, MarkedV
}
// 7. Let argArray be CreateArrayFromList(argumentsList).
- auto* arguments_array = Array::create_from(global_object, arguments_list);
+ auto* arguments_array = Array::create_from(realm, arguments_list);
// 8. Return ? Call(trap, handler, « target, thisArgument, argArray »).
return call(global_object, trap, &m_handler, &m_target, this_argument, arguments_array);
@@ -804,6 +805,7 @@ ThrowCompletionOr<Object*> ProxyObject::internal_construct(MarkedVector<Value> a
{
auto& vm = this->vm();
auto& global_object = this->global_object();
+ auto& realm = *global_object.associated_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.
@@ -831,7 +833,7 @@ ThrowCompletionOr<Object*> ProxyObject::internal_construct(MarkedVector<Value> a
}
// 8. Let argArray be CreateArrayFromList(argumentsList).
- auto* arguments_array = Array::create_from(global_object, arguments_list);
+ auto* arguments_array = Array::create_from(realm, arguments_list);
// 9. Let newObj be ? Call(trap, handler, « target, argArray, newTarget »).
auto new_object = TRY(call(global_object, trap, &m_handler, &m_target, arguments_array, &new_target));
diff --git a/Userland/Libraries/LibJS/Runtime/ProxyObject.h b/Userland/Libraries/LibJS/Runtime/ProxyObject.h
index 572bafc64d..b6c228641a 100644
--- a/Userland/Libraries/LibJS/Runtime/ProxyObject.h
+++ b/Userland/Libraries/LibJS/Runtime/ProxyObject.h
@@ -16,7 +16,7 @@ class ProxyObject final : public FunctionObject {
JS_OBJECT(ProxyObject, FunctionObject);
public:
- static ProxyObject* create(GlobalObject&, Object& target, Object& handler);
+ static ProxyObject* create(Realm&, Object& target, Object& handler);
ProxyObject(Object& target, Object& handler, Object& prototype);
virtual ~ProxyObject() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp
index edc52b2db1..a6b39ffadf 100644
--- a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp
@@ -215,6 +215,8 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::is_extensible)
// 28.1.10 Reflect.ownKeys ( target ), https://tc39.es/ecma262/#sec-reflect.ownkeys
JS_DEFINE_NATIVE_FUNCTION(ReflectObject::own_keys)
{
+ auto& realm = *global_object.associated_realm();
+
auto target = vm.argument(0);
// 1. If Type(target) is not Object, throw a TypeError exception.
@@ -225,7 +227,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::own_keys)
auto keys = TRY(target.as_object().internal_own_property_keys());
// 3. Return CreateArrayFromList(keys).
- return Array::create_from(global_object, keys);
+ return Array::create_from(realm, keys);
}
// 28.1.11 Reflect.preventExtensions ( target ), https://tc39.es/ecma262/#sec-reflect.preventextensions
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp b/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp
index d7a0c717e2..f91c8581eb 100644
--- a/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp
@@ -122,14 +122,14 @@ ThrowCompletionOr<String> parse_regex_pattern(StringView pattern, VM& vm, Global
return result.release_value();
}
-RegExpObject* RegExpObject::create(GlobalObject& global_object)
+RegExpObject* RegExpObject::create(Realm& realm)
{
- return global_object.heap().allocate<RegExpObject>(global_object, *global_object.regexp_prototype());
+ return realm.heap().allocate<RegExpObject>(realm.global_object(), *realm.global_object().regexp_prototype());
}
-RegExpObject* RegExpObject::create(GlobalObject& global_object, Regex<ECMA262> regex, String pattern, String flags)
+RegExpObject* RegExpObject::create(Realm& realm, Regex<ECMA262> regex, String pattern, String flags)
{
- return global_object.heap().allocate<RegExpObject>(global_object, move(regex), move(pattern), move(flags), *global_object.regexp_prototype());
+ return realm.heap().allocate<RegExpObject>(realm.global_object(), move(regex), move(pattern), move(flags), *realm.global_object().regexp_prototype());
}
RegExpObject::RegExpObject(Object& prototype)
@@ -207,7 +207,8 @@ String RegExpObject::escape_regexp_pattern() const
// 22.2.3.2.4 RegExpCreate ( P, F ), https://tc39.es/ecma262/#sec-regexpcreate
ThrowCompletionOr<RegExpObject*> regexp_create(GlobalObject& global_object, Value pattern, Value flags)
{
- auto* regexp_object = RegExpObject::create(global_object);
+ auto& realm = *global_object.associated_realm();
+ auto* regexp_object = RegExpObject::create(realm);
return TRY(regexp_object->regexp_initialize(global_object, pattern, flags));
}
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpObject.h b/Userland/Libraries/LibJS/Runtime/RegExpObject.h
index 8497239813..ddce90133a 100644
--- a/Userland/Libraries/LibJS/Runtime/RegExpObject.h
+++ b/Userland/Libraries/LibJS/Runtime/RegExpObject.h
@@ -36,8 +36,8 @@ public:
| regex::ECMAScriptFlags::BrowserExtended
};
- static RegExpObject* create(GlobalObject&);
- static RegExpObject* create(GlobalObject&, Regex<ECMA262> regex, String pattern, String flags);
+ static RegExpObject* create(Realm&);
+ static RegExpObject* create(Realm&, Regex<ECMA262> regex, String pattern, String flags);
RegExpObject(Object& prototype);
RegExpObject(Regex<ECMA262> regex, String pattern, String flags, Object& prototype);
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp
index 219f5e5a05..c23f6202dc 100644
--- a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp
@@ -82,6 +82,8 @@ struct Match {
// 22.2.5.2.7 GetMatchIndexPair ( S, match ), https://tc39.es/ecma262/#sec-getmatchindexpair
static Value get_match_index_par(GlobalObject& global_object, Utf16View const& string, Match const& match)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Assert: match.[[StartIndex]] is an integer value ≥ 0 and ≤ the length of S.
VERIFY(match.start_index <= string.length_in_code_units());
@@ -90,7 +92,7 @@ static Value get_match_index_par(GlobalObject& global_object, Utf16View const& s
VERIFY(match.end_index <= string.length_in_code_units());
// 3. Return CreateArrayFromList(« match.[[StartIndex]], match.[[EndIndex]] »).
- return Array::create_from(global_object, { Value(match.start_index), Value(match.end_index) });
+ return Array::create_from(realm, { Value(match.start_index), Value(match.end_index) });
}
// 22.2.5.2.8 MakeMatchIndicesIndexPairArray ( S, indices, groupNames, hasGroups ), https://tc39.es/ecma262/#sec-makematchindicesindexpairarray
@@ -111,6 +113,7 @@ static Value make_match_indices_index_pair_array(GlobalObject& global_object, Ut
// names align with the indices. The end result is the same.
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let n be the number of elements in indices.
// 2. Assert: n < 2^32-1.
@@ -120,13 +123,13 @@ static Value make_match_indices_index_pair_array(GlobalObject& global_object, Ut
// 4. NOTE: The groupNames List contains elements aligned with the indices List starting at indices[1].
// 5. Set A to ! ArrayCreate(n).
- auto* array = MUST(Array::create(global_object, indices.size()));
+ auto* array = MUST(Array::create(realm, indices.size()));
// 6. If hasGroups is true, then
// a. Let groups be ! ObjectCreate(null).
// 7. Else,
// a. Let groups be undefined.
- auto groups = has_groups ? Object::create(global_object, nullptr) : js_undefined();
+ auto groups = has_groups ? Object::create(realm, nullptr) : js_undefined();
// 9. For each integer i such that i ≥ 0 and i < n, do
for (size_t i = 0; i < indices.size(); ++i) {
@@ -166,6 +169,7 @@ static Value make_match_indices_index_pair_array(GlobalObject& global_object, Ut
static ThrowCompletionOr<Value> regexp_builtin_exec(GlobalObject& global_object, RegExpObject& regexp_object, Utf16String string)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let length be the length of S.
// 2. Let lastIndex be ℝ(? ToLength(? Get(R, "lastIndex"))).
@@ -251,7 +255,7 @@ static ThrowCompletionOr<Value> regexp_builtin_exec(GlobalObject& global_object,
VERIFY(result.n_named_capture_groups < NumericLimits<u32>::max());
// 19. Let A be ! ArrayCreate(n + 1).
- auto* array = MUST(Array::create(global_object, result.n_named_capture_groups + 1));
+ auto* array = MUST(Array::create(realm, result.n_named_capture_groups + 1));
// 20. Assert: The mathematical value of A's "length" property is n + 1.
@@ -281,7 +285,7 @@ static ThrowCompletionOr<Value> regexp_builtin_exec(GlobalObject& global_object,
// a. Let groups be undefined.
// b. Let hasGroups be false.
bool has_groups = result.n_named_capture_groups != 0;
- Object* groups_object = has_groups ? Object::create(global_object, nullptr) : nullptr;
+ Object* groups_object = has_groups ? Object::create(realm, nullptr) : nullptr;
// 32. For each integer i such that i ≥ 1 and i ≤ n, in ascending order, do
for (size_t i = 1; i <= result.n_capture_groups; ++i) {
@@ -489,6 +493,8 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::flags)
// With changes from https://arai-a.github.io/ecma262-compare/?pr=2418&id=sec-regexp.prototype-%2540%2540match
JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let rx be the this value.
// 2. If Type(rx) is not Object, throw a TypeError exception.
auto* regexp_object = TRY(this_object(global_object));
@@ -519,7 +525,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match)
TRY(regexp_object->set(vm.names.lastIndex, Value(0), Object::ShouldThrowExceptions::Yes));
// e. Let A be ! ArrayCreate(0).
- auto* array = MUST(Array::create(global_object, 0));
+ auto* array = MUST(Array::create(realm, 0));
// f. Let n be 0.
size_t n = 0;
@@ -563,6 +569,8 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match)
// With changes from https://arai-a.github.io/ecma262-compare/?pr=2418&id=sec-regexp-prototype-matchall
JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match_all)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let R be the this value.
// 2. If Type(R) is not Object, throw a TypeError exception.
auto* regexp_object = TRY(this_object(global_object));
@@ -598,7 +606,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match_all)
TRY(matcher->set(vm.names.lastIndex, Value(last_index), Object::ShouldThrowExceptions::Yes));
// 13. Return CreateRegExpStringIterator(matcher, S, global, fullUnicode).
- return RegExpStringIterator::create(global_object, *matcher, move(string), global, full_unicode);
+ return RegExpStringIterator::create(realm, *matcher, move(string), global, full_unicode);
}
// 22.2.5.11 RegExp.prototype [ @@replace ] ( string, replaceValue ), https://tc39.es/ecma262/#sec-regexp.prototype-@@replace
@@ -861,6 +869,8 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::source)
// 22.2.5.14 RegExp.prototype [ @@split ] ( string, limit ), https://tc39.es/ecma262/#sec-regexp.prototype-@@split
JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let rx be the this value.
// 2. If Type(rx) is not Object, throw a TypeError exception.
auto* regexp_object = TRY(this_object(global_object));
@@ -887,7 +897,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split)
auto* splitter = TRY(construct(global_object, *constructor, regexp_object, js_string(vm, move(new_flags))));
// 11. Let A be ! ArrayCreate(0).
- auto* array = MUST(Array::create(global_object, 0));
+ auto* array = MUST(Array::create(realm, 0));
// 12. Let lengthA be 0.
size_t array_length = 0;
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp b/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp
index 26832f63ee..ca57f3733f 100644
--- a/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp
+++ b/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp
@@ -10,9 +10,9 @@
namespace JS {
// 22.2.7.1 CreateRegExpStringIterator ( R, S, global, fullUnicode ), https://tc39.es/ecma262/#sec-createregexpstringiterator
-RegExpStringIterator* RegExpStringIterator::create(GlobalObject& global_object, Object& regexp_object, Utf16String string, bool global, bool unicode)
+RegExpStringIterator* RegExpStringIterator::create(Realm& realm, Object& regexp_object, Utf16String string, bool global, bool unicode)
{
- return global_object.heap().allocate<RegExpStringIterator>(global_object, *global_object.regexp_string_iterator_prototype(), regexp_object, move(string), global, unicode);
+ return realm.heap().allocate<RegExpStringIterator>(realm.global_object(), *realm.global_object().regexp_string_iterator_prototype(), regexp_object, move(string), global, unicode);
}
RegExpStringIterator::RegExpStringIterator(Object& prototype, Object& regexp_object, Utf16String string, bool global, bool unicode)
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.h b/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.h
index 3320bad52a..ad46bbf42b 100644
--- a/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.h
+++ b/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.h
@@ -16,7 +16,7 @@ class RegExpStringIterator final : public Object {
JS_OBJECT(RegExpStringIterator, Object);
public:
- static RegExpStringIterator* create(GlobalObject&, Object& regexp_object, Utf16String string, bool global, bool unicode);
+ static RegExpStringIterator* create(Realm&, Object& regexp_object, Utf16String string, bool global, bool unicode);
explicit RegExpStringIterator(Object& prototype, Object& regexp_object, Utf16String string, bool global, bool unicode);
virtual ~RegExpStringIterator() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/Set.cpp b/Userland/Libraries/LibJS/Runtime/Set.cpp
index dd143e7e88..83779d0d28 100644
--- a/Userland/Libraries/LibJS/Runtime/Set.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Set.cpp
@@ -8,9 +8,9 @@
namespace JS {
-Set* Set::create(GlobalObject& global_object)
+Set* Set::create(Realm& realm)
{
- return global_object.heap().allocate<Set>(global_object, *global_object.set_prototype());
+ return realm.heap().allocate<Set>(realm.global_object(), *realm.global_object().set_prototype());
}
Set::Set(Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/Set.h b/Userland/Libraries/LibJS/Runtime/Set.h
index 8f3f09050e..af3ff7890f 100644
--- a/Userland/Libraries/LibJS/Runtime/Set.h
+++ b/Userland/Libraries/LibJS/Runtime/Set.h
@@ -17,7 +17,7 @@ class Set : public Object {
JS_OBJECT(Set, Object);
public:
- static Set* create(GlobalObject&);
+ static Set* create(Realm&);
explicit Set(Object& prototype);
virtual ~Set() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/SetIterator.cpp b/Userland/Libraries/LibJS/Runtime/SetIterator.cpp
index 1e39672668..d8ce9f73ea 100644
--- a/Userland/Libraries/LibJS/Runtime/SetIterator.cpp
+++ b/Userland/Libraries/LibJS/Runtime/SetIterator.cpp
@@ -9,9 +9,9 @@
namespace JS {
-SetIterator* SetIterator::create(GlobalObject& global_object, Set& set, Object::PropertyKind iteration_kind)
+SetIterator* SetIterator::create(Realm& realm, Set& set, Object::PropertyKind iteration_kind)
{
- return global_object.heap().allocate<SetIterator>(global_object, set, iteration_kind, *global_object.set_iterator_prototype());
+ return realm.heap().allocate<SetIterator>(realm.global_object(), set, iteration_kind, *realm.global_object().set_iterator_prototype());
}
SetIterator::SetIterator(Set& set, Object::PropertyKind iteration_kind, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/SetIterator.h b/Userland/Libraries/LibJS/Runtime/SetIterator.h
index 1204de9382..8b077c7f51 100644
--- a/Userland/Libraries/LibJS/Runtime/SetIterator.h
+++ b/Userland/Libraries/LibJS/Runtime/SetIterator.h
@@ -16,7 +16,7 @@ class SetIterator final : public Object {
JS_OBJECT(SetIterator, Object);
public:
- static SetIterator* create(GlobalObject&, Set& set, Object::PropertyKind iteration_kind);
+ static SetIterator* create(Realm&, Set& set, Object::PropertyKind iteration_kind);
explicit SetIterator(Set& set, Object::PropertyKind iteration_kind, Object& prototype);
virtual ~SetIterator() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp
index 801fae3358..a2495161c3 100644
--- a/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp
@@ -32,6 +32,8 @@ void SetIteratorPrototype::initialize(Realm& realm)
// 24.2.5.2.1 %SetIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%setiteratorprototype%.next
JS_DEFINE_NATIVE_FUNCTION(SetIteratorPrototype::next)
{
+ auto& realm = *global_object.associated_realm();
+
auto* set_iterator = TRY(typed_this_value(global_object));
if (set_iterator->done())
return create_iterator_result_object(global_object, js_undefined(), true);
@@ -50,7 +52,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetIteratorPrototype::next)
if (iteration_kind == Object::PropertyKind::Value)
return create_iterator_result_object(global_object, value, false);
- return create_iterator_result_object(global_object, Array::create_from(global_object, { value, value }), false);
+ return create_iterator_result_object(global_object, Array::create_from(realm, { value, value }), false);
}
}
diff --git a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp
index eda345cca4..2035550653 100644
--- a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp
@@ -70,9 +70,11 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::delete_)
// 24.2.3.5 Set.prototype.entries ( ), https://tc39.es/ecma262/#sec-set.prototype.entries
JS_DEFINE_NATIVE_FUNCTION(SetPrototype::entries)
{
+ auto& realm = *global_object.associated_realm();
+
auto* set = TRY(typed_this_object(global_object));
- return SetIterator::create(global_object, *set, Object::PropertyKind::KeyAndValue);
+ return SetIterator::create(realm, *set, Object::PropertyKind::KeyAndValue);
}
// 24.2.3.6 Set.prototype.forEach ( callbackfn [ , thisArg ] ), https://tc39.es/ecma262/#sec-set.prototype.foreach
@@ -97,9 +99,11 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::has)
// 24.2.3.10 Set.prototype.values ( ), https://tc39.es/ecma262/#sec-set.prototype.values
JS_DEFINE_NATIVE_FUNCTION(SetPrototype::values)
{
+ auto& realm = *global_object.associated_realm();
+
auto* set = TRY(typed_this_object(global_object));
- return SetIterator::create(global_object, *set, Object::PropertyKind::Value);
+ return SetIterator::create(realm, *set, Object::PropertyKind::Value);
}
// 24.2.3.9 get Set.prototype.size, https://tc39.es/ecma262/#sec-get-set.prototype.size
diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp
index df3dfe34de..03a7eba4ae 100644
--- a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp
@@ -205,6 +205,7 @@ ThrowCompletionOr<Value> perform_shadow_realm_eval(GlobalObject& global_object,
ThrowCompletionOr<Value> shadow_realm_import_value(GlobalObject& global_object, String specifier_string, String export_name_string, Realm& caller_realm, Realm& eval_realm, ExecutionContext& eval_context)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Assert: evalContext is an execution context associated to a ShadowRealm instance's [[ExecutionContext]].
@@ -261,14 +262,14 @@ ThrowCompletionOr<Value> shadow_realm_import_value(GlobalObject& global_object,
// 10. Let onFulfilled be CreateBuiltinFunction(steps, 1, "", « [[ExportNameString]] », callerRealm).
// 11. Set onFulfilled.[[ExportNameString]] to exportNameString.
- auto* on_fulfilled = NativeFunction::create(global_object, move(steps), 1, "", &caller_realm);
+ auto* on_fulfilled = NativeFunction::create(realm, move(steps), 1, "", &caller_realm);
// 12. Let promiseCapability be ! NewPromiseCapability(%Promise%).
auto promise_capability = MUST(new_promise_capability(global_object, global_object.promise_constructor()));
// NOTE: Even though the spec tells us to use %ThrowTypeError%, it's not observable if we actually do.
// Throw a nicer TypeError forwarding the import error message instead (we know the argument is an Error object).
- auto* throw_type_error = NativeFunction::create(global_object, {}, [](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
+ auto* throw_type_error = NativeFunction::create(realm, {}, [](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
return vm.template throw_completion<TypeError>(global_object, vm.argument(0).as_object().get_without_side_effects(vm.names.message).as_string().string());
});
@@ -280,6 +281,7 @@ ThrowCompletionOr<Value> shadow_realm_import_value(GlobalObject& global_object,
ThrowCompletionOr<Value> get_wrapped_value(GlobalObject& global_object, Realm& caller_realm, Value value)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. If Type(value) is Object, then
if (value.is_object()) {
@@ -288,7 +290,7 @@ ThrowCompletionOr<Value> get_wrapped_value(GlobalObject& global_object, Realm& c
return vm.throw_completion<TypeError>(global_object, ErrorType::ShadowRealmWrappedValueNonFunctionObject, value);
// b. Return ? WrappedFunctionCreate(callerRealm, value).
- return TRY(WrappedFunction::create(global_object, caller_realm, value.as_function()));
+ return TRY(WrappedFunction::create(realm, caller_realm, value.as_function()));
}
// 2. Return value.
diff --git a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp
index a37ef86003..167feab1b6 100644
--- a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp
@@ -51,15 +51,17 @@ ThrowCompletionOr<Value> StringConstructor::call()
// 22.1.1.1 String ( value ), https://tc39.es/ecma262/#sec-string-constructor-string-value
ThrowCompletionOr<Object*> StringConstructor::construct(FunctionObject& new_target)
{
- auto& vm = global_object().vm();
+ auto& vm = this->vm();
+ auto& global_object = this->global_object();
+ auto& realm = *global_object.associated_realm();
PrimitiveString* primitive_string;
if (!vm.argument_count())
primitive_string = js_string(vm, "");
else
- primitive_string = TRY(vm.argument(0).to_primitive_string(global_object()));
- auto* prototype = TRY(get_prototype_from_constructor(global_object(), new_target, &GlobalObject::string_prototype));
- return StringObject::create(global_object(), *primitive_string, *prototype);
+ primitive_string = TRY(vm.argument(0).to_primitive_string(global_object));
+ auto* prototype = TRY(get_prototype_from_constructor(global_object, new_target, &GlobalObject::string_prototype));
+ return StringObject::create(realm, *primitive_string, *prototype);
}
// 22.1.2.4 String.raw ( template, ...substitutions ), https://tc39.es/ecma262/#sec-string.raw
diff --git a/Userland/Libraries/LibJS/Runtime/StringIterator.cpp b/Userland/Libraries/LibJS/Runtime/StringIterator.cpp
index eb1c931477..9c75302a4a 100644
--- a/Userland/Libraries/LibJS/Runtime/StringIterator.cpp
+++ b/Userland/Libraries/LibJS/Runtime/StringIterator.cpp
@@ -10,9 +10,9 @@
namespace JS {
-StringIterator* StringIterator::create(GlobalObject& global_object, String string)
+StringIterator* StringIterator::create(Realm& realm, String string)
{
- return global_object.heap().allocate<StringIterator>(global_object, move(string), *global_object.string_iterator_prototype());
+ return realm.heap().allocate<StringIterator>(realm.global_object(), move(string), *realm.global_object().string_iterator_prototype());
}
StringIterator::StringIterator(String string, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/StringIterator.h b/Userland/Libraries/LibJS/Runtime/StringIterator.h
index 592b441713..fead3dd09b 100644
--- a/Userland/Libraries/LibJS/Runtime/StringIterator.h
+++ b/Userland/Libraries/LibJS/Runtime/StringIterator.h
@@ -15,7 +15,7 @@ class StringIterator final : public Object {
JS_OBJECT(StringIterator, Object);
public:
- static StringIterator* create(GlobalObject&, String string);
+ static StringIterator* create(Realm&, String string);
explicit StringIterator(String string, Object& prototype);
virtual ~StringIterator() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/StringObject.cpp b/Userland/Libraries/LibJS/Runtime/StringObject.cpp
index 5285d5fe76..8106d8776e 100644
--- a/Userland/Libraries/LibJS/Runtime/StringObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/StringObject.cpp
@@ -15,9 +15,9 @@
namespace JS {
// 10.4.3.4 StringCreate ( value, prototype ), https://tc39.es/ecma262/#sec-stringcreate
-StringObject* StringObject::create(GlobalObject& global_object, PrimitiveString& primitive_string, Object& prototype)
+StringObject* StringObject::create(Realm& realm, PrimitiveString& primitive_string, Object& prototype)
{
- return global_object.heap().allocate<StringObject>(global_object, primitive_string, prototype);
+ return realm.heap().allocate<StringObject>(realm.global_object(), primitive_string, prototype);
}
StringObject::StringObject(PrimitiveString& string, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/StringObject.h b/Userland/Libraries/LibJS/Runtime/StringObject.h
index 1c2c457754..eeda31ba33 100644
--- a/Userland/Libraries/LibJS/Runtime/StringObject.h
+++ b/Userland/Libraries/LibJS/Runtime/StringObject.h
@@ -14,7 +14,7 @@ class StringObject : public Object {
JS_OBJECT(StringObject, Object);
public:
- static StringObject* create(GlobalObject&, PrimitiveString&, Object& prototype);
+ static StringObject* create(Realm&, PrimitiveString&, Object& prototype);
StringObject(PrimitiveString&, Object& prototype);
virtual void initialize(Realm&) override;
diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp
index b6816fd8aa..a48a5c2217 100644
--- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp
@@ -650,6 +650,8 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::slice)
// 22.1.3.22 String.prototype.split ( separator, limit ), https://tc39.es/ecma262/#sec-string.prototype.split
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::split)
{
+ auto& realm = *global_object.associated_realm();
+
auto object = TRY(require_object_coercible(global_object, vm.this_value(global_object)));
auto separator_argument = vm.argument(0);
@@ -663,7 +665,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::split)
auto string = TRY(object.to_utf16_string(global_object));
- auto* array = MUST(Array::create(global_object, 0));
+ auto* array = MUST(Array::create(realm, 0));
size_t array_length = 0;
auto limit = NumericLimits<u32>::max();
@@ -771,9 +773,11 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::at)
// 22.1.3.34 String.prototype [ @@iterator ] ( ), https://tc39.es/ecma262/#sec-string.prototype-@@iterator
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::symbol_iterator)
{
+ auto& realm = *global_object.associated_realm();
+
auto this_object = TRY(require_object_coercible(global_object, vm.this_value(global_object)));
auto string = TRY(this_object.to_string(global_object));
- return StringIterator::create(global_object, string);
+ return StringIterator::create(realm, string);
}
// 22.1.3.12 String.prototype.match ( regexp ), https://tc39.es/ecma262/#sec-string.prototype.match
diff --git a/Userland/Libraries/LibJS/Runtime/SymbolObject.cpp b/Userland/Libraries/LibJS/Runtime/SymbolObject.cpp
index 7a4dee5480..08418fa0f9 100644
--- a/Userland/Libraries/LibJS/Runtime/SymbolObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/SymbolObject.cpp
@@ -10,9 +10,9 @@
namespace JS {
-SymbolObject* SymbolObject::create(GlobalObject& global_object, Symbol& primitive_symbol)
+SymbolObject* SymbolObject::create(Realm& realm, Symbol& primitive_symbol)
{
- return global_object.heap().allocate<SymbolObject>(global_object, primitive_symbol, *global_object.symbol_prototype());
+ return realm.heap().allocate<SymbolObject>(realm.global_object(), primitive_symbol, *realm.global_object().symbol_prototype());
}
SymbolObject::SymbolObject(Symbol& symbol, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/SymbolObject.h b/Userland/Libraries/LibJS/Runtime/SymbolObject.h
index 8d3ba8607c..bf04e5a09b 100644
--- a/Userland/Libraries/LibJS/Runtime/SymbolObject.h
+++ b/Userland/Libraries/LibJS/Runtime/SymbolObject.h
@@ -15,7 +15,7 @@ class SymbolObject : public Object {
JS_OBJECT(SymbolObject, Object);
public:
- static SymbolObject* create(GlobalObject&, Symbol&);
+ static SymbolObject* create(Realm&, Symbol&);
SymbolObject(Symbol&, Object& prototype);
virtual ~SymbolObject() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
index 9735e34269..f5adef89f0 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
@@ -82,11 +82,12 @@ ThrowCompletionOr<MarkedVector<Value>> iterable_to_list_of_type(GlobalObject& gl
ThrowCompletionOr<Object*> get_options_object(GlobalObject& global_object, Value options)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. If options is undefined, then
if (options.is_undefined()) {
// a. Return OrdinaryObjectCreate(null).
- return Object::create(global_object, nullptr);
+ return Object::create(realm, nullptr);
}
// 2. If Type(options) is Object, then
@@ -552,6 +553,7 @@ ThrowCompletionOr<Optional<String>> get_temporal_unit(GlobalObject& global_objec
ThrowCompletionOr<Value> to_relative_temporal_object(GlobalObject& global_object, Object const& options)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Assert: Type(options) is Object.
@@ -603,7 +605,7 @@ ThrowCompletionOr<Value> to_relative_temporal_object(GlobalObject& global_object
auto* fields = TRY(prepare_temporal_fields(global_object, value_object, field_names, Vector<StringView> {}));
// f. Let dateOptions be OrdinaryObjectCreate(null).
- auto* date_options = Object::create(global_object, nullptr);
+ auto* date_options = Object::create(realm, nullptr);
// g. Perform ! CreateDataPropertyOrThrow(dateOptions, "overflow", "constrain").
MUST(date_options->create_data_property_or_throw(vm.names.overflow, js_string(vm, "constrain"sv)));
@@ -743,9 +745,10 @@ StringView larger_of_two_temporal_units(StringView unit1, StringView unit2)
ThrowCompletionOr<Object*> merge_largest_unit_option(GlobalObject& global_object, Object const& options, String largest_unit)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let merged be OrdinaryObjectCreate(null).
- auto* merged = Object::create(global_object, nullptr);
+ auto* merged = Object::create(realm, nullptr);
// 2. Let keys be ? EnumerableOwnPropertyNames(options, key).
auto keys = TRY(options.enumerable_own_property_names(Object::PropertyKind::Key));
@@ -1769,9 +1772,10 @@ ThrowCompletionOr<double> to_positive_integer(GlobalObject& global_object, Value
ThrowCompletionOr<Object*> prepare_temporal_fields(GlobalObject& global_object, Object const& fields, Vector<String> const& field_names, Variant<PrepareTemporalFieldsPartial, Vector<StringView>> const& required_fields)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let result be OrdinaryObjectCreate(null).
- auto* result = Object::create(global_object, nullptr);
+ auto* result = Object::create(realm, nullptr);
VERIFY(result);
// 2. Let any be false.
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
index 9ad33c2aaa..aaa227ac49 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
@@ -102,6 +102,7 @@ Calendar* get_iso8601_calendar(GlobalObject& global_object)
ThrowCompletionOr<Vector<String>> calendar_fields(GlobalObject& global_object, Object& calendar, Vector<StringView> const& field_names)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let fields be ? GetMethod(calendar, "fields").
auto fields = TRY(Value(&calendar).get_method(global_object, vm.names.fields));
@@ -110,7 +111,7 @@ ThrowCompletionOr<Vector<String>> calendar_fields(GlobalObject& global_object, O
auto field_names_values = MarkedVector<Value> { vm.heap() };
for (auto& field_name : field_names)
field_names_values.append(js_string(vm, field_name));
- Value fields_array = Array::create_from(global_object, field_names_values);
+ Value fields_array = Array::create_from(realm, field_names_values);
// 3. If fields is not undefined, then
if (fields) {
@@ -925,9 +926,10 @@ u8 iso_day(Object& temporal_object)
ThrowCompletionOr<Object*> default_merge_calendar_fields(GlobalObject& global_object, Object const& fields, Object const& additional_fields)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let merged be OrdinaryObjectCreate(%Object.prototype%).
- auto* merged = Object::create(global_object, global_object.object_prototype());
+ auto* merged = Object::create(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/CalendarPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp
index 82e87ff428..d4a1878c2b 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp
@@ -501,6 +501,8 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::in_leap_year)
// NOTE: This is the minimum fields implementation for engines without ECMA-402.
JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::fields)
{
+ auto& realm = *global_object.associated_realm();
+
auto fields = vm.argument(0);
// 1. Let calendar be the this value.
@@ -561,7 +563,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::fields)
}
// 8. Return CreateArrayFromList(fieldNames).
- return Array::create_from(global_object, field_names);
+ return Array::create_from(realm, field_names);
}
// 12.4.22 Temporal.Calendar.prototype.mergeFields ( fields, additionalFields ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.mergefields
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp
index a8a419fb14..5b39a6fafb 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp
@@ -572,6 +572,7 @@ ThrowCompletionOr<TimeDurationRecord> balance_duration(GlobalObject& global_obje
ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject& global_object, double years, double months, double weeks, double days, String const& largest_unit, Value relative_to)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. If largestUnit is "year", or years, months, weeks, and days are all 0, then
if (largest_unit == "year"sv || (years == 0 && months == 0 && weeks == 0 && days == 0)) {
@@ -631,7 +632,7 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject&
auto* new_relative_to = TRY(calendar_date_add(global_object, *calendar, relative_to, *one_year, nullptr, date_add));
// ii. Let untilOptions be OrdinaryObjectCreate(null).
- auto* until_options = Object::create(global_object, nullptr);
+ auto* until_options = Object::create(realm, nullptr);
// iii. Perform ! CreateDataPropertyOrThrow(untilOptions, "largestUnit", "month").
MUST(until_options->create_data_property_or_throw(vm.names.largestUnit, js_string(vm, "month"sv)));
@@ -755,6 +756,7 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject&
ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& global_object, double years, double months, double weeks, double days, String const& largest_unit, Value relative_to_value)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. If largestUnit is not one of "year", "month", or "week", or years, months, weeks, and days are all 0, then
if (!largest_unit.is_one_of("year"sv, "month"sv, "week"sv) || (years == 0 && months == 0 && weeks == 0 && days == 0)) {
@@ -861,7 +863,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
auto* date_until = TRY(Value(&calendar).get_method(global_object, vm.names.dateUntil));
// l. Let untilOptions be OrdinaryObjectCreate(null).
- auto* until_options = Object::create(global_object, nullptr);
+ auto* until_options = Object::create(realm, nullptr);
// m. Perform ! CreateDataPropertyOrThrow(untilOptions, "largestUnit", "month").
MUST(until_options->create_data_property_or_throw(vm.names.largestUnit, js_string(vm, "month"sv)));
@@ -887,7 +889,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
new_relative_to = TRY(calendar_date_add(global_object, calendar, relative_to, *one_year, nullptr, date_add));
// v. Set untilOptions to OrdinaryObjectCreate(null).
- until_options = Object::create(global_object, nullptr);
+ until_options = Object::create(realm, nullptr);
// vi. Perform ! CreateDataPropertyOrThrow(untilOptions, "largestUnit", "month").
MUST(until_options->create_data_property_or_throw(vm.names.largestUnit, js_string(vm, "month"sv)));
@@ -975,6 +977,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
ThrowCompletionOr<DurationRecord> add_duration(GlobalObject& global_object, double years1, double months1, double weeks1, double days1, double hours1, double minutes1, double seconds1, double milliseconds1, double microseconds1, double nanoseconds1, double years2, double months2, double weeks2, double days2, double hours2, double minutes2, double seconds2, double milliseconds2, double microseconds2, double nanoseconds2, Value relative_to_value)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
VERIFY(all_of(AK::Array { years1, months1, weeks1, days1, hours1, minutes1, seconds1, milliseconds1, microseconds1, nanoseconds1, years2, months2, weeks2, days2, hours2, minutes2, seconds2, milliseconds2, microseconds2, nanoseconds2 }, [](auto value) { return value == trunc(value); }));
@@ -1029,7 +1032,7 @@ ThrowCompletionOr<DurationRecord> add_duration(GlobalObject& global_object, doub
auto date_largest_unit = larger_of_two_temporal_units("day"sv, largest_unit);
// h. Let differenceOptions be OrdinaryObjectCreate(null).
- auto* difference_options = Object::create(global_object, nullptr);
+ auto* difference_options = Object::create(realm, nullptr);
// i. Perform ! CreateDataPropertyOrThrow(differenceOptions, "largestUnit", dateLargestUnit).
MUST(difference_options->create_data_property_or_throw(vm.names.largestUnit, js_string(vm, date_largest_unit)));
@@ -1075,7 +1078,7 @@ ThrowCompletionOr<DurationRecord> add_duration(GlobalObject& global_object, doub
}
// 12. Return ? DifferenceZonedDateTime(relativeTo.[[Nanoseconds]], endNs, timeZone, calendar, largestUnit, OrdinaryObjectCreate(null)).
- return difference_zoned_date_time(global_object, relative_to.nanoseconds(), *end_ns, time_zone, calendar, largest_unit, *Object::create(global_object, nullptr));
+ return difference_zoned_date_time(global_object, relative_to.nanoseconds(), *end_ns, time_zone, calendar, largest_unit, *Object::create(realm, nullptr));
}
// 7.5.23 MoveRelativeDate ( calendar, relativeTo, duration ), https://tc39.es/proposal-temporal/#sec-temporal-moverelativedate
@@ -1105,6 +1108,7 @@ ThrowCompletionOr<ZonedDateTime*> move_relative_zoned_date_time(GlobalObject& gl
ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, u32 increment, StringView unit, StringView rounding_mode, Object* relative_to_object)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
Object* calendar = nullptr;
double fractional_seconds = 0;
@@ -1225,7 +1229,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
auto* days_later = TRY(calendar_date_add(global_object, *calendar, relative_to, *days_duration, nullptr, date_add));
// k. Let untilOptions be OrdinaryObjectCreate(null).
- auto* until_options = Object::create(global_object, nullptr);
+ auto* until_options = Object::create(realm, nullptr);
// l. Perform ! CreateDataPropertyOrThrow(untilOptions, "largestUnit", "year").
MUST(until_options->create_data_property_or_throw(vm.names.largestUnit, js_string(vm, "year"sv)));
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp
index c31b7292ce..dabc0c9756 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp
@@ -322,6 +322,8 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::subtract)
// 7.3.20 Temporal.Duration.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.round
JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let duration be the this value.
// 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
auto* duration = TRY(typed_this_object(global_object));
@@ -339,7 +341,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round)
// a. Let paramString be roundTo.
// b. Set roundTo to OrdinaryObjectCreate(null).
- round_to = Object::create(global_object, nullptr);
+ round_to = Object::create(realm, nullptr);
// c. Perform ! CreateDataPropertyOrThrow(roundTo, "smallestUnit", paramString).
MUST(round_to->create_data_property_or_throw(vm.names.smallestUnit, vm.argument(0)));
@@ -444,6 +446,8 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round)
// 7.3.21 Temporal.Duration.prototype.total ( totalOf ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.total
JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::total)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let duration be the this value.
// 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
auto* duration = TRY(typed_this_object(global_object));
@@ -459,7 +463,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::total)
// a. Let paramString be totalOf.
// b. Set totalOf to OrdinaryObjectCreate(null).
- total_of = Object::create(global_object, nullptr);
+ total_of = Object::create(realm, nullptr);
// c. Perform ! CreateDataPropertyOrThrow(totalOf, "unit", paramString).
MUST(total_of->create_data_property_or_throw(vm.names.unit, vm.argument(0)));
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp
index 15cf4e424b..885e49eff2 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp
@@ -175,6 +175,8 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::since)
// 8.3.11 Temporal.Instant.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.round
JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::round)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let instant be the this value.
// 2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]).
auto* instant = TRY(typed_this_object(global_object));
@@ -192,7 +194,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::round)
// a. Let paramString be roundTo.
// b. Set roundTo to OrdinaryObjectCreate(null).
- round_to = Object::create(global_object, nullptr);
+ round_to = Object::create(realm, nullptr);
// c. Perform ! CreateDataPropertyOrThrow(roundTo, "smallestUnit", paramString).
MUST(round_to->create_data_property_or_throw(vm.names.smallestUnit, vm.argument(0)));
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp
index c68578a429..209ec8a254 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp
@@ -319,12 +319,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_plain_month_day)
// 3.3.18 Temporal.PlainDate.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.getisofields
JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::get_iso_fields)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let temporalDate be the this value.
// 2. Perform ? RequireInternalSlot(temporalDate, [[InitializedTemporalDate]]).
auto* temporal_date = TRY(typed_this_object(global_object));
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
- auto* fields = Object::create(global_object, global_object.object_prototype());
+ auto* fields = Object::create(realm, global_object.object_prototype());
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", temporalDate.[[Calendar]]).
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&temporal_date->calendar())));
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimePrototype.cpp
index ef6c2dc86c..b464fa3da3 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimePrototype.cpp
@@ -517,6 +517,8 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::since)
// 5.3.30 Temporal.PlainDateTime.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.round
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::round)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let dateTime be the this value.
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
auto* date_time = TRY(typed_this_object(global_object));
@@ -534,7 +536,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::round)
// a. Let paramString be roundTo.
// b. Set roundTo to OrdinaryObjectCreate(null).
- round_to = Object::create(global_object, nullptr);
+ round_to = Object::create(realm, nullptr);
// c. Perform ! CreateDataPropertyOrThrow(roundTo, "smallestUnit", paramString).
MUST(round_to->create_data_property_or_throw(vm.names.smallestUnit, vm.argument(0)));
@@ -726,12 +728,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::to_plain_time)
// 5.3.41 Temporal.PlainDateTime.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.getisofields
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::get_iso_fields)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let dateTime be the this value.
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
auto* date_time = TRY(typed_this_object(global_object));
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
- auto* fields = Object::create(global_object, global_object.object_prototype());
+ auto* fields = Object::create(realm, global_object.object_prototype());
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", dateTime.[[Calendar]]).
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&date_time->calendar())));
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp
index 9fef256799..cedb15a93b 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp
@@ -202,6 +202,8 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::value_of)
// 10.3.12 Temporal.PlainMonthDay.prototype.toPlainDate ( item ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.toplaindate
JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_plain_date)
{
+ auto& realm = *global_object.associated_realm();
+
auto item = vm.argument(0);
// 1. Let monthDay be the this value.
@@ -239,7 +241,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_plain_date)
merged_fields = TRY(prepare_temporal_fields(global_object, *merged_fields, merged_field_names, Vector<StringView> {}));
// 12. Let options be OrdinaryObjectCreate(null).
- auto* options = Object::create(global_object, nullptr);
+ auto* options = Object::create(realm, nullptr);
// 13. Perform ! CreateDataPropertyOrThrow(options, "overflow", "reject").
MUST(options->create_data_property_or_throw(vm.names.overflow, js_string(vm, vm.names.reject.as_string())));
@@ -251,12 +253,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_plain_date)
// 10.3.13 Temporal.PlainMonthDay.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.getisofields
JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::get_iso_fields)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let monthDay be the this value.
// 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
auto* month_day = TRY(typed_this_object(global_object));
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
- auto* fields = Object::create(global_object, global_object.object_prototype());
+ auto* fields = Object::create(realm, global_object.object_prototype());
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", monthDay.[[Calendar]]).
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&month_day->calendar())));
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp
index a2ec7e4d64..dff8a34e91 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp
@@ -265,6 +265,8 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::since)
// 4.3.15 Temporal.PlainTime.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.round
JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::round)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let temporalTime be the this value.
// 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
auto* temporal_time = TRY(typed_this_object(global_object));
@@ -282,7 +284,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::round)
// a. Let paramString be roundTo.
// b. Set roundTo to OrdinaryObjectCreate(null).
- round_to = Object::create(global_object, nullptr);
+ round_to = Object::create(realm, nullptr);
// c. Perform ! CreateDataPropertyOrThrow(roundTo, "smallestUnit", paramString).
MUST(round_to->create_data_property_or_throw(vm.names.smallestUnit, vm.argument(0)));
@@ -416,12 +418,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::to_zoned_date_time)
// 4.3.19 Temporal.PlainTime.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.getisofields
JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::get_iso_fields)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let temporalTime be the this value.
// 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
auto* temporal_time = TRY(typed_this_object(global_object));
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
- auto* fields = Object::create(global_object, global_object.object_prototype());
+ auto* fields = Object::create(realm, global_object.object_prototype());
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", temporalTime.[[Calendar]]).
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&temporal_time->calendar())));
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp
index ceb1276a15..a97464d724 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp
@@ -310,6 +310,7 @@ ThrowCompletionOr<Duration*> difference_temporal_plain_year_month(GlobalObject&
ThrowCompletionOr<PlainYearMonth*> add_duration_to_or_subtract_duration_from_plain_year_month(GlobalObject& global_object, ArithmeticOperation operation, PlainYearMonth& year_month, Value temporal_duration_like, Value options_value)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let duration be ? ToTemporalDuration(temporalDurationLike).
auto* duration = TRY(to_temporal_duration(global_object, temporal_duration_like));
@@ -364,7 +365,7 @@ ThrowCompletionOr<PlainYearMonth*> add_duration_to_or_subtract_duration_from_pla
auto* duration_to_add = MUST(create_temporal_duration(global_object, duration->years(), duration->months(), duration->weeks(), balance_result.days, 0, 0, 0, 0, 0, 0));
// 14. Let optionsCopy be OrdinaryObjectCreate(null).
- auto* options_copy = Object::create(global_object, nullptr);
+ auto* options_copy = Object::create(realm, nullptr);
// 15. Let entries be ? EnumerableOwnPropertyNames(options, key+value).
auto entries = TRY(options->enumerable_own_property_names(Object::PropertyKind::KeyAndValue));
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp
index 59cfaa862b..6db9b315e1 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp
@@ -369,6 +369,8 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::value_of)
// 9.3.21 Temporal.PlainYearMonth.prototype.toPlainDate ( item ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.toplaindate
JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_plain_date)
{
+ auto& realm = *global_object.associated_realm();
+
auto item = vm.argument(0);
// 1. Let yearMonth be the this value.
@@ -406,7 +408,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_plain_date)
merged_fields = TRY(prepare_temporal_fields(global_object, *merged_fields, merged_field_names, Vector<StringView> {}));
// 12. Let options be OrdinaryObjectCreate(null).
- auto* options = Object::create(global_object, nullptr);
+ auto* options = Object::create(realm, nullptr);
// 13. Perform ! CreateDataPropertyOrThrow(options, "overflow", "reject").
MUST(options->create_data_property_or_throw(vm.names.overflow, js_string(vm, vm.names.reject.as_string())));
@@ -418,12 +420,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_plain_date)
// 9.3.22 Temporal.PlainYearMonth.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.getisofields
JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::get_iso_fields)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let yearMonth be the this value.
// 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]).
auto* year_month = TRY(typed_this_object(global_object));
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
- auto* fields = Object::create(global_object, global_object.object_prototype());
+ auto* fields = Object::create(realm, global_object.object_prototype());
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", yearMonth.[[Calendar]]).
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&year_month->calendar())));
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp
index 36346ec323..c86d55dbeb 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp
@@ -128,6 +128,8 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_instant_for)
// 11.4.8 Temporal.TimeZone.prototype.getPossibleInstantsFor ( dateTime ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.getpossibleinstantsfor
JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_possible_instants_for)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let timeZone be the this value.
// 2. Perform ? RequireInternalSlot(timeZone, [[InitializedTemporalTimezone]]).
auto* time_zone = TRY(typed_this_object(global_object));
@@ -169,7 +171,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_possible_instants_for)
}
// 8. Return CreateArrayFromList(possibleInstants).
- return Array::create_from(global_object, possible_instants);
+ return Array::create_from(realm, possible_instants);
}
// 11.4.9 Temporal.TimeZone.prototype.getNextTransition ( startingPoint ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.getnexttransition
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp
index ae4fdc5bd5..769376fb70 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp
@@ -447,6 +447,7 @@ ThrowCompletionOr<DurationRecord> difference_zoned_date_time(GlobalObject& globa
ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(GlobalObject& global_object, Crypto::SignedBigInteger nanoseconds, Value relative_to_value)
{
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
// 1. Let dayLengthNs be nsPerDay.
auto day_length_ns = ns_per_day_bigint;
@@ -497,7 +498,7 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(GlobalObject& glo
auto* end_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &relative_to.time_zone(), *end_instant, relative_to.calendar()));
// 12. Let dateDifference be ? DifferenceISODateTime(startDateTime.[[ISOYear]], startDateTime.[[ISOMonth]], startDateTime.[[ISODay]], startDateTime.[[ISOHour]], startDateTime.[[ISOMinute]], startDateTime.[[ISOSecond]], startDateTime.[[ISOMillisecond]], startDateTime.[[ISOMicrosecond]], startDateTime.[[ISONanosecond]], endDateTime.[[ISOYear]], endDateTime.[[ISOMonth]], endDateTime.[[ISODay]], endDateTime.[[ISOHour]], endDateTime.[[ISOMinute]], endDateTime.[[ISOSecond]], endDateTime.[[ISOMillisecond]], endDateTime.[[ISOMicrosecond]], endDateTime.[[ISONanosecond]], relativeTo.[[Calendar]], "day", OrdinaryObjectCreate(null)).
- auto date_difference = TRY(difference_iso_date_time(global_object, start_date_time->iso_year(), start_date_time->iso_month(), start_date_time->iso_day(), start_date_time->iso_hour(), start_date_time->iso_minute(), start_date_time->iso_second(), start_date_time->iso_millisecond(), start_date_time->iso_microsecond(), start_date_time->iso_nanosecond(), end_date_time->iso_year(), end_date_time->iso_month(), end_date_time->iso_day(), end_date_time->iso_hour(), end_date_time->iso_minute(), end_date_time->iso_second(), end_date_time->iso_millisecond(), end_date_time->iso_microsecond(), end_date_time->iso_nanosecond(), relative_to.calendar(), "day"sv, *Object::create(global_object, nullptr)));
+ auto date_difference = TRY(difference_iso_date_time(global_object, start_date_time->iso_year(), start_date_time->iso_month(), start_date_time->iso_day(), start_date_time->iso_hour(), start_date_time->iso_minute(), start_date_time->iso_second(), start_date_time->iso_millisecond(), start_date_time->iso_microsecond(), start_date_time->iso_nanosecond(), end_date_time->iso_year(), end_date_time->iso_month(), end_date_time->iso_day(), end_date_time->iso_hour(), end_date_time->iso_minute(), end_date_time->iso_second(), end_date_time->iso_millisecond(), end_date_time->iso_microsecond(), end_date_time->iso_nanosecond(), relative_to.calendar(), "day"sv, *Object::create(realm, nullptr)));
// 13. Let days be dateDifference.[[Days]].
auto days = date_difference.days;
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp
index 9156916d78..4390d0f46e 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp
@@ -951,6 +951,8 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::since)
// 6.3.39 Temporal.ZonedDateTime.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.round
JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::round)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let zonedDateTime be the this value.
// 2. Perform ? RequireInternalSlot(zonedDateTime, [[InitializedTemporalZonedDateTime]]).
auto* zoned_date_time = TRY(typed_this_object(global_object));
@@ -968,7 +970,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::round)
// a. Let paramString be roundTo.
// b. Set roundTo to OrdinaryObjectCreate(null).
- round_to = Object::create(global_object, nullptr);
+ round_to = Object::create(realm, nullptr);
// c. Perform ! CreateDataPropertyOrThrow(roundTo, "smallestUnit", paramString).
MUST(round_to->create_data_property_or_throw(vm.names.smallestUnit, vm.argument(0)));
@@ -1282,12 +1284,14 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_plain_month_day)
// 6.3.52 Temporal.ZonedDateTime.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.getisofields
JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::get_iso_fields)
{
+ auto& realm = *global_object.associated_realm();
+
// 1. Let zonedDateTime be the this value.
// 2. Perform ? RequireInternalSlot(zonedDateTime, [[InitializedTemporalZonedDateTime]]).
auto* zoned_date_time = TRY(typed_this_object(global_object));
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
- auto* fields = Object::create(global_object, global_object.object_prototype());
+ auto* fields = Object::create(realm, global_object.object_prototype());
// 4. Let timeZone be zonedDateTime.[[TimeZone]].
auto& time_zone = zoned_date_time->time_zone();
diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp
index 4122dc8e12..c9207b73eb 100644
--- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp
+++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp
@@ -431,22 +431,24 @@ void TypedArrayBase::visit_edges(Visitor& visitor)
}
#define JS_DEFINE_TYPED_ARRAY(ClassName, snake_name, PrototypeName, ConstructorName, Type) \
- ThrowCompletionOr<ClassName*> ClassName::create(GlobalObject& global_object, u32 length, FunctionObject& new_target) \
+ ThrowCompletionOr<ClassName*> ClassName::create(Realm& realm, u32 length, FunctionObject& new_target) \
{ \
- auto* prototype = TRY(get_prototype_from_constructor(global_object, new_target, &GlobalObject::snake_name##_prototype)); \
- auto* array_buffer = TRY(ArrayBuffer::create(global_object, length * sizeof(UnderlyingBufferDataType))); \
- return global_object.heap().allocate<ClassName>(global_object, *prototype, length, *array_buffer); \
+ auto* prototype = TRY(get_prototype_from_constructor( \
+ realm.global_object(), new_target, &GlobalObject::snake_name##_prototype)); \
+ auto* array_buffer = TRY(ArrayBuffer::create(realm, length * sizeof(UnderlyingBufferDataType))); \
+ return realm.heap().allocate<ClassName>(realm.global_object(), *prototype, length, *array_buffer); \
} \
\
- ThrowCompletionOr<ClassName*> ClassName::create(GlobalObject& global_object, u32 length) \
+ ThrowCompletionOr<ClassName*> ClassName::create(Realm& realm, u32 length) \
{ \
- auto* array_buffer = TRY(ArrayBuffer::create(global_object, length * sizeof(UnderlyingBufferDataType))); \
- return create(global_object, length, *array_buffer); \
+ auto* array_buffer = TRY(ArrayBuffer::create(realm, length * sizeof(UnderlyingBufferDataType))); \
+ return create(realm, length, *array_buffer); \
} \
\
- ClassName* ClassName::create(GlobalObject& global_object, u32 length, ArrayBuffer& array_buffer) \
+ ClassName* ClassName::create(Realm& realm, u32 length, ArrayBuffer& array_buffer) \
{ \
- return global_object.heap().allocate<ClassName>(global_object, *global_object.snake_name##_prototype(), length, array_buffer); \
+ return realm.heap().allocate<ClassName>( \
+ realm.global_object(), *realm.global_object().snake_name##_prototype(), length, array_buffer); /* */ \
} \
\
ClassName::ClassName(Object& prototype, u32 length, ArrayBuffer& array_buffer) \
@@ -518,47 +520,50 @@ 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(); \
+ \
if (vm.argument_count() == 0) \
- return TRY(ClassName::create(global_object(), 0, new_target)); \
+ return TRY(ClassName::create(realm, 0, new_target)); \
\
auto first_argument = vm.argument(0); \
if (first_argument.is_object()) { \
- auto* typed_array = TRY(ClassName::create(global_object(), 0, new_target)); \
+ auto* typed_array = TRY(ClassName::create(realm, 0, new_target)); \
if (first_argument.as_object().is_typed_array()) { \
auto& arg_typed_array = static_cast<TypedArrayBase&>(first_argument.as_object()); \
- TRY(initialize_typed_array_from_typed_array(global_object(), *typed_array, arg_typed_array)); \
+ TRY(initialize_typed_array_from_typed_array(global_object, *typed_array, arg_typed_array)); \
} else if (is<ArrayBuffer>(first_argument.as_object())) { \
auto& array_buffer = static_cast<ArrayBuffer&>(first_argument.as_object()); \
- TRY(initialize_typed_array_from_array_buffer(global_object(), *typed_array, array_buffer, \
+ TRY(initialize_typed_array_from_array_buffer(global_object, *typed_array, array_buffer, \
vm.argument(1), vm.argument(2))); \
} else { \
- auto iterator = TRY(first_argument.get_method(global_object(), *vm.well_known_symbol_iterator())); \
+ auto iterator = TRY(first_argument.get_method(global_object, *vm.well_known_symbol_iterator())); \
if (iterator) { \
- auto values = TRY(iterable_to_list(global_object(), first_argument, iterator)); \
- TRY(initialize_typed_array_from_list(global_object(), *typed_array, values)); \
+ auto values = TRY(iterable_to_list(global_object, first_argument, iterator)); \
+ TRY(initialize_typed_array_from_list(global_object, *typed_array, values)); \
} else { \
- TRY(initialize_typed_array_from_array_like(global_object(), *typed_array, first_argument.as_object())); \
+ TRY(initialize_typed_array_from_array_like(global_object, *typed_array, first_argument.as_object())); \
} \
} \
return typed_array; \
} \
\
- auto array_length_or_error = first_argument.to_index(global_object()); \
+ auto array_length_or_error = first_argument.to_index(global_object); \
if (array_length_or_error.is_error()) { \
auto error = array_length_or_error.release_error(); \
if (error.value()->is_object() && is<RangeError>(error.value()->as_object())) { \
/* Re-throw more specific RangeError */ \
- return vm.throw_completion<RangeError>(global_object(), ErrorType::InvalidLength, "typed array"); \
+ return vm.throw_completion<RangeError>(global_object, ErrorType::InvalidLength, "typed array"); \
} \
return error; \
} \
auto array_length = array_length_or_error.release_value(); \
if (array_length > NumericLimits<i32>::max() / sizeof(Type)) \
- return vm.throw_completion<RangeError>(global_object(), ErrorType::InvalidLength, "typed array"); \
+ return vm.throw_completion<RangeError>(global_object, ErrorType::InvalidLength, "typed array"); \
/* FIXME: What is the best/correct behavior here? */ \
if (Checked<u32>::multiplication_would_overflow(array_length, sizeof(Type))) \
- return vm.throw_completion<RangeError>(global_object(), ErrorType::InvalidLength, "typed array"); \
- return TRY(ClassName::create(global_object(), array_length, new_target)); \
+ return vm.throw_completion<RangeError>(global_object, ErrorType::InvalidLength, "typed array"); \
+ return TRY(ClassName::create(realm, array_length, new_target)); \
}
#undef __JS_ENUMERATE
diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.h b/Userland/Libraries/LibJS/Runtime/TypedArray.h
index c783f89962..0bb180afa0 100644
--- a/Userland/Libraries/LibJS/Runtime/TypedArray.h
+++ b/Userland/Libraries/LibJS/Runtime/TypedArray.h
@@ -461,9 +461,9 @@ ThrowCompletionOr<double> compare_typed_array_elements(GlobalObject& global_obje
public: \
virtual ~ClassName(); \
static ThrowCompletionOr<ClassName*> create( \
- GlobalObject&, u32 length, FunctionObject& new_target); \
- static ThrowCompletionOr<ClassName*> create(GlobalObject&, u32 length); \
- static ClassName* create(GlobalObject&, u32 length, ArrayBuffer& buffer); \
+ Realm&, u32 length, FunctionObject& new_target); \
+ static ThrowCompletionOr<ClassName*> create(Realm&, u32 length); \
+ static ClassName* create(Realm&, u32 length, ArrayBuffer& buffer); \
ClassName(Object& prototype, u32 length, ArrayBuffer& array_buffer); \
virtual FlyString const& element_name() const override; \
}; \
diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp
index ee294e4a22..fafaf7ead1 100644
--- a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp
@@ -386,8 +386,10 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::copy_within)
// 23.2.3.7 %TypedArray%.prototype.entries ( ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.entries
JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::entries)
{
+ auto& realm = *global_object.associated_realm();
+
auto* typed_array = TRY(validate_typed_array_from_this(global_object));
- return ArrayIterator::create(global_object, typed_array, Object::PropertyKind::KeyAndValue);
+ return ArrayIterator::create(realm, typed_array, Object::PropertyKind::KeyAndValue);
}
// 23.2.3.8 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.every
@@ -686,8 +688,10 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::join)
// 23.2.3.19 %TypedArray%.prototype.keys ( ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.keys
JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::keys)
{
+ auto& realm = *global_object.associated_realm();
+
auto* typed_array = TRY(validate_typed_array_from_this(global_object));
- return ArrayIterator::create(global_object, typed_array, Object::PropertyKind::Key);
+ return ArrayIterator::create(realm, typed_array, Object::PropertyKind::Key);
}
// 23.2.3.20 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.lastindexof
@@ -1622,8 +1626,10 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::with)
// 23.2.3.33 %TypedArray%.prototype.values ( ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.values
JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::values)
{
+ auto& realm = *global_object.associated_realm();
+
auto* typed_array = TRY(typed_array_from_this(global_object));
- return ArrayIterator::create(global_object, typed_array, Object::PropertyKind::Value);
+ return ArrayIterator::create(realm, typed_array, Object::PropertyKind::Value);
}
// 23.2.3.35 get %TypedArray%.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-get-%typedarray%.prototype-@@tostringtag
diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp
index 5156515ade..9afe071d28 100644
--- a/Userland/Libraries/LibJS/Runtime/VM.cpp
+++ b/Userland/Libraries/LibJS/Runtime/VM.cpp
@@ -74,19 +74,19 @@ VM::VM(OwnPtr<CustomData> custom_data)
host_import_module_dynamically = [&](ScriptOrModule, ModuleRequest const&, PromiseCapability promise_capability) {
// By default, we throw on dynamic imports this is to prevent arbitrary file access by scripts.
VERIFY(current_realm());
- auto& global_object = current_realm()->global_object();
- auto* promise = Promise::create(global_object);
+ auto& realm = *current_realm();
+ auto* promise = Promise::create(realm);
// If you are here because you want to enable dynamic module importing make sure it won't be a security problem
// by checking the default implementation of HostImportModuleDynamically and creating your own hook or calling
// vm.enable_default_host_import_module_dynamically_hook().
- promise->reject(Error::create(global_object, ErrorType::DynamicImportNotAllowed.message()));
+ promise->reject(Error::create(realm, ErrorType::DynamicImportNotAllowed.message()));
promise->perform_then(
- NativeFunction::create(global_object, "", [](auto&, auto&) -> ThrowCompletionOr<Value> {
+ NativeFunction::create(realm, "", [](auto&, auto&) -> ThrowCompletionOr<Value> {
VERIFY_NOT_REACHED();
}),
- NativeFunction::create(global_object, "", [reject = make_handle(promise_capability.reject)](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
+ NativeFunction::create(realm, "", [reject = make_handle(promise_capability.reject)](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
auto error = vm.argument(0);
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « error »).
@@ -314,6 +314,7 @@ ThrowCompletionOr<void> VM::binding_initialization(NonnullRefPtr<BindingPattern>
// 14.3.3.1 Runtime Semantics: PropertyBindingInitialization, https://tc39.es/ecma262/#sec-destructuring-binding-patterns-runtime-semantics-propertybindinginitialization
ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const& binding, Value value, Environment* environment, GlobalObject& global_object)
{
+ auto& realm = *global_object.associated_realm();
auto* object = TRY(value.to_object(global_object));
HashTable<PropertyKey> seen_names;
@@ -331,7 +332,7 @@ ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const
VERIFY_NOT_REACHED();
}
- auto* rest_object = Object::create(global_object, global_object.object_prototype());
+ auto* rest_object = Object::create(realm, global_object.object_prototype());
VERIFY(rest_object);
TRY(rest_object->copy_data_properties(object, seen_names, global_object));
@@ -406,6 +407,8 @@ ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const
// 8.5.3 Runtime Semantics: IteratorBindingInitialization, https://tc39.es/ecma262/#sec-runtime-semantics-iteratorbindinginitialization
ThrowCompletionOr<void> VM::iterator_binding_initialization(BindingPattern const& binding, Iterator& iterator_record, Environment* environment, GlobalObject& global_object)
{
+ auto& realm = *global_object.associated_realm();
+
// FIXME: this method is nearly identical to destructuring assignment!
for (size_t i = 0; i < binding.entries.size(); i++) {
auto& entry = binding.entries[i];
@@ -427,7 +430,7 @@ ThrowCompletionOr<void> VM::iterator_binding_initialization(BindingPattern const
VERIFY(i == binding.entries.size() - 1);
// 2. Let A be ! ArrayCreate(0).
- auto* array = MUST(Array::create(global_object, 0));
+ auto* array = MUST(Array::create(realm, 0));
// 3. Let n be 0.
// 4. Repeat,
@@ -955,7 +958,7 @@ ThrowCompletionOr<NonnullRefPtr<Module>> VM::resolve_imported_module(ScriptOrMod
// 16.2.1.8 HostImportModuleDynamically ( referencingScriptOrModule, specifier, promiseCapability ), https://tc39.es/ecma262/#sec-hostimportmoduledynamically
void VM::import_module_dynamically(ScriptOrModule referencing_script_or_module, ModuleRequest module_request, PromiseCapability promise_capability)
{
- auto& global_object = current_realm()->global_object();
+ auto& realm = *current_realm();
// Success path:
// - At some future time, the host environment must perform FinishDynamicImport(referencingScriptOrModule, moduleRequest, promiseCapability, promise),
@@ -969,7 +972,7 @@ void VM::import_module_dynamically(ScriptOrModule referencing_script_or_module,
// FinishDynamicImport(referencingScriptOrModule, moduleRequest, promiseCapability, promise),
// where promise is a Promise rejected with an error representing the cause of failure.
- auto* promise = Promise::create(global_object);
+ auto* promise = Promise::create(realm);
ScopeGuard finish_dynamic_import = [&] {
host_finish_dynamic_import(referencing_script_or_module, move(module_request), promise_capability, promise);
@@ -983,7 +986,7 @@ void VM::import_module_dynamically(ScriptOrModule referencing_script_or_module,
// If there is no ScriptOrModule in any of the execution contexts
if (referencing_script_or_module.has<Empty>()) {
// Throw an error for now
- promise->reject(InternalError::create(global_object, String::formatted(ErrorType::ModuleNotFoundNoReferencingScript.message(), module_request.module_specifier)));
+ promise->reject(InternalError::create(realm, String::formatted(ErrorType::ModuleNotFoundNoReferencingScript.message(), module_request.module_specifier)));
return;
}
}
@@ -1015,6 +1018,8 @@ void VM::finish_dynamic_import(ScriptOrModule referencing_script_or_module, Modu
{
dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] finish_dynamic_import on {}", module_request.module_specifier);
+ auto& realm = *current_realm();
+
// 1. Let fulfilledClosure be a new Abstract Closure with parameters (result) that captures referencingScriptOrModule, specifier, and promiseCapability and performs the following steps when called:
auto fulfilled_closure = [referencing_script_or_module, module_request = move(module_request), resolve_function = make_handle(promise_capability.resolve), reject_function = make_handle(promise_capability.reject)](VM& vm, GlobalObject& global_object) -> ThrowCompletionOr<Value> {
auto result = vm.argument(0);
@@ -1045,7 +1050,7 @@ void VM::finish_dynamic_import(ScriptOrModule referencing_script_or_module, Modu
};
// 2. Let onFulfilled be CreateBuiltinFunction(fulfilledClosure, 0, "", « »).
- auto* on_fulfilled = NativeFunction::create(current_realm()->global_object(), move(fulfilled_closure), 0, "");
+ auto* on_fulfilled = NativeFunction::create(realm, move(fulfilled_closure), 0, "");
// 3. Let rejectedClosure be a new Abstract Closure with parameters (error) that captures promiseCapability and performs the following steps when called:
auto rejected_closure = [rejected_function = make_handle(promise_capability.reject)](VM& vm, GlobalObject& global_object) -> ThrowCompletionOr<Value> {
@@ -1059,7 +1064,7 @@ void VM::finish_dynamic_import(ScriptOrModule referencing_script_or_module, Modu
};
// 4. Let onRejected be CreateBuiltinFunction(rejectedClosure, 0, "", « »).
- auto* on_rejected = NativeFunction::create(current_realm()->global_object(), move(rejected_closure), 0, "");
+ auto* on_rejected = NativeFunction::create(realm, move(rejected_closure), 0, "");
// 5. Perform PerformPromiseThen(innerPromise, onFulfilled, onRejected).
inner_promise->perform_then(on_fulfilled, on_rejected, {});
diff --git a/Userland/Libraries/LibJS/Runtime/VM.h b/Userland/Libraries/LibJS/Runtime/VM.h
index 9a5b4c71c3..8f5270ee28 100644
--- a/Userland/Libraries/LibJS/Runtime/VM.h
+++ b/Userland/Libraries/LibJS/Runtime/VM.h
@@ -165,7 +165,8 @@ public:
template<typename T, typename... Args>
Completion throw_completion(GlobalObject& global_object, Args&&... args)
{
- return JS::throw_completion(T::create(global_object, forward<Args>(args)...));
+ auto& realm = realm_from_global_object(global_object);
+ return JS::throw_completion(T::create(realm, forward<Args>(args)...));
}
template<typename T, typename... Args>
diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp
index 7c3f9445d5..8de73e96ab 100644
--- a/Userland/Libraries/LibJS/Runtime/Value.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Value.cpp
@@ -442,22 +442,23 @@ ThrowCompletionOr<Value> Value::to_primitive(GlobalObject& global_object, Prefer
// 7.1.18 ToObject ( argument ), https://tc39.es/ecma262/#sec-toobject
ThrowCompletionOr<Object*> Value::to_object(GlobalObject& global_object) const
{
+ auto& realm = *global_object.associated_realm();
VERIFY(!is_empty());
if (is_number())
- return NumberObject::create(global_object, as_double());
+ return NumberObject::create(realm, as_double());
switch (m_value.tag) {
case UNDEFINED_TAG:
case NULL_TAG:
return global_object.vm().throw_completion<TypeError>(global_object, ErrorType::ToObjectNullOrUndefined);
case BOOLEAN_TAG:
- return BooleanObject::create(global_object, as_bool());
+ return BooleanObject::create(realm, as_bool());
case STRING_TAG:
- return StringObject::create(global_object, const_cast<JS::PrimitiveString&>(as_string()), *global_object.string_prototype());
+ return StringObject::create(realm, const_cast<JS::PrimitiveString&>(as_string()), *global_object.string_prototype());
case SYMBOL_TAG:
- return SymbolObject::create(global_object, const_cast<JS::Symbol&>(as_symbol()));
+ return SymbolObject::create(realm, const_cast<JS::Symbol&>(as_symbol()));
case BIGINT_TAG:
- return BigIntObject::create(global_object, const_cast<JS::BigInt&>(as_bigint()));
+ return BigIntObject::create(realm, const_cast<JS::BigInt&>(as_bigint()));
case OBJECT_TAG:
return &const_cast<Object&>(as_object());
default:
diff --git a/Userland/Libraries/LibJS/Runtime/WeakMap.cpp b/Userland/Libraries/LibJS/Runtime/WeakMap.cpp
index 9e728c7130..b0edaef071 100644
--- a/Userland/Libraries/LibJS/Runtime/WeakMap.cpp
+++ b/Userland/Libraries/LibJS/Runtime/WeakMap.cpp
@@ -8,9 +8,9 @@
namespace JS {
-WeakMap* WeakMap::create(GlobalObject& global_object)
+WeakMap* WeakMap::create(Realm& realm)
{
- return global_object.heap().allocate<WeakMap>(global_object, *global_object.weak_map_prototype());
+ return realm.heap().allocate<WeakMap>(realm.global_object(), *realm.global_object().weak_map_prototype());
}
WeakMap::WeakMap(Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/WeakMap.h b/Userland/Libraries/LibJS/Runtime/WeakMap.h
index ed1e00f42a..9ea83683df 100644
--- a/Userland/Libraries/LibJS/Runtime/WeakMap.h
+++ b/Userland/Libraries/LibJS/Runtime/WeakMap.h
@@ -19,7 +19,7 @@ class WeakMap final
JS_OBJECT(WeakMap, Object);
public:
- static WeakMap* create(GlobalObject&);
+ static WeakMap* create(Realm&);
explicit WeakMap(Object& prototype);
virtual ~WeakMap() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/WeakRef.cpp b/Userland/Libraries/LibJS/Runtime/WeakRef.cpp
index e03b5adb13..286b1f9322 100644
--- a/Userland/Libraries/LibJS/Runtime/WeakRef.cpp
+++ b/Userland/Libraries/LibJS/Runtime/WeakRef.cpp
@@ -8,14 +8,14 @@
namespace JS {
-WeakRef* WeakRef::create(GlobalObject& global_object, Object& value)
+WeakRef* WeakRef::create(Realm& realm, Object& value)
{
- return global_object.heap().allocate<WeakRef>(global_object, value, *global_object.weak_ref_prototype());
+ return realm.heap().allocate<WeakRef>(realm.global_object(), value, *realm.global_object().weak_ref_prototype());
}
-WeakRef* WeakRef::create(GlobalObject& global_object, Symbol& value)
+WeakRef* WeakRef::create(Realm& realm, Symbol& value)
{
- return global_object.heap().allocate<WeakRef>(global_object, value, *global_object.weak_ref_prototype());
+ return realm.heap().allocate<WeakRef>(realm.global_object(), value, *realm.global_object().weak_ref_prototype());
}
WeakRef::WeakRef(Object& value, Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/WeakRef.h b/Userland/Libraries/LibJS/Runtime/WeakRef.h
index b3aeaf2d8d..c49c4fbef2 100644
--- a/Userland/Libraries/LibJS/Runtime/WeakRef.h
+++ b/Userland/Libraries/LibJS/Runtime/WeakRef.h
@@ -18,8 +18,8 @@ class WeakRef final
JS_OBJECT(WeakRef, Object);
public:
- static WeakRef* create(GlobalObject&, Object&);
- static WeakRef* create(GlobalObject&, Symbol&);
+ static WeakRef* create(Realm&, Object&);
+ static WeakRef* create(Realm&, Symbol&);
explicit WeakRef(Object&, Object& prototype);
explicit WeakRef(Symbol&, Object& prototype);
diff --git a/Userland/Libraries/LibJS/Runtime/WeakSet.cpp b/Userland/Libraries/LibJS/Runtime/WeakSet.cpp
index b31ebb7c70..37dd731258 100644
--- a/Userland/Libraries/LibJS/Runtime/WeakSet.cpp
+++ b/Userland/Libraries/LibJS/Runtime/WeakSet.cpp
@@ -8,9 +8,9 @@
namespace JS {
-WeakSet* WeakSet::create(GlobalObject& global_object)
+WeakSet* WeakSet::create(Realm& realm)
{
- return global_object.heap().allocate<WeakSet>(global_object, *global_object.weak_set_prototype());
+ return realm.heap().allocate<WeakSet>(realm.global_object(), *realm.global_object().weak_set_prototype());
}
WeakSet::WeakSet(Object& prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/WeakSet.h b/Userland/Libraries/LibJS/Runtime/WeakSet.h
index 87def1a56b..7a21bcca03 100644
--- a/Userland/Libraries/LibJS/Runtime/WeakSet.h
+++ b/Userland/Libraries/LibJS/Runtime/WeakSet.h
@@ -19,7 +19,7 @@ class WeakSet final
JS_OBJECT(WeakSet, Object);
public:
- static WeakSet* create(GlobalObject&);
+ static WeakSet* create(Realm&);
explicit WeakSet(Object& prototype);
virtual ~WeakSet() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp b/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp
index 77533876ca..09d95ab0bb 100644
--- a/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp
+++ b/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp
@@ -11,9 +11,9 @@
namespace JS {
// 3.1.1 WrappedFunctionCreate ( callerRealm: a Realm Record, Target: a function object, ), https://tc39.es/proposal-shadowrealm/#sec-wrappedfunctioncreate
-ThrowCompletionOr<WrappedFunction*> WrappedFunction::create(GlobalObject& global_object, Realm& caller_realm, FunctionObject& target)
+ThrowCompletionOr<WrappedFunction*> WrappedFunction::create(Realm& realm, Realm& caller_realm, FunctionObject& target)
{
- auto& vm = global_object.vm();
+ auto& vm = realm.vm();
// 1. Let internalSlotsList be the internal slots listed in Table 2, plus [[Prototype]] and [[Extensible]].
// 2. Let wrapped be MakeBasicObject(internalSlotsList).
@@ -22,14 +22,14 @@ ThrowCompletionOr<WrappedFunction*> WrappedFunction::create(GlobalObject& global
// 5. Set wrapped.[[WrappedTargetFunction]] to Target.
// 6. Set wrapped.[[Realm]] to callerRealm.
auto& prototype = *caller_realm.global_object().function_prototype();
- auto* wrapped = global_object.heap().allocate<WrappedFunction>(global_object, caller_realm, target, prototype);
+ auto* wrapped = vm.heap().allocate<WrappedFunction>(realm.global_object(), caller_realm, target, prototype);
// 7. Let result be CopyNameAndLength(wrapped, Target).
- auto result = copy_name_and_length(global_object, *wrapped, target);
+ auto result = copy_name_and_length(realm.global_object(), *wrapped, target);
// 8. If result is an Abrupt Completion, throw a TypeError exception.
if (result.is_throw_completion())
- return vm.throw_completion<TypeError>(global_object, ErrorType::WrappedFunctionCopyNameAndLengthThrowCompletion);
+ return vm.throw_completion<TypeError>(realm.global_object(), ErrorType::WrappedFunctionCopyNameAndLengthThrowCompletion);
// 9. Return wrapped.
return wrapped;
diff --git a/Userland/Libraries/LibJS/Runtime/WrappedFunction.h b/Userland/Libraries/LibJS/Runtime/WrappedFunction.h
index c0b270e2cb..5008dc32cc 100644
--- a/Userland/Libraries/LibJS/Runtime/WrappedFunction.h
+++ b/Userland/Libraries/LibJS/Runtime/WrappedFunction.h
@@ -15,7 +15,7 @@ class WrappedFunction final : public FunctionObject {
JS_OBJECT(WrappedFunction, FunctionObject);
public:
- static ThrowCompletionOr<WrappedFunction*> create(GlobalObject&, Realm& caller_realm, FunctionObject& target_function);
+ static ThrowCompletionOr<WrappedFunction*> create(Realm&, Realm& caller_realm, FunctionObject& target_function);
WrappedFunction(Realm&, FunctionObject&, Object& prototype);
virtual ~WrappedFunction() = default;
diff --git a/Userland/Libraries/LibJS/SourceTextModule.cpp b/Userland/Libraries/LibJS/SourceTextModule.cpp
index 7bf4e9c678..b984c0ce94 100644
--- a/Userland/Libraries/LibJS/SourceTextModule.cpp
+++ b/Userland/Libraries/LibJS/SourceTextModule.cpp
@@ -457,7 +457,7 @@ ThrowCompletionOr<void> SourceTextModule::initialize_environment(VM& vm)
auto const& function_declaration = static_cast<FunctionDeclaration const&>(declaration);
// 1. Let fo be InstantiateFunctionObject of d with arguments env and privateEnv.
- auto* function = ECMAScriptFunctionObject::create(global_object, function_declaration.name(), function_declaration.source_text(), function_declaration.body(), function_declaration.parameters(), function_declaration.function_length(), environment, private_environment, function_declaration.kind(), function_declaration.is_strict_mode(), function_declaration.might_need_arguments_object(), function_declaration.contains_direct_call_to_eval());
+ auto* function = ECMAScriptFunctionObject::create(realm(), function_declaration.name(), function_declaration.source_text(), function_declaration.body(), function_declaration.parameters(), function_declaration.function_length(), environment, private_environment, function_declaration.kind(), function_declaration.is_strict_mode(), function_declaration.might_need_arguments_object(), function_declaration.contains_direct_call_to_eval());
// 2. Perform ! env.InitializeBinding(dn, fo).
MUST(environment->initialize_binding(global_object, name, function));
diff --git a/Userland/Libraries/LibJS/SyntheticModule.cpp b/Userland/Libraries/LibJS/SyntheticModule.cpp
index 5b5ed3f37f..6a22557834 100644
--- a/Userland/Libraries/LibJS/SyntheticModule.cpp
+++ b/Userland/Libraries/LibJS/SyntheticModule.cpp
@@ -109,7 +109,7 @@ ThrowCompletionOr<Promise*> SyntheticModule::evaluate(VM& vm)
// 12. Return Completion(result).
// Note: Because we expect it to return a promise we convert this here.
- auto* promise = Promise::create(realm().global_object());
+ auto* promise = Promise::create(realm());
if (result.is_error()) {
VERIFY(result.throw_completion().value().has_value());
promise->reject(*result.throw_completion().value());
diff --git a/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.cpp b/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.cpp
index 868bded595..c4fdcae3de 100644
--- a/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.cpp
+++ b/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.cpp
@@ -16,6 +16,7 @@
#include <LibWeb/Bindings/CrossOriginAbstractOperations.h>
#include <LibWeb/Bindings/DOMExceptionWrapper.h>
#include <LibWeb/Bindings/LocationObject.h>
+#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/Bindings/WindowObject.h>
#include <LibWeb/DOM/DOMException.h>
#include <LibWeb/HTML/Scripting/Environments.h>
@@ -93,6 +94,7 @@ bool is_platform_object_same_origin(JS::Object const& object)
// 7.2.3.4 CrossOriginGetOwnPropertyHelper ( O, P ), https://html.spec.whatwg.org/multipage/browsers.html#crossorigingetownpropertyhelper-(-o,-p-)
Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<LocationObject*, WindowObject*> const& object, JS::PropertyKey const& property_key)
{
+ auto& realm = *main_thread_vm().current_realm();
auto const* object_ptr = object.visit([](auto* o) { return static_cast<JS::Object const*>(o); });
auto const object_const_variant = object.visit([](auto* o) { return Variant<LocationObject const*, WindowObject const*> { o }; });
@@ -126,7 +128,7 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<Lo
// 2. If IsCallable(value) is true, then set value to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the IDL operation P on object O.
if (value->is_function()) {
value = JS::NativeFunction::create(
- HTML::current_global_object(), [function = JS::make_handle(*value)](auto&, auto& global_object) {
+ realm, [function = JS::make_handle(*value)](auto&, auto& global_object) {
return JS::call(global_object, function.value(), JS::js_undefined());
},
0, "");
@@ -143,7 +145,7 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<Lo
// 2. If e.[[NeedsGet]] is true, then set crossOriginGet to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the getter of the IDL attribute P on object O.
if (*entry.needs_get) {
cross_origin_get = JS::NativeFunction::create(
- HTML::current_global_object(), [object_ptr, getter = JS::make_handle(*original_descriptor->get)](auto&, auto& global_object) {
+ realm, [object_ptr, getter = JS::make_handle(*original_descriptor->get)](auto&, auto& global_object) {
return JS::call(global_object, getter.cell(), object_ptr);
},
0, "");
@@ -155,7 +157,7 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<Lo
// If e.[[NeedsSet]] is true, then set crossOriginSet to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the setter of the IDL attribute P on object O.
if (*entry.needs_set) {
cross_origin_set = JS::NativeFunction::create(
- HTML::current_global_object(), [object_ptr, setter = JS::make_handle(*original_descriptor->set)](auto&, auto& global_object) {
+ realm, [object_ptr, setter = JS::make_handle(*original_descriptor->set)](auto&, auto& global_object) {
return JS::call(global_object, setter.cell(), object_ptr);
},
0, "");
diff --git a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp
index 27860fbb44..5c57f24cfe 100644
--- a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp
+++ b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp
@@ -299,7 +299,6 @@ JS::VM& main_thread_vm()
// https://dom.spec.whatwg.org/#queue-a-mutation-observer-compound-microtask
void queue_mutation_observer_microtask(DOM::Document& document)
{
- // FIXME: Is this the correct VM?
auto& vm = main_thread_vm();
auto& custom_data = verify_cast<WebEngineCustomData>(*vm.custom_data());
@@ -345,8 +344,9 @@ void queue_mutation_observer_microtask(DOM::Document& document)
if (!records.is_empty()) {
auto& callback = mutation_observer.callback();
auto& global_object = callback.callback_context.global_object();
+ auto& realm = callback.callback_context.realm();
- auto* wrapped_records = MUST(JS::Array::create(global_object, 0));
+ auto* wrapped_records = MUST(JS::Array::create(realm, 0));
for (size_t i = 0; i < records.size(); ++i) {
auto& record = records.at(i);
auto* wrapped_record = Bindings::wrap(global_object, record);
diff --git a/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp b/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp
index b4c2fccc20..1971d346a6 100644
--- a/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp
+++ b/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp
@@ -21,7 +21,7 @@ NavigatorObject::NavigatorObject(JS::Realm& realm)
void NavigatorObject::initialize(JS::Realm& realm)
{
auto& heap = this->heap();
- auto* languages = MUST(JS::Array::create(realm.global_object(), 0));
+ auto* languages = MUST(JS::Array::create(realm, 0));
languages->indexed_properties().append(js_string(heap, "en-US"));
// FIXME: All of these should be in Navigator's prototype and be native accessors
diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp
index b4ff04a58e..efc84daba9 100644
--- a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp
+++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp
@@ -618,6 +618,8 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll)
// https://www.w3.org/TR/cssom-view/#dom-window-scrollby
JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll_by)
{
+ auto& realm = *global_object.associated_realm();
+
auto* impl = TRY(impl_from(vm, global_object));
if (!impl->page())
return JS::js_undefined();
@@ -626,12 +628,12 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll_by)
JS::Object* options = nullptr;
if (vm.argument_count() == 0) {
- options = JS::Object::create(global_object, nullptr);
+ options = JS::Object::create(realm, nullptr);
} else if (vm.argument_count() == 1) {
options = TRY(vm.argument(0).to_object(global_object));
} else if (vm.argument_count() >= 2) {
// We ignore arguments 2+ in line with behavior of Chrome and Firefox
- options = JS::Object::create(global_object, nullptr);
+ options = JS::Object::create(realm, nullptr);
MUST(options->set("left", vm.argument(0), ShouldThrowExceptions::No));
MUST(options->set("top", vm.argument(1), ShouldThrowExceptions::No));
MUST(options->set("behavior", JS::js_string(vm, "auto"), ShouldThrowExceptions::No));
diff --git a/Userland/Libraries/LibWeb/Bindings/Wrappable.h b/Userland/Libraries/LibWeb/Bindings/Wrappable.h
index 79c6b75c6b..2e0c4561a7 100644
--- a/Userland/Libraries/LibWeb/Bindings/Wrappable.h
+++ b/Userland/Libraries/LibWeb/Bindings/Wrappable.h
@@ -30,7 +30,7 @@ inline Wrapper* wrap_impl(JS::GlobalObject& global_object, NativeObject& native_
{
auto& realm = *global_object.associated_realm();
if (!native_object.wrapper()) {
- native_object.set_wrapper(*global_object.heap().allocate<typename NativeObject::WrapperType>(global_object, realm, native_object));
+ native_object.set_wrapper(*realm.heap().allocate<typename NativeObject::WrapperType>(realm.global_object(), realm, native_object));
}
return native_object.wrapper();
}
diff --git a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp
index 31af44c7a8..e84d964dc8 100644
--- a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp
+++ b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp
@@ -18,6 +18,7 @@ namespace Web::Crypto {
JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object> const& data)
{
auto& global_object = wrapper()->global_object();
+ auto& realm = *global_object.associated_realm();
// 1. Let algorithm be the algorithm parameter passed to the digest() method.
@@ -25,7 +26,7 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object
auto data_buffer_or_error = Bindings::IDL::get_buffer_source_copy(*data.cell());
if (data_buffer_or_error.is_error()) {
auto* error = wrap(wrapper()->global_object(), DOM::OperationError::create("Failed to copy bytes from ArrayBuffer"));
- auto* promise = JS::Promise::create(global_object);
+ auto* promise = JS::Promise::create(realm);
promise->reject(error);
return promise;
}
@@ -46,13 +47,13 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object
// 4. If an error occurred, return a Promise rejected with normalizedAlgorithm.
else {
auto* error = wrap(wrapper()->global_object(), DOM::NotSupportedError::create(String::formatted("Invalid hash function '{}'", algorithm)));
- auto* promise = JS::Promise::create(global_object);
+ auto* promise = JS::Promise::create(realm);
promise->reject(error);
return promise;
}
// 5. Let promise be a new Promise.
- auto* promise = JS::Promise::create(global_object);
+ auto* promise = JS::Promise::create(realm);
// 6. Return promise and perform the remaining steps in parallel.
// FIXME: We don't have a good abstraction for this yet, so we do it in sync.
@@ -71,7 +72,7 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object
return promise;
}
- auto* result = JS::ArrayBuffer::create(global_object, result_buffer.release_value());
+ auto* result = JS::ArrayBuffer::create(realm, result_buffer.release_value());
// 9. Resolve promise with result.
promise->fulfill(result);
diff --git a/Userland/Libraries/LibWeb/DOM/EventTarget.cpp b/Userland/Libraries/LibWeb/DOM/EventTarget.cpp
index b56a23498a..ae1905081c 100644
--- a/Userland/Libraries/LibWeb/DOM/EventTarget.cpp
+++ b/Userland/Libraries/LibWeb/DOM/EventTarget.cpp
@@ -437,7 +437,7 @@ Bindings::CallbackType* EventTarget::get_current_value_of_event_handler(FlyStrin
// 6. Return scope. (NOTE: Not necessary)
- auto* function = JS::ECMAScriptFunctionObject::create(global_object, name, builder.to_string(), program->body(), program->parameters(), program->function_length(), scope, nullptr, JS::FunctionKind::Normal, program->is_strict_mode(), program->might_need_arguments_object(), is_arrow_function);
+ auto* function = JS::ECMAScriptFunctionObject::create(realm, name, builder.to_string(), program->body(), program->parameters(), program->function_length(), scope, nullptr, JS::FunctionKind::Normal, program->is_strict_mode(), program->might_need_arguments_object(), is_arrow_function);
VERIFY(function);
// 10. Remove settings object's realm execution context from the JavaScript execution context stack.
@@ -488,7 +488,7 @@ void EventTarget::set_event_handler_attribute(FlyString const& name, Optional<Bi
// Optimization: We pass in the event handler here instead of having activate_event_handler do another hash map lookup just to get the same object.
// This handles a new event handler while the other path handles an existing event handler. As such, both paths must have their own
// unique call to activate_event_handler.
- event_target->activate_event_handler(name, new_event_handler, IsAttribute::No);
+ event_target->activate_event_handler(name, new_event_handler);
handler_map.set(name, move(new_event_handler));
return;
@@ -500,12 +500,14 @@ void EventTarget::set_event_handler_attribute(FlyString const& name, Optional<Bi
// 4. Activate an event handler given eventTarget and name.
// NOTE: See the optimization comment above.
- event_target->activate_event_handler(name, event_handler, IsAttribute::No);
+ event_target->activate_event_handler(name, event_handler);
}
// https://html.spec.whatwg.org/multipage/webappapis.html#activate-an-event-handler
-void EventTarget::activate_event_handler(FlyString const& name, HTML::EventHandler& event_handler, IsAttribute is_attribute)
+void EventTarget::activate_event_handler(FlyString const& name, HTML::EventHandler& event_handler)
{
+ auto& realm = *Bindings::main_thread_vm().current_realm();
+
// 1. Let handlerMap be eventTarget's event handler map.
// 2. Let eventHandler be handlerMap[name].
// NOTE: These are achieved by using the passed in event handler.
@@ -517,36 +519,12 @@ void EventTarget::activate_event_handler(FlyString const& name, HTML::EventHandl
// 4. Let callback be the result of creating a Web IDL EventListener instance representing a reference to a function of one argument that executes the steps of the event handler processing algorithm, given eventTarget, name, and its argument.
// The EventListener's callback context can be arbitrary; it does not impact the steps of the event handler processing algorithm. [DOM]
- // FIXME: This is guess work on what global object the NativeFunction should be allocated on.
- // For <body> or <frameset> elements who just had an element attribute set, it will be this's wrapper, as `this` is the result of determine_target_of_event_handler
- // returning the element's document's global object, which is the HTML::Window object.
- // For any other HTMLElement who just had an element attribute set, `this` will be that HTMLElement, so the global object is this's document's realm's global object.
- // For anything else, it came from JavaScript, so use the global object of the provided callback function.
- JS::GlobalObject* global_object = nullptr;
- if (is_attribute == IsAttribute::Yes) {
- if (is<HTML::Window>(this)) {
- auto& window = verify_cast<HTML::Window>(*this);
- // If an element attribute is set on a <body> element before any script is run, Window::wrapper() will be null.
- // Force creation of the global object via the Document::interpreter() lazy initialization mechanism.
- if (window.wrapper() == nullptr)
- window.associated_document().interpreter();
- global_object = static_cast<JS::GlobalObject*>(window.wrapper());
- } else {
- auto& html_element = verify_cast<HTML::HTMLElement>(*this);
- global_object = &html_element.document().realm().global_object();
- }
- } else {
- global_object = &event_handler.value.get<Bindings::CallbackType>().callback.cell()->global_object();
- }
-
- VERIFY(global_object);
-
// NOTE: The callback must keep `this` alive. For example:
// document.body.onunload = () => { console.log("onunload called!"); }
// document.body.remove();
// location.reload();
// The body element is no longer in the DOM and there is no variable holding onto it. However, the onunload handler is still called, meaning the callback keeps the body element alive.
- auto callback_function = JS::NativeFunction::create(*global_object, "", [event_target = NonnullRefPtr(*this), name](JS::VM& vm, auto&) mutable -> JS::ThrowCompletionOr<JS::Value> {
+ auto callback_function = JS::NativeFunction::create(realm, "", [event_target = NonnullRefPtr(*this), name](JS::VM& vm, auto&) mutable -> JS::ThrowCompletionOr<JS::Value> {
// The event dispatcher should only call this with one argument.
VERIFY(vm.argument_count() == 1);
@@ -561,7 +539,7 @@ void EventTarget::activate_event_handler(FlyString const& name, HTML::EventHandl
});
// NOTE: As per the spec, the callback context is arbitrary.
- Bindings::CallbackType callback { JS::make_handle(static_cast<JS::Object*>(callback_function)), verify_cast<HTML::EnvironmentSettingsObject>(*global_object->associated_realm()->host_defined()) };
+ Bindings::CallbackType callback { JS::make_handle(static_cast<JS::Object*>(callback_function)), verify_cast<HTML::EnvironmentSettingsObject>(*realm.host_defined()) };
// 5. Let listener be a new event listener whose type is the event handler event type corresponding to eventHandler and callback is callback.
auto listener = adopt_ref(*new DOMEventListener);
@@ -725,7 +703,7 @@ void EventTarget::element_event_handler_attribute_changed(FlyString const& local
HTML::EventHandler new_event_handler { value };
// 6. Activate an event handler given eventTarget and name.
- event_target->activate_event_handler(local_name, new_event_handler, IsAttribute::Yes);
+ event_target->activate_event_handler(local_name, new_event_handler);
handler_map.set(local_name, move(new_event_handler));
return;
@@ -735,7 +713,7 @@ void EventTarget::element_event_handler_attribute_changed(FlyString const& local
// 6. Activate an event handler given eventTarget and name.
event_handler.value = value;
- event_target->activate_event_handler(local_name, event_handler, IsAttribute::Yes);
+ event_target->activate_event_handler(local_name, event_handler);
}
bool EventTarget::dispatch_event(NonnullRefPtr<Event> event)
diff --git a/Userland/Libraries/LibWeb/DOM/EventTarget.h b/Userland/Libraries/LibWeb/DOM/EventTarget.h
index 3cef8cd7f3..3882cbc3bb 100644
--- a/Userland/Libraries/LibWeb/DOM/EventTarget.h
+++ b/Userland/Libraries/LibWeb/DOM/EventTarget.h
@@ -75,13 +75,8 @@ private:
// Spec Note: The order of the entries of event handler map could be arbitrary. It is not observable through any algorithms that operate on the map.
HashMap<FlyString, HTML::EventHandler> m_event_handler_map;
- enum class IsAttribute {
- No,
- Yes,
- };
-
Bindings::CallbackType* get_current_value_of_event_handler(FlyString const& name);
- void activate_event_handler(FlyString const& name, HTML::EventHandler& event_handler, IsAttribute is_attribute);
+ void activate_event_handler(FlyString const& name, HTML::EventHandler& event_handler);
void deactivate_event_handler(FlyString const& name);
JS::ThrowCompletionOr<void> process_event_handler_for_event(FlyString const& name, Event& event);
};
diff --git a/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp b/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp
index bd3af0bb55..7a71b0ad6b 100644
--- a/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp
+++ b/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp
@@ -15,6 +15,7 @@ namespace Web::Encoding {
JS::Uint8Array* TextEncoder::encode(String const& input) const
{
auto& global_object = wrapper()->global_object();
+ auto& realm = *global_object.associated_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.
@@ -28,8 +29,8 @@ JS::Uint8Array* TextEncoder::encode(String const& input) const
auto byte_buffer = input.to_byte_buffer();
auto array_length = byte_buffer.size();
- auto* array_buffer = JS::ArrayBuffer::create(global_object, move(byte_buffer));
- return JS::Uint8Array::create(global_object, array_length, *array_buffer);
+ auto* array_buffer = JS::ArrayBuffer::create(realm, move(byte_buffer));
+ return JS::Uint8Array::create(realm, array_length, *array_buffer);
}
// https://encoding.spec.whatwg.org/#dom-textencoder-encoding
diff --git a/Userland/Libraries/LibWeb/Fetch/HeadersIterator.cpp b/Userland/Libraries/LibWeb/Fetch/HeadersIterator.cpp
index f3163042d2..732869a068 100644
--- a/Userland/Libraries/LibWeb/Fetch/HeadersIterator.cpp
+++ b/Userland/Libraries/LibWeb/Fetch/HeadersIterator.cpp
@@ -17,6 +17,7 @@ JS::ThrowCompletionOr<JS::Object*> HeadersIterator::next()
{
auto& global_object = wrapper()->global_object();
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_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>> {
@@ -39,7 +40,7 @@ JS::ThrowCompletionOr<JS::Object*> HeadersIterator::next()
case JS::Object::PropertyKind::Value:
return create_iterator_result_object(global_object, JS::js_string(vm, StringView { pair.value }), false);
case JS::Object::PropertyKind::KeyAndValue: {
- auto* array = JS::Array::create_from(global_object, { JS::js_string(vm, StringView { pair.name }), JS::js_string(vm, StringView { pair.value }) });
+ auto* array = JS::Array::create_from(realm, { JS::js_string(vm, StringView { pair.name }), JS::js_string(vm, StringView { pair.value }) });
return create_iterator_result_object(global_object, array, false);
}
default:
diff --git a/Userland/Libraries/LibWeb/FileAPI/Blob.cpp b/Userland/Libraries/LibWeb/FileAPI/Blob.cpp
index 9487334ce9..4c5f9993c4 100644
--- a/Userland/Libraries/LibWeb/FileAPI/Blob.cpp
+++ b/Userland/Libraries/LibWeb/FileAPI/Blob.cpp
@@ -222,13 +222,14 @@ DOM::ExceptionOr<NonnullRefPtr<Blob>> Blob::slice(Optional<i64> start, Optional<
JS::Promise* Blob::text()
{
auto& global_object = wrapper()->global_object();
+ auto& realm = *global_object.associated_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.
// 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(global_object);
+ auto* promise = JS::Promise::create(realm);
auto* result = JS::js_string(global_object.heap(), 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.
@@ -240,14 +241,15 @@ JS::Promise* Blob::text()
JS::Promise* Blob::array_buffer()
{
auto& global_object = wrapper()->global_object();
+ auto& realm = *global_object.associated_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.
// 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(global_object);
- auto buffer_result = JS::ArrayBuffer::create(global_object, m_byte_buffer.size());
+ auto* promise = JS::Promise::create(realm);
+ auto buffer_result = JS::ArrayBuffer::create(realm, m_byte_buffer.size());
if (buffer_result.is_error()) {
promise->reject(buffer_result.release_error().value().release_value());
return promise;
diff --git a/Userland/Libraries/LibWeb/HTML/ImageData.cpp b/Userland/Libraries/LibWeb/HTML/ImageData.cpp
index 87ed96899f..d6ff365097 100644
--- a/Userland/Libraries/LibWeb/HTML/ImageData.cpp
+++ b/Userland/Libraries/LibWeb/HTML/ImageData.cpp
@@ -12,13 +12,15 @@ namespace Web::HTML {
RefPtr<ImageData> ImageData::create_with_size(JS::GlobalObject& global_object, int width, int height)
{
+ auto& realm = *global_object.associated_realm();
+
if (width <= 0 || height <= 0)
return nullptr;
if (width > 16384 || height > 16384)
return nullptr;
- auto data_or_error = JS::Uint8ClampedArray::create(global_object, width * height * 4);
+ auto data_or_error = JS::Uint8ClampedArray::create(realm, width * height * 4);
if (data_or_error.is_error())
return nullptr;
auto* data = data_or_error.release_value();
diff --git a/Userland/Libraries/LibWeb/URL/URLSearchParamsIterator.cpp b/Userland/Libraries/LibWeb/URL/URLSearchParamsIterator.cpp
index bd92b24515..1827364622 100644
--- a/Userland/Libraries/LibWeb/URL/URLSearchParamsIterator.cpp
+++ b/Userland/Libraries/LibWeb/URL/URLSearchParamsIterator.cpp
@@ -16,6 +16,7 @@ JS::Object* URLSearchParamsIterator::next()
{
auto& global_object = wrapper()->global_object();
auto& vm = global_object.vm();
+ auto& realm = *global_object.associated_realm();
if (m_index >= m_url_search_params.m_list.size())
return create_iterator_result_object(global_object, JS::js_undefined(), true);
@@ -26,7 +27,7 @@ JS::Object* URLSearchParamsIterator::next()
else if (m_iteration_kind == JS::Object::PropertyKind::Value)
return create_iterator_result_object(global_object, JS::js_string(vm, entry.value), false);
- return create_iterator_result_object(global_object, JS::Array::create_from(global_object, { JS::js_string(vm, entry.name), JS::js_string(vm, entry.value) }), false);
+ return create_iterator_result_object(global_object, JS::Array::create_from(realm, { JS::js_string(vm, entry.name), JS::js_string(vm, entry.value) }), false);
}
void URLSearchParamsIterator::visit_edges(JS::Cell::Visitor& visitor)
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp
index 2ff380e32e..3dab7fe6ef 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp
@@ -28,7 +28,7 @@ void WebAssemblyInstanceObject::initialize(JS::Realm& realm)
Object::initialize(realm);
VERIFY(!m_exports_object);
- m_exports_object = create(realm.global_object(), nullptr);
+ m_exports_object = create(realm, nullptr);
auto& instance = this->instance();
auto& cache = this->cache();
for (auto& export_ : instance.exports()) {
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp
index 30f6fa8cf2..98e85b529d 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp
@@ -38,6 +38,8 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::grow)
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::buffer_getter)
{
+ auto& realm = *global_object.associated_realm();
+
auto* this_object = TRY(vm.this_value(global_object).to_object(global_object));
if (!is<WebAssemblyMemoryObject>(this_object))
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory");
@@ -47,7 +49,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::buffer_getter)
if (!memory)
return JS::js_undefined();
- auto* array_buffer = JS::ArrayBuffer::create(global_object, &memory->data());
+ auto* array_buffer = JS::ArrayBuffer::create(realm, &memory->data());
array_buffer->set_detach_key(JS::js_string(vm, "WebAssembly.Memory"));
return array_buffer;
}
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
index 6dec92b7c4..4f99393456 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
@@ -164,7 +164,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::compile)
if (buffer_or_error.is_error())
rejection_value = *buffer_or_error.throw_completion().value();
- auto promise = JS::Promise::create(global_object);
+ auto promise = JS::Promise::create(realm);
if (!rejection_value.is_empty()) {
promise->reject(rejection_value);
return promise;
@@ -323,7 +323,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::instantiate)
// FIXME: This shouldn't block!
auto buffer_or_error = vm.argument(0).to_object(global_object);
- auto promise = JS::Promise::create(global_object);
+ auto promise = JS::Promise::create(realm);
bool should_return_module = false;
if (buffer_or_error.is_error()) {
auto rejection_value = *buffer_or_error.throw_completion().value();
@@ -344,7 +344,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::instantiate)
} else if (is<WebAssemblyModuleObject>(buffer)) {
module = &static_cast<WebAssemblyModuleObject*>(buffer)->module();
} else {
- auto error = JS::TypeError::create(global_object, String::formatted("{} is not an ArrayBuffer or a Module", buffer->class_name()));
+ auto error = JS::TypeError::create(realm, String::formatted("{} is not an ArrayBuffer or a Module", buffer->class_name()));
promise->reject(error);
return promise;
}
@@ -356,7 +356,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::instantiate)
} else {
auto instance_object = vm.heap().allocate<WebAssemblyInstanceObject>(global_object, realm, result.release_value());
if (should_return_module) {
- auto object = JS::Object::create(global_object, nullptr);
+ auto object = JS::Object::create(realm, nullptr);
object->define_direct_property("module", vm.heap().allocate<WebAssemblyModuleObject>(global_object, realm, s_compiled_modules.size() - 1), JS::default_attributes);
object->define_direct_property("instance", instance_object, JS::default_attributes);
promise->fulfill(object);
@@ -442,15 +442,17 @@ JS::ThrowCompletionOr<Wasm::Value> to_webassembly_value(JS::GlobalObject& global
JS::NativeFunction* create_native_function(JS::GlobalObject& global_object, Wasm::FunctionAddress address, String const& name)
{
+ auto& realm = *global_object.associated_realm();
Optional<Wasm::FunctionType> type;
WebAssemblyObject::s_abstract_machine.store().get(address)->visit([&](auto const& value) { type = value.type(); });
if (auto entry = WebAssemblyObject::s_global_cache.function_instances.get(address); entry.has_value())
return *entry;
auto function = JS::NativeFunction::create(
- global_object,
+ realm,
name,
[address, type = type.release_value()](JS::VM& vm, JS::GlobalObject& global_object) -> JS::ThrowCompletionOr<JS::Value> {
+ auto& realm = *global_object.associated_realm();
Vector<Wasm::Value> values;
values.ensure_capacity(type.parameters().size());
@@ -474,7 +476,7 @@ JS::NativeFunction* create_native_function(JS::GlobalObject& global_object, Wasm
for (auto& entry : result.values())
result_values.append(to_js_value(global_object, entry));
- return JS::Value(JS::Array::create_from(global_object, result_values));
+ return JS::Value(JS::Array::create_from(realm, result_values));
});
WebAssemblyObject::s_global_cache.function_instances.set(address, function);
diff --git a/Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp b/Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp
index aace7a8dd9..63b124fdd9 100644
--- a/Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp
+++ b/Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp
@@ -214,8 +214,9 @@ void WebSocket::on_message(ByteBuffer message, bool is_text)
} 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();
HTML::MessageEventInit event_init;
- event_init.data = JS::ArrayBuffer::create(global_object, message);
+ event_init.data = JS::ArrayBuffer::create(realm, message);
event_init.origin = url();
dispatch_event(HTML::MessageEvent::create(HTML::EventNames::message, event_init));
return;
diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp
index e16b9e756d..8f684303e6 100644
--- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp
+++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp
@@ -83,6 +83,7 @@ DOM::ExceptionOr<String> XMLHttpRequest::response_text() const
DOM::ExceptionOr<JS::Value> XMLHttpRequest::response()
{
auto& global_object = wrapper()->global_object();
+ auto& realm = *global_object.associated_realm();
// 1. If this’s response type is the empty string or "text", then:
if (m_response_type == Bindings::XMLHttpRequestResponseType::Empty || m_response_type == Bindings::XMLHttpRequestResponseType::Text) {
@@ -108,7 +109,7 @@ DOM::ExceptionOr<JS::Value> XMLHttpRequest::response()
// 5. If this’s response type is "arraybuffer",
if (m_response_type == Bindings::XMLHttpRequestResponseType::Arraybuffer) {
// then set this’s response object to a new ArrayBuffer object representing this’s received bytes. If this throws an exception, then set this’s response object to failure and return null.
- auto buffer_result = JS::ArrayBuffer::create(global_object, m_received_bytes.size());
+ auto buffer_result = JS::ArrayBuffer::create(realm, m_received_bytes.size());
if (buffer_result.is_error()) {
m_response_object = Failure();
return JS::js_null();
diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp
index 06c0a96e67..a2ecb0f1d8 100644
--- a/Userland/Utilities/js.cpp
+++ b/Userland/Utilities/js.cpp
@@ -1264,15 +1264,17 @@ static bool parse_and_run(JS::Interpreter& interpreter, StringView source, Strin
static JS::ThrowCompletionOr<JS::Value> load_ini_impl(JS::VM& vm, JS::GlobalObject& global_object)
{
+ auto& realm = *global_object.associated_realm();
+
auto filename = TRY(vm.argument(0).to_string(global_object));
auto file = Core::File::construct(filename);
if (!file->open(Core::OpenMode::ReadOnly))
return vm.throw_completion<JS::Error>(global_object, String::formatted("Failed to open '{}': {}", filename, file->error_string()));
auto config_file = MUST(Core::ConfigFile::open(filename, file->fd()));
- auto* object = JS::Object::create(global_object, global_object.object_prototype());
+ auto* object = JS::Object::create(realm, global_object.object_prototype());
for (auto const& group : config_file->groups()) {
- auto* group_object = JS::Object::create(global_object, global_object.object_prototype());
+ auto* group_object = JS::Object::create(realm, global_object.object_prototype());
for (auto const& key : config_file->keys(group)) {
auto entry = config_file->read_entry(group, key);
group_object->define_direct_property(key, js_string(vm, move(entry)), JS::Attribute::Enumerable | JS::Attribute::Configurable | JS::Attribute::Writable);