diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp index 9ed704ff86..f84d5388a5 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp @@ -2006,7 +2006,7 @@ namespace Web::Bindings { @wrapper_class@* @wrapper_class@::create(JS::Realm& realm, @fully_qualified_name@& impl) { - return realm.heap().allocate<@wrapper_class@>(realm.global_object(), realm, impl); + return realm.heap().allocate<@wrapper_class@>(realm, realm, impl); } )~~~"); @@ -3670,7 +3670,7 @@ namespace Web::Bindings { @wrapper_class@* @wrapper_class@::create(JS::Realm& realm, @fully_qualified_name@& impl) { - return realm.heap().allocate<@wrapper_class@>(realm.global_object(), realm, impl); + return realm.heap().allocate<@wrapper_class@>(realm, realm, impl); } @wrapper_class@::@wrapper_class@(JS::Realm& realm, @fully_qualified_name@& impl) diff --git a/Tests/LibWasm/test-wasm.cpp b/Tests/LibWasm/test-wasm.cpp index f6814c6769..821176cd2e 100644 --- a/Tests/LibWasm/test-wasm.cpp +++ b/Tests/LibWasm/test-wasm.cpp @@ -50,7 +50,7 @@ public: static JS::ThrowCompletionOr create(JS::Realm& realm, Wasm::Module module, HashMap const& imports) { auto& vm = realm.vm(); - auto* instance = realm.heap().allocate(realm.global_object(), *realm.global_object().object_prototype()); + auto* instance = realm.heap().allocate(realm, *realm.global_object().object_prototype()); instance->m_module = move(module); Wasm::Linker linker(*instance->m_module); linker.link(imports); diff --git a/Userland/Applications/Spreadsheet/Workbook.cpp b/Userland/Applications/Spreadsheet/Workbook.cpp index aae822b2e8..3ebdd15c6d 100644 --- a/Userland/Applications/Spreadsheet/Workbook.cpp +++ b/Userland/Applications/Spreadsheet/Workbook.cpp @@ -29,7 +29,7 @@ Workbook::Workbook(NonnullRefPtrVector&& sheets, GUI::Window& parent_wind , m_main_execution_context(m_vm->heap()) , m_parent_window(parent_window) { - m_workbook_object = m_vm->heap().allocate(m_interpreter->global_object(), m_interpreter->realm(), *this); + m_workbook_object = m_vm->heap().allocate(m_interpreter->realm(), m_interpreter->realm(), *this); m_interpreter->global_object().define_direct_property("workbook", workbook_object(), JS::default_attributes); m_main_execution_context.current_node = nullptr; diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index 86d86d61a8..64e656a6d3 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -602,7 +602,7 @@ void ContinuePendingUnwind::replace_references_impl(BasicBlock const& from, Basi ThrowCompletionOr PushDeclarativeEnvironment::execute_impl(Bytecode::Interpreter& interpreter) const { - auto* environment = interpreter.vm().heap().allocate_without_global_object(interpreter.vm().lexical_environment()); + auto* environment = interpreter.vm().heap().allocate_without_realm(interpreter.vm().lexical_environment()); interpreter.vm().running_execution_context().lexical_environment = environment; interpreter.vm().running_execution_context().variable_environment = environment; return {}; diff --git a/Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp b/Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp index 2bcd3a9019..6c2701f0fb 100644 --- a/Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp +++ b/Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp @@ -27,8 +27,8 @@ void $262Object::initialize(JS::Realm& realm) { Base::initialize(realm); - m_agent = vm().heap().allocate(realm.global_object(), realm); - m_is_htmldda = vm().heap().allocate(realm.global_object(), realm); + m_agent = vm().heap().allocate(realm, realm); + m_is_htmldda = vm().heap().allocate(realm, realm); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function("clearKeptObjects", clear_kept_objects, 0, attr); @@ -59,7 +59,7 @@ JS_DEFINE_NATIVE_FUNCTION($262Object::create_realm) { auto* realm = Realm::create(vm); VERIFY(realm); - auto* realm_global_object = vm.heap().allocate_without_global_object(*realm); + auto* realm_global_object = vm.heap().allocate_without_realm(*realm); VERIFY(realm_global_object); realm->set_global_object(realm_global_object, nullptr); realm_global_object->set_associated_realm(*realm); diff --git a/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.cpp b/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.cpp index fe6d29f7d4..dd101f2700 100644 --- a/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.cpp +++ b/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.cpp @@ -19,7 +19,7 @@ void GlobalObject::initialize_global_object() Base::initialize_global_object(); auto& realm = *associated_realm(); - m_$262 = vm().heap().allocate<$262Object>(*this, realm); + m_$262 = vm().heap().allocate<$262Object>(realm, realm); // https://github.com/tc39/test262/blob/master/INTERPRETING.md#host-defined-functions u8 attr = Attribute::Writable | Attribute::Configurable; diff --git a/Userland/Libraries/LibJS/Heap/Heap.h b/Userland/Libraries/LibJS/Heap/Heap.h index 110109860c..25e89ebac3 100644 --- a/Userland/Libraries/LibJS/Heap/Heap.h +++ b/Userland/Libraries/LibJS/Heap/Heap.h @@ -36,7 +36,7 @@ public: ~Heap(); template - T* allocate_without_global_object(Args&&... args) + T* allocate_without_realm(Args&&... args) { auto* memory = allocate_cell(sizeof(T)); new (memory) T(forward(args)...); @@ -44,12 +44,11 @@ public: } template - T* allocate(GlobalObject& global_object, Args&&... args) + T* allocate(Realm& realm, Args&&... args) { auto* memory = allocate_cell(sizeof(T)); new (memory) T(forward(args)...); auto* cell = static_cast(memory); - auto& realm = realm_from_global_object(global_object); memory->initialize(realm); return cell; } diff --git a/Userland/Libraries/LibJS/Interpreter.h b/Userland/Libraries/LibJS/Interpreter.h index d48562c50d..9d939ee8c0 100644 --- a/Userland/Libraries/LibJS/Interpreter.h +++ b/Userland/Libraries/LibJS/Interpreter.h @@ -48,7 +48,7 @@ public: interpreter->m_global_execution_context = MUST(Realm::initialize_host_defined_realm( vm, [&](Realm& realm) -> GlobalObject* { - global_object = interpreter->heap().allocate_without_global_object(realm, forward(args)...); + global_object = interpreter->heap().allocate_without_realm(realm, forward(args)...); return global_object; }, nullptr)); diff --git a/Userland/Libraries/LibJS/Module.cpp b/Userland/Libraries/LibJS/Module.cpp index ef3d315a05..f32029e474 100644 --- a/Userland/Libraries/LibJS/Module.cpp +++ b/Userland/Libraries/LibJS/Module.cpp @@ -87,6 +87,8 @@ ThrowCompletionOr Module::get_module_namespace(VM& vm) // 10.4.6.12 ModuleNamespaceCreate ( module, exports ), https://tc39.es/ecma262/#sec-modulenamespacecreate Object* Module::module_namespace_create(VM& vm, Vector unambiguous_names) { + auto& realm = this->realm(); + // 1. Assert: module.[[Namespace]] is empty. VERIFY(m_namespace.is_null()); @@ -97,7 +99,7 @@ Object* Module::module_namespace_create(VM& vm, Vector unambiguous_na // 6. Let sortedExports be a List whose elements are the elements of exports ordered as if an Array of the same values had been sorted using %Array.prototype.sort% using undefined as comparefn. // 7. Set M.[[Exports]] to sortedExports. // 8. Create own properties of M corresponding to the definitions in 28.3. - Object* module_namespace = vm.heap().allocate(realm().global_object(), realm(), this, move(unambiguous_names)); + Object* module_namespace = vm.heap().allocate(realm, realm, this, move(unambiguous_names)); // 9. Set module.[[Namespace]] to M. m_namespace = make_handle(module_namespace); diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp index f0c817b44f..1ae9bdf066 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp @@ -400,14 +400,14 @@ ThrowCompletionOr get_prototype_from_constructor(GlobalObject& global_o // 9.1.2.2 NewDeclarativeEnvironment ( E ), https://tc39.es/ecma262/#sec-newdeclarativeenvironment DeclarativeEnvironment* new_declarative_environment(Environment& environment) { - return environment.heap().allocate_without_global_object(&environment); + return environment.heap().allocate_without_realm(&environment); } // 9.1.2.3 NewObjectEnvironment ( O, W, E ), https://tc39.es/ecma262/#sec-newobjectenvironment ObjectEnvironment* new_object_environment(Object& object, bool is_with_environment, Environment* environment) { auto& heap = object.heap(); - return heap.allocate_without_global_object(object, is_with_environment ? ObjectEnvironment::IsWithEnvironment::Yes : ObjectEnvironment::IsWithEnvironment::No, environment); + return heap.allocate_without_realm(object, is_with_environment ? ObjectEnvironment::IsWithEnvironment::Yes : ObjectEnvironment::IsWithEnvironment::No, environment); } // 9.1.2.4 NewFunctionEnvironment ( F, newTarget ), https://tc39.es/ecma262/#sec-newfunctionenvironment @@ -416,7 +416,7 @@ FunctionEnvironment* new_function_environment(ECMAScriptFunctionObject& function auto& heap = function.heap(); // 1. Let env be a new function Environment Record containing no bindings. - auto* env = heap.allocate_without_global_object(function.environment()); + auto* env = heap.allocate_without_realm(function.environment()); // 2. Set env.[[FunctionObject]] to F. env->set_function_object(function); @@ -443,7 +443,7 @@ PrivateEnvironment* new_private_environment(VM& vm, PrivateEnvironment* outer) { // 1. Let names be a new empty List. // 2. Return the PrivateEnvironment Record { [[OuterPrivateEnvironment]]: outerPrivEnv, [[Names]]: names }. - return vm.heap().allocate_without_global_object(outer); + return vm.heap().allocate_without_realm(outer); } // 9.4.3 GetThisEnvironment ( ), https://tc39.es/ecma262/#sec-getthisenvironment @@ -1093,7 +1093,7 @@ Object* create_mapped_arguments_object(GlobalObject& global_object, FunctionObje // 7. Set obj.[[Set]] as specified in 10.4.4.4. // 8. Set obj.[[Delete]] as specified in 10.4.4.5. // 9. Set obj.[[Prototype]] to %Object.prototype%. - auto* object = vm.heap().allocate(global_object, realm, environment); + auto* object = vm.heap().allocate(realm, realm, environment); // 14. Let index be 0. // 15. Repeat, while index < len, diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h index 795d85c77f..be568018a7 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h @@ -135,7 +135,7 @@ ThrowCompletionOr ordinary_create_from_constructor(GlobalObject& global_obje { auto& realm = *global_object.associated_realm(); auto* prototype = TRY(get_prototype_from_constructor(global_object, constructor, intrinsic_default_prototype)); - return realm.heap().allocate(realm.global_object(), forward(args)..., *prototype); + return realm.heap().allocate(realm, forward(args)..., *prototype); } // 14.1 MergeLists ( a, b ), https://tc39.es/proposal-temporal/#sec-temporal-mergelists diff --git a/Userland/Libraries/LibJS/Runtime/Accessor.h b/Userland/Libraries/LibJS/Runtime/Accessor.h index bd46a87ac8..b9efa43594 100644 --- a/Userland/Libraries/LibJS/Runtime/Accessor.h +++ b/Userland/Libraries/LibJS/Runtime/Accessor.h @@ -17,7 +17,7 @@ class Accessor final : public Cell { public: static Accessor* create(VM& vm, FunctionObject* getter, FunctionObject* setter) { - return vm.heap().allocate_without_global_object(getter, setter); + return vm.heap().allocate_without_realm(getter, setter); } Accessor(FunctionObject* getter, FunctionObject* setter) diff --git a/Userland/Libraries/LibJS/Runtime/AggregateError.cpp b/Userland/Libraries/LibJS/Runtime/AggregateError.cpp index eb530ae04b..cfca1966b1 100644 --- a/Userland/Libraries/LibJS/Runtime/AggregateError.cpp +++ b/Userland/Libraries/LibJS/Runtime/AggregateError.cpp @@ -12,7 +12,7 @@ namespace JS { AggregateError* AggregateError::create(Realm& realm) { - return realm.heap().allocate(realm.global_object(), *realm.global_object().aggregate_error_prototype()); + return realm.heap().allocate(realm, *realm.global_object().aggregate_error_prototype()); } AggregateError::AggregateError(Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/Array.cpp b/Userland/Libraries/LibJS/Runtime/Array.cpp index c03e665dd4..62668cd46b 100644 --- a/Userland/Libraries/LibJS/Runtime/Array.cpp +++ b/Userland/Libraries/LibJS/Runtime/Array.cpp @@ -32,7 +32,7 @@ ThrowCompletionOr Array::create(Realm& realm, u64 length, Object* protot // 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 = realm.heap().allocate(realm.global_object(), *prototype); + auto* array = realm.heap().allocate(realm, *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 })); diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp index 3a820084c3..c177db0f92 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp @@ -17,17 +17,17 @@ ThrowCompletionOr ArrayBuffer::create(Realm& realm, size_t byte_le if (buffer.is_error()) return realm.vm().throw_completion(realm.global_object(), ErrorType::NotEnoughMemoryToAllocate, byte_length); - return realm.heap().allocate(realm.global_object(), buffer.release_value(), *realm.global_object().array_buffer_prototype()); + return realm.heap().allocate(realm, buffer.release_value(), *realm.global_object().array_buffer_prototype()); } ArrayBuffer* ArrayBuffer::create(Realm& realm, ByteBuffer buffer) { - return realm.heap().allocate(realm.global_object(), move(buffer), *realm.global_object().array_buffer_prototype()); + return realm.heap().allocate(realm, move(buffer), *realm.global_object().array_buffer_prototype()); } ArrayBuffer* ArrayBuffer::create(Realm& realm, ByteBuffer* buffer) { - return realm.heap().allocate(realm.global_object(), buffer, *realm.global_object().array_buffer_prototype()); + return realm.heap().allocate(realm, buffer, *realm.global_object().array_buffer_prototype()); } ArrayBuffer::ArrayBuffer(ByteBuffer buffer, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/ArrayIterator.cpp b/Userland/Libraries/LibJS/Runtime/ArrayIterator.cpp index 340ff7db2c..c7dde4fb13 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayIterator.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayIterator.cpp @@ -11,7 +11,7 @@ namespace JS { ArrayIterator* ArrayIterator::create(Realm& realm, Value array, Object::PropertyKind iteration_kind) { - return realm.heap().allocate(realm.global_object(), array, iteration_kind, *realm.global_object().array_iterator_prototype()); + return realm.heap().allocate(realm, 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/AsyncFromSyncIterator.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.cpp index 1747e6c800..a31e5e2729 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.cpp @@ -13,7 +13,7 @@ namespace JS { AsyncFromSyncIterator* AsyncFromSyncIterator::create(Realm& realm, Iterator sync_iterator_record) { - return realm.heap().allocate(realm.global_object(), realm, sync_iterator_record); + return realm.heap().allocate(realm, realm, sync_iterator_record); } AsyncFromSyncIterator::AsyncFromSyncIterator(Realm& realm, Iterator sync_iterator_record) diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp index 731f3f23bb..89ce4cf978 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp @@ -14,7 +14,7 @@ namespace JS { ThrowCompletionOr AsyncFunctionDriverWrapper::create(Realm& realm, GeneratorObject* generator_object) { - auto wrapper = realm.heap().allocate(realm.global_object(), realm, generator_object); + auto wrapper = realm.heap().allocate(realm, realm, generator_object); return wrapper->react_to_async_task_completion(realm.vm(), realm.global_object(), js_undefined(), true); } diff --git a/Userland/Libraries/LibJS/Runtime/BigInt.cpp b/Userland/Libraries/LibJS/Runtime/BigInt.cpp index 8a2d7bc43b..f86b5f5bc3 100644 --- a/Userland/Libraries/LibJS/Runtime/BigInt.cpp +++ b/Userland/Libraries/LibJS/Runtime/BigInt.cpp @@ -19,7 +19,7 @@ BigInt::BigInt(Crypto::SignedBigInteger big_integer) BigInt* js_bigint(Heap& heap, Crypto::SignedBigInteger big_integer) { - return heap.allocate_without_global_object(move(big_integer)); + return heap.allocate_without_realm(move(big_integer)); } BigInt* js_bigint(VM& vm, Crypto::SignedBigInteger big_integer) diff --git a/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp b/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp index ce1f048941..9187b3eb80 100644 --- a/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp @@ -11,7 +11,7 @@ namespace JS { BigIntObject* BigIntObject::create(Realm& realm, BigInt& bigint) { - return realm.heap().allocate(realm.global_object(), bigint, *realm.global_object().bigint_prototype()); + return realm.heap().allocate(realm, bigint, *realm.global_object().bigint_prototype()); } BigIntObject::BigIntObject(BigInt& bigint, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/BooleanObject.cpp b/Userland/Libraries/LibJS/Runtime/BooleanObject.cpp index af0dd4f16f..5a79c32fb2 100644 --- a/Userland/Libraries/LibJS/Runtime/BooleanObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/BooleanObject.cpp @@ -11,7 +11,7 @@ namespace JS { BooleanObject* BooleanObject::create(Realm& realm, bool value) { - return realm.heap().allocate(realm.global_object(), value, *realm.global_object().boolean_prototype()); + return realm.heap().allocate(realm, value, *realm.global_object().boolean_prototype()); } BooleanObject::BooleanObject(bool value, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/BoundFunction.cpp b/Userland/Libraries/LibJS/Runtime/BoundFunction.cpp index 89b44f4129..be7850f7e0 100644 --- a/Userland/Libraries/LibJS/Runtime/BoundFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/BoundFunction.cpp @@ -26,7 +26,7 @@ ThrowCompletionOr BoundFunction::create(Realm& realm, FunctionOb // 7. Set obj.[[BoundTargetFunction]] to targetFunction. // 8. Set obj.[[BoundThis]] to boundThis. // 9. Set obj.[[BoundArguments]] to boundArgs. - auto* object = realm.heap().allocate(realm.global_object(), realm, target_function, bound_this, move(bound_arguments), prototype); + auto* object = realm.heap().allocate(realm, realm, target_function, bound_this, move(bound_arguments), prototype); // 10. Return obj. return object; diff --git a/Userland/Libraries/LibJS/Runtime/DataView.cpp b/Userland/Libraries/LibJS/Runtime/DataView.cpp index f8f247afc9..bb3909b47b 100644 --- a/Userland/Libraries/LibJS/Runtime/DataView.cpp +++ b/Userland/Libraries/LibJS/Runtime/DataView.cpp @@ -10,7 +10,7 @@ namespace JS { DataView* DataView::create(Realm& realm, ArrayBuffer* viewed_buffer, size_t byte_length, size_t byte_offset) { - return realm.heap().allocate(realm.global_object(), viewed_buffer, byte_length, byte_offset, *realm.global_object().data_view_prototype()); + return realm.heap().allocate(realm, 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/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp index bc8bb5c87b..83af042624 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.cpp +++ b/Userland/Libraries/LibJS/Runtime/Date.cpp @@ -18,7 +18,7 @@ namespace JS { Date* Date::create(Realm& realm, double date_value) { - return realm.heap().allocate(realm.global_object(), date_value, *realm.global_object().date_prototype()); + return realm.heap().allocate(realm, date_value, *realm.global_object().date_prototype()); } Date::Date(double date_value, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.cpp b/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.cpp index 0f8e6f1862..4e30e50335 100644 --- a/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.cpp +++ b/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.cpp @@ -18,7 +18,7 @@ DeclarativeEnvironment* DeclarativeEnvironment::create_for_per_iteration_binding auto bindings = other.m_bindings.span().slice(0, bindings_size); auto* parent_environment = other.outer_environment(); - return parent_environment->heap().allocate_without_global_object(parent_environment, bindings); + return parent_environment->heap().allocate_without_realm(parent_environment, bindings); } DeclarativeEnvironment::DeclarativeEnvironment() diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp index 7828d128dd..292a84e7c5 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp @@ -45,12 +45,12 @@ ECMAScriptFunctionObject* ECMAScriptFunctionObject::create(Realm& realm, FlyStri prototype = realm.global_object().async_generator_function_prototype(); break; } - return realm.heap().allocate(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)); + return realm.heap().allocate(realm, 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(Realm& realm, FlyString name, Object& prototype, String source_text, Statement const& ecmascript_code, Vector 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 class_field_initializer_name) { - return realm.heap().allocate(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)); + return realm.heap().allocate(realm, 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 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 class_field_initializer_name) @@ -114,7 +114,7 @@ void ECMAScriptFunctionObject::initialize(Realm& realm) Object* prototype = nullptr; switch (m_kind) { case FunctionKind::Normal: - prototype = vm.heap().allocate(realm.global_object(), *realm.global_object().new_ordinary_function_prototype_object_shape()); + prototype = vm.heap().allocate(realm, *realm.global_object().new_ordinary_function_prototype_object_shape()); MUST(prototype->define_property_or_throw(vm.names.constructor, { .value = this, .writable = true, .enumerable = false, .configurable = true })); break; case FunctionKind::Generator: diff --git a/Userland/Libraries/LibJS/Runtime/Error.cpp b/Userland/Libraries/LibJS/Runtime/Error.cpp index e7dbade620..780aa8b137 100644 --- a/Userland/Libraries/LibJS/Runtime/Error.cpp +++ b/Userland/Libraries/LibJS/Runtime/Error.cpp @@ -16,7 +16,7 @@ namespace JS { Error* Error::create(Realm& realm) { - return realm.heap().allocate(realm.global_object(), *realm.global_object().error_prototype()); + return realm.heap().allocate(realm, *realm.global_object().error_prototype()); } Error* Error::create(Realm& realm, String const& message) @@ -99,8 +99,7 @@ String Error::stack_string() const #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ ClassName* ClassName::create(Realm& realm) \ { \ - return realm.heap().allocate( \ - realm.global_object(), *realm.global_object().snake_name##_prototype()); /* */ \ + return realm.heap().allocate(realm, *realm.global_object().snake_name##_prototype()); /* */ \ } \ \ ClassName* ClassName::create(Realm& realm, String const& message) \ diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp index f9e1d03e90..9737c5630f 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp @@ -27,7 +27,7 @@ ThrowCompletionOr GeneratorObject::create(Realm& realm, Value generating_function_prototype = TRY(generating_function->get(vm.names.prototype)); } auto* generating_function_prototype_object = TRY(generating_function_prototype.to_object(realm.global_object())); - auto object = realm.heap().allocate(realm.global_object(), realm, *generating_function_prototype_object, move(execution_context)); + auto object = realm.heap().allocate(realm, 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; diff --git a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp index 30015e0f6d..0868fac551 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp +++ b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp @@ -19,8 +19,8 @@ GlobalEnvironment::GlobalEnvironment(GlobalObject& global_object, Object& this_v : Environment(nullptr) , m_global_this_value(&this_value) { - m_object_record = global_object.heap().allocate_without_global_object(global_object, ObjectEnvironment::IsWithEnvironment::No, nullptr); - m_declarative_record = global_object.heap().allocate_without_global_object(); + m_object_record = global_object.heap().allocate_without_realm(global_object, ObjectEnvironment::IsWithEnvironment::No, nullptr); + m_declarative_record = global_object.heap().allocate_without_realm(); } void GlobalEnvironment::visit_edges(Cell::Visitor& visitor) diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp index e00b22ded7..0d84028f45 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp @@ -154,47 +154,47 @@ void GlobalObject::initialize_global_object() // These are done first since other prototypes depend on their presence. VERIFY(associated_realm()); auto& realm = *associated_realm(); - m_empty_object_shape = heap().allocate_without_global_object(realm); - m_object_prototype = heap().allocate_without_global_object(realm); - m_function_prototype = heap().allocate_without_global_object(realm); + m_empty_object_shape = heap().allocate_without_realm(realm); + m_object_prototype = heap().allocate_without_realm(realm); + m_function_prototype = heap().allocate_without_realm(realm); - m_new_object_shape = vm.heap().allocate_without_global_object(realm); + m_new_object_shape = vm.heap().allocate_without_realm(realm); m_new_object_shape->set_prototype_without_transition(m_object_prototype); - m_new_ordinary_function_prototype_object_shape = vm.heap().allocate_without_global_object(realm); + m_new_ordinary_function_prototype_object_shape = vm.heap().allocate_without_realm(realm); m_new_ordinary_function_prototype_object_shape->set_prototype_without_transition(m_object_prototype); m_new_ordinary_function_prototype_object_shape->add_property_without_transition(vm.names.constructor, Attribute::Writable | Attribute::Configurable); - // Normally Heap::allocate() takes care of this, but these are allocated via allocate_without_global_object(). + // Normally Heap::allocate() takes care of this, but these are allocated via allocate_without_realm(). static_cast(m_function_prototype)->initialize(realm); static_cast(m_object_prototype)->initialize(realm); Object::set_prototype(m_object_prototype); // This must be initialized before allocating AggregateErrorPrototype, which uses ErrorPrototype as its prototype. - m_error_prototype = heap().allocate(*this, realm); + m_error_prototype = heap().allocate(realm, realm); #define __JS_ENUMERATE(ClassName, snake_name) \ if (!m_##snake_name##_prototype) \ - m_##snake_name##_prototype = heap().allocate(*this, realm); + m_##snake_name##_prototype = heap().allocate(realm, realm); JS_ENUMERATE_ITERATOR_PROTOTYPES #undef __JS_ENUMERATE // These must be initialized separately as they have no companion constructor - m_async_from_sync_iterator_prototype = heap().allocate(*this, realm); - m_async_generator_prototype = heap().allocate(*this, realm); - m_generator_prototype = heap().allocate(*this, realm); - m_intl_segments_prototype = heap().allocate(*this, realm); + m_async_from_sync_iterator_prototype = heap().allocate(realm, realm); + m_async_generator_prototype = heap().allocate(realm, realm); + m_generator_prototype = heap().allocate(realm, realm); + m_intl_segments_prototype = heap().allocate(realm, realm); #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ if (!m_##snake_name##_prototype) \ - m_##snake_name##_prototype = heap().allocate(*this, realm); + m_##snake_name##_prototype = heap().allocate(realm, realm); JS_ENUMERATE_BUILTIN_TYPES #undef __JS_ENUMERATE #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ if (!m_intl_##snake_name##_prototype) \ - m_intl_##snake_name##_prototype = heap().allocate(*this, realm); + m_intl_##snake_name##_prototype = heap().allocate(realm, realm); JS_ENUMERATE_INTL_OBJECTS #undef __JS_ENUMERATE @@ -206,7 +206,7 @@ void GlobalObject::initialize_global_object() #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ if (!m_temporal_##snake_name##_prototype) \ - m_temporal_##snake_name##_prototype = heap().allocate(*this, realm); + m_temporal_##snake_name##_prototype = heap().allocate(realm, realm); JS_ENUMERATE_TEMPORAL_OBJECTS #undef __JS_ENUMERATE @@ -250,13 +250,13 @@ void GlobalObject::initialize_global_object() define_direct_property(vm.names.undefined, js_undefined(), 0); define_direct_property(vm.names.globalThis, this, attr); - define_direct_property(vm.names.console, heap().allocate(*this, realm), attr); - define_direct_property(vm.names.Atomics, heap().allocate(*this, realm), attr); - define_direct_property(vm.names.Math, heap().allocate(*this, realm), attr); - define_direct_property(vm.names.JSON, heap().allocate(*this, realm), attr); - define_direct_property(vm.names.Reflect, heap().allocate(*this, realm), attr); - define_direct_property(vm.names.Intl, heap().allocate(*this, realm), attr); - define_direct_property(vm.names.Temporal, heap().allocate(*this, realm), attr); + define_direct_property(vm.names.console, heap().allocate(realm, realm), attr); + define_direct_property(vm.names.Atomics, heap().allocate(realm, realm), attr); + define_direct_property(vm.names.Math, heap().allocate(realm, realm), attr); + define_direct_property(vm.names.JSON, heap().allocate(realm, realm), attr); + define_direct_property(vm.names.Reflect, heap().allocate(realm, realm), attr); + define_direct_property(vm.names.Intl, heap().allocate(realm, realm), attr); + define_direct_property(vm.names.Temporal, heap().allocate(realm, realm), attr); // This must be initialized before allocating AggregateErrorConstructor, which uses ErrorConstructor as its prototype. initialize_constructor(vm.names.Error, m_error_constructor, m_error_prototype); diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.h b/Userland/Libraries/LibJS/Runtime/GlobalObject.h index 75bb908fa7..c25e480b30 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.h +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.h @@ -178,7 +178,7 @@ inline void GlobalObject::initialize_constructor(PropertyKey const& property_key { auto& vm = this->vm(); auto& realm = *associated_realm(); - constructor = heap().allocate(*this, realm); + constructor = heap().allocate(realm, realm); constructor->define_direct_property(vm.names.name, js_string(heap(), property_key.as_string()), Attribute::Configurable); if (prototype) prototype->define_direct_property(vm.names.constructor, constructor, attributes); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp b/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp index 0c77d01bf4..fbd5a5f350 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp @@ -13,7 +13,7 @@ namespace JS::Intl { CollatorCompareFunction* CollatorCompareFunction::create(Realm& realm, Collator& collator) { - return realm.heap().allocate(realm.global_object(), realm, collator); + return realm.heap().allocate(realm, realm, collator); } CollatorCompareFunction::CollatorCompareFunction(Realm& realm, Collator& collator) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp index d78d110f5e..b926e280d3 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp @@ -16,7 +16,7 @@ namespace JS::Intl { // 11.5.5 DateTime Format Functions, https://tc39.es/ecma402/#sec-datetime-format-functions DateTimeFormatFunction* DateTimeFormatFunction::create(Realm& realm, DateTimeFormat& date_time_format) { - return realm.heap().allocate(realm.global_object(), date_time_format, *realm.global_object().function_prototype()); + return realm.heap().allocate(realm, date_time_format, *realm.global_object().function_prototype()); } DateTimeFormatFunction::DateTimeFormatFunction(DateTimeFormat& date_time_format, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp b/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp index d5bb9c6e6b..75d9f9cce2 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp @@ -16,7 +16,7 @@ namespace JS::Intl { Locale* Locale::create(Realm& realm, Unicode::LocaleID const& locale_id) { - return realm.heap().allocate(realm.global_object(), locale_id, *realm.global_object().intl_locale_prototype()); + return realm.heap().allocate(realm, locale_id, *realm.global_object().intl_locale_prototype()); } // 14 Locale Objects, https://tc39.es/ecma402/#locale-objects diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.cpp index 01d758ea1b..75d0c68171 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.cpp @@ -14,7 +14,7 @@ namespace JS::Intl { // 1.1.4 Number Format Functions, https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/proposed.html#sec-number-format-functions NumberFormatFunction* NumberFormatFunction::create(Realm& realm, NumberFormat& number_format) { - return realm.heap().allocate(realm.global_object(), number_format, *realm.global_object().function_prototype()); + return realm.heap().allocate(realm, number_format, *realm.global_object().function_prototype()); } NumberFormatFunction::NumberFormatFunction(NumberFormat& number_format, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp b/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp index 1095226566..a24ce1a082 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp @@ -19,7 +19,7 @@ SegmentIterator* SegmentIterator::create(Realm& realm, Segmenter& segmenter, Utf // 4. Set iterator.[[IteratedString]] to string. // 5. Set iterator.[[IteratedStringNextSegmentCodeUnitIndex]] to 0. // 6. Return iterator. - return realm.heap().allocate(realm.global_object(), realm, segmenter, move(string), segments); + return realm.heap().allocate(realm, 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/Segments.cpp b/Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp index ce3590ab5a..4ea60d6565 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp @@ -18,7 +18,7 @@ Segments* Segments::create(Realm& realm, Segmenter& segmenter, Utf16String strin // 3. Set segments.[[SegmentsSegmenter]] to segmenter. // 4. Set segments.[[SegmentsString]] to string. // 5. Return segments. - return realm.heap().allocate(realm.global_object(), realm, segmenter, move(string)); + return realm.heap().allocate(realm, realm, segmenter, move(string)); } // 18.5 Segments Objects, https://tc39.es/ecma402/#sec-segments-objects diff --git a/Userland/Libraries/LibJS/Runtime/Map.cpp b/Userland/Libraries/LibJS/Runtime/Map.cpp index 75e8b206b3..6c8824bd59 100644 --- a/Userland/Libraries/LibJS/Runtime/Map.cpp +++ b/Userland/Libraries/LibJS/Runtime/Map.cpp @@ -10,7 +10,7 @@ namespace JS { Map* Map::create(Realm& realm) { - return realm.heap().allocate(realm.global_object(), *realm.global_object().map_prototype()); + return realm.heap().allocate(realm, *realm.global_object().map_prototype()); } Map::Map(Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/MapIterator.cpp b/Userland/Libraries/LibJS/Runtime/MapIterator.cpp index 4a3f75b4a0..52cee6fad5 100644 --- a/Userland/Libraries/LibJS/Runtime/MapIterator.cpp +++ b/Userland/Libraries/LibJS/Runtime/MapIterator.cpp @@ -11,7 +11,7 @@ namespace JS { MapIterator* MapIterator::create(Realm& realm, Map& map, Object::PropertyKind iteration_kind) { - return realm.heap().allocate(realm.global_object(), map, iteration_kind, *realm.global_object().map_iterator_prototype()); + return realm.heap().allocate(realm, 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/NativeFunction.cpp b/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp index 93b1e58f45..64ec73c833 100644 --- a/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp @@ -36,7 +36,7 @@ NativeFunction* NativeFunction::create(Realm& allocating_realm, Function(allocating_realm.global_object(), move(behaviour), prototype.value(), *realm.value()); + auto* function = allocating_realm.heap().allocate(allocating_realm, move(behaviour), prototype.value(), *realm.value()); // 10. Perform SetFunctionLength(func, length). function->set_function_length(length); @@ -53,7 +53,7 @@ NativeFunction* NativeFunction::create(Realm& allocating_realm, Function(VM&, GlobalObject&)> function) { - return realm.heap().allocate(realm.global_object(), name, move(function), *realm.global_object().function_prototype()); + return realm.heap().allocate(realm, name, move(function), *realm.global_object().function_prototype()); } NativeFunction::NativeFunction(Function(VM&, GlobalObject&)> native_function, Object* prototype, Realm& realm) diff --git a/Userland/Libraries/LibJS/Runtime/NumberObject.cpp b/Userland/Libraries/LibJS/Runtime/NumberObject.cpp index 1e02d8a4f1..750d9a4bad 100644 --- a/Userland/Libraries/LibJS/Runtime/NumberObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/NumberObject.cpp @@ -11,7 +11,7 @@ namespace JS { NumberObject* NumberObject::create(Realm& realm, double value) { - return realm.heap().allocate(realm.global_object(), value, *realm.global_object().number_prototype()); + return realm.heap().allocate(realm, value, *realm.global_object().number_prototype()); } NumberObject::NumberObject(double value, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index 36a39156b8..0193767ca9 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -27,11 +27,11 @@ namespace JS { Object* Object::create(Realm& realm, Object* prototype) { if (!prototype) - return realm.heap().allocate(realm.global_object(), *realm.global_object().empty_object_shape()); + return realm.heap().allocate(realm, *realm.global_object().empty_object_shape()); else if (prototype == realm.global_object().object_prototype()) - return realm.heap().allocate(realm.global_object(), *realm.global_object().new_object_shape()); + return realm.heap().allocate(realm, *realm.global_object().new_object_shape()); else - return realm.heap().allocate(realm.global_object(), *prototype); + return realm.heap().allocate(realm, *prototype); } GlobalObject& Object::global_object() const @@ -42,12 +42,12 @@ GlobalObject& Object::global_object() const Object::Object(GlobalObjectTag, Realm& realm) { // This is the global object - m_shape = heap().allocate_without_global_object(realm); + m_shape = heap().allocate_without_realm(realm); } Object::Object(ConstructWithoutPrototypeTag, Realm& realm) { - m_shape = heap().allocate_without_global_object(realm); + m_shape = heap().allocate_without_realm(realm); } Object::Object(Realm& realm, Object* prototype) diff --git a/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp b/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp index 806c7db667..f90276ceb4 100644 --- a/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp +++ b/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp @@ -128,7 +128,7 @@ PrimitiveString* js_string(Heap& heap, Utf16String string) return &heap.vm().single_ascii_character_string(static_cast(code_unit)); } - return heap.allocate_without_global_object(move(string)); + return heap.allocate_without_realm(move(string)); } PrimitiveString* js_string(VM& vm, Utf16String string) @@ -150,7 +150,7 @@ PrimitiveString* js_string(Heap& heap, String string) auto& string_cache = heap.vm().string_cache(); auto it = string_cache.find(string); if (it == string_cache.end()) { - auto* new_string = heap.allocate_without_global_object(string); + auto* new_string = heap.allocate_without_realm(string); string_cache.set(move(string), new_string); return new_string; } @@ -179,7 +179,7 @@ PrimitiveString* js_rope_string(VM& vm, PrimitiveString& lhs, PrimitiveString& r if (rhs_empty) return &lhs; - return vm.heap().allocate_without_global_object(lhs, rhs); + return vm.heap().allocate_without_realm(lhs, rhs); } void PrimitiveString::resolve_rope_if_needed() const diff --git a/Userland/Libraries/LibJS/Runtime/Promise.cpp b/Userland/Libraries/LibJS/Runtime/Promise.cpp index 7367b37bd3..9da044340e 100644 --- a/Userland/Libraries/LibJS/Runtime/Promise.cpp +++ b/Userland/Libraries/LibJS/Runtime/Promise.cpp @@ -45,7 +45,7 @@ ThrowCompletionOr promise_resolve(GlobalObject& global_object, Object& Promise* Promise::create(Realm& realm) { - return realm.heap().allocate(realm.global_object(), *realm.global_object().promise_prototype()); + return realm.heap().allocate(realm, *realm.global_object().promise_prototype()); } // 27.2 Promise Objects, https://tc39.es/ecma262/#sec-promise-objects @@ -64,7 +64,7 @@ Promise::ResolvingFunctions Promise::create_resolving_functions() auto& realm = *global_object.associated_realm(); // 1. Let alreadyResolved be the Record { [[Value]]: false }. - auto* already_resolved = vm.heap().allocate_without_global_object(); + auto* already_resolved = vm.heap().allocate_without_realm(); // 2. Let stepsResolve be the algorithm steps defined in Promise Resolve Functions. // 3. Let lengthResolve be the number of non-optional parameters of the function definition in Promise Resolve Functions. diff --git a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp index 4e9c2bc099..f0e1ad5ade 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp @@ -48,10 +48,10 @@ static ThrowCompletionOr perform_promise_common(GlobalObject& global_obje VERIFY(promise_resolve.is_function()); // 1. Let values be a new empty List. - auto* values = vm.heap().allocate_without_global_object(); + auto* values = vm.heap().allocate_without_realm(); // 2. Let remainingElementsCount be the Record { [[Value]]: 1 }. - auto* remaining_elements_count = vm.heap().allocate_without_global_object(1); + auto* remaining_elements_count = vm.heap().allocate_without_realm(1); // 3. Let index be 0. size_t index = 0; diff --git a/Userland/Libraries/LibJS/Runtime/PromiseReaction.h b/Userland/Libraries/LibJS/Runtime/PromiseReaction.h index 86341473b5..c1acb937d3 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseReaction.h +++ b/Userland/Libraries/LibJS/Runtime/PromiseReaction.h @@ -73,7 +73,7 @@ public: static PromiseReaction* create(VM& vm, Type type, Optional capability, Optional handler) { - return vm.heap().allocate_without_global_object(type, capability, move(handler)); + return vm.heap().allocate_without_realm(type, capability, move(handler)); } PromiseReaction(Type type, Optional capability, Optional handler); diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp index aa21e6a5e3..c831df9578 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp @@ -57,7 +57,7 @@ void PromiseResolvingElementFunction::visit_edges(Cell::Visitor& visitor) PromiseAllResolveElementFunction* PromiseAllResolveElementFunction::create(Realm& realm, size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements) { - return realm.heap().allocate(realm.global_object(), index, values, capability, remaining_elements, *realm.global_object().function_prototype()); + return realm.heap().allocate(realm, index, values, capability, remaining_elements, *realm.global_object().function_prototype()); } PromiseAllResolveElementFunction::PromiseAllResolveElementFunction(size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements, Object& prototype) @@ -90,7 +90,7 @@ ThrowCompletionOr PromiseAllResolveElementFunction::resolve_element() PromiseAllSettledResolveElementFunction* PromiseAllSettledResolveElementFunction::create(Realm& realm, size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements) { - return realm.heap().allocate(realm.global_object(), index, values, capability, remaining_elements, *realm.global_object().function_prototype()); + return realm.heap().allocate(realm, index, values, capability, remaining_elements, *realm.global_object().function_prototype()); } PromiseAllSettledResolveElementFunction::PromiseAllSettledResolveElementFunction(size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements, Object& prototype) @@ -132,7 +132,7 @@ ThrowCompletionOr PromiseAllSettledResolveElementFunction::resolve_elemen PromiseAllSettledRejectElementFunction* PromiseAllSettledRejectElementFunction::create(Realm& realm, size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements) { - return realm.heap().allocate(realm.global_object(), index, values, capability, remaining_elements, *realm.global_object().function_prototype()); + return realm.heap().allocate(realm, index, values, capability, remaining_elements, *realm.global_object().function_prototype()); } PromiseAllSettledRejectElementFunction::PromiseAllSettledRejectElementFunction(size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements, Object& prototype) @@ -174,7 +174,7 @@ ThrowCompletionOr PromiseAllSettledRejectElementFunction::resolve_element PromiseAnyRejectElementFunction* PromiseAnyRejectElementFunction::create(Realm& realm, size_t index, PromiseValueList& errors, PromiseCapability capability, RemainingElements& remaining_elements) { - return realm.heap().allocate(realm.global_object(), index, errors, capability, remaining_elements, *realm.global_object().function_prototype()); + return realm.heap().allocate(realm, index, errors, capability, remaining_elements, *realm.global_object().function_prototype()); } PromiseAnyRejectElementFunction::PromiseAnyRejectElementFunction(size_t index, PromiseValueList& errors, PromiseCapability capability, RemainingElements& remaining_elements, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp index b556ab154a..546e7f3ed8 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp @@ -13,7 +13,7 @@ namespace JS { PromiseResolvingFunction* PromiseResolvingFunction::create(Realm& realm, Promise& promise, AlreadyResolved& already_resolved, FunctionType function) { - return realm.heap().allocate(realm.global_object(), promise, already_resolved, move(function), *realm.global_object().function_prototype()); + return realm.heap().allocate(realm, 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/ProxyObject.cpp b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp index 2ff103201c..ae51a7d2ae 100644 --- a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp @@ -17,7 +17,7 @@ namespace JS { ProxyObject* ProxyObject::create(Realm& realm, Object& target, Object& handler) { - return realm.heap().allocate(realm.global_object(), target, handler, *realm.global_object().object_prototype()); + return realm.heap().allocate(realm, target, handler, *realm.global_object().object_prototype()); } ProxyObject::ProxyObject(Object& target, Object& handler, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/Realm.cpp b/Userland/Libraries/LibJS/Runtime/Realm.cpp index 93cfb071d5..32444af365 100644 --- a/Userland/Libraries/LibJS/Runtime/Realm.cpp +++ b/Userland/Libraries/LibJS/Runtime/Realm.cpp @@ -17,7 +17,7 @@ namespace JS { // 9.3.1 CreateRealm ( ), https://tc39.es/ecma262/#sec-createrealm Realm* Realm::create(VM& vm) { - return vm.heap().allocate_without_global_object(); + return vm.heap().allocate_without_realm(); } // 9.6 InitializeHostDefinedRealm ( ), https://tc39.es/ecma262/#sec-initializehostdefinedrealm @@ -79,7 +79,7 @@ void Realm::set_global_object(GlobalObject* global_object, GlobalObject* this_va // b. Set globalObj to OrdinaryObjectCreate(intrinsics.[[%Object.prototype%]]). // NOTE: We allocate a proper GlobalObject directly as this plain object is // turned into one via SetDefaultGlobalBindings in the spec. - global_object = heap().allocate_without_global_object(*this); + global_object = heap().allocate_without_realm(*this); } // 2. Assert: Type(globalObj) is Object. @@ -100,7 +100,7 @@ void Realm::set_global_object(GlobalObject* global_object, GlobalObject* this_va // 5. Let newGlobalEnv be NewGlobalEnvironment(globalObj, thisValue). // 6. Set realmRec.[[GlobalEnv]] to newGlobalEnv. - m_global_environment = m_global_object->heap().allocate_without_global_object(*global_object, *this_value); + m_global_environment = m_global_object->heap().allocate_without_realm(*global_object, *this_value); // 7. Return unused. } diff --git a/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp b/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp index f91c8581eb..d7295a3d9a 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp @@ -124,12 +124,12 @@ ThrowCompletionOr parse_regex_pattern(StringView pattern, VM& vm, Global RegExpObject* RegExpObject::create(Realm& realm) { - return realm.heap().allocate(realm.global_object(), *realm.global_object().regexp_prototype()); + return realm.heap().allocate(realm, *realm.global_object().regexp_prototype()); } RegExpObject* RegExpObject::create(Realm& realm, Regex regex, String pattern, String flags) { - return realm.heap().allocate(realm.global_object(), move(regex), move(pattern), move(flags), *realm.global_object().regexp_prototype()); + return realm.heap().allocate(realm, move(regex), move(pattern), move(flags), *realm.global_object().regexp_prototype()); } RegExpObject::RegExpObject(Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp b/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp index ca57f3733f..a79b2350b2 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp @@ -12,7 +12,7 @@ namespace JS { // 22.2.7.1 CreateRegExpStringIterator ( R, S, global, fullUnicode ), https://tc39.es/ecma262/#sec-createregexpstringiterator RegExpStringIterator* RegExpStringIterator::create(Realm& realm, Object& regexp_object, Utf16String string, bool global, bool unicode) { - return realm.heap().allocate(realm.global_object(), *realm.global_object().regexp_string_iterator_prototype(), regexp_object, move(string), global, unicode); + return realm.heap().allocate(realm, *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/Set.cpp b/Userland/Libraries/LibJS/Runtime/Set.cpp index 83779d0d28..9f3b940655 100644 --- a/Userland/Libraries/LibJS/Runtime/Set.cpp +++ b/Userland/Libraries/LibJS/Runtime/Set.cpp @@ -10,7 +10,7 @@ namespace JS { Set* Set::create(Realm& realm) { - return realm.heap().allocate(realm.global_object(), *realm.global_object().set_prototype()); + return realm.heap().allocate(realm, *realm.global_object().set_prototype()); } Set::Set(Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/SetIterator.cpp b/Userland/Libraries/LibJS/Runtime/SetIterator.cpp index d8ce9f73ea..2797ee1833 100644 --- a/Userland/Libraries/LibJS/Runtime/SetIterator.cpp +++ b/Userland/Libraries/LibJS/Runtime/SetIterator.cpp @@ -11,7 +11,7 @@ namespace JS { SetIterator* SetIterator::create(Realm& realm, Set& set, Object::PropertyKind iteration_kind) { - return realm.heap().allocate(realm.global_object(), set, iteration_kind, *realm.global_object().set_iterator_prototype()); + return realm.heap().allocate(realm, 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/ShadowRealmConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp index e475bba818..8abf0e5f95 100644 --- a/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp @@ -63,7 +63,7 @@ ThrowCompletionOr ShadowRealmConstructor::construct(FunctionObject& new auto* object = TRY(ordinary_create_from_constructor(global_object, new_target, &GlobalObject::shadow_realm_prototype, *realm, move(context))); // 10. Perform ? SetRealmGlobalObject(realmRec, undefined, undefined). - auto* new_global_object = vm.heap().allocate_without_global_object(*realm); + auto* new_global_object = vm.heap().allocate_without_realm(*realm); realm->set_global_object(new_global_object, nullptr); new_global_object->initialize_global_object(); diff --git a/Userland/Libraries/LibJS/Runtime/Shape.cpp b/Userland/Libraries/LibJS/Runtime/Shape.cpp index 5f4397656a..6cf2e2a506 100644 --- a/Userland/Libraries/LibJS/Runtime/Shape.cpp +++ b/Userland/Libraries/LibJS/Runtime/Shape.cpp @@ -12,7 +12,7 @@ namespace JS { Shape* Shape::create_unique_clone() const { - auto* new_shape = heap().allocate_without_global_object(m_realm); + auto* new_shape = heap().allocate_without_realm(m_realm); new_shape->m_unique = true; new_shape->m_prototype = m_prototype; ensure_property_table(); @@ -57,7 +57,7 @@ Shape* Shape::create_put_transition(StringOrSymbol const& property_key, Property TransitionKey key { property_key, attributes }; if (auto* existing_shape = get_or_prune_cached_forward_transition(key)) return existing_shape; - auto* new_shape = heap().allocate_without_global_object(*this, property_key, attributes, TransitionType::Put); + auto* new_shape = heap().allocate_without_realm(*this, property_key, attributes, TransitionType::Put); if (!m_forward_transitions) m_forward_transitions = make>>(); m_forward_transitions->set(key, new_shape); @@ -69,7 +69,7 @@ Shape* Shape::create_configure_transition(StringOrSymbol const& property_key, Pr TransitionKey key { property_key, attributes }; if (auto* existing_shape = get_or_prune_cached_forward_transition(key)) return existing_shape; - auto* new_shape = heap().allocate_without_global_object(*this, property_key, attributes, TransitionType::Configure); + auto* new_shape = heap().allocate_without_realm(*this, property_key, attributes, TransitionType::Configure); if (!m_forward_transitions) m_forward_transitions = make>>(); m_forward_transitions->set(key, new_shape); @@ -80,7 +80,7 @@ Shape* Shape::create_prototype_transition(Object* new_prototype) { if (auto* existing_shape = get_or_prune_cached_prototype_transition(new_prototype)) return existing_shape; - auto* new_shape = heap().allocate_without_global_object(*this, new_prototype); + auto* new_shape = heap().allocate_without_realm(*this, new_prototype); if (!m_prototype_transitions) m_prototype_transitions = make>>(); m_prototype_transitions->set(new_prototype, new_shape); diff --git a/Userland/Libraries/LibJS/Runtime/StringIterator.cpp b/Userland/Libraries/LibJS/Runtime/StringIterator.cpp index 9c75302a4a..0a72b029e6 100644 --- a/Userland/Libraries/LibJS/Runtime/StringIterator.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringIterator.cpp @@ -12,7 +12,7 @@ namespace JS { StringIterator* StringIterator::create(Realm& realm, String string) { - return realm.heap().allocate(realm.global_object(), move(string), *realm.global_object().string_iterator_prototype()); + return realm.heap().allocate(realm, move(string), *realm.global_object().string_iterator_prototype()); } StringIterator::StringIterator(String string, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/StringObject.cpp b/Userland/Libraries/LibJS/Runtime/StringObject.cpp index 8106d8776e..702b36eea4 100644 --- a/Userland/Libraries/LibJS/Runtime/StringObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringObject.cpp @@ -17,7 +17,7 @@ namespace JS { // 10.4.3.4 StringCreate ( value, prototype ), https://tc39.es/ecma262/#sec-stringcreate StringObject* StringObject::create(Realm& realm, PrimitiveString& primitive_string, Object& prototype) { - return realm.heap().allocate(realm.global_object(), primitive_string, prototype); + return realm.heap().allocate(realm, primitive_string, prototype); } StringObject::StringObject(PrimitiveString& string, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/Symbol.cpp b/Userland/Libraries/LibJS/Runtime/Symbol.cpp index a91f0c289f..6821fe719a 100644 --- a/Userland/Libraries/LibJS/Runtime/Symbol.cpp +++ b/Userland/Libraries/LibJS/Runtime/Symbol.cpp @@ -18,7 +18,7 @@ Symbol::Symbol(Optional description, bool is_global) Symbol* js_symbol(Heap& heap, Optional description, bool is_global) { - return heap.allocate_without_global_object(move(description), is_global); + return heap.allocate_without_realm(move(description), is_global); } Symbol* js_symbol(VM& vm, Optional description, bool is_global) diff --git a/Userland/Libraries/LibJS/Runtime/SymbolObject.cpp b/Userland/Libraries/LibJS/Runtime/SymbolObject.cpp index 08418fa0f9..61344a3b13 100644 --- a/Userland/Libraries/LibJS/Runtime/SymbolObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/SymbolObject.cpp @@ -12,7 +12,7 @@ namespace JS { SymbolObject* SymbolObject::create(Realm& realm, Symbol& primitive_symbol) { - return realm.heap().allocate(realm.global_object(), primitive_symbol, *realm.global_object().symbol_prototype()); + return realm.heap().allocate(realm, primitive_symbol, *realm.global_object().symbol_prototype()); } SymbolObject::SymbolObject(Symbol& symbol, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp index 1304141f03..7cfb762247 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp @@ -36,7 +36,7 @@ void Temporal::initialize(Realm& realm) define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Temporal"), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; - define_direct_property(vm.names.Now, heap().allocate(realm.global_object(), realm), attr); + define_direct_property(vm.names.Now, heap().allocate(realm, realm), attr); define_direct_property(vm.names.Calendar, realm.global_object().temporal_calendar_constructor(), attr); define_direct_property(vm.names.Duration, realm.global_object().temporal_duration_constructor(), attr); define_direct_property(vm.names.Instant, realm.global_object().temporal_instant_constructor(), attr); diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp index c9207b73eb..288566b85d 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp @@ -436,7 +436,7 @@ void TypedArrayBase::visit_edges(Visitor& visitor) 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(realm.global_object(), *prototype, length, *array_buffer); \ + return realm.heap().allocate(realm, *prototype, length, *array_buffer); \ } \ \ ThrowCompletionOr ClassName::create(Realm& realm, u32 length) \ @@ -447,8 +447,7 @@ void TypedArrayBase::visit_edges(Visitor& visitor) \ ClassName* ClassName::create(Realm& realm, u32 length, ArrayBuffer& array_buffer) \ { \ - return realm.heap().allocate( \ - realm.global_object(), *realm.global_object().snake_name##_prototype(), length, array_buffer); /* */ \ + return realm.heap().allocate(realm, *realm.global_object().snake_name##_prototype(), length, array_buffer); /* */ \ } \ \ ClassName::ClassName(Object& prototype, u32 length, ArrayBuffer& array_buffer) \ diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index 9afe071d28..e57ea9c05a 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -41,9 +41,9 @@ VM::VM(OwnPtr custom_data) : m_heap(*this) , m_custom_data(move(custom_data)) { - m_empty_string = m_heap.allocate_without_global_object(String::empty()); + m_empty_string = m_heap.allocate_without_realm(String::empty()); for (size_t i = 0; i < 128; ++i) { - m_single_ascii_character_strings[i] = m_heap.allocate_without_global_object(String::formatted("{:c}", i)); + m_single_ascii_character_strings[i] = m_heap.allocate_without_realm(String::formatted("{:c}", i)); } // Default hook implementations. These can be overridden by the host, for example, LibWeb overrides the default hooks to place promise jobs on the microtask queue. diff --git a/Userland/Libraries/LibJS/Runtime/WeakMap.cpp b/Userland/Libraries/LibJS/Runtime/WeakMap.cpp index b0edaef071..2da2b3f40e 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakMap.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakMap.cpp @@ -10,7 +10,7 @@ namespace JS { WeakMap* WeakMap::create(Realm& realm) { - return realm.heap().allocate(realm.global_object(), *realm.global_object().weak_map_prototype()); + return realm.heap().allocate(realm, *realm.global_object().weak_map_prototype()); } WeakMap::WeakMap(Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/WeakRef.cpp b/Userland/Libraries/LibJS/Runtime/WeakRef.cpp index 286b1f9322..d3d10a2cb9 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakRef.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakRef.cpp @@ -10,12 +10,12 @@ namespace JS { WeakRef* WeakRef::create(Realm& realm, Object& value) { - return realm.heap().allocate(realm.global_object(), value, *realm.global_object().weak_ref_prototype()); + return realm.heap().allocate(realm, value, *realm.global_object().weak_ref_prototype()); } WeakRef* WeakRef::create(Realm& realm, Symbol& value) { - return realm.heap().allocate(realm.global_object(), value, *realm.global_object().weak_ref_prototype()); + return realm.heap().allocate(realm, value, *realm.global_object().weak_ref_prototype()); } WeakRef::WeakRef(Object& value, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/WeakSet.cpp b/Userland/Libraries/LibJS/Runtime/WeakSet.cpp index 37dd731258..afa0f30a8b 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakSet.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakSet.cpp @@ -10,7 +10,7 @@ namespace JS { WeakSet* WeakSet::create(Realm& realm) { - return realm.heap().allocate(realm.global_object(), *realm.global_object().weak_set_prototype()); + return realm.heap().allocate(realm, *realm.global_object().weak_set_prototype()); } WeakSet::WeakSet(Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp b/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp index 09d95ab0bb..fe57e04f50 100644 --- a/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp @@ -22,7 +22,7 @@ ThrowCompletionOr WrappedFunction::create(Realm& realm, Realm& // 5. Set wrapped.[[WrappedTargetFunction]] to Target. // 6. Set wrapped.[[Realm]] to callerRealm. auto& prototype = *caller_realm.global_object().function_prototype(); - auto* wrapped = vm.heap().allocate(realm.global_object(), caller_realm, target, prototype); + auto* wrapped = vm.heap().allocate(realm, caller_realm, target, prototype); // 7. Let result be CopyNameAndLength(wrapped, Target). auto result = copy_name_and_length(realm.global_object(), *wrapped, target); diff --git a/Userland/Libraries/LibJS/SourceTextModule.cpp b/Userland/Libraries/LibJS/SourceTextModule.cpp index b984c0ce94..872f7b0292 100644 --- a/Userland/Libraries/LibJS/SourceTextModule.cpp +++ b/Userland/Libraries/LibJS/SourceTextModule.cpp @@ -328,7 +328,7 @@ ThrowCompletionOr SourceTextModule::initialize_environment(VM& vm) auto& global_object = realm().global_object(); // 5. Let env be NewModuleEnvironment(realm.[[GlobalEnv]]). - auto* environment = vm.heap().allocate_without_global_object(&realm().global_environment()); + auto* environment = vm.heap().allocate_without_realm(&realm().global_environment()); // 6. Set module.[[Environment]] to env. set_environment(environment); diff --git a/Userland/Libraries/LibJS/SyntheticModule.cpp b/Userland/Libraries/LibJS/SyntheticModule.cpp index 6a22557834..d289c05031 100644 --- a/Userland/Libraries/LibJS/SyntheticModule.cpp +++ b/Userland/Libraries/LibJS/SyntheticModule.cpp @@ -53,7 +53,7 @@ ThrowCompletionOr SyntheticModule::link(VM& vm) auto& global_object = realm().global_object(); // 3. Let env be NewModuleEnvironment(realm.[[GlobalEnv]]). - auto* environment = vm.heap().allocate_without_global_object(&realm().global_environment()); + auto* environment = vm.heap().allocate_without_realm(&realm().global_environment()); // 4. Set module.[[Environment]] to env. set_environment(environment); diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp index efc84daba9..985e8a2451 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp @@ -119,7 +119,7 @@ void WindowObject::initialize_global_object() define_native_accessor("screenLeft", screen_left_getter, {}, attr); define_native_accessor("screenTop", screen_top_getter, {}, attr); - define_direct_property("CSS", heap().allocate(*this, realm), 0); + define_direct_property("CSS", heap().allocate(realm, realm), 0); define_native_accessor("localStorage", local_storage_getter, {}, attr); define_native_accessor("sessionStorage", session_storage_getter, {}, attr); @@ -128,9 +128,9 @@ void WindowObject::initialize_global_object() // Legacy define_native_accessor("event", event_getter, event_setter, JS::Attribute::Enumerable); - m_location_object = heap().allocate(*this, realm); + m_location_object = heap().allocate(realm, realm); - auto* m_navigator_object = heap().allocate(*this, realm); + auto* m_navigator_object = heap().allocate(realm, realm); define_direct_property("navigator", m_navigator_object, JS::Attribute::Enumerable | JS::Attribute::Configurable); define_direct_property("clientInformation", m_navigator_object, JS::Attribute::Enumerable | JS::Attribute::Configurable); @@ -138,7 +138,7 @@ void WindowObject::initialize_global_object() define_native_accessor("location", location_getter, location_setter, JS::Attribute::Enumerable); // WebAssembly "namespace" - define_direct_property("WebAssembly", heap().allocate(*this, realm), JS::Attribute::Enumerable | JS::Attribute::Configurable); + define_direct_property("WebAssembly", heap().allocate(realm, realm), JS::Attribute::Enumerable | JS::Attribute::Configurable); // HTML::GlobalEventHandlers and HTML::WindowEventHandlers #define __ENUMERATE(attribute, event_name) \ diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.h b/Userland/Libraries/LibWeb/Bindings/WindowObject.h index 5d7f3be406..5d7f187b46 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObject.h +++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.h @@ -54,7 +54,7 @@ public: if (it != m_prototypes.end()) return *it->value; auto& realm = *associated_realm(); - auto* prototype = heap().allocate(*this, realm); + auto* prototype = heap().allocate(realm, realm); m_prototypes.set(class_name, prototype); return *prototype; } @@ -66,7 +66,7 @@ public: if (it != m_constructors.end()) return *it->value; auto& realm = *associated_realm(); - auto* constructor = heap().allocate(*this, realm); + auto* constructor = heap().allocate(realm, realm); m_constructors.set(class_name, constructor); define_direct_property(class_name, JS::Value(constructor), JS::Attribute::Writable | JS::Attribute::Configurable); return *constructor; diff --git a/Userland/Libraries/LibWeb/Bindings/Wrappable.h b/Userland/Libraries/LibWeb/Bindings/Wrappable.h index 2e0c4561a7..0e0a5dc7ad 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(*realm.heap().allocate(realm.global_object(), realm, native_object)); + native_object.set_wrapper(*realm.heap().allocate(realm, realm, native_object)); } return native_object.wrapper(); } diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index c72e5dbe8a..b9d9aaa6d5 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -171,7 +171,7 @@ NonnullRefPtr Document::create_and_initialize(Type type, String conten [&](JS::Realm& realm) -> JS::GlobalObject* { // - For the global object, create a new Window object. window = HTML::Window::create(); - auto* global_object = realm.heap().allocate_without_global_object(realm, *window); + auto* global_object = realm.heap().allocate_without_realm(realm, *window); VERIFY(window->wrapper() == global_object); return global_object; }, diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp index e2c0e665f5..918f5671c2 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp @@ -124,7 +124,7 @@ NonnullRefPtr BrowsingContext::create_a_new_browsing_context(Pa [&](JS::Realm& realm) -> JS::GlobalObject* { // - For the global object, create a new Window object. window = HTML::Window::create(); - auto* global_object = realm.heap().allocate_without_global_object(realm, *window); + auto* global_object = realm.heap().allocate_without_realm(realm, *window); VERIFY(window->wrapper() == global_object); return global_object; }, diff --git a/Userland/Libraries/LibWeb/HTML/Worker.cpp b/Userland/Libraries/LibWeb/HTML/Worker.cpp index e1b9f108d7..9cafb21f37 100644 --- a/Userland/Libraries/LibWeb/HTML/Worker.cpp +++ b/Userland/Libraries/LibWeb/HTML/Worker.cpp @@ -110,7 +110,7 @@ void Worker::run_a_worker(AK::URL& url, EnvironmentSettingsObject& outside_setti TODO(); // FIXME: Make and use subclasses of WorkerGlobalScope, however this requires JS::GlobalObject to // play nicely with the IDL interpreter, to make spec-compliant extensions, which it currently does not. - m_worker_scope = m_worker_vm->heap().allocate_without_global_object(realm); + m_worker_scope = m_worker_vm->heap().allocate_without_realm(realm); return m_worker_scope; }, nullptr); diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp index 71bf399464..afaa28d2cd 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp @@ -37,7 +37,7 @@ JS::ThrowCompletionOr WebAssemblyInstanceConstructor::construct(Fun return vm.throw_completion(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Module"); auto& module_object = static_cast(*module_argument); auto result = TRY(WebAssemblyObject::instantiate_module(module_object.module(), vm, global_object)); - return heap().allocate(global_object, realm, result); + return heap().allocate(realm, realm, result); } void WebAssemblyInstanceConstructor::initialize(JS::Realm& realm) diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp index 3dab7fe6ef..0540f6d5e7 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp @@ -44,7 +44,7 @@ void WebAssemblyInstanceObject::initialize(JS::Realm& realm) [&](Wasm::MemoryAddress const& address) { Optional object = cache.memory_instances.get(address); if (!object.has_value()) { - object = heap().allocate(realm.global_object(), realm, address); + object = heap().allocate(realm, realm, address); cache.memory_instances.set(address, *object); } m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes); diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp index 077c0d8196..1e5a99744d 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp @@ -51,7 +51,7 @@ JS::ThrowCompletionOr WebAssemblyMemoryConstructor::construct(Funct if (!WebAssemblyObject::s_abstract_machine.store().get(*address)->grow(initial)) return vm.throw_completion(global_object, String::formatted("Wasm Memory grow failed: {}", initial)); - return vm.heap().allocate(global_object, realm, *address); + return vm.heap().allocate(realm, realm, *address); } void WebAssemblyMemoryConstructor::initialize(JS::Realm& realm) diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp index 53705691e6..230a78cb2d 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp @@ -35,7 +35,7 @@ JS::ThrowCompletionOr WebAssemblyModuleConstructor::construct(Funct auto* buffer_object = TRY(vm.argument(0).to_object(global_object)); auto result = TRY(parse_module(global_object, buffer_object)); - return heap().allocate(global_object, realm, result); + return heap().allocate(realm, realm, result); } void WebAssemblyModuleConstructor::initialize(JS::Realm& realm) diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp index 4f99393456..a2895c115b 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp @@ -174,7 +174,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::compile) if (result.is_error()) promise->reject(*result.release_error().value()); else - promise->fulfill(vm.heap().allocate(global_object, realm, result.release_value())); + promise->fulfill(vm.heap().allocate(realm, realm, result.release_value())); return promise; } @@ -354,10 +354,10 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::instantiate) if (result.is_error()) { promise->reject(*result.release_error().value()); } else { - auto instance_object = vm.heap().allocate(global_object, realm, result.release_value()); + auto instance_object = vm.heap().allocate(realm, realm, result.release_value()); if (should_return_module) { auto object = JS::Object::create(realm, nullptr); - object->define_direct_property("module", vm.heap().allocate(global_object, realm, s_compiled_modules.size() - 1), JS::default_attributes); + object->define_direct_property("module", vm.heap().allocate(realm, realm, s_compiled_modules.size() - 1), JS::default_attributes); object->define_direct_property("instance", instance_object, JS::default_attributes); promise->fulfill(object); } else { @@ -369,9 +369,10 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::instantiate) JS::Value to_js_value(JS::GlobalObject& global_object, Wasm::Value& wasm_value) { + auto& realm = *global_object.associated_realm(); switch (wasm_value.type().kind()) { case Wasm::ValueType::I64: - return global_object.heap().allocate(global_object, ::Crypto::SignedBigInteger::create_from(wasm_value.to().value())); + return realm.heap().allocate(realm, ::Crypto::SignedBigInteger::create_from(wasm_value.to().value())); case Wasm::ValueType::I32: return JS::Value(wasm_value.to().value()); case Wasm::ValueType::F64: diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp index 1ff1d30ddb..8adf908090 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp @@ -78,7 +78,7 @@ JS::ThrowCompletionOr WebAssemblyTableConstructor::construct(Functi for (auto& element : table.elements()) element = reference; - return vm.heap().allocate(global_object, realm, *address); + return vm.heap().allocate(realm, realm, *address); } void WebAssemblyTableConstructor::initialize(JS::Realm& realm) diff --git a/Userland/Services/WebContent/WebContentConsoleClient.cpp b/Userland/Services/WebContent/WebContentConsoleClient.cpp index dd59dbae53..6c4a2171a6 100644 --- a/Userland/Services/WebContent/WebContentConsoleClient.cpp +++ b/Userland/Services/WebContent/WebContentConsoleClient.cpp @@ -26,7 +26,7 @@ WebContentConsoleClient::WebContentConsoleClient(JS::Console& console, WeakPtrvm(); auto& global_object = m_interpreter->global_object(); - auto console_global_object = m_interpreter->heap().allocate_without_global_object(m_interpreter->realm(), static_cast(global_object)); + auto console_global_object = m_interpreter->heap().allocate_without_realm(m_interpreter->realm(), static_cast(global_object)); // NOTE: We need to push an execution context here for NativeFunction::create() to succeed during global object initialization. // It gets removed immediately after creating the interpreter in Document::interpreter().