mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-11 02:29:21 +00:00
LibJS+LibWeb: Use realm.create<T> instead of heap.allocate<T>
The main motivation behind this is to remove JS specifics of the Realm from the implementation of the Heap. As a side effect of this change, this is a bit nicer to read than the previous approach, and in my opinion, also makes it a little more clear that this method is specific to a JavaScript Realm.
This commit is contained in:
parent
2a5dbedad4
commit
9b79a686eb
Notes:
github-actions[bot]
2024-11-13 21:52:48 +00:00
Author: https://github.com/shannonbooth
Commit: 9b79a686eb
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2322
Reviewed-by: https://github.com/gmta
326 changed files with 697 additions and 714 deletions
|
@ -1742,7 +1742,7 @@ inline ThrowCompletionOr<Object*> get_object_property_iterator(VM& vm, Value val
|
|||
}
|
||||
},
|
||||
1, vm.names.next);
|
||||
return vm.heap().allocate<IteratorRecord>(realm, realm, object, callback, false).ptr();
|
||||
return realm.create<IteratorRecord>(realm, object, callback, false).ptr();
|
||||
}
|
||||
|
||||
ByteString Instruction::to_byte_string(Bytecode::Executable const& executable) const
|
||||
|
|
|
@ -32,8 +32,8 @@ void $262Object::initialize(Realm& realm)
|
|||
{
|
||||
Base::initialize(realm);
|
||||
|
||||
m_agent = vm().heap().allocate<AgentObject>(realm, realm);
|
||||
m_is_htmldda = vm().heap().allocate<IsHTMLDDA>(realm, realm);
|
||||
m_agent = realm.create<AgentObject>(realm);
|
||||
m_is_htmldda = realm.create<IsHTMLDDA>(realm);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(realm, "clearKeptObjects", clear_kept_objects, 0, attr);
|
||||
|
|
|
@ -20,7 +20,7 @@ void GlobalObject::initialize(Realm& realm)
|
|||
{
|
||||
Base::initialize(realm);
|
||||
|
||||
m_$262 = vm().heap().allocate<$262Object>(realm, realm);
|
||||
m_$262 = realm.create<$262Object>(realm);
|
||||
|
||||
// https://github.com/tc39/test262/blob/master/INTERPRETING.md#host-defined-functions
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
|
|
|
@ -45,18 +45,6 @@ public:
|
|||
return *static_cast<T*>(memory);
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
NonnullGCPtr<T> allocate(Realm& realm, Args&&... args)
|
||||
{
|
||||
auto* memory = allocate_cell<T>();
|
||||
defer_gc();
|
||||
new (memory) T(forward<Args>(args)...);
|
||||
undefer_gc();
|
||||
auto* cell = static_cast<T*>(memory);
|
||||
memory->initialize(realm);
|
||||
return *cell;
|
||||
}
|
||||
|
||||
enum class CollectionType {
|
||||
CollectGarbage,
|
||||
CollectEverything,
|
||||
|
|
|
@ -147,7 +147,7 @@ ThrowCompletionOr<Object*> Module::get_module_namespace(VM& vm)
|
|||
}
|
||||
|
||||
// d. Set namespace to ModuleNamespaceCreate(module, unambiguousNames).
|
||||
namespace_ = module_namespace_create(vm, unambiguous_names);
|
||||
namespace_ = module_namespace_create(unambiguous_names);
|
||||
VERIFY(m_namespace);
|
||||
// Note: This set the local variable 'namespace' and not the member variable which is done by ModuleNamespaceCreate
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ ThrowCompletionOr<Object*> Module::get_module_namespace(VM& vm)
|
|||
}
|
||||
|
||||
// 10.4.6.12 ModuleNamespaceCreate ( module, exports ), https://tc39.es/ecma262/#sec-modulenamespacecreate
|
||||
Object* Module::module_namespace_create(VM& vm, Vector<DeprecatedFlyString> unambiguous_names)
|
||||
Object* Module::module_namespace_create(Vector<DeprecatedFlyString> unambiguous_names)
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
|
||||
|
@ -171,7 +171,7 @@ Object* Module::module_namespace_create(VM& vm, Vector<DeprecatedFlyString> unam
|
|||
// 6. Let sortedExports be a List whose elements are the elements of exports ordered as if an Array of the same values had been sorted using %Array.prototype.sort% using undefined as comparefn.
|
||||
// 7. Set M.[[Exports]] to sortedExports.
|
||||
// 8. Create own properties of M corresponding to the definitions in 28.3.
|
||||
auto module_namespace = vm.heap().allocate<ModuleNamespaceObject>(realm, realm, this, move(unambiguous_names));
|
||||
auto module_namespace = realm.create<ModuleNamespaceObject>(realm, this, move(unambiguous_names));
|
||||
|
||||
// 9. Set module.[[Namespace]] to M.
|
||||
m_namespace = make_handle(module_namespace);
|
||||
|
|
|
@ -128,7 +128,7 @@ protected:
|
|||
}
|
||||
|
||||
private:
|
||||
Object* module_namespace_create(VM& vm, Vector<DeprecatedFlyString> unambiguous_names);
|
||||
Object* module_namespace_create(Vector<DeprecatedFlyString> unambiguous_names);
|
||||
|
||||
// These handles are only safe as long as the VM they live in is valid.
|
||||
// But evaluated modules SHOULD be stored in the VM so unless you intentionally
|
||||
|
|
|
@ -1087,7 +1087,7 @@ Object* create_mapped_arguments_object(VM& vm, FunctionObject& function, Vector<
|
|||
// 7. Set obj.[[Set]] as specified in 10.4.4.4.
|
||||
// 8. Set obj.[[Delete]] as specified in 10.4.4.5.
|
||||
// 9. Set obj.[[Prototype]] to %Object.prototype%.
|
||||
auto object = vm.heap().allocate<ArgumentsObject>(realm, realm, environment);
|
||||
auto object = realm.create<ArgumentsObject>(realm, environment);
|
||||
|
||||
// 14. Let index be 0.
|
||||
// 15. Repeat, while index < len,
|
||||
|
|
|
@ -147,7 +147,7 @@ ThrowCompletionOr<NonnullGCPtr<T>> ordinary_create_from_constructor(VM& vm, Func
|
|||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto* prototype = TRY(get_prototype_from_constructor(vm, constructor, intrinsic_default_prototype));
|
||||
return realm.heap().allocate<T>(realm, forward<Args>(args)..., *prototype);
|
||||
return realm.create<T>(forward<Args>(args)..., *prototype);
|
||||
}
|
||||
|
||||
// 14.1 MergeLists ( a, b ), https://tc39.es/proposal-temporal/#sec-temporal-mergelists
|
||||
|
|
|
@ -14,7 +14,7 @@ JS_DEFINE_ALLOCATOR(AggregateError);
|
|||
|
||||
NonnullGCPtr<AggregateError> AggregateError::create(Realm& realm)
|
||||
{
|
||||
return realm.heap().allocate<AggregateError>(realm, realm.intrinsics().aggregate_error_prototype());
|
||||
return realm.create<AggregateError>(realm.intrinsics().aggregate_error_prototype());
|
||||
}
|
||||
|
||||
AggregateError::AggregateError(Object& prototype)
|
||||
|
|
|
@ -35,7 +35,7 @@ ThrowCompletionOr<NonnullGCPtr<Array>> Array::create(Realm& realm, u64 length, O
|
|||
// 3. Let A be MakeBasicObject(« [[Prototype]], [[Extensible]] »).
|
||||
// 4. Set A.[[Prototype]] to proto.
|
||||
// 5. Set A.[[DefineOwnProperty]] as specified in 10.4.2.1.
|
||||
auto array = realm.heap().allocate<Array>(realm, *prototype);
|
||||
auto array = realm.create<Array>(*prototype);
|
||||
|
||||
// 6. Perform ! OrdinaryDefineOwnProperty(A, "length", PropertyDescriptor { [[Value]]: 𝔽(length), [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
|
||||
MUST(array->internal_define_own_property(vm.names.length, { .value = Value(length), .writable = true, .enumerable = false, .configurable = false }));
|
||||
|
|
|
@ -19,17 +19,17 @@ ThrowCompletionOr<NonnullGCPtr<ArrayBuffer>> ArrayBuffer::create(Realm& realm, s
|
|||
if (buffer.is_error())
|
||||
return realm.vm().throw_completion<RangeError>(ErrorType::NotEnoughMemoryToAllocate, byte_length);
|
||||
|
||||
return realm.heap().allocate<ArrayBuffer>(realm, buffer.release_value(), realm.intrinsics().array_buffer_prototype());
|
||||
return realm.create<ArrayBuffer>(buffer.release_value(), realm.intrinsics().array_buffer_prototype());
|
||||
}
|
||||
|
||||
NonnullGCPtr<ArrayBuffer> ArrayBuffer::create(Realm& realm, ByteBuffer buffer)
|
||||
{
|
||||
return realm.heap().allocate<ArrayBuffer>(realm, move(buffer), realm.intrinsics().array_buffer_prototype());
|
||||
return realm.create<ArrayBuffer>(move(buffer), realm.intrinsics().array_buffer_prototype());
|
||||
}
|
||||
|
||||
NonnullGCPtr<ArrayBuffer> ArrayBuffer::create(Realm& realm, ByteBuffer* buffer)
|
||||
{
|
||||
return realm.heap().allocate<ArrayBuffer>(realm, buffer, realm.intrinsics().array_buffer_prototype());
|
||||
return realm.create<ArrayBuffer>(buffer, realm.intrinsics().array_buffer_prototype());
|
||||
}
|
||||
|
||||
ArrayBuffer::ArrayBuffer(ByteBuffer buffer, Object& prototype)
|
||||
|
|
|
@ -13,7 +13,7 @@ JS_DEFINE_ALLOCATOR(ArrayIterator);
|
|||
|
||||
NonnullGCPtr<ArrayIterator> ArrayIterator::create(Realm& realm, Value array, Object::PropertyKind iteration_kind)
|
||||
{
|
||||
return realm.heap().allocate<ArrayIterator>(realm, array, iteration_kind, realm.intrinsics().array_iterator_prototype());
|
||||
return realm.create<ArrayIterator>(array, iteration_kind, realm.intrinsics().array_iterator_prototype());
|
||||
}
|
||||
|
||||
ArrayIterator::ArrayIterator(Value array, Object::PropertyKind iteration_kind, Object& prototype)
|
||||
|
|
|
@ -15,7 +15,7 @@ JS_DEFINE_ALLOCATOR(AsyncFromSyncIterator);
|
|||
|
||||
NonnullGCPtr<AsyncFromSyncIterator> AsyncFromSyncIterator::create(Realm& realm, NonnullGCPtr<IteratorRecord> sync_iterator_record)
|
||||
{
|
||||
return realm.heap().allocate<AsyncFromSyncIterator>(realm, realm, sync_iterator_record);
|
||||
return realm.create<AsyncFromSyncIterator>(realm, sync_iterator_record);
|
||||
}
|
||||
|
||||
AsyncFromSyncIterator::AsyncFromSyncIterator(Realm& realm, NonnullGCPtr<IteratorRecord> sync_iterator_record)
|
||||
|
|
|
@ -211,7 +211,7 @@ NonnullGCPtr<IteratorRecord> create_async_from_sync_iterator(VM& vm, NonnullGCPt
|
|||
auto next_method = MUST(async_iterator->get(vm.names.next));
|
||||
|
||||
// 4. Let iteratorRecord be the Iterator Record { [[Iterator]]: asyncIterator, [[NextMethod]]: nextMethod, [[Done]]: false }.
|
||||
auto iterator_record = vm.heap().allocate<IteratorRecord>(realm, realm, async_iterator, next_method, false);
|
||||
auto iterator_record = realm.create<IteratorRecord>(realm, async_iterator, next_method, false);
|
||||
|
||||
// 5. Return iteratorRecord.
|
||||
return iterator_record;
|
||||
|
|
|
@ -21,7 +21,7 @@ NonnullGCPtr<Promise> AsyncFunctionDriverWrapper::create(Realm& realm, Generator
|
|||
{
|
||||
auto top_level_promise = Promise::create(realm);
|
||||
// Note: The top_level_promise is also kept alive by this Wrapper
|
||||
auto wrapper = realm.heap().allocate<AsyncFunctionDriverWrapper>(realm, realm, *generator_object, *top_level_promise);
|
||||
auto wrapper = realm.create<AsyncFunctionDriverWrapper>(realm, *generator_object, *top_level_promise);
|
||||
// Prime the generator:
|
||||
// This runs until the first `await value;`
|
||||
wrapper->continue_async_execution(realm.vm(), js_undefined(), true, IsInitialExecution::Yes);
|
||||
|
|
|
@ -22,7 +22,7 @@ ThrowCompletionOr<NonnullGCPtr<AsyncGenerator>> AsyncGenerator::create(Realm& re
|
|||
// This is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png)
|
||||
auto generating_function_prototype = TRY(generating_function->get(vm.names.prototype));
|
||||
auto generating_function_prototype_object = TRY(generating_function_prototype.to_object(vm));
|
||||
auto object = realm.heap().allocate<AsyncGenerator>(realm, realm, generating_function_prototype_object, move(execution_context));
|
||||
auto object = realm.create<AsyncGenerator>(realm, generating_function_prototype_object, move(execution_context));
|
||||
object->m_generating_function = generating_function;
|
||||
object->m_previous_value = initial_value;
|
||||
return object;
|
||||
|
|
|
@ -13,7 +13,7 @@ JS_DEFINE_ALLOCATOR(BigIntObject);
|
|||
|
||||
NonnullGCPtr<BigIntObject> BigIntObject::create(Realm& realm, BigInt& bigint)
|
||||
{
|
||||
return realm.heap().allocate<BigIntObject>(realm, bigint, realm.intrinsics().bigint_prototype());
|
||||
return realm.create<BigIntObject>(bigint, realm.intrinsics().bigint_prototype());
|
||||
}
|
||||
|
||||
BigIntObject::BigIntObject(BigInt& bigint, Object& prototype)
|
||||
|
|
|
@ -13,7 +13,7 @@ JS_DEFINE_ALLOCATOR(BooleanObject);
|
|||
|
||||
NonnullGCPtr<BooleanObject> BooleanObject::create(Realm& realm, bool value)
|
||||
{
|
||||
return realm.heap().allocate<BooleanObject>(realm, value, realm.intrinsics().boolean_prototype());
|
||||
return realm.create<BooleanObject>(value, realm.intrinsics().boolean_prototype());
|
||||
}
|
||||
|
||||
BooleanObject::BooleanObject(bool value, Object& prototype)
|
||||
|
|
|
@ -28,7 +28,7 @@ ThrowCompletionOr<NonnullGCPtr<BoundFunction>> BoundFunction::create(Realm& real
|
|||
// 7. Set obj.[[BoundTargetFunction]] to targetFunction.
|
||||
// 8. Set obj.[[BoundThis]] to boundThis.
|
||||
// 9. Set obj.[[BoundArguments]] to boundArgs.
|
||||
auto object = realm.heap().allocate<BoundFunction>(realm, realm, target_function, bound_this, move(bound_arguments), prototype);
|
||||
auto object = realm.create<BoundFunction>(realm, target_function, bound_this, move(bound_arguments), prototype);
|
||||
|
||||
// 10. Return obj.
|
||||
return object;
|
||||
|
|
|
@ -17,7 +17,7 @@ JS_DEFINE_ALLOCATOR(ConsoleObject);
|
|||
|
||||
static NonnullGCPtr<ConsoleObjectPrototype> create_console_prototype(Realm& realm)
|
||||
{
|
||||
return realm.heap().allocate<ConsoleObjectPrototype>(realm, realm);
|
||||
return realm.create<ConsoleObjectPrototype>(realm);
|
||||
}
|
||||
|
||||
ConsoleObject::ConsoleObject(Realm& realm)
|
||||
|
@ -37,7 +37,7 @@ void ConsoleObject::initialize(Realm& realm)
|
|||
{
|
||||
auto& vm = this->vm();
|
||||
Base::initialize(realm);
|
||||
m_console = vm.heap().allocate<Console>(realm, realm);
|
||||
m_console = realm.create<Console>(realm);
|
||||
u8 attr = Attribute::Writable | Attribute::Enumerable | Attribute::Configurable;
|
||||
define_native_function(realm, vm.names.assert, assert_, 0, attr);
|
||||
define_native_function(realm, vm.names.clear, clear, 0, attr);
|
||||
|
|
|
@ -12,7 +12,7 @@ JS_DEFINE_ALLOCATOR(DataView);
|
|||
|
||||
NonnullGCPtr<DataView> DataView::create(Realm& realm, ArrayBuffer* viewed_buffer, ByteLength byte_length, size_t byte_offset)
|
||||
{
|
||||
return realm.heap().allocate<DataView>(realm, viewed_buffer, move(byte_length), byte_offset, realm.intrinsics().data_view_prototype());
|
||||
return realm.create<DataView>(viewed_buffer, move(byte_length), byte_offset, realm.intrinsics().data_view_prototype());
|
||||
}
|
||||
|
||||
DataView::DataView(ArrayBuffer* viewed_buffer, ByteLength byte_length, size_t byte_offset, Object& prototype)
|
||||
|
|
|
@ -27,7 +27,7 @@ Crypto::SignedBigInteger const ns_per_day_bigint { static_cast<i64>(ns_per_day)
|
|||
|
||||
NonnullGCPtr<Date> Date::create(Realm& realm, double date_value)
|
||||
{
|
||||
return realm.heap().allocate<Date>(realm, date_value, realm.intrinsics().date_prototype());
|
||||
return realm.create<Date>(date_value, realm.intrinsics().date_prototype());
|
||||
}
|
||||
|
||||
Date::Date(double date_value, Object& prototype)
|
||||
|
|
|
@ -50,12 +50,12 @@ NonnullGCPtr<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& r
|
|||
prototype = realm.intrinsics().async_generator_function_prototype();
|
||||
break;
|
||||
}
|
||||
return realm.heap().allocate<ECMAScriptFunctionObject>(realm, 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));
|
||||
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)
|
||||
{
|
||||
return realm.heap().allocate<ECMAScriptFunctionObject>(realm, 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));
|
||||
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));
|
||||
}
|
||||
|
||||
ECMAScriptFunctionObject::ECMAScriptFunctionObject(DeprecatedFlyString name, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> formal_parameters, i32 function_length, Vector<DeprecatedFlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, Object& prototype, FunctionKind kind, bool strict, FunctionParsingInsights parsing_insights, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
|
||||
|
|
|
@ -36,7 +36,7 @@ SourceRange const& TracebackFrame::source_range() const
|
|||
|
||||
NonnullGCPtr<Error> Error::create(Realm& realm)
|
||||
{
|
||||
return realm.heap().allocate<Error>(realm, realm.intrinsics().error_prototype());
|
||||
return realm.create<Error>(realm.intrinsics().error_prototype());
|
||||
}
|
||||
|
||||
NonnullGCPtr<Error> Error::create(Realm& realm, String message)
|
||||
|
@ -160,7 +160,7 @@ String Error::stack_string(CompactTraceback compact) const
|
|||
JS_DEFINE_ALLOCATOR(ClassName); \
|
||||
NonnullGCPtr<ClassName> ClassName::create(Realm& realm) \
|
||||
{ \
|
||||
return realm.heap().allocate<ClassName>(realm, realm.intrinsics().snake_name##_prototype()); \
|
||||
return realm.create<ClassName>(realm.intrinsics().snake_name##_prototype()); \
|
||||
} \
|
||||
\
|
||||
NonnullGCPtr<ClassName> ClassName::create(Realm& realm, String message) \
|
||||
|
|
|
@ -30,7 +30,7 @@ ThrowCompletionOr<NonnullGCPtr<GeneratorObject>> GeneratorObject::create(Realm&
|
|||
generating_function_prototype = TRY(generating_function->get(vm.names.prototype));
|
||||
}
|
||||
auto generating_function_prototype_object = TRY(generating_function_prototype.to_object(vm));
|
||||
auto object = realm.heap().allocate<GeneratorObject>(realm, realm, generating_function_prototype_object, move(execution_context));
|
||||
auto object = realm.create<GeneratorObject>(realm, generating_function_prototype_object, move(execution_context));
|
||||
object->m_generating_function = generating_function;
|
||||
object->m_previous_value = initial_value;
|
||||
return object;
|
||||
|
|
|
@ -15,7 +15,7 @@ JS_DEFINE_ALLOCATOR(CollatorCompareFunction);
|
|||
|
||||
NonnullGCPtr<CollatorCompareFunction> CollatorCompareFunction::create(Realm& realm, Collator& collator)
|
||||
{
|
||||
return realm.heap().allocate<CollatorCompareFunction>(realm, realm, collator);
|
||||
return realm.create<CollatorCompareFunction>(realm, collator);
|
||||
}
|
||||
|
||||
CollatorCompareFunction::CollatorCompareFunction(Realm& realm, Collator& collator)
|
||||
|
|
|
@ -19,7 +19,7 @@ JS_DEFINE_ALLOCATOR(DateTimeFormatFunction);
|
|||
// 11.5.4 DateTime Format Functions, https://tc39.es/ecma402/#sec-datetime-format-functions
|
||||
NonnullGCPtr<DateTimeFormatFunction> DateTimeFormatFunction::create(Realm& realm, DateTimeFormat& date_time_format)
|
||||
{
|
||||
return realm.heap().allocate<DateTimeFormatFunction>(realm, date_time_format, realm.intrinsics().function_prototype());
|
||||
return realm.create<DateTimeFormatFunction>(date_time_format, realm.intrinsics().function_prototype());
|
||||
}
|
||||
|
||||
DateTimeFormatFunction::DateTimeFormatFunction(DateTimeFormat& date_time_format, Object& prototype)
|
||||
|
|
|
@ -19,7 +19,7 @@ JS_DEFINE_ALLOCATOR(Locale);
|
|||
|
||||
NonnullGCPtr<Locale> Locale::create(Realm& realm, NonnullGCPtr<Locale> source_locale, String locale_tag)
|
||||
{
|
||||
auto locale = realm.heap().allocate<Locale>(realm, realm.intrinsics().intl_locale_prototype());
|
||||
auto locale = realm.create<Locale>(realm.intrinsics().intl_locale_prototype());
|
||||
|
||||
locale->set_locale(move(locale_tag));
|
||||
locale->m_calendar = source_locale->m_calendar;
|
||||
|
|
|
@ -15,7 +15,7 @@ JS_DEFINE_ALLOCATOR(NumberFormatFunction);
|
|||
// 15.5.2 Number Format Functions, https://tc39.es/ecma402/#sec-number-format-functions
|
||||
NonnullGCPtr<NumberFormatFunction> NumberFormatFunction::create(Realm& realm, NumberFormat& number_format)
|
||||
{
|
||||
return realm.heap().allocate<NumberFormatFunction>(realm, number_format, realm.intrinsics().function_prototype());
|
||||
return realm.create<NumberFormatFunction>(number_format, realm.intrinsics().function_prototype());
|
||||
}
|
||||
|
||||
NumberFormatFunction::NumberFormatFunction(NumberFormat& number_format, Object& prototype)
|
||||
|
|
|
@ -21,7 +21,7 @@ NonnullGCPtr<SegmentIterator> SegmentIterator::create(Realm& realm, Unicode::Seg
|
|||
// 4. Set iterator.[[IteratedString]] to string.
|
||||
// 5. Set iterator.[[IteratedStringNextSegmentCodeUnitIndex]] to 0.
|
||||
// 6. Return iterator.
|
||||
return realm.heap().allocate<SegmentIterator>(realm, realm, segmenter, string, segments);
|
||||
return realm.create<SegmentIterator>(realm, segmenter, string, segments);
|
||||
}
|
||||
|
||||
// 18.6 Segment Iterator Objects, https://tc39.es/ecma402/#sec-segment-iterator-objects
|
||||
|
|
|
@ -20,7 +20,7 @@ NonnullGCPtr<Segments> Segments::create(Realm& realm, Unicode::Segmenter const&
|
|||
// 3. Set segments.[[SegmentsSegmenter]] to segmenter.
|
||||
// 4. Set segments.[[SegmentsString]] to string.
|
||||
// 5. Return segments.
|
||||
return realm.heap().allocate<Segments>(realm, realm, segmenter, move(string));
|
||||
return realm.create<Segments>(realm, segmenter, move(string));
|
||||
}
|
||||
|
||||
// 18.5 Segments Objects, https://tc39.es/ecma402/#sec-segments-objects
|
||||
|
|
|
@ -198,33 +198,33 @@ ThrowCompletionOr<void> Intrinsics::initialize_intrinsics(Realm& realm)
|
|||
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 Heap::allocate() takes care of this, but these are allocated via allocate_without_realm().
|
||||
// Normally Realm::create() takes care of this, but these are allocated via Heap::allocate_without_realm().
|
||||
m_function_prototype->initialize(realm);
|
||||
m_object_prototype->initialize(realm);
|
||||
|
||||
#define __JS_ENUMERATE(ClassName, snake_name) \
|
||||
VERIFY(!m_##snake_name##_prototype); \
|
||||
m_##snake_name##_prototype = heap().allocate<ClassName##Prototype>(realm, realm);
|
||||
m_##snake_name##_prototype = realm.create<ClassName##Prototype>(realm);
|
||||
JS_ENUMERATE_ITERATOR_PROTOTYPES
|
||||
#undef __JS_ENUMERATE
|
||||
|
||||
// These must be initialized separately as they have no companion constructor
|
||||
m_async_from_sync_iterator_prototype = heap().allocate<AsyncFromSyncIteratorPrototype>(realm, realm);
|
||||
m_async_generator_prototype = heap().allocate<AsyncGeneratorPrototype>(realm, realm);
|
||||
m_generator_prototype = heap().allocate<GeneratorPrototype>(realm, realm);
|
||||
m_intl_segments_prototype = heap().allocate<Intl::SegmentsPrototype>(realm, realm);
|
||||
m_wrap_for_valid_iterator_prototype = heap().allocate<WrapForValidIteratorPrototype>(realm, realm);
|
||||
m_async_from_sync_iterator_prototype = realm.create<AsyncFromSyncIteratorPrototype>(realm);
|
||||
m_async_generator_prototype = realm.create<AsyncGeneratorPrototype>(realm);
|
||||
m_generator_prototype = realm.create<GeneratorPrototype>(realm);
|
||||
m_intl_segments_prototype = realm.create<Intl::SegmentsPrototype>(realm);
|
||||
m_wrap_for_valid_iterator_prototype = realm.create<WrapForValidIteratorPrototype>(realm);
|
||||
|
||||
// These must be initialized before allocating...
|
||||
// - AggregateErrorPrototype, which uses ErrorPrototype as its prototype
|
||||
// - AggregateErrorConstructor, which uses ErrorConstructor as its prototype
|
||||
// - AsyncFunctionConstructor, which uses FunctionConstructor as its prototype
|
||||
m_error_prototype = heap().allocate<ErrorPrototype>(realm, realm);
|
||||
m_error_constructor = heap().allocate<ErrorConstructor>(realm, realm);
|
||||
m_function_constructor = heap().allocate<FunctionConstructor>(realm, realm);
|
||||
m_error_prototype = realm.create<ErrorPrototype>(realm);
|
||||
m_error_constructor = realm.create<ErrorConstructor>(realm);
|
||||
m_function_constructor = realm.create<FunctionConstructor>(realm);
|
||||
|
||||
// Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
|
||||
m_proxy_constructor = heap().allocate<ProxyConstructor>(realm, realm);
|
||||
m_proxy_constructor = realm.create<ProxyConstructor>(realm);
|
||||
|
||||
// Global object functions
|
||||
m_eval_function = NativeFunction::create(realm, GlobalObject::eval, 1, vm.names.eval, &realm);
|
||||
|
@ -239,7 +239,7 @@ ThrowCompletionOr<void> Intrinsics::initialize_intrinsics(Realm& realm)
|
|||
m_escape_function = NativeFunction::create(realm, GlobalObject::escape, 1, vm.names.escape, &realm);
|
||||
m_unescape_function = NativeFunction::create(realm, GlobalObject::unescape, 1, vm.names.unescape, &realm);
|
||||
|
||||
m_object_constructor = heap().allocate<ObjectConstructor>(realm, realm);
|
||||
m_object_constructor = realm.create<ObjectConstructor>(realm);
|
||||
|
||||
// 10.2.4.1 %ThrowTypeError% ( ), https://tc39.es/ecma262/#sec-%throwtypeerror%
|
||||
m_throw_type_error_function = NativeFunction::create(
|
||||
|
@ -292,11 +292,11 @@ JS_ENUMERATE_TYPED_ARRAYS
|
|||
VERIFY(!m_##snake_namespace##snake_name##_prototype); \
|
||||
VERIFY(!m_##snake_namespace##snake_name##_constructor); \
|
||||
if constexpr (IsTypedArrayConstructor<Namespace::ConstructorName>) { \
|
||||
m_##snake_namespace##snake_name##_prototype = heap().allocate<Namespace::PrototypeName>(m_realm, *typed_array_prototype()); \
|
||||
m_##snake_namespace##snake_name##_constructor = heap().allocate<Namespace::ConstructorName>(m_realm, m_realm, *typed_array_constructor()); \
|
||||
m_##snake_namespace##snake_name##_prototype = m_realm->create<Namespace::PrototypeName>(*typed_array_prototype()); \
|
||||
m_##snake_namespace##snake_name##_constructor = m_realm->create<Namespace::ConstructorName>(m_realm, *typed_array_constructor()); \
|
||||
} else { \
|
||||
m_##snake_namespace##snake_name##_prototype = heap().allocate<Namespace::PrototypeName>(m_realm, m_realm); \
|
||||
m_##snake_namespace##snake_name##_constructor = heap().allocate<Namespace::ConstructorName>(m_realm, m_realm); \
|
||||
m_##snake_namespace##snake_name##_prototype = m_realm->create<Namespace::PrototypeName>(m_realm); \
|
||||
m_##snake_namespace##snake_name##_constructor = m_realm->create<Namespace::ConstructorName>(m_realm); \
|
||||
} \
|
||||
\
|
||||
/* FIXME: Add these special cases to JS_ENUMERATE_NATIVE_OBJECTS */ \
|
||||
|
@ -351,12 +351,12 @@ JS_ENUMERATE_TEMPORAL_OBJECTS
|
|||
|
||||
#undef __JS_ENUMERATE_INNER
|
||||
|
||||
#define __JS_ENUMERATE(ClassName, snake_name) \
|
||||
NonnullGCPtr<ClassName> Intrinsics::snake_name##_object() \
|
||||
{ \
|
||||
if (!m_##snake_name##_object) \
|
||||
m_##snake_name##_object = heap().allocate<ClassName>(m_realm, m_realm); \
|
||||
return *m_##snake_name##_object; \
|
||||
#define __JS_ENUMERATE(ClassName, snake_name) \
|
||||
NonnullGCPtr<ClassName> Intrinsics::snake_name##_object() \
|
||||
{ \
|
||||
if (!m_##snake_name##_object) \
|
||||
m_##snake_name##_object = m_realm->create<ClassName>(m_realm); \
|
||||
return *m_##snake_name##_object; \
|
||||
}
|
||||
JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS
|
||||
#undef __JS_ENUMERATE
|
||||
|
|
|
@ -21,7 +21,7 @@ JS_DEFINE_ALLOCATOR(IteratorRecord);
|
|||
|
||||
NonnullGCPtr<Iterator> Iterator::create(Realm& realm, Object& prototype, NonnullGCPtr<IteratorRecord> iterated)
|
||||
{
|
||||
return realm.heap().allocate<Iterator>(realm, prototype, move(iterated));
|
||||
return realm.create<Iterator>(prototype, move(iterated));
|
||||
}
|
||||
|
||||
Iterator::Iterator(Object& prototype, NonnullGCPtr<IteratorRecord> iterated)
|
||||
|
@ -31,7 +31,7 @@ Iterator::Iterator(Object& prototype, NonnullGCPtr<IteratorRecord> iterated)
|
|||
}
|
||||
|
||||
Iterator::Iterator(Object& prototype)
|
||||
: Iterator(prototype, prototype.heap().allocate<IteratorRecord>(prototype.shape().realm(), prototype.shape().realm(), nullptr, js_undefined(), false))
|
||||
: Iterator(prototype, prototype.shape().realm().create<IteratorRecord>(prototype.shape().realm(), nullptr, js_undefined(), false))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ ThrowCompletionOr<NonnullGCPtr<IteratorRecord>> get_iterator_direct(VM& vm, Obje
|
|||
// 2. Let iteratorRecord be Record { [[Iterator]]: obj, [[NextMethod]]: nextMethod, [[Done]]: false }.
|
||||
// 3. Return iteratorRecord.
|
||||
auto& realm = *vm.current_realm();
|
||||
return vm.heap().allocate<IteratorRecord>(realm, realm, object, next_method, false);
|
||||
return realm.create<IteratorRecord>(realm, object, next_method, false);
|
||||
}
|
||||
|
||||
// 7.4.3 GetIteratorFromMethod ( obj, method ), https://tc39.es/ecma262/#sec-getiteratorfrommethod
|
||||
|
@ -62,7 +62,7 @@ ThrowCompletionOr<NonnullGCPtr<IteratorRecord>> get_iterator_from_method(VM& vm,
|
|||
|
||||
// 4. Let iteratorRecord be the Iterator Record { [[Iterator]]: iterator, [[NextMethod]]: nextMethod, [[Done]]: false }.
|
||||
auto& realm = *vm.current_realm();
|
||||
auto iterator_record = vm.heap().allocate<IteratorRecord>(realm, realm, iterator.as_object(), next_method, false);
|
||||
auto iterator_record = realm.create<IteratorRecord>(realm, iterator.as_object(), next_method, false);
|
||||
|
||||
// 5. Return iteratorRecord.
|
||||
return iterator_record;
|
||||
|
|
|
@ -15,7 +15,7 @@ JS_DEFINE_ALLOCATOR(IteratorHelper);
|
|||
|
||||
ThrowCompletionOr<NonnullGCPtr<IteratorHelper>> IteratorHelper::create(Realm& realm, NonnullGCPtr<IteratorRecord> underlying_iterator, NonnullGCPtr<Closure> closure, GCPtr<AbruptClosure> abrupt_closure)
|
||||
{
|
||||
return realm.heap().allocate<IteratorHelper>(realm, realm, realm.intrinsics().iterator_helper_prototype(), move(underlying_iterator), closure, abrupt_closure);
|
||||
return realm.create<IteratorHelper>(realm, realm.intrinsics().iterator_helper_prototype(), move(underlying_iterator), closure, abrupt_closure);
|
||||
}
|
||||
|
||||
IteratorHelper::IteratorHelper(Realm& realm, Object& prototype, NonnullGCPtr<IteratorRecord> underlying_iterator, NonnullGCPtr<Closure> closure, GCPtr<AbruptClosure> abrupt_closure)
|
||||
|
|
|
@ -413,7 +413,7 @@ JS_DEFINE_NATIVE_FUNCTION(IteratorPrototype::flat_map)
|
|||
// 4. Let iterated be ? GetIteratorDirect(O).
|
||||
auto iterated = TRY(get_iterator_direct(vm, object));
|
||||
|
||||
auto flat_map_iterator = vm.heap().allocate<FlatMapIterator>(realm);
|
||||
auto flat_map_iterator = realm.create<FlatMapIterator>();
|
||||
|
||||
// 5. Let closure be a new Abstract Closure with no parameters that captures iterated and mapper and performs the following steps when called:
|
||||
auto closure = JS::create_heap_function(realm.heap(), [flat_map_iterator, mapper = NonnullGCPtr { mapper.as_function() }](VM& vm, IteratorHelper& iterator) mutable -> ThrowCompletionOr<Value> {
|
||||
|
|
|
@ -12,7 +12,7 @@ JS_DEFINE_ALLOCATOR(Map);
|
|||
|
||||
NonnullGCPtr<Map> Map::create(Realm& realm)
|
||||
{
|
||||
return realm.heap().allocate<Map>(realm, realm.intrinsics().map_prototype());
|
||||
return realm.create<Map>(realm.intrinsics().map_prototype());
|
||||
}
|
||||
|
||||
Map::Map(Object& prototype)
|
||||
|
|
|
@ -13,7 +13,7 @@ JS_DEFINE_ALLOCATOR(MapIterator);
|
|||
|
||||
NonnullGCPtr<MapIterator> MapIterator::create(Realm& realm, Map& map, Object::PropertyKind iteration_kind)
|
||||
{
|
||||
return realm.heap().allocate<MapIterator>(realm, map, iteration_kind, realm.intrinsics().map_iterator_prototype());
|
||||
return realm.create<MapIterator>(map, iteration_kind, realm.intrinsics().map_iterator_prototype());
|
||||
}
|
||||
|
||||
MapIterator::MapIterator(Map& map, Object::PropertyKind iteration_kind, Object& prototype)
|
||||
|
|
|
@ -53,7 +53,7 @@ NonnullGCPtr<NativeFunction> NativeFunction::create(Realm& allocating_realm, Fun
|
|||
// 7. Set func.[[Extensible]] to true.
|
||||
// 8. Set func.[[Realm]] to realm.
|
||||
// 9. Set func.[[InitialName]] to null.
|
||||
auto function = allocating_realm.heap().allocate<NativeFunction>(allocating_realm, JS::create_heap_function(vm.heap(), move(behaviour)), prototype.value(), *realm.value());
|
||||
auto function = allocating_realm.create<NativeFunction>(JS::create_heap_function(vm.heap(), move(behaviour)), prototype.value(), *realm.value());
|
||||
|
||||
// 10. Perform SetFunctionLength(func, length).
|
||||
function->set_function_length(length);
|
||||
|
@ -70,7 +70,7 @@ NonnullGCPtr<NativeFunction> NativeFunction::create(Realm& allocating_realm, Fun
|
|||
|
||||
NonnullGCPtr<NativeFunction> NativeFunction::create(Realm& realm, DeprecatedFlyString const& name, Function<ThrowCompletionOr<Value>(VM&)> function)
|
||||
{
|
||||
return realm.heap().allocate<NativeFunction>(realm, name, JS::create_heap_function(realm.heap(), move(function)), realm.intrinsics().function_prototype());
|
||||
return realm.create<NativeFunction>(name, JS::create_heap_function(realm.heap(), move(function)), realm.intrinsics().function_prototype());
|
||||
}
|
||||
|
||||
NativeFunction::NativeFunction(JS::GCPtr<JS::HeapFunction<ThrowCompletionOr<Value>(VM&)>> native_function, Object* prototype, Realm& realm)
|
||||
|
|
|
@ -13,7 +13,7 @@ JS_DEFINE_ALLOCATOR(NumberObject);
|
|||
|
||||
NonnullGCPtr<NumberObject> NumberObject::create(Realm& realm, double value)
|
||||
{
|
||||
return realm.heap().allocate<NumberObject>(realm, value, realm.intrinsics().number_prototype());
|
||||
return realm.create<NumberObject>(value, realm.intrinsics().number_prototype());
|
||||
}
|
||||
|
||||
NumberObject::NumberObject(double value, Object& prototype)
|
||||
|
|
|
@ -31,10 +31,10 @@ static HashMap<GCPtr<Object const>, HashMap<DeprecatedFlyString, Object::Intrins
|
|||
NonnullGCPtr<Object> Object::create(Realm& realm, Object* prototype)
|
||||
{
|
||||
if (!prototype)
|
||||
return realm.heap().allocate<Object>(realm, realm.intrinsics().empty_object_shape());
|
||||
return realm.create<Object>(realm.intrinsics().empty_object_shape());
|
||||
if (prototype == realm.intrinsics().object_prototype())
|
||||
return realm.heap().allocate<Object>(realm, realm.intrinsics().new_object_shape());
|
||||
return realm.heap().allocate<Object>(realm, ConstructWithPrototypeTag::Tag, *prototype);
|
||||
return realm.create<Object>(realm.intrinsics().new_object_shape());
|
||||
return realm.create<Object>(ConstructWithPrototypeTag::Tag, *prototype);
|
||||
}
|
||||
|
||||
NonnullGCPtr<Object> Object::create_prototype(Realm& realm, Object* prototype)
|
||||
|
@ -42,12 +42,12 @@ NonnullGCPtr<Object> Object::create_prototype(Realm& realm, Object* prototype)
|
|||
auto shape = realm.heap().allocate_without_realm<Shape>(realm);
|
||||
if (prototype)
|
||||
shape->set_prototype_without_transition(prototype);
|
||||
return realm.heap().allocate<Object>(realm, shape);
|
||||
return realm.create<Object>(shape);
|
||||
}
|
||||
|
||||
NonnullGCPtr<Object> Object::create_with_premade_shape(Shape& shape)
|
||||
{
|
||||
return shape.heap().allocate<Object>(shape.realm(), shape);
|
||||
return shape.realm().create<Object>(shape);
|
||||
}
|
||||
|
||||
Object::Object(GlobalObjectTag, Realm& realm, MayInterfereWithIndexedPropertyAccess may_interfere_with_indexed_property_access)
|
||||
|
|
|
@ -46,7 +46,7 @@ ThrowCompletionOr<Object*> promise_resolve(VM& vm, Object& constructor, Value va
|
|||
|
||||
NonnullGCPtr<Promise> Promise::create(Realm& realm)
|
||||
{
|
||||
return realm.heap().allocate<Promise>(realm, realm.intrinsics().promise_prototype());
|
||||
return realm.create<Promise>(realm.intrinsics().promise_prototype());
|
||||
}
|
||||
|
||||
// 27.2 Promise Objects, https://tc39.es/ecma262/#sec-promise-objects
|
||||
|
|
|
@ -63,7 +63,7 @@ ThrowCompletionOr<NonnullGCPtr<PromiseCapability>> new_promise_capability(VM& vm
|
|||
// 2. NOTE: C is assumed to be a constructor function that supports the parameter conventions of the Promise constructor (see 27.2.3.1).
|
||||
|
||||
// 3. Let resolvingFunctions be the Record { [[Resolve]]: undefined, [[Reject]]: undefined }.
|
||||
auto resolving_functions = vm.heap().allocate<ResolvingFunctions>(realm);
|
||||
auto resolving_functions = realm.create<ResolvingFunctions>();
|
||||
|
||||
// 4. Let executorClosure be a new Abstract Closure with parameters (resolve, reject) that captures resolvingFunctions and performs the following steps when called:
|
||||
auto executor_closure = [resolving_functions](auto& vm) -> ThrowCompletionOr<Value> {
|
||||
|
|
|
@ -62,7 +62,7 @@ void PromiseResolvingElementFunction::visit_edges(Cell::Visitor& visitor)
|
|||
|
||||
NonnullGCPtr<PromiseAllResolveElementFunction> PromiseAllResolveElementFunction::create(Realm& realm, size_t index, PromiseValueList& values, NonnullGCPtr<PromiseCapability const> capability, RemainingElements& remaining_elements)
|
||||
{
|
||||
return realm.heap().allocate<PromiseAllResolveElementFunction>(realm, index, values, capability, remaining_elements, realm.intrinsics().function_prototype());
|
||||
return realm.create<PromiseAllResolveElementFunction>(index, values, capability, remaining_elements, realm.intrinsics().function_prototype());
|
||||
}
|
||||
|
||||
PromiseAllResolveElementFunction::PromiseAllResolveElementFunction(size_t index, PromiseValueList& values, NonnullGCPtr<PromiseCapability const> capability, RemainingElements& remaining_elements, Object& prototype)
|
||||
|
@ -94,7 +94,7 @@ ThrowCompletionOr<Value> PromiseAllResolveElementFunction::resolve_element()
|
|||
|
||||
NonnullGCPtr<PromiseAllSettledResolveElementFunction> PromiseAllSettledResolveElementFunction::create(Realm& realm, size_t index, PromiseValueList& values, NonnullGCPtr<PromiseCapability const> capability, RemainingElements& remaining_elements)
|
||||
{
|
||||
return realm.heap().allocate<PromiseAllSettledResolveElementFunction>(realm, index, values, capability, remaining_elements, realm.intrinsics().function_prototype());
|
||||
return realm.create<PromiseAllSettledResolveElementFunction>(index, values, capability, remaining_elements, realm.intrinsics().function_prototype());
|
||||
}
|
||||
|
||||
PromiseAllSettledResolveElementFunction::PromiseAllSettledResolveElementFunction(size_t index, PromiseValueList& values, NonnullGCPtr<PromiseCapability const> capability, RemainingElements& remaining_elements, Object& prototype)
|
||||
|
@ -135,7 +135,7 @@ ThrowCompletionOr<Value> PromiseAllSettledResolveElementFunction::resolve_elemen
|
|||
|
||||
NonnullGCPtr<PromiseAllSettledRejectElementFunction> PromiseAllSettledRejectElementFunction::create(Realm& realm, size_t index, PromiseValueList& values, NonnullGCPtr<PromiseCapability const> capability, RemainingElements& remaining_elements)
|
||||
{
|
||||
return realm.heap().allocate<PromiseAllSettledRejectElementFunction>(realm, index, values, capability, remaining_elements, realm.intrinsics().function_prototype());
|
||||
return realm.create<PromiseAllSettledRejectElementFunction>(index, values, capability, remaining_elements, realm.intrinsics().function_prototype());
|
||||
}
|
||||
|
||||
PromiseAllSettledRejectElementFunction::PromiseAllSettledRejectElementFunction(size_t index, PromiseValueList& values, NonnullGCPtr<PromiseCapability const> capability, RemainingElements& remaining_elements, Object& prototype)
|
||||
|
@ -176,7 +176,7 @@ ThrowCompletionOr<Value> PromiseAllSettledRejectElementFunction::resolve_element
|
|||
|
||||
NonnullGCPtr<PromiseAnyRejectElementFunction> PromiseAnyRejectElementFunction::create(Realm& realm, size_t index, PromiseValueList& errors, NonnullGCPtr<PromiseCapability const> capability, RemainingElements& remaining_elements)
|
||||
{
|
||||
return realm.heap().allocate<PromiseAnyRejectElementFunction>(realm, index, errors, capability, remaining_elements, realm.intrinsics().function_prototype());
|
||||
return realm.create<PromiseAnyRejectElementFunction>(index, errors, capability, remaining_elements, realm.intrinsics().function_prototype());
|
||||
}
|
||||
|
||||
PromiseAnyRejectElementFunction::PromiseAnyRejectElementFunction(size_t index, PromiseValueList& errors, NonnullGCPtr<PromiseCapability const> capability, RemainingElements& remaining_elements, Object& prototype)
|
||||
|
|
|
@ -16,7 +16,7 @@ JS_DEFINE_ALLOCATOR(PromiseResolvingFunction);
|
|||
|
||||
NonnullGCPtr<PromiseResolvingFunction> PromiseResolvingFunction::create(Realm& realm, Promise& promise, AlreadyResolved& already_resolved, FunctionType function)
|
||||
{
|
||||
return realm.heap().allocate<PromiseResolvingFunction>(realm, promise, already_resolved, move(function), realm.intrinsics().function_prototype());
|
||||
return realm.create<PromiseResolvingFunction>(promise, already_resolved, move(function), realm.intrinsics().function_prototype());
|
||||
}
|
||||
|
||||
PromiseResolvingFunction::PromiseResolvingFunction(Promise& promise, AlreadyResolved& already_resolved, FunctionType native_function, Object& prototype)
|
||||
|
|
|
@ -38,7 +38,7 @@ struct RecursionDepthUpdater {
|
|||
|
||||
NonnullGCPtr<ProxyObject> ProxyObject::create(Realm& realm, Object& target, Object& handler)
|
||||
{
|
||||
return realm.heap().allocate<ProxyObject>(realm, target, handler, realm.intrinsics().object_prototype());
|
||||
return realm.create<ProxyObject>(target, handler, realm.intrinsics().object_prototype());
|
||||
}
|
||||
|
||||
ProxyObject::ProxyObject(Object& target, Object& handler, Object& prototype)
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <LibJS/Bytecode/Builtins.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
#include <LibJS/Heap/CellAllocator.h>
|
||||
#include <LibJS/Heap/Heap.h>
|
||||
#include <LibJS/Runtime/Intrinsics.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
|
||||
|
@ -31,6 +32,14 @@ public:
|
|||
virtual void visit_edges(Cell::Visitor&) { }
|
||||
};
|
||||
|
||||
template<typename T, typename... Args>
|
||||
NonnullGCPtr<T> create(Args&&... args)
|
||||
{
|
||||
auto object = heap().allocate_without_realm<T>(forward<Args>(args)...);
|
||||
static_cast<Cell*>(object)->initialize(*this);
|
||||
return *object;
|
||||
}
|
||||
|
||||
static ThrowCompletionOr<NonnullOwnPtr<ExecutionContext>> initialize_host_defined_realm(VM&, Function<Object*(Realm&)> create_global_object, Function<Object*(Realm&)> create_global_this_value);
|
||||
|
||||
[[nodiscard]] Object& global_object() const { return *m_global_object; }
|
||||
|
|
|
@ -148,12 +148,12 @@ ThrowCompletionOr<ByteString> parse_regex_pattern(VM& vm, StringView pattern, bo
|
|||
|
||||
NonnullGCPtr<RegExpObject> RegExpObject::create(Realm& realm)
|
||||
{
|
||||
return realm.heap().allocate<RegExpObject>(realm, realm.intrinsics().regexp_prototype());
|
||||
return realm.create<RegExpObject>(realm.intrinsics().regexp_prototype());
|
||||
}
|
||||
|
||||
NonnullGCPtr<RegExpObject> RegExpObject::create(Realm& realm, Regex<ECMA262> regex, ByteString pattern, ByteString flags)
|
||||
{
|
||||
return realm.heap().allocate<RegExpObject>(realm, move(regex), move(pattern), move(flags), realm.intrinsics().regexp_prototype());
|
||||
return realm.create<RegExpObject>(move(regex), move(pattern), move(flags), realm.intrinsics().regexp_prototype());
|
||||
}
|
||||
|
||||
RegExpObject::RegExpObject(Object& prototype)
|
||||
|
|
|
@ -14,7 +14,7 @@ JS_DEFINE_ALLOCATOR(RegExpStringIterator);
|
|||
// 22.2.9.1 CreateRegExpStringIterator ( R, S, global, fullUnicode ), https://tc39.es/ecma262/#sec-createregexpstringiterator
|
||||
NonnullGCPtr<RegExpStringIterator> RegExpStringIterator::create(Realm& realm, Object& regexp_object, Utf16String string, bool global, bool unicode)
|
||||
{
|
||||
return realm.heap().allocate<RegExpStringIterator>(realm, realm.intrinsics().regexp_string_iterator_prototype(), regexp_object, move(string), global, unicode);
|
||||
return realm.create<RegExpStringIterator>(realm.intrinsics().regexp_string_iterator_prototype(), regexp_object, move(string), global, unicode);
|
||||
}
|
||||
|
||||
RegExpStringIterator::RegExpStringIterator(Object& prototype, Object& regexp_object, Utf16String string, bool global, bool unicode)
|
||||
|
|
|
@ -14,7 +14,7 @@ JS_DEFINE_ALLOCATOR(Set);
|
|||
|
||||
NonnullGCPtr<Set> Set::create(Realm& realm)
|
||||
{
|
||||
return realm.heap().allocate<Set>(realm, realm.intrinsics().set_prototype());
|
||||
return realm.create<Set>(realm.intrinsics().set_prototype());
|
||||
}
|
||||
|
||||
Set::Set(Object& prototype)
|
||||
|
|
|
@ -13,7 +13,7 @@ JS_DEFINE_ALLOCATOR(SetIterator);
|
|||
|
||||
NonnullGCPtr<SetIterator> SetIterator::create(Realm& realm, Set& set, Object::PropertyKind iteration_kind)
|
||||
{
|
||||
return realm.heap().allocate<SetIterator>(realm, set, iteration_kind, realm.intrinsics().set_iterator_prototype());
|
||||
return realm.create<SetIterator>(set, iteration_kind, realm.intrinsics().set_iterator_prototype());
|
||||
}
|
||||
|
||||
SetIterator::SetIterator(Set& set, Object::PropertyKind iteration_kind, Object& prototype)
|
||||
|
|
|
@ -14,7 +14,7 @@ JS_DEFINE_ALLOCATOR(StringIterator);
|
|||
|
||||
NonnullGCPtr<StringIterator> StringIterator::create(Realm& realm, String string)
|
||||
{
|
||||
return realm.heap().allocate<StringIterator>(realm, move(string), realm.intrinsics().string_iterator_prototype());
|
||||
return realm.create<StringIterator>(move(string), realm.intrinsics().string_iterator_prototype());
|
||||
}
|
||||
|
||||
StringIterator::StringIterator(String string, Object& prototype)
|
||||
|
|
|
@ -28,7 +28,7 @@ NonnullGCPtr<StringObject> StringObject::create(Realm& realm, PrimitiveString& p
|
|||
// 7. Let length be the length of value.
|
||||
// 8. Perform ! DefinePropertyOrThrow(S, "length", PropertyDescriptor { [[Value]]: 𝔽(length), [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }).
|
||||
// 9. Return S.
|
||||
return realm.heap().allocate<StringObject>(realm, primitive_string, prototype);
|
||||
return realm.create<StringObject>(primitive_string, prototype);
|
||||
}
|
||||
|
||||
StringObject::StringObject(PrimitiveString& string, Object& prototype)
|
||||
|
|
|
@ -14,7 +14,7 @@ JS_DEFINE_ALLOCATOR(SuppressedError);
|
|||
|
||||
NonnullGCPtr<SuppressedError> SuppressedError::create(Realm& realm)
|
||||
{
|
||||
return realm.heap().allocate<SuppressedError>(realm, realm.intrinsics().suppressed_error_prototype());
|
||||
return realm.create<SuppressedError>(realm.intrinsics().suppressed_error_prototype());
|
||||
}
|
||||
|
||||
SuppressedError::SuppressedError(Object& prototype)
|
||||
|
|
|
@ -14,7 +14,7 @@ JS_DEFINE_ALLOCATOR(SymbolObject);
|
|||
|
||||
NonnullGCPtr<SymbolObject> SymbolObject::create(Realm& realm, Symbol& primitive_symbol)
|
||||
{
|
||||
return realm.heap().allocate<SymbolObject>(realm, primitive_symbol, realm.intrinsics().symbol_prototype());
|
||||
return realm.create<SymbolObject>(primitive_symbol, realm.intrinsics().symbol_prototype());
|
||||
}
|
||||
|
||||
SymbolObject::SymbolObject(Symbol& symbol, Object& prototype)
|
||||
|
|
|
@ -38,7 +38,7 @@ void Temporal::initialize(Realm& realm)
|
|||
define_direct_property(vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Temporal"_string), Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_direct_property(vm.names.Now, heap().allocate<Now>(realm, realm), attr);
|
||||
define_direct_property(vm.names.Now, realm.create<Now>(realm), attr);
|
||||
define_intrinsic_accessor(vm.names.Calendar, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_calendar_constructor(); });
|
||||
define_intrinsic_accessor(vm.names.Duration, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_duration_constructor(); });
|
||||
define_intrinsic_accessor(vm.names.Instant, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_instant_constructor(); });
|
||||
|
|
|
@ -453,7 +453,7 @@ void TypedArrayBase::visit_edges(Visitor& visitor)
|
|||
{ \
|
||||
auto* prototype = TRY(get_prototype_from_constructor(realm.vm(), new_target, &Intrinsics::snake_name##_prototype)); \
|
||||
auto array_buffer = TRY(ArrayBuffer::create(realm, length * sizeof(UnderlyingBufferDataType))); \
|
||||
return realm.heap().allocate<ClassName>(realm, *prototype, length, *array_buffer); \
|
||||
return realm.create<ClassName>(*prototype, length, *array_buffer); \
|
||||
} \
|
||||
\
|
||||
ThrowCompletionOr<NonnullGCPtr<ClassName>> ClassName::create(Realm& realm, u32 length) \
|
||||
|
@ -464,7 +464,7 @@ void TypedArrayBase::visit_edges(Visitor& visitor)
|
|||
\
|
||||
NonnullGCPtr<ClassName> ClassName::create(Realm& realm, u32 length, ArrayBuffer& array_buffer) \
|
||||
{ \
|
||||
return realm.heap().allocate<ClassName>(realm, realm.intrinsics().snake_name##_prototype(), length, array_buffer); \
|
||||
return realm.create<ClassName>(realm.intrinsics().snake_name##_prototype(), length, array_buffer); \
|
||||
} \
|
||||
\
|
||||
ClassName::ClassName(Object& prototype, u32 length, ArrayBuffer& array_buffer) \
|
||||
|
|
|
@ -12,7 +12,7 @@ JS_DEFINE_ALLOCATOR(WeakMap);
|
|||
|
||||
NonnullGCPtr<WeakMap> WeakMap::create(Realm& realm)
|
||||
{
|
||||
return realm.heap().allocate<WeakMap>(realm, realm.intrinsics().weak_map_prototype());
|
||||
return realm.create<WeakMap>(realm.intrinsics().weak_map_prototype());
|
||||
}
|
||||
|
||||
WeakMap::WeakMap(Object& prototype)
|
||||
|
|
|
@ -12,12 +12,12 @@ JS_DEFINE_ALLOCATOR(WeakRef);
|
|||
|
||||
NonnullGCPtr<WeakRef> WeakRef::create(Realm& realm, Object& value)
|
||||
{
|
||||
return realm.heap().allocate<WeakRef>(realm, value, realm.intrinsics().weak_ref_prototype());
|
||||
return realm.create<WeakRef>(value, realm.intrinsics().weak_ref_prototype());
|
||||
}
|
||||
|
||||
NonnullGCPtr<WeakRef> WeakRef::create(Realm& realm, Symbol& value)
|
||||
{
|
||||
return realm.heap().allocate<WeakRef>(realm, value, realm.intrinsics().weak_ref_prototype());
|
||||
return realm.create<WeakRef>(value, realm.intrinsics().weak_ref_prototype());
|
||||
}
|
||||
|
||||
WeakRef::WeakRef(Object& value, Object& prototype)
|
||||
|
|
|
@ -12,7 +12,7 @@ JS_DEFINE_ALLOCATOR(WeakSet);
|
|||
|
||||
NonnullGCPtr<WeakSet> WeakSet::create(Realm& realm)
|
||||
{
|
||||
return realm.heap().allocate<WeakSet>(realm, realm.intrinsics().weak_set_prototype());
|
||||
return realm.create<WeakSet>(realm.intrinsics().weak_set_prototype());
|
||||
}
|
||||
|
||||
WeakSet::WeakSet(Object& prototype)
|
||||
|
|
|
@ -24,7 +24,7 @@ ThrowCompletionOr<NonnullGCPtr<WrappedFunction>> WrappedFunction::create(Realm&
|
|||
// 5. Set wrapped.[[WrappedTargetFunction]] to Target.
|
||||
// 6. Set wrapped.[[Realm]] to callerRealm.
|
||||
auto& prototype = *caller_realm.intrinsics().function_prototype();
|
||||
auto wrapped = vm.heap().allocate<WrappedFunction>(realm, caller_realm, target, prototype);
|
||||
auto wrapped = realm.create<WrappedFunction>(caller_realm, target, prototype);
|
||||
|
||||
// 7. Let result be CopyNameAndLength(wrapped, Target).
|
||||
auto result = copy_name_and_length(vm, *wrapped, target);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue