LibGC+Everywhere: Factor out a LibGC from LibJS

Resulting in a massive rename across almost everywhere! Alongside the
namespace change, we now have the following names:

 * JS::NonnullGCPtr -> GC::Ref
 * JS::GCPtr -> GC::Ptr
 * JS::HeapFunction -> GC::Function
 * JS::CellImpl -> GC::Cell
 * JS::Handle -> GC::Root
This commit is contained in:
Shannon Booth 2024-11-15 04:01:23 +13:00 committed by Andreas Kling
commit f87041bf3a
Notes: github-actions[bot] 2024-11-15 13:50:17 +00:00
1722 changed files with 9939 additions and 9906 deletions

View file

@ -73,7 +73,7 @@ ThrowCompletionOr<Value> call_impl(VM&, FunctionObject& function, Value this_val
}
// 7.3.15 Construct ( F [ , argumentsList [ , newTarget ] ] ), https://tc39.es/ecma262/#sec-construct
ThrowCompletionOr<NonnullGCPtr<Object>> construct_impl(VM&, FunctionObject& function, ReadonlySpan<Value> arguments_list, FunctionObject* new_target)
ThrowCompletionOr<GC::Ref<Object>> construct_impl(VM&, FunctionObject& function, ReadonlySpan<Value> arguments_list, FunctionObject* new_target)
{
// 1. If newTarget is not present, set newTarget to F.
if (!new_target)
@ -97,7 +97,7 @@ ThrowCompletionOr<size_t> length_of_array_like(VM& vm, Object const& object)
}
// 7.3.20 CreateListFromArrayLike ( obj [ , elementTypes ] ), https://tc39.es/ecma262/#sec-createlistfromarraylike
ThrowCompletionOr<MarkedVector<Value>> create_list_from_array_like(VM& vm, Value value, Function<ThrowCompletionOr<void>(Value)> check_value)
ThrowCompletionOr<GC::MarkedVector<Value>> create_list_from_array_like(VM& vm, Value value, Function<ThrowCompletionOr<void>(Value)> check_value)
{
// 1. If elementTypes is not present, set elementTypes to « Undefined, Null, Boolean, String, Symbol, Number, BigInt, Object ».
@ -111,7 +111,7 @@ ThrowCompletionOr<MarkedVector<Value>> create_list_from_array_like(VM& vm, Value
auto length = TRY(length_of_array_like(vm, array_like));
// 4. Let list be a new empty List.
auto list = MarkedVector<Value> { vm.heap() };
auto list = GC::MarkedVector<Value> { vm.heap() };
list.ensure_capacity(length);
// 5. Let index be 0.
@ -366,7 +366,7 @@ bool validate_and_apply_property_descriptor(Object* object, PropertyKey const& p
}
// 10.1.14 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ), https://tc39.es/ecma262/#sec-getprototypefromconstructor
ThrowCompletionOr<Object*> get_prototype_from_constructor(VM& vm, FunctionObject const& constructor, NonnullGCPtr<Object> (Intrinsics::*intrinsic_default_prototype)())
ThrowCompletionOr<Object*> get_prototype_from_constructor(VM& vm, FunctionObject const& constructor, GC::Ref<Object> (Intrinsics::*intrinsic_default_prototype)())
{
// 1. Assert: intrinsicDefaultProto is this specification's name of an intrinsic object. The corresponding object must be an intrinsic that is intended to be used as the [[Prototype]] value of an object.
@ -387,7 +387,7 @@ ThrowCompletionOr<Object*> get_prototype_from_constructor(VM& vm, FunctionObject
}
// 9.1.2.2 NewDeclarativeEnvironment ( E ), https://tc39.es/ecma262/#sec-newdeclarativeenvironment
NonnullGCPtr<DeclarativeEnvironment> new_declarative_environment(Environment& environment)
GC::Ref<DeclarativeEnvironment> new_declarative_environment(Environment& environment)
{
auto& heap = environment.heap();
@ -398,7 +398,7 @@ NonnullGCPtr<DeclarativeEnvironment> new_declarative_environment(Environment& en
}
// 9.1.2.3 NewObjectEnvironment ( O, W, E ), https://tc39.es/ecma262/#sec-newobjectenvironment
NonnullGCPtr<ObjectEnvironment> new_object_environment(Object& object, bool is_with_environment, Environment* environment)
GC::Ref<ObjectEnvironment> new_object_environment(Object& object, bool is_with_environment, Environment* environment)
{
auto& heap = object.heap();
@ -411,7 +411,7 @@ NonnullGCPtr<ObjectEnvironment> new_object_environment(Object& object, bool is_w
}
// 9.1.2.4 NewFunctionEnvironment ( F, newTarget ), https://tc39.es/ecma262/#sec-newfunctionenvironment
NonnullGCPtr<FunctionEnvironment> new_function_environment(ECMAScriptFunctionObject& function, Object* new_target)
GC::Ref<FunctionEnvironment> new_function_environment(ECMAScriptFunctionObject& function, Object* new_target)
{
auto& heap = function.heap();
@ -439,7 +439,7 @@ NonnullGCPtr<FunctionEnvironment> new_function_environment(ECMAScriptFunctionObj
}
// 9.2.1.1 NewPrivateEnvironment ( outerPrivEnv ), https://tc39.es/ecma262/#sec-newprivateenvironment
NonnullGCPtr<PrivateEnvironment> new_private_environment(VM& vm, PrivateEnvironment* outer)
GC::Ref<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 }.
@ -447,7 +447,7 @@ NonnullGCPtr<PrivateEnvironment> new_private_environment(VM& vm, PrivateEnvironm
}
// 9.4.3 GetThisEnvironment ( ), https://tc39.es/ecma262/#sec-getthisenvironment
NonnullGCPtr<Environment> get_this_environment(VM& vm)
GC::Ref<Environment> get_this_environment(VM& vm)
{
// 1. Let env be the running execution context's LexicalEnvironment.
// 2. Repeat,
@ -1482,7 +1482,7 @@ ThrowCompletionOr<DisposableResource> create_disposable_resource(VM& vm, Value v
}
// 2.1.4 GetDisposeMethod ( V, hint ), https://tc39.es/proposal-explicit-resource-management/#sec-getdisposemethod
ThrowCompletionOr<GCPtr<FunctionObject>> get_dispose_method(VM& vm, Value value, Environment::InitializeBindingHint hint)
ThrowCompletionOr<GC::Ptr<FunctionObject>> get_dispose_method(VM& vm, Value value, Environment::InitializeBindingHint hint)
{
// NOTE: We only have sync dispose for now which means we ignore step 1.
VERIFY(hint == Environment::InitializeBindingHint::SyncDispose);
@ -1493,7 +1493,7 @@ ThrowCompletionOr<GCPtr<FunctionObject>> get_dispose_method(VM& vm, Value value,
}
// 2.1.5 Dispose ( V, hint, method ), https://tc39.es/proposal-explicit-resource-management/#sec-dispose
Completion dispose(VM& vm, Value value, NonnullGCPtr<FunctionObject> method)
Completion dispose(VM& vm, Value value, GC::Ref<FunctionObject> method)
{
// 1. Let result be ? Call(method, V).
[[maybe_unused]] auto result = TRY(call(vm, *method, value));
@ -1550,7 +1550,7 @@ Completion dispose_resources(VM& vm, Vector<DisposableResource> const& disposabl
return completion;
}
Completion dispose_resources(VM& vm, GCPtr<DeclarativeEnvironment> disposable, Completion completion)
Completion dispose_resources(VM& vm, GC::Ptr<DeclarativeEnvironment> disposable, Completion completion)
{
// 1. If disposable is not undefined, then
if (disposable)
@ -1588,12 +1588,12 @@ ThrowCompletionOr<Value> perform_import_call(VM& vm, Value specifier, Value opti
// 2. If referrer is null, set referrer to the current Realm Record.
if (active_script_or_module.has<Empty>())
return NonnullGCPtr<Realm> { realm };
return GC::Ref<Realm> { realm };
if (active_script_or_module.has<NonnullGCPtr<Script>>())
return active_script_or_module.get<NonnullGCPtr<Script>>();
if (active_script_or_module.has<GC::Ref<Script>>())
return active_script_or_module.get<GC::Ref<Script>>();
return NonnullGCPtr<CyclicModule> { verify_cast<CyclicModule>(*active_script_or_module.get<NonnullGCPtr<Module>>()) };
return GC::Ref<CyclicModule> { verify_cast<CyclicModule>(*active_script_or_module.get<GC::Ref<Module>>()) };
}();
// 7. Let promiseCapability be ! NewPromiseCapability(%Promise%).

View file

@ -9,8 +9,8 @@
#include <AK/Concepts.h>
#include <AK/Forward.h>
#include <LibCrypto/Forward.h>
#include <LibGC/MarkedVector.h>
#include <LibJS/Forward.h>
#include <LibJS/Heap/MarkedVector.h>
#include <LibJS/Runtime/CanonicalIndex.h>
#include <LibJS/Runtime/FunctionObject.h>
#include <LibJS/Runtime/GlobalObject.h>
@ -22,38 +22,38 @@
namespace JS {
NonnullGCPtr<DeclarativeEnvironment> new_declarative_environment(Environment&);
NonnullGCPtr<ObjectEnvironment> new_object_environment(Object&, bool is_with_environment, Environment*);
NonnullGCPtr<FunctionEnvironment> new_function_environment(ECMAScriptFunctionObject&, Object* new_target);
NonnullGCPtr<PrivateEnvironment> new_private_environment(VM& vm, PrivateEnvironment* outer);
NonnullGCPtr<Environment> get_this_environment(VM&);
GC::Ref<DeclarativeEnvironment> new_declarative_environment(Environment&);
GC::Ref<ObjectEnvironment> new_object_environment(Object&, bool is_with_environment, Environment*);
GC::Ref<FunctionEnvironment> new_function_environment(ECMAScriptFunctionObject&, Object* new_target);
GC::Ref<PrivateEnvironment> new_private_environment(VM& vm, PrivateEnvironment* outer);
GC::Ref<Environment> get_this_environment(VM&);
bool can_be_held_weakly(Value);
Object* get_super_constructor(VM&);
ThrowCompletionOr<Value> require_object_coercible(VM&, Value);
ThrowCompletionOr<Value> call_impl(VM&, Value function, Value this_value, ReadonlySpan<Value> arguments = {});
ThrowCompletionOr<Value> call_impl(VM&, FunctionObject& function, Value this_value, ReadonlySpan<Value> arguments = {});
ThrowCompletionOr<NonnullGCPtr<Object>> construct_impl(VM&, FunctionObject&, ReadonlySpan<Value> arguments = {}, FunctionObject* new_target = nullptr);
ThrowCompletionOr<GC::Ref<Object>> construct_impl(VM&, FunctionObject&, ReadonlySpan<Value> arguments = {}, FunctionObject* new_target = nullptr);
ThrowCompletionOr<size_t> length_of_array_like(VM&, Object const&);
ThrowCompletionOr<MarkedVector<Value>> create_list_from_array_like(VM&, Value, Function<ThrowCompletionOr<void>(Value)> = {});
ThrowCompletionOr<GC::MarkedVector<Value>> create_list_from_array_like(VM&, Value, Function<ThrowCompletionOr<void>(Value)> = {});
ThrowCompletionOr<FunctionObject*> species_constructor(VM&, Object const&, FunctionObject& default_constructor);
ThrowCompletionOr<Realm*> get_function_realm(VM&, FunctionObject const&);
ThrowCompletionOr<void> initialize_bound_name(VM&, DeprecatedFlyString const&, Value, Environment*);
bool is_compatible_property_descriptor(bool extensible, PropertyDescriptor const&, Optional<PropertyDescriptor> const& current);
bool validate_and_apply_property_descriptor(Object*, PropertyKey const&, bool extensible, PropertyDescriptor const&, Optional<PropertyDescriptor> const& current);
ThrowCompletionOr<Object*> get_prototype_from_constructor(VM&, FunctionObject const& constructor, NonnullGCPtr<Object> (Intrinsics::*intrinsic_default_prototype)());
ThrowCompletionOr<Object*> get_prototype_from_constructor(VM&, FunctionObject const& constructor, GC::Ref<Object> (Intrinsics::*intrinsic_default_prototype)());
Object* create_unmapped_arguments_object(VM&, ReadonlySpan<Value> arguments);
Object* create_mapped_arguments_object(VM&, FunctionObject&, Vector<FunctionParameter> const&, ReadonlySpan<Value> arguments, Environment&);
struct DisposableResource {
Value resource_value;
NonnullGCPtr<FunctionObject> dispose_method;
GC::Ref<FunctionObject> dispose_method;
};
ThrowCompletionOr<void> add_disposable_resource(VM&, Vector<DisposableResource>& disposable, Value, Environment::InitializeBindingHint, FunctionObject* = nullptr);
ThrowCompletionOr<DisposableResource> create_disposable_resource(VM&, Value, Environment::InitializeBindingHint, FunctionObject* method = nullptr);
ThrowCompletionOr<GCPtr<FunctionObject>> get_dispose_method(VM&, Value, Environment::InitializeBindingHint);
Completion dispose(VM& vm, Value, NonnullGCPtr<FunctionObject> method);
ThrowCompletionOr<GC::Ptr<FunctionObject>> get_dispose_method(VM&, Value, Environment::InitializeBindingHint);
Completion dispose(VM& vm, Value, GC::Ref<FunctionObject> method);
Completion dispose_resources(VM& vm, Vector<DisposableResource> const& disposable, Completion completion);
Completion dispose_resources(VM& vm, GCPtr<DeclarativeEnvironment> disposable, Completion completion);
Completion dispose_resources(VM& vm, GC::Ptr<DeclarativeEnvironment> disposable, Completion completion);
ThrowCompletionOr<Value> perform_import_call(VM&, Value specifier, Value options_value);
@ -120,7 +120,7 @@ ALWAYS_INLINE ThrowCompletionOr<Value> call(VM& vm, FunctionObject& function, Va
// 7.3.15 Construct ( F [ , argumentsList [ , newTarget ] ] ), https://tc39.es/ecma262/#sec-construct
template<typename... Args>
ALWAYS_INLINE ThrowCompletionOr<NonnullGCPtr<Object>> construct(VM& vm, FunctionObject& function, Args&&... args)
ALWAYS_INLINE ThrowCompletionOr<GC::Ref<Object>> construct(VM& vm, FunctionObject& function, Args&&... args)
{
constexpr auto argument_count = sizeof...(Args);
if constexpr (argument_count > 0) {
@ -131,19 +131,19 @@ ALWAYS_INLINE ThrowCompletionOr<NonnullGCPtr<Object>> construct(VM& vm, Function
return construct_impl(vm, function);
}
ALWAYS_INLINE ThrowCompletionOr<NonnullGCPtr<Object>> construct(VM& vm, FunctionObject& function, ReadonlySpan<Value> arguments_list, FunctionObject* new_target = nullptr)
ALWAYS_INLINE ThrowCompletionOr<GC::Ref<Object>> construct(VM& vm, FunctionObject& function, ReadonlySpan<Value> arguments_list, FunctionObject* new_target = nullptr)
{
return construct_impl(vm, function, arguments_list, new_target);
}
ALWAYS_INLINE ThrowCompletionOr<NonnullGCPtr<Object>> construct(VM& vm, FunctionObject& function, Span<Value> arguments_list, FunctionObject* new_target = nullptr)
ALWAYS_INLINE ThrowCompletionOr<GC::Ref<Object>> construct(VM& vm, FunctionObject& function, Span<Value> arguments_list, FunctionObject* new_target = nullptr)
{
return construct_impl(vm, function, static_cast<ReadonlySpan<Value>>(arguments_list), new_target);
}
// 10.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ), https://tc39.es/ecma262/#sec-ordinarycreatefromconstructor
template<typename T, typename... Args>
ThrowCompletionOr<NonnullGCPtr<T>> ordinary_create_from_constructor(VM& vm, FunctionObject const& constructor, NonnullGCPtr<Object> (Intrinsics::*intrinsic_default_prototype)(), Args&&... args)
ThrowCompletionOr<GC::Ref<T>> ordinary_create_from_constructor(VM& vm, FunctionObject const& constructor, GC::Ref<Object> (Intrinsics::*intrinsic_default_prototype)(), Args&&... args)
{
auto& realm = *vm.current_realm();
auto* prototype = TRY(get_prototype_from_constructor(vm, constructor, intrinsic_default_prototype));
@ -199,7 +199,7 @@ void add_value_to_keyed_group(VM& vm, GroupsType& groups, KeyType key, Value val
}
// 2. Let group be the Record { [[Key]]: key, [[Elements]]: « value » }.
MarkedVector<Value> new_elements { vm.heap() };
GC::MarkedVector<Value> new_elements { vm.heap() };
new_elements.append(value);
// 3. Append group as the last element of groups.
@ -278,7 +278,7 @@ ThrowCompletionOr<GroupsType> group_by(VM& vm, Value items, Value callback_funct
// ii. Set key to CanonicalizeKeyedCollectionKey(key).
key = canonicalize_keyed_collection_key(key.value());
add_value_to_keyed_group(vm, groups, make_handle(key.release_value()), value);
add_value_to_keyed_group(vm, groups, make_root(key.release_value()), value);
}
// i. Perform AddValueToKeyedGroup(groups, key, value).

View file

@ -8,6 +8,6 @@
namespace JS {
JS_DEFINE_ALLOCATOR(Accessor);
GC_DEFINE_ALLOCATOR(Accessor);
}

View file

@ -14,11 +14,11 @@
namespace JS {
class Accessor final : public Cell {
JS_CELL(Accessor, Cell);
JS_DECLARE_ALLOCATOR(Accessor);
GC_CELL(Accessor, Cell);
GC_DECLARE_ALLOCATOR(Accessor);
public:
static NonnullGCPtr<Accessor> create(VM& vm, FunctionObject* getter, FunctionObject* setter)
static GC::Ref<Accessor> create(VM& vm, FunctionObject* getter, FunctionObject* setter)
{
return vm.heap().allocate<Accessor>(getter, setter);
}
@ -43,8 +43,8 @@ private:
{
}
GCPtr<FunctionObject> m_getter;
GCPtr<FunctionObject> m_setter;
GC::Ptr<FunctionObject> m_getter;
GC::Ptr<FunctionObject> m_setter;
};
}

View file

@ -10,9 +10,9 @@
namespace JS {
JS_DEFINE_ALLOCATOR(AggregateError);
GC_DEFINE_ALLOCATOR(AggregateError);
NonnullGCPtr<AggregateError> AggregateError::create(Realm& realm)
GC::Ref<AggregateError> AggregateError::create(Realm& realm)
{
return realm.create<AggregateError>(realm.intrinsics().aggregate_error_prototype());
}

View file

@ -13,10 +13,10 @@ namespace JS {
class AggregateError : public Error {
JS_OBJECT(AggregateError, Error);
JS_DECLARE_ALLOCATOR(AggregateError);
GC_DECLARE_ALLOCATOR(AggregateError);
public:
static NonnullGCPtr<AggregateError> create(Realm&);
static GC::Ref<AggregateError> create(Realm&);
virtual ~AggregateError() override = default;
private:

View file

@ -14,7 +14,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(AggregateErrorConstructor);
GC_DEFINE_ALLOCATOR(AggregateErrorConstructor);
AggregateErrorConstructor::AggregateErrorConstructor(Realm& realm)
: NativeFunction(static_cast<Object&>(*realm.intrinsics().error_constructor()))
@ -40,7 +40,7 @@ ThrowCompletionOr<Value> AggregateErrorConstructor::call()
}
// 20.5.7.1.1 AggregateError ( errors, message [ , options ] ), https://tc39.es/ecma262/#sec-aggregate-error
ThrowCompletionOr<NonnullGCPtr<Object>> AggregateErrorConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> AggregateErrorConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();
auto& realm = *vm.current_realm();

View file

@ -12,14 +12,14 @@ namespace JS {
class AggregateErrorConstructor final : public NativeFunction {
JS_OBJECT(AggregateErrorConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(AggregateErrorConstructor);
GC_DECLARE_ALLOCATOR(AggregateErrorConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~AggregateErrorConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
private:
explicit AggregateErrorConstructor(Realm&);

View file

@ -10,7 +10,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(AggregateErrorPrototype);
GC_DEFINE_ALLOCATOR(AggregateErrorPrototype);
AggregateErrorPrototype::AggregateErrorPrototype(Realm& realm)
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().error_prototype())

View file

@ -12,7 +12,7 @@ namespace JS {
class AggregateErrorPrototype final : public Object {
JS_OBJECT(AggregateErrorPrototype, Object);
JS_DECLARE_ALLOCATOR(AggregateErrorPrototype);
GC_DECLARE_ALLOCATOR(AggregateErrorPrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -10,7 +10,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(ArgumentsObject);
GC_DEFINE_ALLOCATOR(ArgumentsObject);
ArgumentsObject::ArgumentsObject(Realm& realm, Environment& environment)
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype(), MayInterfereWithIndexedPropertyAccess::Yes)

View file

@ -14,7 +14,7 @@ namespace JS {
class ArgumentsObject final : public Object {
JS_OBJECT(ArgumentsObject, Object);
JS_DECLARE_ALLOCATOR(ArgumentsObject);
GC_DECLARE_ALLOCATOR(ArgumentsObject);
public:
virtual void initialize(Realm&) override;
@ -36,8 +36,8 @@ private:
virtual void visit_edges(Cell::Visitor&) override;
NonnullGCPtr<Environment> m_environment;
GCPtr<Object> m_parameter_map;
GC::Ref<Environment> m_environment;
GC::Ptr<Object> m_parameter_map;
};
}

View file

@ -17,10 +17,10 @@
namespace JS {
JS_DEFINE_ALLOCATOR(Array);
GC_DEFINE_ALLOCATOR(Array);
// 10.4.2.2 ArrayCreate ( length [ , proto ] ), https://tc39.es/ecma262/#sec-arraycreate
ThrowCompletionOr<NonnullGCPtr<Array>> Array::create(Realm& realm, u64 length, Object* prototype)
ThrowCompletionOr<GC::Ref<Array>> Array::create(Realm& realm, u64 length, Object* prototype)
{
auto& vm = realm.vm();
@ -45,7 +45,7 @@ ThrowCompletionOr<NonnullGCPtr<Array>> Array::create(Realm& realm, u64 length, O
}
// 7.3.18 CreateArrayFromList ( elements ), https://tc39.es/ecma262/#sec-createarrayfromlist
NonnullGCPtr<Array> Array::create_from(Realm& realm, ReadonlySpan<Value> elements)
GC::Ref<Array> Array::create_from(Realm& realm, ReadonlySpan<Value> elements)
{
// 1. Let array be ! ArrayCreate(0).
auto array = MUST(Array::create(realm, 0));
@ -161,10 +161,10 @@ ThrowCompletionOr<bool> Array::set_length(PropertyDescriptor const& property_des
}
// 23.1.3.30.1 SortIndexedProperties ( obj, len, SortCompare, holes ), https://tc39.es/ecma262/#sec-sortindexedproperties
ThrowCompletionOr<MarkedVector<Value>> sort_indexed_properties(VM& vm, Object const& object, size_t length, Function<ThrowCompletionOr<double>(Value, Value)> const& sort_compare, Holes holes)
ThrowCompletionOr<GC::MarkedVector<Value>> sort_indexed_properties(VM& vm, Object const& object, size_t length, Function<ThrowCompletionOr<double>(Value, Value)> const& sort_compare, Holes holes)
{
// 1. Let items be a new empty List.
auto items = MarkedVector<Value> { vm.heap() };
auto items = GC::MarkedVector<Value> { vm.heap() };
// 2. Let k be 0.
// 3. Repeat, while k < len,
@ -330,7 +330,7 @@ ThrowCompletionOr<bool> Array::internal_delete(PropertyKey const& property_key)
}
// NON-STANDARD: Used to inject the ephemeral length property's key
ThrowCompletionOr<MarkedVector<Value>> Array::internal_own_property_keys() const
ThrowCompletionOr<GC::MarkedVector<Value>> Array::internal_own_property_keys() const
{
auto& vm = this->vm();
auto keys = TRY(Object::internal_own_property_keys());

View file

@ -21,23 +21,23 @@ namespace JS {
class Array : public Object {
JS_OBJECT(Array, Object);
JS_DECLARE_ALLOCATOR(Array);
GC_DECLARE_ALLOCATOR(Array);
public:
static ThrowCompletionOr<NonnullGCPtr<Array>> create(Realm&, u64 length, Object* prototype = nullptr);
static NonnullGCPtr<Array> create_from(Realm&, ReadonlySpan<Value>);
static ThrowCompletionOr<GC::Ref<Array>> create(Realm&, u64 length, Object* prototype = nullptr);
static GC::Ref<Array> create_from(Realm&, ReadonlySpan<Value>);
template<size_t N>
static NonnullGCPtr<Array> create_from(Realm& realm, Value const (&values)[N])
static GC::Ref<Array> create_from(Realm& realm, Value const (&values)[N])
{
return create_from(realm, ReadonlySpan<Value> { values, N });
}
// Non-standard but equivalent to CreateArrayFromList.
template<typename T>
static NonnullGCPtr<Array> create_from(Realm& realm, ReadonlySpan<T> elements, Function<Value(T const&)> map_fn)
static GC::Ref<Array> create_from(Realm& realm, ReadonlySpan<T> elements, Function<Value(T const&)> map_fn)
{
auto values = MarkedVector<Value> { realm.heap() };
auto values = GC::MarkedVector<Value> { realm.heap() };
values.ensure_capacity(elements.size());
for (auto const& element : elements)
values.append(map_fn(element));
@ -50,7 +50,7 @@ public:
virtual ThrowCompletionOr<Optional<PropertyDescriptor>> internal_get_own_property(PropertyKey const&) const override final;
virtual ThrowCompletionOr<bool> internal_define_own_property(PropertyKey const&, PropertyDescriptor const&, Optional<PropertyDescriptor>* precomputed_get_own_property = nullptr) override final;
virtual ThrowCompletionOr<bool> internal_delete(PropertyKey const&) override;
virtual ThrowCompletionOr<MarkedVector<Value>> internal_own_property_keys() const override final;
virtual ThrowCompletionOr<GC::MarkedVector<Value>> internal_own_property_keys() const override final;
[[nodiscard]] bool length_is_writable() const { return m_length_writable; }
@ -68,7 +68,7 @@ enum class Holes {
ReadThroughHoles,
};
ThrowCompletionOr<MarkedVector<Value>> sort_indexed_properties(VM&, Object const&, size_t length, Function<ThrowCompletionOr<double>(Value, Value)> const& sort_compare, Holes holes);
ThrowCompletionOr<GC::MarkedVector<Value>> sort_indexed_properties(VM&, Object const&, size_t length, Function<ThrowCompletionOr<double>(Value, Value)> const& sort_compare, Holes holes);
ThrowCompletionOr<double> compare_array_elements(VM&, Value x, Value y, FunctionObject* comparefn);
}

View file

@ -11,9 +11,9 @@
namespace JS {
JS_DEFINE_ALLOCATOR(ArrayBuffer);
GC_DEFINE_ALLOCATOR(ArrayBuffer);
ThrowCompletionOr<NonnullGCPtr<ArrayBuffer>> ArrayBuffer::create(Realm& realm, size_t byte_length)
ThrowCompletionOr<GC::Ref<ArrayBuffer>> ArrayBuffer::create(Realm& realm, size_t byte_length)
{
auto buffer = ByteBuffer::create_zeroed(byte_length);
if (buffer.is_error())
@ -22,12 +22,12 @@ ThrowCompletionOr<NonnullGCPtr<ArrayBuffer>> ArrayBuffer::create(Realm& realm, s
return realm.create<ArrayBuffer>(buffer.release_value(), realm.intrinsics().array_buffer_prototype());
}
NonnullGCPtr<ArrayBuffer> ArrayBuffer::create(Realm& realm, ByteBuffer buffer)
GC::Ref<ArrayBuffer> ArrayBuffer::create(Realm& realm, ByteBuffer buffer)
{
return realm.create<ArrayBuffer>(move(buffer), realm.intrinsics().array_buffer_prototype());
}
NonnullGCPtr<ArrayBuffer> ArrayBuffer::create(Realm& realm, ByteBuffer* buffer)
GC::Ref<ArrayBuffer> ArrayBuffer::create(Realm& realm, ByteBuffer* buffer)
{
return realm.create<ArrayBuffer>(buffer, realm.intrinsics().array_buffer_prototype());
}
@ -302,7 +302,7 @@ ThrowCompletionOr<Optional<size_t>> get_array_buffer_max_byte_length_option(VM&
}
// 25.2.2.1 AllocateSharedArrayBuffer ( constructor, byteLength [ , maxByteLength ] ), https://tc39.es/ecma262/#sec-allocatesharedarraybuffer
ThrowCompletionOr<NonnullGCPtr<ArrayBuffer>> allocate_shared_array_buffer(VM& vm, FunctionObject& constructor, size_t byte_length)
ThrowCompletionOr<GC::Ref<ArrayBuffer>> allocate_shared_array_buffer(VM& vm, FunctionObject& constructor, size_t byte_length)
{
// 1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%SharedArrayBuffer.prototype%", « [[ArrayBufferData]], [[ArrayBufferByteLength]] »).
auto obj = TRY(ordinary_create_from_constructor<ArrayBuffer>(vm, constructor, &Intrinsics::shared_array_buffer_prototype, nullptr));

View file

@ -56,12 +56,12 @@ struct DataBlock {
class ArrayBuffer : public Object {
JS_OBJECT(ArrayBuffer, Object);
JS_DECLARE_ALLOCATOR(ArrayBuffer);
GC_DECLARE_ALLOCATOR(ArrayBuffer);
public:
static ThrowCompletionOr<NonnullGCPtr<ArrayBuffer>> create(Realm&, size_t);
static NonnullGCPtr<ArrayBuffer> create(Realm&, ByteBuffer);
static NonnullGCPtr<ArrayBuffer> create(Realm&, ByteBuffer*);
static ThrowCompletionOr<GC::Ref<ArrayBuffer>> create(Realm&, size_t);
static GC::Ref<ArrayBuffer> create(Realm&, ByteBuffer);
static GC::Ref<ArrayBuffer> create(Realm&, ByteBuffer*);
virtual ~ArrayBuffer() override = default;
@ -152,7 +152,7 @@ ThrowCompletionOr<ArrayBuffer*> array_buffer_copy_and_detach(VM&, ArrayBuffer& a
ThrowCompletionOr<void> detach_array_buffer(VM&, ArrayBuffer& array_buffer, Optional<Value> key = {});
ThrowCompletionOr<Optional<size_t>> get_array_buffer_max_byte_length_option(VM&, Value options);
ThrowCompletionOr<ArrayBuffer*> clone_array_buffer(VM&, ArrayBuffer& source_buffer, size_t source_byte_offset, size_t source_length);
ThrowCompletionOr<NonnullGCPtr<ArrayBuffer>> allocate_shared_array_buffer(VM&, FunctionObject& constructor, size_t byte_length);
ThrowCompletionOr<GC::Ref<ArrayBuffer>> allocate_shared_array_buffer(VM&, FunctionObject& constructor, size_t byte_length);
// 25.1.3.2 ArrayBufferByteLength ( arrayBuffer, order ), https://tc39.es/ecma262/#sec-arraybufferbytelength
inline size_t array_buffer_byte_length(ArrayBuffer const& array_buffer, ArrayBuffer::Order)

View file

@ -14,7 +14,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(ArrayBufferConstructor);
GC_DEFINE_ALLOCATOR(ArrayBufferConstructor);
ArrayBufferConstructor::ArrayBufferConstructor(Realm& realm)
: NativeFunction(realm.vm().names.ArrayBuffer.as_string(), realm.intrinsics().function_prototype())
@ -48,7 +48,7 @@ ThrowCompletionOr<Value> ArrayBufferConstructor::call()
}
// 25.1.4.1 ArrayBuffer ( length [ , options ] ), https://tc39.es/ecma262/#sec-arraybuffer-length
ThrowCompletionOr<NonnullGCPtr<Object>> ArrayBufferConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> ArrayBufferConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();

View file

@ -12,14 +12,14 @@ namespace JS {
class ArrayBufferConstructor final : public NativeFunction {
JS_OBJECT(ArrayBufferConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(ArrayBufferConstructor);
GC_DECLARE_ALLOCATOR(ArrayBufferConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~ArrayBufferConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
private:
explicit ArrayBufferConstructor(Realm&);

View file

@ -14,7 +14,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(ArrayBufferPrototype);
GC_DEFINE_ALLOCATOR(ArrayBufferPrototype);
ArrayBufferPrototype::ArrayBufferPrototype(Realm& realm)
: PrototypeObject(realm.intrinsics().object_prototype())

View file

@ -13,7 +13,7 @@ namespace JS {
class ArrayBufferPrototype final : public PrototypeObject<ArrayBufferPrototype, ArrayBuffer> {
JS_PROTOTYPE_OBJECT(ArrayBufferPrototype, ArrayBuffer, ArrayBuffer);
JS_DECLARE_ALLOCATOR(ArrayBufferPrototype);
GC_DECLARE_ALLOCATOR(ArrayBufferPrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -22,7 +22,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(ArrayConstructor);
GC_DEFINE_ALLOCATOR(ArrayConstructor);
ArrayConstructor::ArrayConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Array.as_string(), realm.intrinsics().function_prototype())
@ -57,7 +57,7 @@ ThrowCompletionOr<Value> ArrayConstructor::call()
}
// 23.1.1.1 Array ( ...values ), https://tc39.es/ecma262/#sec-array
ThrowCompletionOr<NonnullGCPtr<Object>> ArrayConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> ArrayConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();
auto& realm = *vm.current_realm();
@ -149,7 +149,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
auto constructor = vm.this_value();
// 2. If mapfn is undefined, let mapping be false.
GCPtr<FunctionObject> mapfn;
GC::Ptr<FunctionObject> mapfn;
// 3. Else,
if (!mapfn_value.is_undefined()) {
@ -166,7 +166,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
// 5. If usingIterator is not undefined, then
if (using_iterator) {
GCPtr<Object> array;
GC::Ptr<Object> array;
// a. If IsConstructor(C) is true, then
if (constructor.is_constructor()) {
@ -245,7 +245,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
// 8. Let len be ? LengthOfArrayLike(arrayLike).
auto length = TRY(length_of_array_like(vm, array_like));
GCPtr<Object> array;
GC::Ptr<Object> array;
// 9. If IsConstructor(C) is true, then
if (constructor.is_constructor()) {
@ -306,7 +306,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from_async)
auto promise_capability = MUST(new_promise_capability(vm, realm.intrinsics().promise_constructor()));
// 3. Let fromAsyncClosure be a new Abstract Closure with no parameters that captures C, mapfn, and thisArg and performs the following steps when called:
auto from_async_closure = create_heap_function(realm.heap(), [constructor, mapfn, this_arg, &vm, &realm, async_items]() mutable -> Completion {
auto from_async_closure = GC::create_function(realm.heap(), [constructor, mapfn, this_arg, &vm, &realm, async_items]() mutable -> Completion {
bool mapping;
// a. If mapfn is undefined, let mapping be false.
@ -326,7 +326,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from_async)
// c. Let usingAsyncIterator be ? GetMethod(asyncItems, @@asyncIterator).
auto using_async_iterator = TRY(async_items.get_method(vm, vm.well_known_symbol_async_iterator()));
GCPtr<FunctionObject> using_sync_iterator;
GC::Ptr<FunctionObject> using_sync_iterator;
// d. If usingAsyncIterator is undefined, then
if (!using_async_iterator) {
@ -335,7 +335,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from_async)
}
// e. Let iteratorRecord be undefined.
GCPtr<IteratorRecord> iterator_record;
GC::Ptr<IteratorRecord> iterator_record;
// f. If usingAsyncIterator is not undefined, then
if (using_async_iterator) {
@ -352,7 +352,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from_async)
// h. If iteratorRecord is not undefined, then
if (iterator_record) {
GCPtr<Object> array;
GC::Ptr<Object> array;
// i. If IsConstructor(C) is true, then
if (constructor.is_constructor()) {
@ -458,7 +458,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from_async)
// iii. Let len be ? LengthOfArrayLike(arrayLike).
auto length = TRY(length_of_array_like(vm, array_like));
GCPtr<Object> array;
GC::Ptr<Object> array;
// iv. If IsConstructor(C) is true, then
if (constructor.is_constructor()) {
@ -542,7 +542,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::of)
// 3. Let C be the this value.
auto constructor = vm.this_value();
GCPtr<Object> array;
GC::Ptr<Object> array;
// 4. If IsConstructor(C) is true, then
if (constructor.is_constructor()) {

View file

@ -12,14 +12,14 @@ namespace JS {
class ArrayConstructor final : public NativeFunction {
JS_OBJECT(ArrayConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(ArrayConstructor);
GC_DECLARE_ALLOCATOR(ArrayConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~ArrayConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
private:
explicit ArrayConstructor(Realm&);

View file

@ -9,9 +9,9 @@
namespace JS {
JS_DEFINE_ALLOCATOR(ArrayIterator);
GC_DEFINE_ALLOCATOR(ArrayIterator);
NonnullGCPtr<ArrayIterator> ArrayIterator::create(Realm& realm, Value array, Object::PropertyKind iteration_kind)
GC::Ref<ArrayIterator> ArrayIterator::create(Realm& realm, Value array, Object::PropertyKind iteration_kind)
{
return realm.create<ArrayIterator>(array, iteration_kind, realm.intrinsics().array_iterator_prototype());
}

View file

@ -12,10 +12,10 @@ namespace JS {
class ArrayIterator final : public Object {
JS_OBJECT(ArrayIterator, Object);
JS_DECLARE_ALLOCATOR(ArrayIterator);
GC_DECLARE_ALLOCATOR(ArrayIterator);
public:
static NonnullGCPtr<ArrayIterator> create(Realm&, Value array, Object::PropertyKind iteration_kind);
static GC::Ref<ArrayIterator> create(Realm&, Value array, Object::PropertyKind iteration_kind);
virtual ~ArrayIterator() override = default;

View file

@ -14,7 +14,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(ArrayIteratorPrototype);
GC_DEFINE_ALLOCATOR(ArrayIteratorPrototype);
ArrayIteratorPrototype::ArrayIteratorPrototype(Realm& realm)
: PrototypeObject(realm.intrinsics().iterator_prototype())

View file

@ -13,7 +13,7 @@ namespace JS {
class ArrayIteratorPrototype final : public PrototypeObject<ArrayIteratorPrototype, ArrayIterator> {
JS_PROTOTYPE_OBJECT(ArrayIteratorPrototype, ArrayIterator, ArrayIterator);
JS_DECLARE_ALLOCATOR(ArrayIteratorPrototype);
GC_DECLARE_ALLOCATOR(ArrayIteratorPrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -27,9 +27,9 @@
namespace JS {
JS_DEFINE_ALLOCATOR(ArrayPrototype);
GC_DEFINE_ALLOCATOR(ArrayPrototype);
static HashTable<NonnullGCPtr<Object>> s_array_join_seen_objects;
static HashTable<GC::Ref<Object>> s_array_join_seen_objects;
ArrayPrototype::ArrayPrototype(Realm& realm)
: Array(realm.intrinsics().object_prototype())
@ -1339,15 +1339,15 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::some)
return Value(false);
}
ThrowCompletionOr<void> array_merge_sort(VM& vm, Function<ThrowCompletionOr<double>(Value, Value)> const& compare_func, MarkedVector<Value>& arr_to_sort)
ThrowCompletionOr<void> array_merge_sort(VM& vm, Function<ThrowCompletionOr<double>(Value, Value)> const& compare_func, GC::MarkedVector<Value>& arr_to_sort)
{
// FIXME: it would probably be better to switch to insertion sort for small arrays for
// better performance
if (arr_to_sort.size() <= 1)
return {};
MarkedVector<Value> left(vm.heap());
MarkedVector<Value> right(vm.heap());
GC::MarkedVector<Value> left(vm.heap());
GC::MarkedVector<Value> right(vm.heap());
left.ensure_capacity(arr_to_sort.size() / 2);
right.ensure_capacity(arr_to_sort.size() / 2 + (arr_to_sort.size() & 1));

View file

@ -13,7 +13,7 @@ namespace JS {
class ArrayPrototype final : public Array {
JS_OBJECT(ArrayPrototype, Array);
JS_DECLARE_ALLOCATOR(ArrayPrototype);
GC_DECLARE_ALLOCATOR(ArrayPrototype);
public:
virtual void initialize(Realm&) override;
@ -64,6 +64,6 @@ private:
JS_DECLARE_NATIVE_FUNCTION(with);
};
ThrowCompletionOr<void> array_merge_sort(VM&, Function<ThrowCompletionOr<double>(Value, Value)> const& compare_func, MarkedVector<Value>& arr_to_sort);
ThrowCompletionOr<void> array_merge_sort(VM&, Function<ThrowCompletionOr<double>(Value, Value)> const& compare_func, GC::MarkedVector<Value>& arr_to_sort);
}

View file

@ -11,14 +11,14 @@
namespace JS {
JS_DEFINE_ALLOCATOR(AsyncFromSyncIterator);
GC_DEFINE_ALLOCATOR(AsyncFromSyncIterator);
NonnullGCPtr<AsyncFromSyncIterator> AsyncFromSyncIterator::create(Realm& realm, NonnullGCPtr<IteratorRecord> sync_iterator_record)
GC::Ref<AsyncFromSyncIterator> AsyncFromSyncIterator::create(Realm& realm, GC::Ref<IteratorRecord> sync_iterator_record)
{
return realm.create<AsyncFromSyncIterator>(realm, sync_iterator_record);
}
AsyncFromSyncIterator::AsyncFromSyncIterator(Realm& realm, NonnullGCPtr<IteratorRecord> sync_iterator_record)
AsyncFromSyncIterator::AsyncFromSyncIterator(Realm& realm, GC::Ref<IteratorRecord> sync_iterator_record)
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().async_from_sync_iterator_prototype())
, m_sync_iterator_record(sync_iterator_record)
{

View file

@ -15,10 +15,10 @@ namespace JS {
// 27.1.4.3 Properties of Async-from-Sync Iterator Instances, https://tc39.es/ecma262/#sec-properties-of-async-from-sync-iterator-instances
class AsyncFromSyncIterator final : public Object {
JS_OBJECT(AsyncFromSyncIterator, Object);
JS_DECLARE_ALLOCATOR(AsyncFromSyncIterator);
GC_DECLARE_ALLOCATOR(AsyncFromSyncIterator);
public:
static NonnullGCPtr<AsyncFromSyncIterator> create(Realm&, NonnullGCPtr<IteratorRecord> sync_iterator_record);
static GC::Ref<AsyncFromSyncIterator> create(Realm&, GC::Ref<IteratorRecord> sync_iterator_record);
virtual ~AsyncFromSyncIterator() override = default;
@ -28,9 +28,9 @@ public:
IteratorRecord const& sync_iterator_record() const { return m_sync_iterator_record; }
private:
AsyncFromSyncIterator(Realm&, NonnullGCPtr<IteratorRecord> sync_iterator_record);
AsyncFromSyncIterator(Realm&, GC::Ref<IteratorRecord> sync_iterator_record);
NonnullGCPtr<IteratorRecord> m_sync_iterator_record; // [[SyncIteratorRecord]]
GC::Ref<IteratorRecord> m_sync_iterator_record; // [[SyncIteratorRecord]]
};
}

View file

@ -14,7 +14,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(AsyncFromSyncIteratorPrototype);
GC_DEFINE_ALLOCATOR(AsyncFromSyncIteratorPrototype);
AsyncFromSyncIteratorPrototype::AsyncFromSyncIteratorPrototype(Realm& realm)
: PrototypeObject(realm.intrinsics().async_iterator_prototype())
@ -199,7 +199,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::throw_)
}
// 27.1.4.1 CreateAsyncFromSyncIterator ( syncIteratorRecord ), https://tc39.es/ecma262/#sec-createasyncfromsynciterator
NonnullGCPtr<IteratorRecord> create_async_from_sync_iterator(VM& vm, NonnullGCPtr<IteratorRecord> sync_iterator_record)
GC::Ref<IteratorRecord> create_async_from_sync_iterator(VM& vm, GC::Ref<IteratorRecord> sync_iterator_record)
{
auto& realm = *vm.current_realm();

View file

@ -17,7 +17,7 @@ namespace JS {
// 27.1.4.2 The %AsyncFromSyncIteratorPrototype% Object, https://tc39.es/ecma262/#sec-%asyncfromsynciteratorprototype%-object
class AsyncFromSyncIteratorPrototype final : public PrototypeObject<AsyncFromSyncIteratorPrototype, AsyncFromSyncIterator> {
JS_PROTOTYPE_OBJECT(AsyncFromSyncIteratorPrototype, AsyncFromSyncIterator, AsyncFromSyncIterator);
JS_DECLARE_ALLOCATOR(AsyncFromSyncIteratorPrototype);
GC_DECLARE_ALLOCATOR(AsyncFromSyncIteratorPrototype);
public:
virtual void initialize(Realm&) override;
@ -31,6 +31,6 @@ private:
JS_DECLARE_NATIVE_FUNCTION(throw_);
};
NonnullGCPtr<IteratorRecord> create_async_from_sync_iterator(VM&, NonnullGCPtr<IteratorRecord> sync_iterator);
GC::Ref<IteratorRecord> create_async_from_sync_iterator(VM&, GC::Ref<IteratorRecord> sync_iterator);
}

View file

@ -12,7 +12,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(AsyncFunctionConstructor);
GC_DEFINE_ALLOCATOR(AsyncFunctionConstructor);
AsyncFunctionConstructor::AsyncFunctionConstructor(Realm& realm)
: NativeFunction(realm.vm().names.AsyncFunction.as_string(), realm.intrinsics().function_constructor())
@ -37,7 +37,7 @@ ThrowCompletionOr<Value> AsyncFunctionConstructor::call()
}
// 27.7.1.1 AsyncFunction ( ...parameterArgs, bodyArg ), https://tc39.es/ecma262/#sec-async-function-constructor-arguments
ThrowCompletionOr<NonnullGCPtr<Object>> AsyncFunctionConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> AsyncFunctionConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();

View file

@ -12,14 +12,14 @@ namespace JS {
class AsyncFunctionConstructor final : public NativeFunction {
JS_OBJECT(AsyncFunctionConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(AsyncFunctionConstructor);
GC_DECLARE_ALLOCATOR(AsyncFunctionConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~AsyncFunctionConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
private:
explicit AsyncFunctionConstructor(Realm&);

View file

@ -15,9 +15,9 @@
namespace JS {
JS_DEFINE_ALLOCATOR(AsyncFunctionDriverWrapper);
GC_DEFINE_ALLOCATOR(AsyncFunctionDriverWrapper);
NonnullGCPtr<Promise> AsyncFunctionDriverWrapper::create(Realm& realm, GeneratorObject* generator_object)
GC::Ref<Promise> AsyncFunctionDriverWrapper::create(Realm& realm, GeneratorObject* generator_object)
{
auto top_level_promise = Promise::create(realm);
// Note: The top_level_promise is also kept alive by this Wrapper
@ -29,7 +29,7 @@ NonnullGCPtr<Promise> AsyncFunctionDriverWrapper::create(Realm& realm, Generator
return top_level_promise;
}
AsyncFunctionDriverWrapper::AsyncFunctionDriverWrapper(Realm& realm, NonnullGCPtr<GeneratorObject> generator_object, NonnullGCPtr<Promise> top_level_promise)
AsyncFunctionDriverWrapper::AsyncFunctionDriverWrapper(Realm& realm, GC::Ref<GeneratorObject> generator_object, GC::Ref<Promise> top_level_promise)
: Promise(realm.intrinsics().promise_prototype())
, m_generator_object(generator_object)
, m_top_level_promise(top_level_promise)

View file

@ -16,7 +16,7 @@ namespace JS {
class AsyncFunctionDriverWrapper final : public Promise {
JS_OBJECT(AsyncFunctionDriverWrapper, Promise);
JS_DECLARE_ALLOCATOR(AsyncFunctionDriverWrapper);
GC_DECLARE_ALLOCATOR(AsyncFunctionDriverWrapper);
public:
enum class IsInitialExecution {
@ -24,7 +24,7 @@ public:
Yes,
};
[[nodiscard]] static NonnullGCPtr<Promise> create(Realm&, GeneratorObject*);
[[nodiscard]] static GC::Ref<Promise> create(Realm&, GeneratorObject*);
virtual ~AsyncFunctionDriverWrapper() override = default;
void visit_edges(Cell::Visitor&) override;
@ -32,12 +32,12 @@ public:
void continue_async_execution(VM&, Value, bool is_successful, IsInitialExecution is_initial_execution = IsInitialExecution::No);
private:
AsyncFunctionDriverWrapper(Realm&, NonnullGCPtr<GeneratorObject>, NonnullGCPtr<Promise> top_level_promise);
AsyncFunctionDriverWrapper(Realm&, GC::Ref<GeneratorObject>, GC::Ref<Promise> top_level_promise);
ThrowCompletionOr<void> await(Value);
NonnullGCPtr<GeneratorObject> m_generator_object;
NonnullGCPtr<Promise> m_top_level_promise;
GCPtr<Promise> m_current_promise { nullptr };
GC::Ref<GeneratorObject> m_generator_object;
GC::Ref<Promise> m_top_level_promise;
GC::Ptr<Promise> m_current_promise { nullptr };
OwnPtr<ExecutionContext> m_suspended_execution_context;
};

View file

@ -9,7 +9,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(AsyncFunctionPrototype);
GC_DEFINE_ALLOCATOR(AsyncFunctionPrototype);
AsyncFunctionPrototype::AsyncFunctionPrototype(Realm& realm)
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().function_prototype())

View file

@ -12,7 +12,7 @@ namespace JS {
class AsyncFunctionPrototype final : public Object {
JS_OBJECT(AsyncFunctionPrototype, Object);
JS_DECLARE_ALLOCATOR(AsyncFunctionPrototype);
GC_DECLARE_ALLOCATOR(AsyncFunctionPrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -14,9 +14,9 @@
namespace JS {
JS_DEFINE_ALLOCATOR(AsyncGenerator);
GC_DEFINE_ALLOCATOR(AsyncGenerator);
ThrowCompletionOr<NonnullGCPtr<AsyncGenerator>> AsyncGenerator::create(Realm& realm, Value initial_value, ECMAScriptFunctionObject* generating_function, NonnullOwnPtr<ExecutionContext> execution_context)
ThrowCompletionOr<GC::Ref<AsyncGenerator>> AsyncGenerator::create(Realm& realm, Value initial_value, ECMAScriptFunctionObject* generating_function, NonnullOwnPtr<ExecutionContext> execution_context)
{
auto& vm = realm.vm();
// This is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png)
@ -51,7 +51,7 @@ void AsyncGenerator::visit_edges(Cell::Visitor& visitor)
}
// 27.6.3.4 AsyncGeneratorEnqueue ( generator, completion, promiseCapability ), https://tc39.es/ecma262/#sec-asyncgeneratorenqueue
void AsyncGenerator::async_generator_enqueue(Completion completion, NonnullGCPtr<PromiseCapability> promise_capability)
void AsyncGenerator::async_generator_enqueue(Completion completion, GC::Ref<PromiseCapability> promise_capability)
{
// 1. Let request be AsyncGeneratorRequest { [[Completion]]: completion, [[Capability]]: promiseCapability }.
auto request = AsyncGeneratorRequest { .completion = move(completion), .capability = promise_capability };
@ -458,7 +458,7 @@ void AsyncGenerator::complete_step(Completion completion, bool done, Realm* real
// a. Assert: completion.[[Type]] is normal.
VERIFY(completion.type() == Completion::Type::Normal);
GCPtr<Object> iterator_result;
GC::Ptr<Object> iterator_result;
// b. If realm is present, then
if (realm) {

View file

@ -17,7 +17,7 @@ namespace JS {
// 27.6.2 Properties of AsyncGenerator Instances, https://tc39.es/ecma262/#sec-properties-of-asyncgenerator-intances
class AsyncGenerator final : public Object {
JS_OBJECT(AsyncGenerator, Object);
JS_DECLARE_ALLOCATOR(AsyncGenerator);
GC_DECLARE_ALLOCATOR(AsyncGenerator);
public:
enum class State {
@ -28,11 +28,11 @@ public:
Completed,
};
static ThrowCompletionOr<NonnullGCPtr<AsyncGenerator>> create(Realm&, Value, ECMAScriptFunctionObject*, NonnullOwnPtr<ExecutionContext>);
static ThrowCompletionOr<GC::Ref<AsyncGenerator>> create(Realm&, Value, ECMAScriptFunctionObject*, NonnullOwnPtr<ExecutionContext>);
virtual ~AsyncGenerator() override;
void async_generator_enqueue(Completion, NonnullGCPtr<PromiseCapability>);
void async_generator_enqueue(Completion, GC::Ref<PromiseCapability>);
ThrowCompletionOr<void> resume(VM&, Completion completion);
void await_return();
void complete_step(Completion, bool done, Realm* realm = nullptr);
@ -58,9 +58,9 @@ private:
Vector<AsyncGeneratorRequest> m_async_generator_queue; // [[AsyncGeneratorQueue]]
Optional<String> m_generator_brand; // [[GeneratorBrand]]
GCPtr<ECMAScriptFunctionObject> m_generating_function;
GC::Ptr<ECMAScriptFunctionObject> m_generating_function;
Value m_previous_value;
GCPtr<Promise> m_current_promise;
GC::Ptr<Promise> m_current_promise;
};
}

View file

@ -12,7 +12,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(AsyncGeneratorFunctionConstructor);
GC_DEFINE_ALLOCATOR(AsyncGeneratorFunctionConstructor);
AsyncGeneratorFunctionConstructor::AsyncGeneratorFunctionConstructor(Realm& realm)
: NativeFunction(realm.vm().names.AsyncGeneratorFunction.as_string(), realm.intrinsics().function_prototype())
@ -38,7 +38,7 @@ ThrowCompletionOr<Value> AsyncGeneratorFunctionConstructor::call()
}
// 27.4.1.1 AsyncGeneratorFunction ( ...parameterArgs, bodyArg ), https://tc39.es/ecma262/#sec-asyncgeneratorfunction
ThrowCompletionOr<NonnullGCPtr<Object>> AsyncGeneratorFunctionConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> AsyncGeneratorFunctionConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();

View file

@ -12,14 +12,14 @@ namespace JS {
class AsyncGeneratorFunctionConstructor final : public NativeFunction {
JS_OBJECT(AsyncGeneratorFunctionConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(AsyncGeneratorFunctionConstructor);
GC_DECLARE_ALLOCATOR(AsyncGeneratorFunctionConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~AsyncGeneratorFunctionConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
private:
explicit AsyncGeneratorFunctionConstructor(Realm&);

View file

@ -11,7 +11,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(AsyncGeneratorFunctionPrototype);
GC_DEFINE_ALLOCATOR(AsyncGeneratorFunctionPrototype);
AsyncGeneratorFunctionPrototype::AsyncGeneratorFunctionPrototype(Realm& realm)
: PrototypeObject(realm.intrinsics().function_prototype())

View file

@ -12,7 +12,7 @@ namespace JS {
class AsyncGeneratorFunctionPrototype final : public PrototypeObject<AsyncGeneratorFunctionPrototype, AsyncGeneratorFunction> {
JS_PROTOTYPE_OBJECT(AsyncGeneratorFunctionPrototype, AsyncGeneratorFunction, AsyncGeneratorFunction);
JS_DECLARE_ALLOCATOR(AsyncGeneratorFunctionPrototype);
GC_DECLARE_ALLOCATOR(AsyncGeneratorFunctionPrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -12,7 +12,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(AsyncGeneratorPrototype);
GC_DEFINE_ALLOCATOR(AsyncGeneratorPrototype);
// 27.6.1 Properties of the AsyncGenerator Prototype Object, https://tc39.es/ecma262/#sec-properties-of-asyncgenerator-prototype
AsyncGeneratorPrototype::AsyncGeneratorPrototype(Realm& realm)
@ -34,7 +34,7 @@ void AsyncGeneratorPrototype::initialize(Realm& realm)
}
// 27.6.3.3 AsyncGeneratorValidate ( generator, generatorBrand ), https://tc39.es/ecma262/#sec-asyncgeneratorvalidate
static ThrowCompletionOr<NonnullGCPtr<AsyncGenerator>> async_generator_validate(VM& vm, Value generator, Optional<String> generator_brand)
static ThrowCompletionOr<GC::Ref<AsyncGenerator>> async_generator_validate(VM& vm, Value generator, Optional<String> generator_brand)
{
// 1. Perform ? RequireInternalSlot(generator, [[AsyncGeneratorContext]]).
// 2. Perform ? RequireInternalSlot(generator, [[AsyncGeneratorState]]).

View file

@ -14,7 +14,7 @@ namespace JS {
class AsyncGeneratorPrototype final : public PrototypeObject<AsyncGeneratorPrototype, AsyncGenerator> {
JS_PROTOTYPE_OBJECT(AsyncGeneratorPrototype, AsyncGenerator, AsyncGenerator)
JS_DECLARE_ALLOCATOR(AsyncGeneratorPrototype);
GC_DECLARE_ALLOCATOR(AsyncGeneratorPrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -13,8 +13,8 @@ namespace JS {
// 27.6.3.1 AsyncGeneratorRequest Records, https://tc39.es/ecma262/#sec-asyncgeneratorrequest-records
struct AsyncGeneratorRequest {
Completion completion; // [[Completion]]
NonnullGCPtr<PromiseCapability> capability; // [[Capability]]
Completion completion; // [[Completion]]
GC::Ref<PromiseCapability> capability; // [[Capability]]
};
}

View file

@ -8,7 +8,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(AsyncIteratorPrototype);
GC_DEFINE_ALLOCATOR(AsyncIteratorPrototype);
AsyncIteratorPrototype::AsyncIteratorPrototype(Realm& realm)
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())

View file

@ -12,7 +12,7 @@ namespace JS {
class AsyncIteratorPrototype final : public Object {
JS_OBJECT(AsyncIteratorPrototype, Object)
JS_DECLARE_ALLOCATOR(AsyncIteratorPrototype);
GC_DECLARE_ALLOCATOR(AsyncIteratorPrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -25,7 +25,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(AtomicsObject);
GC_DEFINE_ALLOCATOR(AtomicsObject);
// 25.4.2.1 ValidateIntegerTypedArray ( typedArray, waitable ), https://tc39.es/ecma262/#sec-validateintegertypedarray
static ThrowCompletionOr<TypedArrayWithBufferWitness> validate_integer_typed_array(VM& vm, TypedArrayBase const& typed_array, bool waitable)

View file

@ -12,7 +12,7 @@ namespace JS {
class AtomicsObject : public Object {
JS_OBJECT(AtomicsObject, Object);
JS_DECLARE_ALLOCATOR(AtomicsObject);
GC_DECLARE_ALLOCATOR(AtomicsObject);
public:
virtual void initialize(Realm&) override;

View file

@ -5,15 +5,15 @@
*/
#include <LibCrypto/BigInt/SignedBigInteger.h>
#include <LibJS/Heap/Heap.h>
#include <LibGC/Heap.h>
#include <LibJS/Runtime/BigInt.h>
#include <LibJS/Runtime/GlobalObject.h>
namespace JS {
JS_DEFINE_ALLOCATOR(BigInt);
GC_DEFINE_ALLOCATOR(BigInt);
NonnullGCPtr<BigInt> BigInt::create(VM& vm, Crypto::SignedBigInteger big_integer)
GC::Ref<BigInt> BigInt::create(VM& vm, Crypto::SignedBigInteger big_integer)
{
return vm.heap().allocate<BigInt>(move(big_integer));
}

View file

@ -10,17 +10,17 @@
#include <AK/String.h>
#include <AK/StringView.h>
#include <LibCrypto/BigInt/SignedBigInteger.h>
#include <LibGC/CellAllocator.h>
#include <LibJS/Heap/Cell.h>
#include <LibJS/Heap/CellAllocator.h>
namespace JS {
class BigInt final : public Cell {
JS_CELL(BigInt, Cell);
JS_DECLARE_ALLOCATOR(BigInt);
GC_CELL(BigInt, Cell);
GC_DECLARE_ALLOCATOR(BigInt);
public:
[[nodiscard]] static NonnullGCPtr<BigInt> create(VM&, Crypto::SignedBigInteger);
[[nodiscard]] static GC::Ref<BigInt> create(VM&, Crypto::SignedBigInteger);
virtual ~BigInt() override = default;

View file

@ -15,7 +15,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(BigIntConstructor);
GC_DEFINE_ALLOCATOR(BigIntConstructor);
static Crypto::SignedBigInteger const BIGINT_ONE { 1 };
@ -58,7 +58,7 @@ ThrowCompletionOr<Value> BigIntConstructor::call()
}
// 21.2.1.1 BigInt ( value ), https://tc39.es/ecma262/#sec-bigint-constructor-number-value
ThrowCompletionOr<NonnullGCPtr<Object>> BigIntConstructor::construct(FunctionObject&)
ThrowCompletionOr<GC::Ref<Object>> BigIntConstructor::construct(FunctionObject&)
{
return vm().throw_completion<TypeError>(ErrorType::NotAConstructor, "BigInt");
}

View file

@ -12,14 +12,14 @@ namespace JS {
class BigIntConstructor final : public NativeFunction {
JS_OBJECT(BigIntConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(BigIntConstructor);
GC_DECLARE_ALLOCATOR(BigIntConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~BigIntConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
private:
explicit BigIntConstructor(Realm&);

View file

@ -9,9 +9,9 @@
namespace JS {
JS_DEFINE_ALLOCATOR(BigIntObject);
GC_DEFINE_ALLOCATOR(BigIntObject);
NonnullGCPtr<BigIntObject> BigIntObject::create(Realm& realm, BigInt& bigint)
GC::Ref<BigIntObject> BigIntObject::create(Realm& realm, BigInt& bigint)
{
return realm.create<BigIntObject>(bigint, realm.intrinsics().bigint_prototype());
}

View file

@ -13,10 +13,10 @@ namespace JS {
class BigIntObject final : public Object {
JS_OBJECT(BigIntObject, Object);
JS_DECLARE_ALLOCATOR(BigIntObject);
GC_DECLARE_ALLOCATOR(BigIntObject);
public:
static NonnullGCPtr<BigIntObject> create(Realm&, BigInt&);
static GC::Ref<BigIntObject> create(Realm&, BigInt&);
virtual ~BigIntObject() override = default;
@ -28,7 +28,7 @@ private:
virtual void visit_edges(Visitor&) override;
NonnullGCPtr<BigInt> m_bigint;
GC::Ref<BigInt> m_bigint;
};
}

View file

@ -17,7 +17,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(BigIntPrototype);
GC_DEFINE_ALLOCATOR(BigIntPrototype);
BigIntPrototype::BigIntPrototype(Realm& realm)
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
@ -38,7 +38,7 @@ void BigIntPrototype::initialize(Realm& realm)
}
// thisBigIntValue ( value ), https://tc39.es/ecma262/#thisbigintvalue
static ThrowCompletionOr<NonnullGCPtr<BigInt>> this_bigint_value(VM& vm, Value value)
static ThrowCompletionOr<GC::Ref<BigInt>> this_bigint_value(VM& vm, Value value)
{
// 1. If value is a BigInt, return value.
if (value.is_bigint())

View file

@ -12,7 +12,7 @@ namespace JS {
class BigIntPrototype final : public Object {
JS_OBJECT(BigIntPrototype, Object);
JS_DECLARE_ALLOCATOR(BigIntPrototype);
GC_DECLARE_ALLOCATOR(BigIntPrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -13,7 +13,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(BooleanConstructor);
GC_DEFINE_ALLOCATOR(BooleanConstructor);
BooleanConstructor::BooleanConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Boolean.as_string(), realm.intrinsics().function_prototype())
@ -45,7 +45,7 @@ ThrowCompletionOr<Value> BooleanConstructor::call()
}
// 20.3.1.1 Boolean ( value ), https://tc39.es/ecma262/#sec-boolean-constructor-boolean-value
ThrowCompletionOr<NonnullGCPtr<Object>> BooleanConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> BooleanConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();
auto value = vm.argument(0);

View file

@ -12,14 +12,14 @@ namespace JS {
class BooleanConstructor final : public NativeFunction {
JS_OBJECT(BooleanConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(BooleanConstructor);
GC_DECLARE_ALLOCATOR(BooleanConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~BooleanConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
private:
explicit BooleanConstructor(Realm&);

View file

@ -9,9 +9,9 @@
namespace JS {
JS_DEFINE_ALLOCATOR(BooleanObject);
GC_DEFINE_ALLOCATOR(BooleanObject);
NonnullGCPtr<BooleanObject> BooleanObject::create(Realm& realm, bool value)
GC::Ref<BooleanObject> BooleanObject::create(Realm& realm, bool value)
{
return realm.create<BooleanObject>(value, realm.intrinsics().boolean_prototype());
}

View file

@ -12,10 +12,10 @@ namespace JS {
class BooleanObject : public Object {
JS_OBJECT(BooleanObject, Object);
JS_DECLARE_ALLOCATOR(BooleanObject);
GC_DECLARE_ALLOCATOR(BooleanObject);
public:
static NonnullGCPtr<BooleanObject> create(Realm&, bool);
static GC::Ref<BooleanObject> create(Realm&, bool);
virtual ~BooleanObject() override = default;

View file

@ -13,7 +13,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(BooleanPrototype);
GC_DEFINE_ALLOCATOR(BooleanPrototype);
BooleanPrototype::BooleanPrototype(Realm& realm)
: BooleanObject(false, realm.intrinsics().object_prototype())

View file

@ -12,7 +12,7 @@ namespace JS {
class BooleanPrototype final : public BooleanObject {
JS_OBJECT(BooleanPrototype, BooleanObject);
JS_DECLARE_ALLOCATOR(BooleanPrototype);
GC_DECLARE_ALLOCATOR(BooleanPrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -11,10 +11,10 @@
namespace JS {
JS_DEFINE_ALLOCATOR(BoundFunction);
GC_DEFINE_ALLOCATOR(BoundFunction);
// 10.4.1.3 BoundFunctionCreate ( targetFunction, boundThis, boundArgs ), https://tc39.es/ecma262/#sec-boundfunctioncreate
ThrowCompletionOr<NonnullGCPtr<BoundFunction>> BoundFunction::create(Realm& realm, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments)
ThrowCompletionOr<GC::Ref<BoundFunction>> BoundFunction::create(Realm& realm, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments)
{
// 1. Let proto be ? targetFunction.[[GetPrototypeOf]]().
auto* prototype = TRY(target_function.internal_get_prototype_of());
@ -69,7 +69,7 @@ ThrowCompletionOr<Value> BoundFunction::internal_call([[maybe_unused]] Value thi
}
// 10.4.1.2 [[Construct]] ( argumentsList, newTarget ), https://tc39.es/ecma262/#sec-bound-function-exotic-objects-construct-argumentslist-newtarget
ThrowCompletionOr<NonnullGCPtr<Object>> BoundFunction::internal_construct(ReadonlySpan<Value> arguments_list, FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> BoundFunction::internal_construct(ReadonlySpan<Value> arguments_list, FunctionObject& new_target)
{
auto& vm = this->vm();
@ -83,7 +83,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> BoundFunction::internal_construct(Readon
auto& bound_args = m_bound_arguments;
// 4. Let args be the list-concatenation of boundArgs and argumentsList.
auto args = MarkedVector<Value> { heap() };
auto args = GC::MarkedVector<Value> { heap() };
args.extend(bound_args);
args.append(arguments_list.data(), arguments_list.size());

View file

@ -13,15 +13,15 @@ namespace JS {
class BoundFunction final : public FunctionObject {
JS_OBJECT(BoundFunction, FunctionObject);
JS_DECLARE_ALLOCATOR(BoundFunction);
GC_DECLARE_ALLOCATOR(BoundFunction);
public:
static ThrowCompletionOr<NonnullGCPtr<BoundFunction>> create(Realm&, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments);
static ThrowCompletionOr<GC::Ref<BoundFunction>> create(Realm&, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments);
virtual ~BoundFunction() override = default;
virtual ThrowCompletionOr<Value> internal_call(Value this_argument, ReadonlySpan<Value> arguments_list) override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> internal_construct(ReadonlySpan<Value> arguments_list, FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> internal_construct(ReadonlySpan<Value> arguments_list, FunctionObject& new_target) override;
virtual DeprecatedFlyString const& name() const override { return m_name; }
virtual bool is_strict_mode() const override { return m_bound_target_function->is_strict_mode(); }
@ -36,9 +36,9 @@ private:
virtual void visit_edges(Visitor&) override;
GCPtr<FunctionObject> m_bound_target_function; // [[BoundTargetFunction]]
Value m_bound_this; // [[BoundThis]]
Vector<Value> m_bound_arguments; // [[BoundArguments]]
GC::Ptr<FunctionObject> m_bound_target_function; // [[BoundTargetFunction]]
Value m_bound_this; // [[BoundThis]]
Vector<Value> m_bound_arguments; // [[BoundArguments]]
DeprecatedFlyString m_name;
};

View file

@ -7,8 +7,8 @@
#pragma once
#include <AK/Forward.h>
#include <LibGC/Root.h>
#include <LibJS/Forward.h>
#include <LibJS/Heap/Handle.h>
#include <LibJS/Runtime/Environment.h>
namespace JS {
@ -17,8 +17,8 @@ using ClassElementName = Variant<PropertyKey, PrivateName>;
// 6.2.10 The ClassFieldDefinition Record Specification Type, https://tc39.es/ecma262/#sec-classfielddefinition-record-specification-type
struct ClassFieldDefinition {
ClassElementName name; // [[Name]]
GCPtr<ECMAScriptFunctionObject> initializer; // [[Initializer]]
ClassElementName name; // [[Name]]
GC::Ptr<ECMAScriptFunctionObject> initializer; // [[Initializer]]
};
}

View file

@ -101,7 +101,7 @@ ThrowCompletionOr<Value> await(VM& vm, Value value)
// running all queued promise jobs.
// Note: This is not used by LibJS itself, and is performed for the embedder (i.e. LibWeb).
if (auto* custom_data = vm.custom_data()) {
custom_data->spin_event_loop_until(create_heap_function(vm.heap(), [success] {
custom_data->spin_event_loop_until(GC::create_function(vm.heap(), [success] {
return success.has_value();
}));
}

View file

@ -13,9 +13,9 @@
namespace JS {
JS_DEFINE_ALLOCATOR(ConsoleObject);
GC_DEFINE_ALLOCATOR(ConsoleObject);
static NonnullGCPtr<ConsoleObjectPrototype> create_console_prototype(Realm& realm)
static GC::Ref<ConsoleObjectPrototype> create_console_prototype(Realm& realm)
{
return realm.create<ConsoleObjectPrototype>(realm);
}

View file

@ -12,7 +12,7 @@ namespace JS {
class ConsoleObject final : public Object {
JS_OBJECT(ConsoleObject, Object);
JS_DECLARE_ALLOCATOR(ConsoleObject);
GC_DECLARE_ALLOCATOR(ConsoleObject);
public:
virtual void initialize(Realm&) override;
@ -43,7 +43,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(time_log);
JS_DECLARE_NATIVE_FUNCTION(time_end);
GCPtr<Console> m_console;
GC::Ptr<Console> m_console;
};
}

View file

@ -22,7 +22,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(ConsoleObjectPrototype);
GC_DEFINE_ALLOCATOR(ConsoleObjectPrototype);
ConsoleObjectPrototype::ConsoleObjectPrototype(JS::Realm& realm)
: Object(JS::Object::ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())

View file

@ -12,7 +12,7 @@ namespace JS {
class ConsoleObjectPrototype final : public Object {
JS_OBJECT(ConsoleObjectPrototype, Object);
JS_DECLARE_ALLOCATOR(ConsoleObjectPrototype);
GC_DECLARE_ALLOCATOR(ConsoleObjectPrototype);
public:
virtual void initialize(JS::Realm&) override;

View file

@ -8,9 +8,9 @@
namespace JS {
JS_DEFINE_ALLOCATOR(DataView);
GC_DEFINE_ALLOCATOR(DataView);
NonnullGCPtr<DataView> DataView::create(Realm& realm, ArrayBuffer* viewed_buffer, ByteLength byte_length, size_t byte_offset)
GC::Ref<DataView> DataView::create(Realm& realm, ArrayBuffer* viewed_buffer, ByteLength byte_length, size_t byte_offset)
{
return realm.create<DataView>(viewed_buffer, move(byte_length), byte_offset, realm.intrinsics().data_view_prototype());
}

View file

@ -15,10 +15,10 @@ namespace JS {
class DataView : public Object {
JS_OBJECT(DataView, Object);
JS_DECLARE_ALLOCATOR(DataView);
GC_DECLARE_ALLOCATOR(DataView);
public:
static NonnullGCPtr<DataView> create(Realm&, ArrayBuffer*, ByteLength byte_length, size_t byte_offset);
static GC::Ref<DataView> create(Realm&, ArrayBuffer*, ByteLength byte_length, size_t byte_offset);
virtual ~DataView() override = default;
@ -31,14 +31,14 @@ private:
virtual void visit_edges(Visitor& visitor) override;
GCPtr<ArrayBuffer> m_viewed_array_buffer;
GC::Ptr<ArrayBuffer> m_viewed_array_buffer;
ByteLength m_byte_length { 0 };
size_t m_byte_offset { 0 };
};
// 25.3.1.1 DataView With Buffer Witness Records, https://tc39.es/ecma262/#sec-dataview-with-buffer-witness-records
struct DataViewWithBufferWitness {
NonnullGCPtr<DataView const> object; // [[Object]]
GC::Ref<DataView const> object; // [[Object]]
ByteLength cached_buffer_byte_length; // [[CachedBufferByteLength]]
};

View file

@ -14,7 +14,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(DataViewConstructor);
GC_DEFINE_ALLOCATOR(DataViewConstructor);
DataViewConstructor::DataViewConstructor(Realm& realm)
: NativeFunction(realm.vm().names.DataView.as_string(), realm.intrinsics().function_prototype())
@ -42,7 +42,7 @@ ThrowCompletionOr<Value> DataViewConstructor::call()
}
// 25.3.2.1 DataView ( buffer [ , byteOffset [ , byteLength ] ] ), https://tc39.es/ecma262/#sec-dataview-buffer-byteoffset-bytelength
ThrowCompletionOr<NonnullGCPtr<Object>> DataViewConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> DataViewConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();

View file

@ -12,14 +12,14 @@ namespace JS {
class DataViewConstructor final : public NativeFunction {
JS_OBJECT(DataViewConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(DataViewConstructor);
GC_DECLARE_ALLOCATOR(DataViewConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~DataViewConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject&) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject&) override;
private:
explicit DataViewConstructor(Realm&);

View file

@ -11,7 +11,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(DataViewPrototype);
GC_DEFINE_ALLOCATOR(DataViewPrototype);
DataViewPrototype::DataViewPrototype(Realm& realm)
: PrototypeObject(realm.intrinsics().object_prototype())

View file

@ -13,7 +13,7 @@ namespace JS {
class DataViewPrototype final : public PrototypeObject<DataViewPrototype, DataView> {
JS_PROTOTYPE_OBJECT(DataViewPrototype, DataView, DataView);
JS_DECLARE_ALLOCATOR(DataViewPrototype);
GC_DECLARE_ALLOCATOR(DataViewPrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -17,7 +17,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(Date);
GC_DEFINE_ALLOCATOR(Date);
static Crypto::SignedBigInteger const s_one_billion_bigint { 1'000'000'000 };
static Crypto::SignedBigInteger const s_one_million_bigint { 1'000'000 };
@ -25,7 +25,7 @@ static Crypto::SignedBigInteger const s_one_thousand_bigint { 1'000 };
Crypto::SignedBigInteger const ns_per_day_bigint { static_cast<i64>(ns_per_day) };
NonnullGCPtr<Date> Date::create(Realm& realm, double date_value)
GC::Ref<Date> Date::create(Realm& realm, double date_value)
{
return realm.create<Date>(date_value, realm.intrinsics().date_prototype());
}

View file

@ -15,10 +15,10 @@ namespace JS {
class Date final : public Object {
JS_OBJECT(Date, Object);
JS_DECLARE_ALLOCATOR(Date);
GC_DECLARE_ALLOCATOR(Date);
public:
static NonnullGCPtr<Date> create(Realm&, double date_value);
static GC::Ref<Date> create(Realm&, double date_value);
// Out of line to ensure we have a key function
virtual ~Date() override;

View file

@ -23,7 +23,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(DateConstructor);
GC_DEFINE_ALLOCATOR(DateConstructor);
// 21.4.3.2 Date.parse ( string ), https://tc39.es/ecma262/#sec-date.parse
static double parse_simplified_iso8601(ByteString const& iso_8601)
@ -237,7 +237,7 @@ ThrowCompletionOr<Value> DateConstructor::call()
}
// 21.4.2.1 Date ( ...values ), https://tc39.es/ecma262/#sec-date
ThrowCompletionOr<NonnullGCPtr<Object>> DateConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> DateConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();

View file

@ -12,14 +12,14 @@ namespace JS {
class DateConstructor final : public NativeFunction {
JS_OBJECT(DateConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(DateConstructor);
GC_DECLARE_ALLOCATOR(DateConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~DateConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
private:
explicit DateConstructor(Realm&);

View file

@ -30,7 +30,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(DatePrototype);
GC_DEFINE_ALLOCATOR(DatePrototype);
DatePrototype::DatePrototype(Realm& realm)
: PrototypeObject(realm.intrinsics().object_prototype())

View file

@ -13,7 +13,7 @@ namespace JS {
class DatePrototype final : public PrototypeObject<DatePrototype, Date> {
JS_PROTOTYPE_OBJECT(DatePrototype, Date, Date);
JS_DECLARE_ALLOCATOR(DatePrototype);
GC_DECLARE_ALLOCATOR(DatePrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -13,7 +13,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(DeclarativeEnvironment);
GC_DEFINE_ALLOCATOR(DeclarativeEnvironment);
DeclarativeEnvironment* DeclarativeEnvironment::create_for_per_iteration_bindings(Badge<ForStatement>, DeclarativeEnvironment& other, size_t bindings_size)
{

View file

@ -17,7 +17,7 @@ namespace JS {
class DeclarativeEnvironment : public Environment {
JS_ENVIRONMENT(DeclarativeEnvironment, Environment);
JS_DECLARE_ALLOCATOR(DeclarativeEnvironment);
GC_DECLARE_ALLOCATOR(DeclarativeEnvironment);
struct Binding {
DeprecatedFlyString name;
@ -73,7 +73,7 @@ private:
ThrowCompletionOr<Value> get_binding_value_direct(VM&, Binding const&) const;
ThrowCompletionOr<void> set_mutable_binding_direct(VM&, Binding&, Value, bool strict);
friend Completion dispose_resources(VM&, GCPtr<DeclarativeEnvironment>, Completion);
friend Completion dispose_resources(VM&, GC::Ptr<DeclarativeEnvironment>, Completion);
Vector<DisposableResource> const& disposable_resource_stack() const { return m_disposable_resource_stack; }
protected:

View file

@ -8,7 +8,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(DisposableStack);
GC_DEFINE_ALLOCATOR(DisposableStack);
DisposableStack::DisposableStack(Vector<DisposableResource> stack, Object& prototype)
: Object(ConstructWithPrototypeTag::Tag, prototype)

View file

@ -13,7 +13,7 @@ namespace JS {
class DisposableStack final : public Object {
JS_OBJECT(DisposableStack, Object);
JS_DECLARE_ALLOCATOR(DisposableStack);
GC_DECLARE_ALLOCATOR(DisposableStack);
public:
virtual ~DisposableStack() override = default;

View file

@ -10,7 +10,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(DisposableStackConstructor);
GC_DEFINE_ALLOCATOR(DisposableStackConstructor);
DisposableStackConstructor::DisposableStackConstructor(Realm& realm)
: NativeFunction(realm.vm().names.DisposableStack.as_string(), realm.intrinsics().function_prototype())
@ -38,7 +38,7 @@ ThrowCompletionOr<Value> DisposableStackConstructor::call()
}
// 11.3.1.1 DisposableStack ( ), https://tc39.es/proposal-explicit-resource-management/#sec-disposablestack
ThrowCompletionOr<NonnullGCPtr<Object>> DisposableStackConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> DisposableStackConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();

View file

@ -12,14 +12,14 @@ namespace JS {
class DisposableStackConstructor final : public NativeFunction {
JS_OBJECT(DisposableStackConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(DisposableStackConstructor);
GC_DECLARE_ALLOCATOR(DisposableStackConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~DisposableStackConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject&) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject&) override;
private:
explicit DisposableStackConstructor(Realm&);

View file

@ -12,7 +12,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(DisposableStackPrototype);
GC_DEFINE_ALLOCATOR(DisposableStackPrototype);
DisposableStackPrototype::DisposableStackPrototype(Realm& realm)
: PrototypeObject(realm.intrinsics().object_prototype())
@ -136,7 +136,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisposableStackPrototype::adopt)
// 11.3.3.4.1 DisposableStack Adopt Callback Functions, https://tc39.es/proposal-explicit-resource-management/#sec-disposablestack-adopt-callback-functions
// A DisposableStack adopt callback function is an anonymous built-in function object that has [[Argument]] and [[OnDisposeCallback]] internal slots.
auto function = NativeFunction::create(
realm, [argument = make_handle(value), callback = make_handle(on_dispose)](VM& vm) {
realm, [argument = make_root(value), callback = make_root(on_dispose)](VM& vm) {
// When a DisposableStack adopt callback function is called, the following steps are taken:
// 1. Let F be the active function object.
// 2. Assert: IsCallable(F.[[OnDisposeCallback]]) is true.

View file

@ -13,7 +13,7 @@ namespace JS {
class DisposableStackPrototype final : public PrototypeObject<DisposableStackPrototype, DisposableStack> {
JS_PROTOTYPE_OBJECT(DisposableStackPrototype, DisposableStack, DisposableStack);
JS_DECLARE_ALLOCATOR(DisposableStackPrototype);
GC_DECLARE_ALLOCATOR(DisposableStackPrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -31,9 +31,9 @@
namespace JS {
JS_DEFINE_ALLOCATOR(ECMAScriptFunctionObject);
GC_DEFINE_ALLOCATOR(ECMAScriptFunctionObject);
NonnullGCPtr<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& realm, DeprecatedFlyString name, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> parameters, i32 m_function_length, Vector<DeprecatedFlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind kind, bool is_strict, FunctionParsingInsights parsing_insights, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& realm, DeprecatedFlyString name, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> parameters, i32 m_function_length, Vector<DeprecatedFlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind kind, bool is_strict, FunctionParsingInsights parsing_insights, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
{
Object* prototype = nullptr;
switch (kind) {
@ -53,7 +53,7 @@ NonnullGCPtr<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& r
return realm.create<ECMAScriptFunctionObject>(move(name), move(source_text), ecmascript_code, move(parameters), m_function_length, move(local_variables_names), parent_environment, private_environment, *prototype, kind, is_strict, parsing_insights, is_arrow_function, move(class_field_initializer_name));
}
NonnullGCPtr<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& realm, DeprecatedFlyString name, Object& prototype, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> parameters, i32 m_function_length, Vector<DeprecatedFlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind kind, bool is_strict, FunctionParsingInsights parsing_insights, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& realm, DeprecatedFlyString name, Object& prototype, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> parameters, i32 m_function_length, Vector<DeprecatedFlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind kind, bool is_strict, FunctionParsingInsights parsing_insights, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
{
return realm.create<ECMAScriptFunctionObject>(move(name), move(source_text), ecmascript_code, move(parameters), m_function_length, move(local_variables_names), parent_environment, private_environment, prototype, kind, is_strict, parsing_insights, is_arrow_function, move(class_field_initializer_name));
}
@ -438,7 +438,7 @@ ThrowCompletionOr<Value> ECMAScriptFunctionObject::internal_call(Value this_argu
}
// 10.2.2 [[Construct]] ( argumentsList, newTarget ), https://tc39.es/ecma262/#sec-ecmascript-function-objects-construct-argumentslist-newtarget
ThrowCompletionOr<NonnullGCPtr<Object>> ECMAScriptFunctionObject::internal_construct(ReadonlySpan<Value> arguments_list, FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> ECMAScriptFunctionObject::internal_construct(ReadonlySpan<Value> arguments_list, FunctionObject& new_target)
{
auto& vm = this->vm();
@ -448,7 +448,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> ECMAScriptFunctionObject::internal_const
// 2. Let kind be F.[[ConstructorKind]].
auto kind = m_constructor_kind;
GCPtr<Object> this_argument;
GC::Ptr<Object> this_argument;
// 3. If kind is base, then
if (kind == ConstructorKind::Base) {
@ -735,7 +735,7 @@ void async_block_start(VM& vm, T const& async_body, PromiseCapability const& pro
Completion result;
// a. If asyncBody is a Parse Node, then
if constexpr (!IsSame<T, HeapFunction<Completion()>>) {
if constexpr (!IsSame<T, GC::Function<Completion()>>) {
// a. Let result be the result of evaluating asyncBody.
// FIXME: Cache this executable somewhere.
auto maybe_executable = Bytecode::compile(vm, async_body, FunctionKind::Async, "AsyncBlockStart"sv);
@ -810,8 +810,8 @@ void async_block_start(VM& vm, T const& async_body, PromiseCapability const& pro
template void async_block_start(VM&, NonnullRefPtr<Statement const> const& async_body, PromiseCapability const&, ExecutionContext&);
template void async_function_start(VM&, PromiseCapability const&, NonnullRefPtr<Statement const> const& async_function_body);
template void async_block_start(VM&, HeapFunction<Completion()> const& async_body, PromiseCapability const&, ExecutionContext&);
template void async_function_start(VM&, PromiseCapability const&, HeapFunction<Completion()> const& async_function_body);
template void async_block_start(VM&, GC::Function<Completion()> const& async_body, PromiseCapability const&, ExecutionContext&);
template void async_function_start(VM&, PromiseCapability const&, GC::Function<Completion()> const& async_function_body);
// 10.2.1.4 OrdinaryCallEvaluateBody ( F, argumentsList ), https://tc39.es/ecma262/#sec-ordinarycallevaluatebody
// 15.8.4 Runtime Semantics: EvaluateAsyncFunctionBody, https://tc39.es/ecma262/#sec-runtime-semantics-evaluatefunctionbody

View file

@ -25,7 +25,7 @@ void async_function_start(VM&, PromiseCapability const&, T const& async_function
// 10.2 ECMAScript Function Objects, https://tc39.es/ecma262/#sec-ecmascript-function-objects
class ECMAScriptFunctionObject final : public FunctionObject {
JS_OBJECT(ECMAScriptFunctionObject, FunctionObject);
JS_DECLARE_ALLOCATOR(ECMAScriptFunctionObject);
GC_DECLARE_ALLOCATOR(ECMAScriptFunctionObject);
public:
enum class ConstructorKind : u8 {
@ -39,14 +39,14 @@ public:
Global,
};
static NonnullGCPtr<ECMAScriptFunctionObject> create(Realm&, DeprecatedFlyString name, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> parameters, i32 m_function_length, Vector<DeprecatedFlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind, bool is_strict, FunctionParsingInsights, bool is_arrow_function = false, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name = {});
static NonnullGCPtr<ECMAScriptFunctionObject> create(Realm&, DeprecatedFlyString name, Object& prototype, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> parameters, i32 m_function_length, Vector<DeprecatedFlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind, bool is_strict, FunctionParsingInsights, bool is_arrow_function = false, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name = {});
static GC::Ref<ECMAScriptFunctionObject> create(Realm&, DeprecatedFlyString name, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> parameters, i32 m_function_length, Vector<DeprecatedFlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind, bool is_strict, FunctionParsingInsights, bool is_arrow_function = false, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name = {});
static GC::Ref<ECMAScriptFunctionObject> create(Realm&, DeprecatedFlyString name, Object& prototype, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> parameters, i32 m_function_length, Vector<DeprecatedFlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind, bool is_strict, FunctionParsingInsights, bool is_arrow_function = false, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name = {});
virtual void initialize(Realm&) override;
virtual ~ECMAScriptFunctionObject() override = default;
virtual ThrowCompletionOr<Value> internal_call(Value this_argument, ReadonlySpan<Value> arguments_list) override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> internal_construct(ReadonlySpan<Value> arguments_list, FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> internal_construct(ReadonlySpan<Value> arguments_list, FunctionObject& new_target) override;
void make_method(Object& home_object);
@ -118,20 +118,20 @@ private:
void ordinary_call_bind_this(ExecutionContext&, Value this_argument);
DeprecatedFlyString m_name;
GCPtr<PrimitiveString> m_name_string;
GC::Ptr<PrimitiveString> m_name_string;
GCPtr<Bytecode::Executable> m_bytecode_executable;
GC::Ptr<Bytecode::Executable> m_bytecode_executable;
i32 m_function_length { 0 };
Vector<DeprecatedFlyString> m_local_variables_names;
// Internal Slots of ECMAScript Function Objects, https://tc39.es/ecma262/#table-internal-slots-of-ecmascript-function-objects
GCPtr<Environment> m_environment; // [[Environment]]
GCPtr<PrivateEnvironment> m_private_environment; // [[PrivateEnvironment]]
GC::Ptr<Environment> m_environment; // [[Environment]]
GC::Ptr<PrivateEnvironment> m_private_environment; // [[PrivateEnvironment]]
Vector<FunctionParameter> const m_formal_parameters; // [[FormalParameters]]
NonnullRefPtr<Statement const> m_ecmascript_code; // [[ECMAScriptCode]]
GCPtr<Realm> m_realm; // [[Realm]]
GC::Ptr<Realm> m_realm; // [[Realm]]
ScriptOrModule m_script_or_module; // [[ScriptOrModule]]
GCPtr<Object> m_home_object; // [[HomeObject]]
GC::Ptr<Object> m_home_object; // [[HomeObject]]
ByteString m_source_text; // [[SourceText]]
Vector<ClassFieldDefinition> m_fields; // [[Fields]]
Vector<PrivateElement> m_private_methods; // [[PrivateMethods]]

View file

@ -17,10 +17,10 @@ struct Variable {
DeclarationKind declaration_kind;
};
#define JS_ENVIRONMENT(class_, base_class) JS_CELL(class_, base_class)
#define JS_ENVIRONMENT(class_, base_class) GC_CELL(class_, base_class)
class Environment : public Cell {
JS_CELL(Environment, Cell);
GC_CELL(Environment, Cell);
public:
enum class InitializeBindingHint {
@ -70,7 +70,7 @@ private:
bool m_permanently_screwed_by_eval { false };
bool m_declarative { false };
GCPtr<Environment> m_outer_environment;
GC::Ptr<Environment> m_outer_environment;
};
}

View file

@ -15,7 +15,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(Error);
GC_DEFINE_ALLOCATOR(Error);
static SourceRange dummy_source_range { SourceCode::create(String {}, String {}), {}, {} };
@ -34,12 +34,12 @@ SourceRange const& TracebackFrame::source_range() const
return cached_source_range->source_range.get<SourceRange>();
}
NonnullGCPtr<Error> Error::create(Realm& realm)
GC::Ref<Error> Error::create(Realm& realm)
{
return realm.create<Error>(realm.intrinsics().error_prototype());
}
NonnullGCPtr<Error> Error::create(Realm& realm, String message)
GC::Ref<Error> Error::create(Realm& realm, String message)
{
auto& vm = realm.vm();
auto error = Error::create(realm);
@ -48,7 +48,7 @@ NonnullGCPtr<Error> Error::create(Realm& realm, String message)
return error;
}
NonnullGCPtr<Error> Error::create(Realm& realm, StringView message)
GC::Ref<Error> Error::create(Realm& realm, StringView message)
{
return create(realm, MUST(String::from_utf8(message)));
}
@ -157,13 +157,13 @@ String Error::stack_string(CompactTraceback compact) const
}
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
JS_DEFINE_ALLOCATOR(ClassName); \
NonnullGCPtr<ClassName> ClassName::create(Realm& realm) \
GC_DEFINE_ALLOCATOR(ClassName); \
GC::Ref<ClassName> ClassName::create(Realm& realm) \
{ \
return realm.create<ClassName>(realm.intrinsics().snake_name##_prototype()); \
} \
\
NonnullGCPtr<ClassName> ClassName::create(Realm& realm, String message) \
GC::Ref<ClassName> ClassName::create(Realm& realm, String message) \
{ \
auto& vm = realm.vm(); \
auto error = ClassName::create(realm); \
@ -172,7 +172,7 @@ String Error::stack_string(CompactTraceback compact) const
return error; \
} \
\
NonnullGCPtr<ClassName> ClassName::create(Realm& realm, StringView message) \
GC::Ref<ClassName> ClassName::create(Realm& realm, StringView message) \
{ \
return create(realm, MUST(String::from_utf8(message))); \
} \

View file

@ -29,12 +29,12 @@ enum CompactTraceback {
class Error : public Object {
JS_OBJECT(Error, Object);
JS_DECLARE_ALLOCATOR(Error);
GC_DECLARE_ALLOCATOR(Error);
public:
static NonnullGCPtr<Error> create(Realm&);
static NonnullGCPtr<Error> create(Realm&, String message);
static NonnullGCPtr<Error> create(Realm&, StringView message);
static GC::Ref<Error> create(Realm&);
static GC::Ref<Error> create(Realm&, String message);
static GC::Ref<Error> create(Realm&, StringView message);
virtual ~Error() override = default;
@ -58,12 +58,12 @@ private:
#define DECLARE_NATIVE_ERROR(ClassName, snake_name, PrototypeName, ConstructorName) \
class ClassName final : public Error { \
JS_OBJECT(ClassName, Error); \
JS_DECLARE_ALLOCATOR(ClassName); \
GC_DECLARE_ALLOCATOR(ClassName); \
\
public: \
static NonnullGCPtr<ClassName> create(Realm&); \
static NonnullGCPtr<ClassName> create(Realm&, String message); \
static NonnullGCPtr<ClassName> create(Realm&, StringView message); \
static GC::Ref<ClassName> create(Realm&); \
static GC::Ref<ClassName> create(Realm&, String message); \
static GC::Ref<ClassName> create(Realm&, StringView message); \
\
explicit ClassName(Object& prototype); \
virtual ~ClassName() override = default; \

View file

@ -11,7 +11,7 @@
namespace JS {
JS_DEFINE_ALLOCATOR(ErrorConstructor);
GC_DEFINE_ALLOCATOR(ErrorConstructor);
ErrorConstructor::ErrorConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Error.as_string(), realm.intrinsics().function_prototype())
@ -40,7 +40,7 @@ ThrowCompletionOr<Value> ErrorConstructor::call()
}
// 20.5.1.1 Error ( message [ , options ] ), https://tc39.es/ecma262/#sec-error-message
ThrowCompletionOr<NonnullGCPtr<Object>> ErrorConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> ErrorConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();
@ -67,7 +67,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> ErrorConstructor::construct(FunctionObje
}
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
JS_DEFINE_ALLOCATOR(ConstructorName); \
GC_DEFINE_ALLOCATOR(ConstructorName); \
ConstructorName::ConstructorName(Realm& realm) \
: NativeFunction(realm.vm().names.ClassName.as_string(), realm.intrinsics().error_constructor()) \
{ \
@ -94,7 +94,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> ErrorConstructor::construct(FunctionObje
} \
\
/* 20.5.6.1.1 NativeError ( message [ , options ] ), https://tc39.es/ecma262/#sec-nativeerror */ \
ThrowCompletionOr<NonnullGCPtr<Object>> ConstructorName::construct(FunctionObject& new_target) \
ThrowCompletionOr<GC::Ref<Object>> ConstructorName::construct(FunctionObject& new_target) \
{ \
auto& vm = this->vm(); \
\

View file

@ -13,14 +13,14 @@ namespace JS {
class ErrorConstructor final : public NativeFunction {
JS_OBJECT(ErrorConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(ErrorConstructor);
GC_DECLARE_ALLOCATOR(ErrorConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~ErrorConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
private:
explicit ErrorConstructor(Realm&);
@ -30,24 +30,24 @@ private:
JS_DECLARE_NATIVE_FUNCTION(is_error);
};
#define DECLARE_NATIVE_ERROR_CONSTRUCTOR(ClassName, snake_name, PrototypeName, ConstructorName) \
class ConstructorName final : public NativeFunction { \
JS_OBJECT(ConstructorName, NativeFunction); \
JS_DECLARE_ALLOCATOR(ConstructorName); \
\
public: \
virtual void initialize(Realm&) override; \
virtual ~ConstructorName() override; \
virtual ThrowCompletionOr<Value> call() override; \
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override; \
\
private: \
explicit ConstructorName(Realm&); \
\
virtual bool has_constructor() const override \
{ \
return true; \
} \
#define DECLARE_NATIVE_ERROR_CONSTRUCTOR(ClassName, snake_name, PrototypeName, ConstructorName) \
class ConstructorName final : public NativeFunction { \
JS_OBJECT(ConstructorName, NativeFunction); \
GC_DECLARE_ALLOCATOR(ConstructorName); \
\
public: \
virtual void initialize(Realm&) override; \
virtual ~ConstructorName() override; \
virtual ThrowCompletionOr<Value> call() override; \
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override; \
\
private: \
explicit ConstructorName(Realm&); \
\
virtual bool has_constructor() const override \
{ \
return true; \
} \
};
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \

Some files were not shown because too many files have changed in this diff Show more