LibJS+LibWeb: Rename Heap::allocate_without_realm to Heap::allocate

Now that the heap has no knowledge about a JavaScript realm and is
purely for managing the memory of the heap, it does not make sense
to name this function to say that it is a non-realm variant.
This commit is contained in:
Shannon Booth 2024-11-14 06:13:46 +13:00 committed by Tim Flynn
commit 1e54003cb1
Notes: github-actions[bot] 2024-11-13 21:52:39 +00:00
115 changed files with 243 additions and 243 deletions

View file

@ -394,7 +394,7 @@ NonnullGCPtr<DeclarativeEnvironment> new_declarative_environment(Environment& en
// 1. Let env be a new Declarative Environment Record containing no bindings.
// 2. Set env.[[OuterEnv]] to E.
// 3. Return env.
return heap.allocate_without_realm<DeclarativeEnvironment>(&environment);
return heap.allocate<DeclarativeEnvironment>(&environment);
}
// 9.1.2.3 NewObjectEnvironment ( O, W, E ), https://tc39.es/ecma262/#sec-newobjectenvironment
@ -407,7 +407,7 @@ NonnullGCPtr<ObjectEnvironment> new_object_environment(Object& object, bool is_w
// 3. Set env.[[IsWithEnvironment]] to W.
// 4. Set env.[[OuterEnv]] to E.
// 5. Return env.
return heap.allocate_without_realm<ObjectEnvironment>(object, is_with_environment ? ObjectEnvironment::IsWithEnvironment::Yes : ObjectEnvironment::IsWithEnvironment::No, environment);
return heap.allocate<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 @@ NonnullGCPtr<FunctionEnvironment> new_function_environment(ECMAScriptFunctionObj
auto& heap = function.heap();
// 1. Let env be a new function Environment Record containing no bindings.
auto env = heap.allocate_without_realm<FunctionEnvironment>(function.environment());
auto env = heap.allocate<FunctionEnvironment>(function.environment());
// 2. Set env.[[FunctionObject]] to F.
env->set_function_object(function);
@ -443,7 +443,7 @@ NonnullGCPtr<PrivateEnvironment> new_private_environment(VM& vm, PrivateEnvironm
{
// 1. Let names be a new empty List.
// 2. Return the PrivateEnvironment Record { [[OuterPrivateEnvironment]]: outerPrivEnv, [[Names]]: names }.
return vm.heap().allocate_without_realm<PrivateEnvironment>(outer);
return vm.heap().allocate<PrivateEnvironment>(outer);
}
// 9.4.3 GetThisEnvironment ( ), https://tc39.es/ecma262/#sec-getthisenvironment

View file

@ -20,7 +20,7 @@ class Accessor final : public Cell {
public:
static NonnullGCPtr<Accessor> create(VM& vm, FunctionObject* getter, FunctionObject* setter)
{
return vm.heap().allocate_without_realm<Accessor>(getter, setter);
return vm.heap().allocate<Accessor>(getter, setter);
}
FunctionObject* getter() const { return m_getter; }

View file

@ -15,7 +15,7 @@ JS_DEFINE_ALLOCATOR(BigInt);
NonnullGCPtr<BigInt> BigInt::create(VM& vm, Crypto::SignedBigInteger big_integer)
{
return vm.heap().allocate_without_realm<BigInt>(move(big_integer));
return vm.heap().allocate<BigInt>(move(big_integer));
}
BigInt::BigInt(Crypto::SignedBigInteger big_integer)

View file

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

View file

@ -21,8 +21,8 @@ GlobalEnvironment::GlobalEnvironment(Object& global_object, Object& this_value)
: Environment(nullptr)
, m_global_this_value(&this_value)
{
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>();
m_object_record = global_object.heap().allocate<ObjectEnvironment>(global_object, ObjectEnvironment::IsWithEnvironment::No, nullptr);
m_declarative_record = global_object.heap().allocate<DeclarativeEnvironment>();
}
void GlobalEnvironment::visit_edges(Cell::Visitor& visitor)

View file

@ -148,7 +148,7 @@ ThrowCompletionOr<NonnullGCPtr<Intrinsics>> Intrinsics::create(Realm& realm)
auto& vm = realm.vm();
// 1. Set realmRec.[[Intrinsics]] to a new Record.
auto intrinsics = vm.heap().allocate_without_realm<Intrinsics>(realm);
auto intrinsics = vm.heap().allocate<Intrinsics>(realm);
realm.set_intrinsics({}, intrinsics);
// 2. Set fields of realmRec.[[Intrinsics]] with the values listed in Table 6.
@ -179,26 +179,26 @@ ThrowCompletionOr<void> Intrinsics::initialize_intrinsics(Realm& realm)
auto& vm = this->vm();
// These are done first since other prototypes depend on their presence.
m_empty_object_shape = heap().allocate_without_realm<Shape>(realm);
m_object_prototype = heap().allocate_without_realm<ObjectPrototype>(realm);
m_empty_object_shape = heap().allocate<Shape>(realm);
m_object_prototype = heap().allocate<ObjectPrototype>(realm);
m_object_prototype->convert_to_prototype_if_needed();
m_function_prototype = heap().allocate_without_realm<FunctionPrototype>(realm);
m_function_prototype = heap().allocate<FunctionPrototype>(realm);
m_function_prototype->convert_to_prototype_if_needed();
m_new_object_shape = heap().allocate_without_realm<Shape>(realm);
m_new_object_shape = heap().allocate<Shape>(realm);
m_new_object_shape->set_prototype_without_transition(m_object_prototype);
// OPTIMIZATION: A lot of runtime algorithms create an "iterator result" object.
// We pre-bake a shape for these objects and remember the property offsets.
// This allows us to construct them very quickly.
m_iterator_result_object_shape = heap().allocate_without_realm<Shape>(realm);
m_iterator_result_object_shape = heap().allocate<Shape>(realm);
m_iterator_result_object_shape->set_prototype_without_transition(m_object_prototype);
m_iterator_result_object_shape->add_property_without_transition(vm.names.value, Attribute::Writable | Attribute::Configurable | Attribute::Enumerable);
m_iterator_result_object_shape->add_property_without_transition(vm.names.done, Attribute::Writable | Attribute::Configurable | Attribute::Enumerable);
m_iterator_result_object_value_offset = m_iterator_result_object_shape->lookup(vm.names.value.to_string_or_symbol()).value().offset;
m_iterator_result_object_done_offset = m_iterator_result_object_shape->lookup(vm.names.done.to_string_or_symbol()).value().offset;
// Normally Realm::create() takes care of this, but these are allocated via Heap::allocate_without_realm().
// Normally Realm::create() takes care of this, but these are allocated via Heap::allocate().
m_function_prototype->initialize(realm);
m_object_prototype->initialize(realm);

View file

@ -13,7 +13,7 @@ JS_DEFINE_ALLOCATOR(JobCallback);
JS::NonnullGCPtr<JobCallback> JobCallback::create(JS::VM& vm, FunctionObject& callback, OwnPtr<CustomData> custom_data)
{
return vm.heap().allocate_without_realm<JobCallback>(callback, move(custom_data));
return vm.heap().allocate<JobCallback>(callback, move(custom_data));
}
void JobCallback::visit_edges(Visitor& visitor)

View file

@ -39,7 +39,7 @@ NonnullGCPtr<Object> Object::create(Realm& realm, Object* prototype)
NonnullGCPtr<Object> Object::create_prototype(Realm& realm, Object* prototype)
{
auto shape = realm.heap().allocate_without_realm<Shape>(realm);
auto shape = realm.heap().allocate<Shape>(realm);
if (prototype)
shape->set_prototype_without_transition(prototype);
return realm.create<Object>(shape);
@ -54,13 +54,13 @@ Object::Object(GlobalObjectTag, Realm& realm, MayInterfereWithIndexedPropertyAcc
: m_may_interfere_with_indexed_property_access(may_interfere_with_indexed_property_access == MayInterfereWithIndexedPropertyAccess::Yes)
{
// This is the global object
m_shape = heap().allocate_without_realm<Shape>(realm);
m_shape = heap().allocate<Shape>(realm);
}
Object::Object(ConstructWithoutPrototypeTag, Realm& realm, MayInterfereWithIndexedPropertyAccess may_interfere_with_indexed_property_access)
: m_may_interfere_with_indexed_property_access(may_interfere_with_indexed_property_access == MayInterfereWithIndexedPropertyAccess::Yes)
{
m_shape = heap().allocate_without_realm<Shape>(realm);
m_shape = heap().allocate<Shape>(realm);
}
Object::Object(Realm& realm, Object* prototype, MayInterfereWithIndexedPropertyAccess may_interfere_with_indexed_property_access)

View file

@ -173,7 +173,7 @@ NonnullGCPtr<PrimitiveString> PrimitiveString::create(VM& vm, Utf16String string
if (auto it = string_cache.find(string); it != string_cache.end())
return *it->value;
auto new_string = vm.heap().allocate_without_realm<PrimitiveString>(string);
auto new_string = vm.heap().allocate<PrimitiveString>(string);
string_cache.set(move(string), new_string);
return *new_string;
}
@ -193,7 +193,7 @@ NonnullGCPtr<PrimitiveString> PrimitiveString::create(VM& vm, String string)
if (auto it = string_cache.find(string); it != string_cache.end())
return *it->value;
auto new_string = vm.heap().allocate_without_realm<PrimitiveString>(string);
auto new_string = vm.heap().allocate<PrimitiveString>(string);
string_cache.set(move(string), new_string);
return *new_string;
}
@ -222,7 +222,7 @@ NonnullGCPtr<PrimitiveString> PrimitiveString::create(VM& vm, ByteString string)
auto& string_cache = vm.byte_string_cache();
auto it = string_cache.find(string);
if (it == string_cache.end()) {
auto new_string = vm.heap().allocate_without_realm<PrimitiveString>(string);
auto new_string = vm.heap().allocate<PrimitiveString>(string);
string_cache.set(move(string), new_string);
return *new_string;
}
@ -251,7 +251,7 @@ NonnullGCPtr<PrimitiveString> PrimitiveString::create(VM& vm, PrimitiveString& l
if (rhs_empty)
return lhs;
return vm.heap().allocate_without_realm<PrimitiveString>(lhs, rhs);
return vm.heap().allocate<PrimitiveString>(lhs, rhs);
}
void PrimitiveString::resolve_rope_if_needed(EncodingPreference preference) const

View file

@ -64,7 +64,7 @@ Promise::ResolvingFunctions Promise::create_resolving_functions()
auto& realm = *vm.current_realm();
// 1. Let alreadyResolved be the Record { [[Value]]: false }.
auto already_resolved = vm.heap().allocate_without_realm<AlreadyResolved>();
auto already_resolved = vm.heap().allocate<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

@ -15,7 +15,7 @@ JS_DEFINE_ALLOCATOR(PromiseCapability);
NonnullGCPtr<PromiseCapability> PromiseCapability::create(VM& vm, NonnullGCPtr<Object> promise, NonnullGCPtr<FunctionObject> resolve, NonnullGCPtr<FunctionObject> reject)
{
return vm.heap().allocate_without_realm<PromiseCapability>(promise, resolve, reject);
return vm.heap().allocate<PromiseCapability>(promise, resolve, reject);
}
PromiseCapability::PromiseCapability(NonnullGCPtr<Object> promise, NonnullGCPtr<FunctionObject> resolve, NonnullGCPtr<FunctionObject> reject)

View file

@ -46,10 +46,10 @@ static ThrowCompletionOr<Value> perform_promise_common(VM& vm, IteratorRecord& i
VERIFY(promise_resolve.is_function());
// 1. Let values be a new empty List.
auto values = vm.heap().allocate_without_realm<PromiseValueList>();
auto values = vm.heap().allocate<PromiseValueList>();
// 2. Let remainingElementsCount be the Record { [[Value]]: 1 }.
auto remaining_elements_count = vm.heap().allocate_without_realm<RemainingElements>(1);
auto remaining_elements_count = vm.heap().allocate<RemainingElements>(1);
// 3. Let index be 0.
size_t index = 0;

View file

@ -14,7 +14,7 @@ JS_DEFINE_ALLOCATOR(PromiseReaction);
NonnullGCPtr<PromiseReaction> PromiseReaction::create(VM& vm, Type type, GCPtr<PromiseCapability> capability, GCPtr<JobCallback> handler)
{
return vm.heap().allocate_without_realm<PromiseReaction>(type, capability, move(handler));
return vm.heap().allocate<PromiseReaction>(type, capability, move(handler));
}
PromiseReaction::PromiseReaction(Type type, GCPtr<PromiseCapability> capability, GCPtr<JobCallback> handler)

View file

@ -22,7 +22,7 @@ ThrowCompletionOr<NonnullOwnPtr<ExecutionContext>> Realm::initialize_host_define
DeferGC defer_gc(vm.heap());
// 1. Let realm be a new Realm Record
auto realm = vm.heap().allocate_without_realm<Realm>();
auto realm = vm.heap().allocate<Realm>();
// 2. Perform CreateIntrinsics(realm).
MUST(Intrinsics::create(*realm));
@ -61,7 +61,7 @@ ThrowCompletionOr<NonnullOwnPtr<ExecutionContext>> Realm::initialize_host_define
// a. Let global be OrdinaryObjectCreate(realm.[[Intrinsics]].[[%Object.prototype%]]).
// NOTE: We allocate a proper GlobalObject directly as this plain object is
// turned into one via SetDefaultGlobalBindings in the spec.
global = vm.heap().allocate_without_realm<GlobalObject>(realm);
global = vm.heap().allocate<GlobalObject>(realm);
}
// 14. If the host requires that the this binding in realm's global scope return an object other than the global object, then
@ -80,7 +80,7 @@ ThrowCompletionOr<NonnullOwnPtr<ExecutionContext>> Realm::initialize_host_define
realm->m_global_object = global;
// 17. Set realm.[[GlobalEnv]] to NewGlobalEnvironment(global, thisValue).
realm->m_global_environment = vm.heap().allocate_without_realm<GlobalEnvironment>(*global, *this_value);
realm->m_global_environment = vm.heap().allocate<GlobalEnvironment>(*global, *this_value);
// 18. Perform ? SetDefaultGlobalBindings(realm).
set_default_global_bindings(*realm);

View file

@ -35,7 +35,7 @@ public:
template<typename T, typename... Args>
NonnullGCPtr<T> create(Args&&... args)
{
auto object = heap().allocate_without_realm<T>(forward<Args>(args)...);
auto object = heap().allocate<T>(forward<Args>(args)...);
static_cast<Cell*>(object)->initialize(*this);
return *object;
}

View file

@ -23,7 +23,7 @@ Shape::~Shape()
NonnullGCPtr<Shape> Shape::create_cacheable_dictionary_transition()
{
auto new_shape = heap().allocate_without_realm<Shape>(m_realm);
auto new_shape = heap().allocate<Shape>(m_realm);
new_shape->m_dictionary = true;
new_shape->m_cacheable = true;
new_shape->m_prototype = m_prototype;
@ -37,7 +37,7 @@ NonnullGCPtr<Shape> Shape::create_cacheable_dictionary_transition()
NonnullGCPtr<Shape> Shape::create_uncacheable_dictionary_transition()
{
auto new_shape = heap().allocate_without_realm<Shape>(m_realm);
auto new_shape = heap().allocate<Shape>(m_realm);
new_shape->m_dictionary = true;
new_shape->m_cacheable = true;
new_shape->m_prototype = m_prototype;
@ -105,7 +105,7 @@ NonnullGCPtr<Shape> Shape::create_put_transition(StringOrSymbol const& 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_realm<Shape>(*this, property_key, attributes, TransitionType::Put);
auto new_shape = heap().allocate<Shape>(*this, property_key, attributes, TransitionType::Put);
invalidate_prototype_if_needed_for_new_prototype(new_shape);
if (!m_is_prototype_shape) {
if (!m_forward_transitions)
@ -120,7 +120,7 @@ NonnullGCPtr<Shape> Shape::create_configure_transition(StringOrSymbol const& pro
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_realm<Shape>(*this, property_key, attributes, TransitionType::Configure);
auto new_shape = heap().allocate<Shape>(*this, property_key, attributes, TransitionType::Configure);
invalidate_prototype_if_needed_for_new_prototype(new_shape);
if (!m_is_prototype_shape) {
if (!m_forward_transitions)
@ -136,7 +136,7 @@ NonnullGCPtr<Shape> Shape::create_prototype_transition(Object* new_prototype)
new_prototype->convert_to_prototype_if_needed();
if (auto existing_shape = get_or_prune_cached_prototype_transition(new_prototype))
return *existing_shape;
auto new_shape = heap().allocate_without_realm<Shape>(*this, new_prototype);
auto new_shape = heap().allocate<Shape>(*this, new_prototype);
invalidate_prototype_if_needed_for_new_prototype(new_shape);
if (!m_is_prototype_shape) {
if (!m_prototype_transitions)
@ -274,7 +274,7 @@ NonnullGCPtr<Shape> Shape::create_delete_transition(StringOrSymbol const& proper
{
if (auto existing_shape = get_or_prune_cached_delete_transition(property_key))
return *existing_shape;
auto new_shape = heap().allocate_without_realm<Shape>(*this, property_key, TransitionType::Delete);
auto new_shape = heap().allocate<Shape>(*this, property_key, TransitionType::Delete);
invalidate_prototype_if_needed_for_new_prototype(new_shape);
if (!m_delete_transitions)
m_delete_transitions = make<HashMap<StringOrSymbol, WeakPtr<Shape>>>();
@ -321,11 +321,11 @@ void Shape::remove_property_without_transition(StringOrSymbol const& property_ke
NonnullGCPtr<Shape> Shape::create_for_prototype(NonnullGCPtr<Realm> realm, GCPtr<Object> prototype)
{
auto new_shape = realm->heap().allocate_without_realm<Shape>(realm);
auto new_shape = realm->heap().allocate<Shape>(realm);
s_all_prototype_shapes.set(new_shape);
new_shape->m_is_prototype_shape = true;
new_shape->m_prototype = prototype;
new_shape->m_prototype_chain_validity = realm->heap().allocate_without_realm<PrototypeChainValidity>();
new_shape->m_prototype_chain_validity = realm->heap().allocate<PrototypeChainValidity>();
return new_shape;
}
@ -333,7 +333,7 @@ NonnullGCPtr<Shape> Shape::clone_for_prototype()
{
VERIFY(!m_is_prototype_shape);
VERIFY(!m_prototype_chain_validity);
auto new_shape = heap().allocate_without_realm<Shape>(m_realm);
auto new_shape = heap().allocate<Shape>(m_realm);
s_all_prototype_shapes.set(new_shape);
new_shape->m_is_prototype_shape = true;
new_shape->m_prototype = m_prototype;
@ -341,7 +341,7 @@ NonnullGCPtr<Shape> Shape::clone_for_prototype()
new_shape->ensure_property_table();
(*new_shape->m_property_table) = *m_property_table;
new_shape->m_property_count = new_shape->m_property_table->size();
new_shape->m_prototype_chain_validity = heap().allocate_without_realm<PrototypeChainValidity>();
new_shape->m_prototype_chain_validity = heap().allocate<PrototypeChainValidity>();
return new_shape;
}
@ -357,7 +357,7 @@ void Shape::set_prototype_shape()
VERIFY(!m_is_prototype_shape);
s_all_prototype_shapes.set(this);
m_is_prototype_shape = true;
m_prototype_chain_validity = heap().allocate_without_realm<PrototypeChainValidity>();
m_prototype_chain_validity = heap().allocate<PrototypeChainValidity>();
}
void Shape::invalidate_prototype_if_needed_for_new_prototype(NonnullGCPtr<Shape> new_prototype_shape)
@ -388,7 +388,7 @@ void Shape::invalidate_all_prototype_chains_leading_to_this()
return;
for (auto* shape : shapes_to_invalidate) {
shape->m_prototype_chain_validity->set_valid(false);
shape->m_prototype_chain_validity = heap().allocate_without_realm<PrototypeChainValidity>();
shape->m_prototype_chain_validity = heap().allocate<PrototypeChainValidity>();
}
}

View file

@ -21,7 +21,7 @@ Symbol::Symbol(Optional<String> description, bool is_global)
NonnullGCPtr<Symbol> Symbol::create(VM& vm, Optional<String> description, bool is_global)
{
return vm.heap().allocate_without_realm<Symbol>(move(description), is_global);
return vm.heap().allocate<Symbol>(move(description), is_global);
}
// 20.4.3.3.1 SymbolDescriptiveString ( sym ), https://tc39.es/ecma262/#sec-symboldescriptivestring

View file

@ -68,21 +68,21 @@ VM::VM(OwnPtr<CustomData> custom_data, ErrorMessages error_messages)
{
m_bytecode_interpreter = make<Bytecode::Interpreter>(*this);
m_empty_string = m_heap.allocate_without_realm<PrimitiveString>(String {});
m_empty_string = m_heap.allocate<PrimitiveString>(String {});
typeof_strings = {
.number = m_heap.allocate_without_realm<PrimitiveString>("number"),
.undefined = m_heap.allocate_without_realm<PrimitiveString>("undefined"),
.object = m_heap.allocate_without_realm<PrimitiveString>("object"),
.string = m_heap.allocate_without_realm<PrimitiveString>("string"),
.symbol = m_heap.allocate_without_realm<PrimitiveString>("symbol"),
.boolean = m_heap.allocate_without_realm<PrimitiveString>("boolean"),
.bigint = m_heap.allocate_without_realm<PrimitiveString>("bigint"),
.function = m_heap.allocate_without_realm<PrimitiveString>("function"),
.number = m_heap.allocate<PrimitiveString>("number"),
.undefined = m_heap.allocate<PrimitiveString>("undefined"),
.object = m_heap.allocate<PrimitiveString>("object"),
.string = m_heap.allocate<PrimitiveString>("string"),
.symbol = m_heap.allocate<PrimitiveString>("symbol"),
.boolean = m_heap.allocate<PrimitiveString>("boolean"),
.bigint = m_heap.allocate<PrimitiveString>("bigint"),
.function = m_heap.allocate<PrimitiveString>("function"),
};
for (size_t i = 0; i < single_ascii_character_strings.size(); ++i)
m_single_ascii_character_strings[i] = m_heap.allocate_without_realm<PrimitiveString>(single_ascii_character_strings[i]);
m_single_ascii_character_strings[i] = m_heap.allocate<PrimitiveString>(single_ascii_character_strings[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.
host_promise_rejection_tracker = [this](Promise& promise, Promise::RejectionOperation operation) {

View file

@ -358,7 +358,7 @@ template<typename GlobalObjectType, typename... Args>
auto root_execution_context = MUST(Realm::initialize_host_defined_realm(
vm,
[&](Realm& realm_) -> GlobalObject* {
return vm.heap().allocate_without_realm<GlobalObjectType>(realm_, forward<Args>(args)...);
return vm.heap().allocate<GlobalObjectType>(realm_, forward<Args>(args)...);
},
nullptr));
return root_execution_context;