LibJS+LibWeb: Replace GlobalObject with Realm in Heap::allocate<T>()

This is a continuation of the previous three commits.

Now that create() receives the allocating realm, we can simply forward
that to allocate(), which accounts for the majority of these changes.
Additionally, we can get rid of the realm_from_global_object() in one
place, with one more remaining in VM::throw_completion().
This commit is contained in:
Linus Groh 2022-08-16 00:20:50 +01:00
parent b99cc7d050
commit e992a9f469
Notes: sideshowbarker 2024-07-17 09:49:48 +09:00
82 changed files with 148 additions and 148 deletions

View file

@ -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)

View file

@ -50,7 +50,7 @@ public:
static JS::ThrowCompletionOr<WebAssemblyModule*> create(JS::Realm& realm, Wasm::Module module, HashMap<Wasm::Linker::Name, Wasm::ExternValue> const& imports)
{
auto& vm = realm.vm();
auto* instance = realm.heap().allocate<WebAssemblyModule>(realm.global_object(), *realm.global_object().object_prototype());
auto* instance = realm.heap().allocate<WebAssemblyModule>(realm, *realm.global_object().object_prototype());
instance->m_module = move(module);
Wasm::Linker linker(*instance->m_module);
linker.link(imports);

View file

@ -29,7 +29,7 @@ Workbook::Workbook(NonnullRefPtrVector<Sheet>&& sheets, GUI::Window& parent_wind
, m_main_execution_context(m_vm->heap())
, m_parent_window(parent_window)
{
m_workbook_object = m_vm->heap().allocate<WorkbookObject>(m_interpreter->global_object(), m_interpreter->realm(), *this);
m_workbook_object = m_vm->heap().allocate<WorkbookObject>(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;

View file

@ -602,7 +602,7 @@ void ContinuePendingUnwind::replace_references_impl(BasicBlock const& from, Basi
ThrowCompletionOr<void> PushDeclarativeEnvironment::execute_impl(Bytecode::Interpreter& interpreter) const
{
auto* environment = interpreter.vm().heap().allocate_without_global_object<DeclarativeEnvironment>(interpreter.vm().lexical_environment());
auto* environment = interpreter.vm().heap().allocate_without_realm<DeclarativeEnvironment>(interpreter.vm().lexical_environment());
interpreter.vm().running_execution_context().lexical_environment = environment;
interpreter.vm().running_execution_context().variable_environment = environment;
return {};

View file

@ -27,8 +27,8 @@ void $262Object::initialize(JS::Realm& realm)
{
Base::initialize(realm);
m_agent = vm().heap().allocate<AgentObject>(realm.global_object(), realm);
m_is_htmldda = vm().heap().allocate<IsHTMLDDA>(realm.global_object(), realm);
m_agent = vm().heap().allocate<AgentObject>(realm, realm);
m_is_htmldda = vm().heap().allocate<IsHTMLDDA>(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<GlobalObject>(*realm);
auto* realm_global_object = vm.heap().allocate_without_realm<GlobalObject>(*realm);
VERIFY(realm_global_object);
realm->set_global_object(realm_global_object, nullptr);
realm_global_object->set_associated_realm(*realm);

View file

@ -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;

View file

@ -36,7 +36,7 @@ public:
~Heap();
template<typename T, typename... Args>
T* allocate_without_global_object(Args&&... args)
T* allocate_without_realm(Args&&... args)
{
auto* memory = allocate_cell(sizeof(T));
new (memory) T(forward<Args>(args)...);
@ -44,12 +44,11 @@ public:
}
template<typename T, typename... Args>
T* allocate(GlobalObject& global_object, Args&&... args)
T* allocate(Realm& realm, Args&&... args)
{
auto* memory = allocate_cell(sizeof(T));
new (memory) T(forward<Args>(args)...);
auto* cell = static_cast<T*>(memory);
auto& realm = realm_from_global_object(global_object);
memory->initialize(realm);
return cell;
}

View file

@ -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<GlobalObjectType>(realm, forward<Args>(args)...);
global_object = interpreter->heap().allocate_without_realm<GlobalObjectType>(realm, forward<Args>(args)...);
return global_object;
},
nullptr));

View file

@ -87,6 +87,8 @@ ThrowCompletionOr<Object*> 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<FlyString> 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<FlyString> 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<ModuleNamespaceObject>(realm().global_object(), realm(), this, move(unambiguous_names));
Object* module_namespace = vm.heap().allocate<ModuleNamespaceObject>(realm, realm, this, move(unambiguous_names));
// 9. Set module.[[Namespace]] to M.
m_namespace = make_handle(module_namespace);

View file

@ -400,14 +400,14 @@ ThrowCompletionOr<Object*> 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<DeclarativeEnvironment>(&environment);
return environment.heap().allocate_without_realm<DeclarativeEnvironment>(&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<ObjectEnvironment>(object, is_with_environment ? ObjectEnvironment::IsWithEnvironment::Yes : ObjectEnvironment::IsWithEnvironment::No, environment);
return heap.allocate_without_realm<ObjectEnvironment>(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<FunctionEnvironment>(function.environment());
auto* env = heap.allocate_without_realm<FunctionEnvironment>(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<PrivateEnvironment>(outer);
return vm.heap().allocate_without_realm<PrivateEnvironment>(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<ArgumentsObject>(global_object, realm, environment);
auto* object = vm.heap().allocate<ArgumentsObject>(realm, realm, environment);
// 14. Let index be 0.
// 15. Repeat, while index < len,

View file

@ -135,7 +135,7 @@ ThrowCompletionOr<T*> 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<T>(realm.global_object(), forward<Args>(args)..., *prototype);
return realm.heap().allocate<T>(realm, forward<Args>(args)..., *prototype);
}
// 14.1 MergeLists ( a, b ), https://tc39.es/proposal-temporal/#sec-temporal-mergelists

View file

@ -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<Accessor>(getter, setter);
return vm.heap().allocate_without_realm<Accessor>(getter, setter);
}
Accessor(FunctionObject* getter, FunctionObject* setter)

View file

@ -12,7 +12,7 @@ namespace JS {
AggregateError* AggregateError::create(Realm& realm)
{
return realm.heap().allocate<AggregateError>(realm.global_object(), *realm.global_object().aggregate_error_prototype());
return realm.heap().allocate<AggregateError>(realm, *realm.global_object().aggregate_error_prototype());
}
AggregateError::AggregateError(Object& prototype)

View file

@ -32,7 +32,7 @@ ThrowCompletionOr<Array*> 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<Array>(realm.global_object(), *prototype);
auto* array = realm.heap().allocate<Array>(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 }));

View file

@ -17,17 +17,17 @@ ThrowCompletionOr<ArrayBuffer*> ArrayBuffer::create(Realm& realm, size_t byte_le
if (buffer.is_error())
return realm.vm().throw_completion<RangeError>(realm.global_object(), ErrorType::NotEnoughMemoryToAllocate, byte_length);
return realm.heap().allocate<ArrayBuffer>(realm.global_object(), buffer.release_value(), *realm.global_object().array_buffer_prototype());
return realm.heap().allocate<ArrayBuffer>(realm, buffer.release_value(), *realm.global_object().array_buffer_prototype());
}
ArrayBuffer* ArrayBuffer::create(Realm& realm, ByteBuffer buffer)
{
return realm.heap().allocate<ArrayBuffer>(realm.global_object(), move(buffer), *realm.global_object().array_buffer_prototype());
return realm.heap().allocate<ArrayBuffer>(realm, move(buffer), *realm.global_object().array_buffer_prototype());
}
ArrayBuffer* ArrayBuffer::create(Realm& realm, ByteBuffer* buffer)
{
return realm.heap().allocate<ArrayBuffer>(realm.global_object(), buffer, *realm.global_object().array_buffer_prototype());
return realm.heap().allocate<ArrayBuffer>(realm, buffer, *realm.global_object().array_buffer_prototype());
}
ArrayBuffer::ArrayBuffer(ByteBuffer buffer, Object& prototype)

View file

@ -11,7 +11,7 @@ namespace JS {
ArrayIterator* ArrayIterator::create(Realm& realm, Value array, Object::PropertyKind iteration_kind)
{
return realm.heap().allocate<ArrayIterator>(realm.global_object(), array, iteration_kind, *realm.global_object().array_iterator_prototype());
return realm.heap().allocate<ArrayIterator>(realm, array, iteration_kind, *realm.global_object().array_iterator_prototype());
}
ArrayIterator::ArrayIterator(Value array, Object::PropertyKind iteration_kind, Object& prototype)

View file

@ -13,7 +13,7 @@ namespace JS {
AsyncFromSyncIterator* AsyncFromSyncIterator::create(Realm& realm, Iterator sync_iterator_record)
{
return realm.heap().allocate<AsyncFromSyncIterator>(realm.global_object(), realm, sync_iterator_record);
return realm.heap().allocate<AsyncFromSyncIterator>(realm, realm, sync_iterator_record);
}
AsyncFromSyncIterator::AsyncFromSyncIterator(Realm& realm, Iterator sync_iterator_record)

View file

@ -14,7 +14,7 @@ namespace JS {
ThrowCompletionOr<Value> AsyncFunctionDriverWrapper::create(Realm& realm, GeneratorObject* generator_object)
{
auto wrapper = realm.heap().allocate<AsyncFunctionDriverWrapper>(realm.global_object(), realm, generator_object);
auto wrapper = realm.heap().allocate<AsyncFunctionDriverWrapper>(realm, realm, generator_object);
return wrapper->react_to_async_task_completion(realm.vm(), realm.global_object(), js_undefined(), true);
}

View file

@ -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<BigInt>(move(big_integer));
return heap.allocate_without_realm<BigInt>(move(big_integer));
}
BigInt* js_bigint(VM& vm, Crypto::SignedBigInteger big_integer)

View file

@ -11,7 +11,7 @@ namespace JS {
BigIntObject* BigIntObject::create(Realm& realm, BigInt& bigint)
{
return realm.heap().allocate<BigIntObject>(realm.global_object(), bigint, *realm.global_object().bigint_prototype());
return realm.heap().allocate<BigIntObject>(realm, bigint, *realm.global_object().bigint_prototype());
}
BigIntObject::BigIntObject(BigInt& bigint, Object& prototype)

View file

@ -11,7 +11,7 @@ namespace JS {
BooleanObject* BooleanObject::create(Realm& realm, bool value)
{
return realm.heap().allocate<BooleanObject>(realm.global_object(), value, *realm.global_object().boolean_prototype());
return realm.heap().allocate<BooleanObject>(realm, value, *realm.global_object().boolean_prototype());
}
BooleanObject::BooleanObject(bool value, Object& prototype)

View file

@ -26,7 +26,7 @@ ThrowCompletionOr<BoundFunction*> 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<BoundFunction>(realm.global_object(), realm, target_function, bound_this, move(bound_arguments), prototype);
auto* object = realm.heap().allocate<BoundFunction>(realm, realm, target_function, bound_this, move(bound_arguments), prototype);
// 10. Return obj.
return object;

View file

@ -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<DataView>(realm.global_object(), viewed_buffer, byte_length, byte_offset, *realm.global_object().data_view_prototype());
return realm.heap().allocate<DataView>(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)

View file

@ -18,7 +18,7 @@ namespace JS {
Date* Date::create(Realm& realm, double date_value)
{
return realm.heap().allocate<Date>(realm.global_object(), date_value, *realm.global_object().date_prototype());
return realm.heap().allocate<Date>(realm, date_value, *realm.global_object().date_prototype());
}
Date::Date(double date_value, Object& prototype)

View file

@ -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<DeclarativeEnvironment>(parent_environment, bindings);
return parent_environment->heap().allocate_without_realm<DeclarativeEnvironment>(parent_environment, bindings);
}
DeclarativeEnvironment::DeclarativeEnvironment()

View file

@ -45,12 +45,12 @@ ECMAScriptFunctionObject* ECMAScriptFunctionObject::create(Realm& realm, FlyStri
prototype = realm.global_object().async_generator_function_prototype();
break;
}
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));
return realm.heap().allocate<ECMAScriptFunctionObject>(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<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 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));
return realm.heap().allocate<ECMAScriptFunctionObject>(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<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)
@ -114,7 +114,7 @@ void ECMAScriptFunctionObject::initialize(Realm& realm)
Object* prototype = nullptr;
switch (m_kind) {
case FunctionKind::Normal:
prototype = vm.heap().allocate<Object>(realm.global_object(), *realm.global_object().new_ordinary_function_prototype_object_shape());
prototype = vm.heap().allocate<Object>(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:

View file

@ -16,7 +16,7 @@ namespace JS {
Error* Error::create(Realm& realm)
{
return realm.heap().allocate<Error>(realm.global_object(), *realm.global_object().error_prototype());
return realm.heap().allocate<Error>(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<ClassName>( \
realm.global_object(), *realm.global_object().snake_name##_prototype()); /* */ \
return realm.heap().allocate<ClassName>(realm, *realm.global_object().snake_name##_prototype()); /* */ \
} \
\
ClassName* ClassName::create(Realm& realm, String const& message) \

View file

@ -27,7 +27,7 @@ ThrowCompletionOr<GeneratorObject*> 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<GeneratorObject>(realm.global_object(), realm, *generating_function_prototype_object, move(execution_context));
auto object = realm.heap().allocate<GeneratorObject>(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;

View file

@ -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<ObjectEnvironment>(global_object, ObjectEnvironment::IsWithEnvironment::No, nullptr);
m_declarative_record = global_object.heap().allocate_without_global_object<DeclarativeEnvironment>();
m_object_record = global_object.heap().allocate_without_realm<ObjectEnvironment>(global_object, ObjectEnvironment::IsWithEnvironment::No, nullptr);
m_declarative_record = global_object.heap().allocate_without_realm<DeclarativeEnvironment>();
}
void GlobalEnvironment::visit_edges(Cell::Visitor& visitor)

View file

@ -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<Shape>(realm);
m_object_prototype = heap().allocate_without_global_object<ObjectPrototype>(realm);
m_function_prototype = heap().allocate_without_global_object<FunctionPrototype>(realm);
m_empty_object_shape = heap().allocate_without_realm<Shape>(realm);
m_object_prototype = heap().allocate_without_realm<ObjectPrototype>(realm);
m_function_prototype = heap().allocate_without_realm<FunctionPrototype>(realm);
m_new_object_shape = vm.heap().allocate_without_global_object<Shape>(realm);
m_new_object_shape = vm.heap().allocate_without_realm<Shape>(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<Shape>(realm);
m_new_ordinary_function_prototype_object_shape = vm.heap().allocate_without_realm<Shape>(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<FunctionPrototype*>(m_function_prototype)->initialize(realm);
static_cast<ObjectPrototype*>(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<ErrorPrototype>(*this, realm);
m_error_prototype = heap().allocate<ErrorPrototype>(realm, realm);
#define __JS_ENUMERATE(ClassName, snake_name) \
if (!m_##snake_name##_prototype) \
m_##snake_name##_prototype = heap().allocate<ClassName##Prototype>(*this, realm);
m_##snake_name##_prototype = heap().allocate<ClassName##Prototype>(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<AsyncFromSyncIteratorPrototype>(*this, realm);
m_async_generator_prototype = heap().allocate<AsyncGeneratorPrototype>(*this, realm);
m_generator_prototype = heap().allocate<GeneratorPrototype>(*this, realm);
m_intl_segments_prototype = heap().allocate<Intl::SegmentsPrototype>(*this, realm);
m_async_from_sync_iterator_prototype = heap().allocate<AsyncFromSyncIteratorPrototype>(realm, realm);
m_async_generator_prototype = heap().allocate<AsyncGeneratorPrototype>(realm, realm);
m_generator_prototype = heap().allocate<GeneratorPrototype>(realm, realm);
m_intl_segments_prototype = heap().allocate<Intl::SegmentsPrototype>(realm, realm);
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
if (!m_##snake_name##_prototype) \
m_##snake_name##_prototype = heap().allocate<PrototypeName>(*this, realm);
m_##snake_name##_prototype = heap().allocate<PrototypeName>(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<Intl::PrototypeName>(*this, realm);
m_intl_##snake_name##_prototype = heap().allocate<Intl::PrototypeName>(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<Temporal::PrototypeName>(*this, realm);
m_temporal_##snake_name##_prototype = heap().allocate<Temporal::PrototypeName>(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<ConsoleObject>(*this, realm), attr);
define_direct_property(vm.names.Atomics, heap().allocate<AtomicsObject>(*this, realm), attr);
define_direct_property(vm.names.Math, heap().allocate<MathObject>(*this, realm), attr);
define_direct_property(vm.names.JSON, heap().allocate<JSONObject>(*this, realm), attr);
define_direct_property(vm.names.Reflect, heap().allocate<ReflectObject>(*this, realm), attr);
define_direct_property(vm.names.Intl, heap().allocate<Intl::Intl>(*this, realm), attr);
define_direct_property(vm.names.Temporal, heap().allocate<Temporal::Temporal>(*this, realm), attr);
define_direct_property(vm.names.console, heap().allocate<ConsoleObject>(realm, realm), attr);
define_direct_property(vm.names.Atomics, heap().allocate<AtomicsObject>(realm, realm), attr);
define_direct_property(vm.names.Math, heap().allocate<MathObject>(realm, realm), attr);
define_direct_property(vm.names.JSON, heap().allocate<JSONObject>(realm, realm), attr);
define_direct_property(vm.names.Reflect, heap().allocate<ReflectObject>(realm, realm), attr);
define_direct_property(vm.names.Intl, heap().allocate<Intl::Intl>(realm, realm), attr);
define_direct_property(vm.names.Temporal, heap().allocate<Temporal::Temporal>(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);

View file

@ -178,7 +178,7 @@ inline void GlobalObject::initialize_constructor(PropertyKey const& property_key
{
auto& vm = this->vm();
auto& realm = *associated_realm();
constructor = heap().allocate<ConstructorType>(*this, realm);
constructor = heap().allocate<ConstructorType>(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);

View file

@ -13,7 +13,7 @@ namespace JS::Intl {
CollatorCompareFunction* CollatorCompareFunction::create(Realm& realm, Collator& collator)
{
return realm.heap().allocate<CollatorCompareFunction>(realm.global_object(), realm, collator);
return realm.heap().allocate<CollatorCompareFunction>(realm, realm, collator);
}
CollatorCompareFunction::CollatorCompareFunction(Realm& realm, Collator& collator)

View file

@ -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<DateTimeFormatFunction>(realm.global_object(), date_time_format, *realm.global_object().function_prototype());
return realm.heap().allocate<DateTimeFormatFunction>(realm, date_time_format, *realm.global_object().function_prototype());
}
DateTimeFormatFunction::DateTimeFormatFunction(DateTimeFormat& date_time_format, Object& prototype)

View file

@ -16,7 +16,7 @@ namespace JS::Intl {
Locale* Locale::create(Realm& realm, Unicode::LocaleID const& locale_id)
{
return realm.heap().allocate<Locale>(realm.global_object(), locale_id, *realm.global_object().intl_locale_prototype());
return realm.heap().allocate<Locale>(realm, locale_id, *realm.global_object().intl_locale_prototype());
}
// 14 Locale Objects, https://tc39.es/ecma402/#locale-objects

View file

@ -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<NumberFormatFunction>(realm.global_object(), number_format, *realm.global_object().function_prototype());
return realm.heap().allocate<NumberFormatFunction>(realm, number_format, *realm.global_object().function_prototype());
}
NumberFormatFunction::NumberFormatFunction(NumberFormat& number_format, Object& prototype)

View file

@ -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<SegmentIterator>(realm.global_object(), realm, segmenter, move(string), segments);
return realm.heap().allocate<SegmentIterator>(realm, realm, segmenter, move(string), segments);
}
// 18.6 Segment Iterator Objects, https://tc39.es/ecma402/#sec-segment-iterator-objects

View file

@ -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<Segments>(realm.global_object(), realm, segmenter, move(string));
return realm.heap().allocate<Segments>(realm, realm, segmenter, move(string));
}
// 18.5 Segments Objects, https://tc39.es/ecma402/#sec-segments-objects

View file

@ -10,7 +10,7 @@ namespace JS {
Map* Map::create(Realm& realm)
{
return realm.heap().allocate<Map>(realm.global_object(), *realm.global_object().map_prototype());
return realm.heap().allocate<Map>(realm, *realm.global_object().map_prototype());
}
Map::Map(Object& prototype)

View file

@ -11,7 +11,7 @@ namespace JS {
MapIterator* MapIterator::create(Realm& realm, Map& map, Object::PropertyKind iteration_kind)
{
return realm.heap().allocate<MapIterator>(realm.global_object(), map, iteration_kind, *realm.global_object().map_iterator_prototype());
return realm.heap().allocate<MapIterator>(realm, map, iteration_kind, *realm.global_object().map_iterator_prototype());
}
MapIterator::MapIterator(Map& map, Object::PropertyKind iteration_kind, Object& prototype)

View file

@ -36,7 +36,7 @@ NativeFunction* NativeFunction::create(Realm& allocating_realm, Function<ThrowCo
// 7. Set func.[[Extensible]] to true.
// 8. Set func.[[Realm]] to realm.
// 9. Set func.[[InitialName]] to null.
auto* function = allocating_realm.heap().allocate<NativeFunction>(allocating_realm.global_object(), move(behaviour), prototype.value(), *realm.value());
auto* function = allocating_realm.heap().allocate<NativeFunction>(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<ThrowCo
NativeFunction* NativeFunction::create(Realm& realm, FlyString const& name, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> function)
{
return realm.heap().allocate<NativeFunction>(realm.global_object(), name, move(function), *realm.global_object().function_prototype());
return realm.heap().allocate<NativeFunction>(realm, name, move(function), *realm.global_object().function_prototype());
}
NativeFunction::NativeFunction(Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> native_function, Object* prototype, Realm& realm)

View file

@ -11,7 +11,7 @@ namespace JS {
NumberObject* NumberObject::create(Realm& realm, double value)
{
return realm.heap().allocate<NumberObject>(realm.global_object(), value, *realm.global_object().number_prototype());
return realm.heap().allocate<NumberObject>(realm, value, *realm.global_object().number_prototype());
}
NumberObject::NumberObject(double value, Object& prototype)

View file

@ -27,11 +27,11 @@ namespace JS {
Object* Object::create(Realm& realm, Object* prototype)
{
if (!prototype)
return realm.heap().allocate<Object>(realm.global_object(), *realm.global_object().empty_object_shape());
return realm.heap().allocate<Object>(realm, *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());
return realm.heap().allocate<Object>(realm, *realm.global_object().new_object_shape());
else
return realm.heap().allocate<Object>(realm.global_object(), *prototype);
return realm.heap().allocate<Object>(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<Shape>(realm);
m_shape = heap().allocate_without_realm<Shape>(realm);
}
Object::Object(ConstructWithoutPrototypeTag, Realm& realm)
{
m_shape = heap().allocate_without_global_object<Shape>(realm);
m_shape = heap().allocate_without_realm<Shape>(realm);
}
Object::Object(Realm& realm, Object* prototype)

View file

@ -128,7 +128,7 @@ PrimitiveString* js_string(Heap& heap, Utf16String string)
return &heap.vm().single_ascii_character_string(static_cast<u8>(code_unit));
}
return heap.allocate_without_global_object<PrimitiveString>(move(string));
return heap.allocate_without_realm<PrimitiveString>(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<PrimitiveString>(string);
auto* new_string = heap.allocate_without_realm<PrimitiveString>(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<PrimitiveString>(lhs, rhs);
return vm.heap().allocate_without_realm<PrimitiveString>(lhs, rhs);
}
void PrimitiveString::resolve_rope_if_needed() const

View file

@ -45,7 +45,7 @@ ThrowCompletionOr<Object*> promise_resolve(GlobalObject& global_object, Object&
Promise* Promise::create(Realm& realm)
{
return realm.heap().allocate<Promise>(realm.global_object(), *realm.global_object().promise_prototype());
return realm.heap().allocate<Promise>(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<AlreadyResolved>();
auto* already_resolved = vm.heap().allocate_without_realm<AlreadyResolved>();
// 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.

View file

@ -48,10 +48,10 @@ static ThrowCompletionOr<Value> 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<PromiseValueList>();
auto* values = vm.heap().allocate_without_realm<PromiseValueList>();
// 2. Let remainingElementsCount be the Record { [[Value]]: 1 }.
auto* remaining_elements_count = vm.heap().allocate_without_global_object<RemainingElements>(1);
auto* remaining_elements_count = vm.heap().allocate_without_realm<RemainingElements>(1);
// 3. Let index be 0.
size_t index = 0;

View file

@ -73,7 +73,7 @@ public:
static PromiseReaction* create(VM& vm, Type type, Optional<PromiseCapability> capability, Optional<JobCallback> handler)
{
return vm.heap().allocate_without_global_object<PromiseReaction>(type, capability, move(handler));
return vm.heap().allocate_without_realm<PromiseReaction>(type, capability, move(handler));
}
PromiseReaction(Type type, Optional<PromiseCapability> capability, Optional<JobCallback> handler);

View file

@ -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<PromiseAllResolveElementFunction>(realm.global_object(), index, values, capability, remaining_elements, *realm.global_object().function_prototype());
return realm.heap().allocate<PromiseAllResolveElementFunction>(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<Value> PromiseAllResolveElementFunction::resolve_element()
PromiseAllSettledResolveElementFunction* PromiseAllSettledResolveElementFunction::create(Realm& realm, size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements)
{
return realm.heap().allocate<PromiseAllSettledResolveElementFunction>(realm.global_object(), index, values, capability, remaining_elements, *realm.global_object().function_prototype());
return realm.heap().allocate<PromiseAllSettledResolveElementFunction>(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<Value> PromiseAllSettledResolveElementFunction::resolve_elemen
PromiseAllSettledRejectElementFunction* PromiseAllSettledRejectElementFunction::create(Realm& realm, size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements)
{
return realm.heap().allocate<PromiseAllSettledRejectElementFunction>(realm.global_object(), index, values, capability, remaining_elements, *realm.global_object().function_prototype());
return realm.heap().allocate<PromiseAllSettledRejectElementFunction>(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<Value> PromiseAllSettledRejectElementFunction::resolve_element
PromiseAnyRejectElementFunction* PromiseAnyRejectElementFunction::create(Realm& realm, size_t index, PromiseValueList& errors, PromiseCapability capability, RemainingElements& remaining_elements)
{
return realm.heap().allocate<PromiseAnyRejectElementFunction>(realm.global_object(), index, errors, capability, remaining_elements, *realm.global_object().function_prototype());
return realm.heap().allocate<PromiseAnyRejectElementFunction>(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)

View file

@ -13,7 +13,7 @@ namespace JS {
PromiseResolvingFunction* PromiseResolvingFunction::create(Realm& realm, Promise& promise, AlreadyResolved& already_resolved, FunctionType function)
{
return realm.heap().allocate<PromiseResolvingFunction>(realm.global_object(), promise, already_resolved, move(function), *realm.global_object().function_prototype());
return realm.heap().allocate<PromiseResolvingFunction>(realm, promise, already_resolved, move(function), *realm.global_object().function_prototype());
}
PromiseResolvingFunction::PromiseResolvingFunction(Promise& promise, AlreadyResolved& already_resolved, FunctionType native_function, Object& prototype)

View file

@ -17,7 +17,7 @@ namespace JS {
ProxyObject* ProxyObject::create(Realm& realm, Object& target, Object& handler)
{
return realm.heap().allocate<ProxyObject>(realm.global_object(), target, handler, *realm.global_object().object_prototype());
return realm.heap().allocate<ProxyObject>(realm, target, handler, *realm.global_object().object_prototype());
}
ProxyObject::ProxyObject(Object& target, Object& handler, Object& prototype)

View file

@ -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<Realm>();
return vm.heap().allocate_without_realm<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<GlobalObject>(*this);
global_object = heap().allocate_without_realm<GlobalObject>(*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<GlobalEnvironment>(*global_object, *this_value);
m_global_environment = m_global_object->heap().allocate_without_realm<GlobalEnvironment>(*global_object, *this_value);
// 7. Return unused.
}

View file

@ -124,12 +124,12 @@ ThrowCompletionOr<String> parse_regex_pattern(StringView pattern, VM& vm, Global
RegExpObject* RegExpObject::create(Realm& realm)
{
return realm.heap().allocate<RegExpObject>(realm.global_object(), *realm.global_object().regexp_prototype());
return realm.heap().allocate<RegExpObject>(realm, *realm.global_object().regexp_prototype());
}
RegExpObject* RegExpObject::create(Realm& realm, Regex<ECMA262> regex, String pattern, String flags)
{
return realm.heap().allocate<RegExpObject>(realm.global_object(), move(regex), move(pattern), move(flags), *realm.global_object().regexp_prototype());
return realm.heap().allocate<RegExpObject>(realm, move(regex), move(pattern), move(flags), *realm.global_object().regexp_prototype());
}
RegExpObject::RegExpObject(Object& prototype)

View file

@ -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<RegExpStringIterator>(realm.global_object(), *realm.global_object().regexp_string_iterator_prototype(), regexp_object, move(string), global, unicode);
return realm.heap().allocate<RegExpStringIterator>(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)

View file

@ -10,7 +10,7 @@ namespace JS {
Set* Set::create(Realm& realm)
{
return realm.heap().allocate<Set>(realm.global_object(), *realm.global_object().set_prototype());
return realm.heap().allocate<Set>(realm, *realm.global_object().set_prototype());
}
Set::Set(Object& prototype)

View file

@ -11,7 +11,7 @@ namespace JS {
SetIterator* SetIterator::create(Realm& realm, Set& set, Object::PropertyKind iteration_kind)
{
return realm.heap().allocate<SetIterator>(realm.global_object(), set, iteration_kind, *realm.global_object().set_iterator_prototype());
return realm.heap().allocate<SetIterator>(realm, set, iteration_kind, *realm.global_object().set_iterator_prototype());
}
SetIterator::SetIterator(Set& set, Object::PropertyKind iteration_kind, Object& prototype)

View file

@ -63,7 +63,7 @@ ThrowCompletionOr<Object*> ShadowRealmConstructor::construct(FunctionObject& new
auto* object = TRY(ordinary_create_from_constructor<ShadowRealm>(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<GlobalObject>(*realm);
auto* new_global_object = vm.heap().allocate_without_realm<GlobalObject>(*realm);
realm->set_global_object(new_global_object, nullptr);
new_global_object->initialize_global_object();

View file

@ -12,7 +12,7 @@ namespace JS {
Shape* Shape::create_unique_clone() const
{
auto* new_shape = heap().allocate_without_global_object<Shape>(m_realm);
auto* new_shape = heap().allocate_without_realm<Shape>(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<Shape>(*this, property_key, attributes, TransitionType::Put);
auto* new_shape = heap().allocate_without_realm<Shape>(*this, property_key, attributes, TransitionType::Put);
if (!m_forward_transitions)
m_forward_transitions = make<HashMap<TransitionKey, WeakPtr<Shape>>>();
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<Shape>(*this, property_key, attributes, TransitionType::Configure);
auto* new_shape = heap().allocate_without_realm<Shape>(*this, property_key, attributes, TransitionType::Configure);
if (!m_forward_transitions)
m_forward_transitions = make<HashMap<TransitionKey, WeakPtr<Shape>>>();
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<Shape>(*this, new_prototype);
auto* new_shape = heap().allocate_without_realm<Shape>(*this, new_prototype);
if (!m_prototype_transitions)
m_prototype_transitions = make<HashMap<Object*, WeakPtr<Shape>>>();
m_prototype_transitions->set(new_prototype, new_shape);

View file

@ -12,7 +12,7 @@ namespace JS {
StringIterator* StringIterator::create(Realm& realm, String string)
{
return realm.heap().allocate<StringIterator>(realm.global_object(), move(string), *realm.global_object().string_iterator_prototype());
return realm.heap().allocate<StringIterator>(realm, move(string), *realm.global_object().string_iterator_prototype());
}
StringIterator::StringIterator(String string, Object& prototype)

View file

@ -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<StringObject>(realm.global_object(), primitive_string, prototype);
return realm.heap().allocate<StringObject>(realm, primitive_string, prototype);
}
StringObject::StringObject(PrimitiveString& string, Object& prototype)

View file

@ -18,7 +18,7 @@ Symbol::Symbol(Optional<String> description, bool is_global)
Symbol* js_symbol(Heap& heap, Optional<String> description, bool is_global)
{
return heap.allocate_without_global_object<Symbol>(move(description), is_global);
return heap.allocate_without_realm<Symbol>(move(description), is_global);
}
Symbol* js_symbol(VM& vm, Optional<String> description, bool is_global)

View file

@ -12,7 +12,7 @@ namespace JS {
SymbolObject* SymbolObject::create(Realm& realm, Symbol& primitive_symbol)
{
return realm.heap().allocate<SymbolObject>(realm.global_object(), primitive_symbol, *realm.global_object().symbol_prototype());
return realm.heap().allocate<SymbolObject>(realm, primitive_symbol, *realm.global_object().symbol_prototype());
}
SymbolObject::SymbolObject(Symbol& symbol, Object& prototype)

View file

@ -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<Now>(realm.global_object(), realm), attr);
define_direct_property(vm.names.Now, heap().allocate<Now>(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);

View file

@ -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<ClassName>(realm.global_object(), *prototype, length, *array_buffer); \
return realm.heap().allocate<ClassName>(realm, *prototype, length, *array_buffer); \
} \
\
ThrowCompletionOr<ClassName*> 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<ClassName>( \
realm.global_object(), *realm.global_object().snake_name##_prototype(), length, array_buffer); /* */ \
return realm.heap().allocate<ClassName>(realm, *realm.global_object().snake_name##_prototype(), length, array_buffer); /* */ \
} \
\
ClassName::ClassName(Object& prototype, u32 length, ArrayBuffer& array_buffer) \

View file

@ -41,9 +41,9 @@ VM::VM(OwnPtr<CustomData> custom_data)
: m_heap(*this)
, m_custom_data(move(custom_data))
{
m_empty_string = m_heap.allocate_without_global_object<PrimitiveString>(String::empty());
m_empty_string = m_heap.allocate_without_realm<PrimitiveString>(String::empty());
for (size_t i = 0; i < 128; ++i) {
m_single_ascii_character_strings[i] = m_heap.allocate_without_global_object<PrimitiveString>(String::formatted("{:c}", i));
m_single_ascii_character_strings[i] = m_heap.allocate_without_realm<PrimitiveString>(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.

View file

@ -10,7 +10,7 @@ namespace JS {
WeakMap* WeakMap::create(Realm& realm)
{
return realm.heap().allocate<WeakMap>(realm.global_object(), *realm.global_object().weak_map_prototype());
return realm.heap().allocate<WeakMap>(realm, *realm.global_object().weak_map_prototype());
}
WeakMap::WeakMap(Object& prototype)

View file

@ -10,12 +10,12 @@ namespace JS {
WeakRef* WeakRef::create(Realm& realm, Object& value)
{
return realm.heap().allocate<WeakRef>(realm.global_object(), value, *realm.global_object().weak_ref_prototype());
return realm.heap().allocate<WeakRef>(realm, value, *realm.global_object().weak_ref_prototype());
}
WeakRef* WeakRef::create(Realm& realm, Symbol& value)
{
return realm.heap().allocate<WeakRef>(realm.global_object(), value, *realm.global_object().weak_ref_prototype());
return realm.heap().allocate<WeakRef>(realm, value, *realm.global_object().weak_ref_prototype());
}
WeakRef::WeakRef(Object& value, Object& prototype)

View file

@ -10,7 +10,7 @@ namespace JS {
WeakSet* WeakSet::create(Realm& realm)
{
return realm.heap().allocate<WeakSet>(realm.global_object(), *realm.global_object().weak_set_prototype());
return realm.heap().allocate<WeakSet>(realm, *realm.global_object().weak_set_prototype());
}
WeakSet::WeakSet(Object& prototype)

View file

@ -22,7 +22,7 @@ ThrowCompletionOr<WrappedFunction*> 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<WrappedFunction>(realm.global_object(), caller_realm, target, prototype);
auto* wrapped = vm.heap().allocate<WrappedFunction>(realm, caller_realm, target, prototype);
// 7. Let result be CopyNameAndLength(wrapped, Target).
auto result = copy_name_and_length(realm.global_object(), *wrapped, target);

View file

@ -328,7 +328,7 @@ ThrowCompletionOr<void> 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<ModuleEnvironment>(&realm().global_environment());
auto* environment = vm.heap().allocate_without_realm<ModuleEnvironment>(&realm().global_environment());
// 6. Set module.[[Environment]] to env.
set_environment(environment);

View file

@ -53,7 +53,7 @@ ThrowCompletionOr<void> 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<ModuleEnvironment>(&realm().global_environment());
auto* environment = vm.heap().allocate_without_realm<ModuleEnvironment>(&realm().global_environment());
// 4. Set module.[[Environment]] to env.
set_environment(environment);

View file

@ -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<CSSNamespace>(*this, realm), 0);
define_direct_property("CSS", heap().allocate<CSSNamespace>(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<LocationObject>(*this, realm);
m_location_object = heap().allocate<LocationObject>(realm, realm);
auto* m_navigator_object = heap().allocate<NavigatorObject>(*this, realm);
auto* m_navigator_object = heap().allocate<NavigatorObject>(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<WebAssemblyObject>(*this, realm), JS::Attribute::Enumerable | JS::Attribute::Configurable);
define_direct_property("WebAssembly", heap().allocate<WebAssemblyObject>(realm, realm), JS::Attribute::Enumerable | JS::Attribute::Configurable);
// HTML::GlobalEventHandlers and HTML::WindowEventHandlers
#define __ENUMERATE(attribute, event_name) \

View file

@ -54,7 +54,7 @@ public:
if (it != m_prototypes.end())
return *it->value;
auto& realm = *associated_realm();
auto* prototype = heap().allocate<T>(*this, realm);
auto* prototype = heap().allocate<T>(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<T>(*this, realm);
auto* constructor = heap().allocate<T>(realm, realm);
m_constructors.set(class_name, constructor);
define_direct_property(class_name, JS::Value(constructor), JS::Attribute::Writable | JS::Attribute::Configurable);
return *constructor;

View file

@ -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<typename NativeObject::WrapperType>(realm.global_object(), realm, native_object));
native_object.set_wrapper(*realm.heap().allocate<typename NativeObject::WrapperType>(realm, realm, native_object));
}
return native_object.wrapper();
}

View file

@ -171,7 +171,7 @@ NonnullRefPtr<Document> 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<Bindings::WindowObject>(realm, *window);
auto* global_object = realm.heap().allocate_without_realm<Bindings::WindowObject>(realm, *window);
VERIFY(window->wrapper() == global_object);
return global_object;
},

View file

@ -124,7 +124,7 @@ NonnullRefPtr<BrowsingContext> 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<Bindings::WindowObject>(realm, *window);
auto* global_object = realm.heap().allocate_without_realm<Bindings::WindowObject>(realm, *window);
VERIFY(window->wrapper() == global_object);
return global_object;
},

View file

@ -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<JS::GlobalObject>(realm);
m_worker_scope = m_worker_vm->heap().allocate_without_realm<JS::GlobalObject>(realm);
return m_worker_scope;
},
nullptr);

View file

@ -37,7 +37,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyInstanceConstructor::construct(Fun
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Module");
auto& module_object = static_cast<WebAssemblyModuleObject&>(*module_argument);
auto result = TRY(WebAssemblyObject::instantiate_module(module_object.module(), vm, global_object));
return heap().allocate<WebAssemblyInstanceObject>(global_object, realm, result);
return heap().allocate<WebAssemblyInstanceObject>(realm, realm, result);
}
void WebAssemblyInstanceConstructor::initialize(JS::Realm& realm)

View file

@ -44,7 +44,7 @@ void WebAssemblyInstanceObject::initialize(JS::Realm& realm)
[&](Wasm::MemoryAddress const& address) {
Optional<WebAssemblyMemoryObject*> object = cache.memory_instances.get(address);
if (!object.has_value()) {
object = heap().allocate<Web::Bindings::WebAssemblyMemoryObject>(realm.global_object(), realm, address);
object = heap().allocate<Web::Bindings::WebAssemblyMemoryObject>(realm, realm, address);
cache.memory_instances.set(address, *object);
}
m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes);

View file

@ -51,7 +51,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyMemoryConstructor::construct(Funct
if (!WebAssemblyObject::s_abstract_machine.store().get(*address)->grow(initial))
return vm.throw_completion<JS::TypeError>(global_object, String::formatted("Wasm Memory grow failed: {}", initial));
return vm.heap().allocate<WebAssemblyMemoryObject>(global_object, realm, *address);
return vm.heap().allocate<WebAssemblyMemoryObject>(realm, realm, *address);
}
void WebAssemblyMemoryConstructor::initialize(JS::Realm& realm)

View file

@ -35,7 +35,7 @@ JS::ThrowCompletionOr<JS::Object*> 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<WebAssemblyModuleObject>(global_object, realm, result);
return heap().allocate<WebAssemblyModuleObject>(realm, realm, result);
}
void WebAssemblyModuleConstructor::initialize(JS::Realm& realm)

View file

@ -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<WebAssemblyModuleObject>(global_object, realm, result.release_value()));
promise->fulfill(vm.heap().allocate<WebAssemblyModuleObject>(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<WebAssemblyInstanceObject>(global_object, realm, result.release_value());
auto instance_object = vm.heap().allocate<WebAssemblyInstanceObject>(realm, realm, result.release_value());
if (should_return_module) {
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("module", vm.heap().allocate<WebAssemblyModuleObject>(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<JS::BigInt>(global_object, ::Crypto::SignedBigInteger::create_from(wasm_value.to<i64>().value()));
return realm.heap().allocate<JS::BigInt>(realm, ::Crypto::SignedBigInteger::create_from(wasm_value.to<i64>().value()));
case Wasm::ValueType::I32:
return JS::Value(wasm_value.to<i32>().value());
case Wasm::ValueType::F64:

View file

@ -78,7 +78,7 @@ JS::ThrowCompletionOr<JS::Object*> WebAssemblyTableConstructor::construct(Functi
for (auto& element : table.elements())
element = reference;
return vm.heap().allocate<WebAssemblyTableObject>(global_object, realm, *address);
return vm.heap().allocate<WebAssemblyTableObject>(realm, realm, *address);
}
void WebAssemblyTableConstructor::initialize(JS::Realm& realm)

View file

@ -26,7 +26,7 @@ WebContentConsoleClient::WebContentConsoleClient(JS::Console& console, WeakPtr<J
auto& vm = m_interpreter->vm();
auto& global_object = m_interpreter->global_object();
auto console_global_object = m_interpreter->heap().allocate_without_global_object<ConsoleGlobalObject>(m_interpreter->realm(), static_cast<Web::Bindings::WindowObject&>(global_object));
auto console_global_object = m_interpreter->heap().allocate_without_realm<ConsoleGlobalObject>(m_interpreter->realm(), static_cast<Web::Bindings::WindowObject&>(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().