mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 20:12:43 +00:00 
			
		
		
		
	LibJS: Make Heap::allocate<T>() infallible
Stop worrying about tiny OOMs. Work towards #20449. While going through these, I also changed the function signature in many places where returning ThrowCompletionOr<T> is no longer necessary.
This commit is contained in:
		
							parent
							
								
									980e7164fe
								
							
						
					
					
						commit
						72c9f56c66
					
				
					 337 changed files with 1229 additions and 1251 deletions
				
			
		|  | @ -3473,7 +3473,7 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> @constructor_class@::constru | |||
|         // 3. Set element's namespace to the HTML namespace.
 | ||||
|         // 4. Set element's namespace prefix to null.
 | ||||
|         // 5. Set element's local name to definition's local name.
 | ||||
|         auto element = realm.heap().allocate<@fully_qualified_name@>(realm, window.associated_document(), DOM::QualifiedName { definition->local_name().to_deprecated_string(), {}, Namespace::HTML }).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|         auto element = realm.heap().allocate<@fully_qualified_name@>(realm, window.associated_document(), DOM::QualifiedName { definition->local_name().to_deprecated_string(), {}, Namespace::HTML }); | ||||
| 
 | ||||
|         // https://webidl.spec.whatwg.org/#internally-create-a-new-object-implementing-the-interface
 | ||||
|         // Important steps from "internally create a new object implementing the interface"
 | ||||
|  |  | |||
|  | @ -157,7 +157,7 @@ namespace Web::Bindings { | |||
| template<> | ||||
| void Intrinsics::create_web_namespace<@namespace_class@>(JS::Realm& realm) | ||||
| { | ||||
|     auto namespace_object = heap().allocate<@namespace_class@>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     auto namespace_object = heap().allocate<@namespace_class@>(realm, realm); | ||||
|     m_namespaces.set("@interface_name@"sv, namespace_object); | ||||
| 
 | ||||
|     [[maybe_unused]] static constexpr u8 attr = JS::Attribute::Writable | JS::Attribute::Configurable;)~~~"); | ||||
|  | @ -189,10 +189,10 @@ void Intrinsics::create_web_prototype_and_constructor<@prototype_class@>(JS::Rea | |||
| { | ||||
|     auto& vm = realm.vm(); | ||||
| 
 | ||||
|     auto prototype = heap().allocate<@prototype_class@>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     auto prototype = heap().allocate<@prototype_class@>(realm, realm); | ||||
|     m_prototypes.set("@interface_name@"sv, prototype); | ||||
| 
 | ||||
|     auto constructor = heap().allocate<@constructor_class@>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     auto constructor = heap().allocate<@constructor_class@>(realm, realm); | ||||
|     m_constructors.set("@interface_name@"sv, constructor); | ||||
| 
 | ||||
|     prototype->define_direct_property(vm.names.constructor, constructor.ptr(), JS::Attribute::Writable | JS::Attribute::Configurable); | ||||
|  | @ -203,7 +203,7 @@ void Intrinsics::create_web_prototype_and_constructor<@prototype_class@>(JS::Rea | |||
|             gen.set("legacy_interface_name", legacy_constructor->name); | ||||
|             gen.set("legacy_constructor_class", legacy_constructor->constructor_class); | ||||
|             gen.append(R"~~~( | ||||
|     auto legacy_constructor = heap().allocate<@legacy_constructor_class@>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     auto legacy_constructor = heap().allocate<@legacy_constructor_class@>(realm, realm); | ||||
|     m_constructors.set("@legacy_interface_name@"sv, legacy_constructor); | ||||
| 
 | ||||
|     legacy_constructor->define_direct_property(vm.names.name, JS::PrimitiveString::create(vm, "@legacy_interface_name@"_string), JS::Attribute::Configurable);)~~~"); | ||||
|  |  | |||
|  | @ -56,7 +56,7 @@ public: | |||
|     static JS::ThrowCompletionOr<WebAssemblyModule*> create(JS::Realm& realm, Wasm::Module module, HashMap<Wasm::Linker::Name, Wasm::ExternValue> const& imports) | ||||
|     { | ||||
|         auto& vm = realm.vm(); | ||||
|         auto instance = MUST_OR_THROW_OOM(realm.heap().allocate<WebAssemblyModule>(realm, realm.intrinsics().object_prototype())); | ||||
|         auto instance = realm.heap().allocate<WebAssemblyModule>(realm, realm.intrinsics().object_prototype()); | ||||
|         instance->m_module = move(module); | ||||
|         Wasm::Linker linker(*instance->m_module); | ||||
|         linker.link(imports); | ||||
|  |  | |||
|  | @ -28,7 +28,7 @@ Workbook::Workbook(Vector<NonnullRefPtr<Sheet>>&& sheets, GUI::Window& parent_wi | |||
| { | ||||
|     auto& realm = *m_root_execution_context->realm; | ||||
|     auto& vm = realm.vm(); | ||||
|     m_workbook_object = vm.heap().allocate<WorkbookObject>(realm, realm, *this).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     m_workbook_object = vm.heap().allocate<WorkbookObject>(realm, realm, *this); | ||||
|     realm.global_object().define_direct_property("workbook", workbook_object(), JS::default_attributes); | ||||
| 
 | ||||
|     m_main_execution_context.this_value = &realm.global_object(); | ||||
|  |  | |||
|  | @ -30,8 +30,8 @@ void $262Object::initialize(Realm& realm) | |||
| { | ||||
|     Base::initialize(realm); | ||||
| 
 | ||||
|     m_agent = MUST(vm().heap().allocate<AgentObject>(realm, realm)); | ||||
|     m_is_htmldda = MUST(vm().heap().allocate<IsHTMLDDA>(realm, realm)); | ||||
|     m_agent = vm().heap().allocate<AgentObject>(realm, realm); | ||||
|     m_is_htmldda = vm().heap().allocate<IsHTMLDDA>(realm, realm); | ||||
| 
 | ||||
|     u8 attr = Attribute::Writable | Attribute::Configurable; | ||||
|     define_native_function(realm, "clearKeptObjects", clear_kept_objects, 0, attr); | ||||
|  |  | |||
|  | @ -18,7 +18,7 @@ void GlobalObject::initialize(Realm& realm) | |||
| { | ||||
|     Base::initialize(realm); | ||||
| 
 | ||||
|     m_$262 = MUST(vm().heap().allocate<$262Object>(realm, realm)); | ||||
|     m_$262 = vm().heap().allocate<$262Object>(realm, realm); | ||||
| 
 | ||||
|     // https://github.com/tc39/test262/blob/master/INTERPRETING.md#host-defined-functions
 | ||||
|     u8 attr = Attribute::Writable | Attribute::Configurable; | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| /*
 | ||||
|  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> | ||||
|  * Copyright (c) 2020-2023, Andreas Kling <kling@serenityos.org> | ||||
|  * | ||||
|  * SPDX-License-Identifier: BSD-2-Clause | ||||
|  */ | ||||
|  | @ -43,7 +43,7 @@ public: | |||
|     } | ||||
| 
 | ||||
|     template<typename T, typename... Args> | ||||
|     ThrowCompletionOr<NonnullGCPtr<T>> allocate(Realm& realm, Args&&... args) | ||||
|     NonnullGCPtr<T> allocate(Realm& realm, Args&&... args) | ||||
|     { | ||||
|         auto* memory = allocate_cell(sizeof(T)); | ||||
|         new (memory) T(forward<Args>(args)...); | ||||
|  |  | |||
|  | @ -114,7 +114,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)).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     auto module_namespace = vm.heap().allocate<ModuleNamespaceObject>(realm, realm, this, move(unambiguous_names)); | ||||
| 
 | ||||
|     // 9. Set module.[[Namespace]] to M.
 | ||||
|     m_namespace = make_handle(module_namespace); | ||||
|  |  | |||
|  | @ -1103,7 +1103,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).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     auto object = vm.heap().allocate<ArgumentsObject>(realm, realm, environment); | ||||
| 
 | ||||
|     // 14. Let index be 0.
 | ||||
|     // 15. Repeat, while index < len,
 | ||||
|  |  | |||
|  | @ -149,7 +149,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 MUST_OR_THROW_OOM(realm.heap().allocate<T>(realm, forward<Args>(args)..., *prototype)); | ||||
|     return realm.heap().allocate<T>(realm, forward<Args>(args)..., *prototype); | ||||
| } | ||||
| 
 | ||||
| // 14.1 MergeLists ( a, b ), https://tc39.es/proposal-temporal/#sec-temporal-mergelists
 | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ namespace JS { | |||
| 
 | ||||
| NonnullGCPtr<AggregateError> AggregateError::create(Realm& realm) | ||||
| { | ||||
|     return realm.heap().allocate<AggregateError>(realm, realm.intrinsics().aggregate_error_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<AggregateError>(realm, realm.intrinsics().aggregate_error_prototype()); | ||||
| } | ||||
| 
 | ||||
| AggregateError::AggregateError(Object& prototype) | ||||
|  |  | |||
|  | @ -32,7 +32,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 = MUST_OR_THROW_OOM(realm.heap().allocate<Array>(realm, *prototype)); | ||||
|     auto array = realm.heap().allocate<Array>(realm, *prototype); | ||||
| 
 | ||||
|     // 6. Perform ! OrdinaryDefineOwnProperty(A, "length", PropertyDescriptor { [[Value]]: 𝔽(length), [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
 | ||||
|     MUST(array->internal_define_own_property(vm.names.length, { .value = Value(length), .writable = true, .enumerable = false, .configurable = false })); | ||||
|  |  | |||
|  | @ -17,17 +17,17 @@ ThrowCompletionOr<NonnullGCPtr<ArrayBuffer>> ArrayBuffer::create(Realm& realm, s | |||
|     if (buffer.is_error()) | ||||
|         return realm.vm().throw_completion<RangeError>(ErrorType::NotEnoughMemoryToAllocate, byte_length); | ||||
| 
 | ||||
|     return MUST_OR_THROW_OOM(realm.heap().allocate<ArrayBuffer>(realm, buffer.release_value(), realm.intrinsics().array_buffer_prototype())); | ||||
|     return realm.heap().allocate<ArrayBuffer>(realm, 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()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<ArrayBuffer>(realm, 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()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<ArrayBuffer>(realm, buffer, realm.intrinsics().array_buffer_prototype()); | ||||
| } | ||||
| 
 | ||||
| ArrayBuffer::ArrayBuffer(ByteBuffer buffer, Object& prototype) | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ namespace JS { | |||
| 
 | ||||
| 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()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<ArrayIterator>(realm, array, iteration_kind, realm.intrinsics().array_iterator_prototype()); | ||||
| } | ||||
| 
 | ||||
| ArrayIterator::ArrayIterator(Value array, Object::PropertyKind iteration_kind, Object& prototype) | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ namespace JS { | |||
| 
 | ||||
| NonnullGCPtr<AsyncFromSyncIterator> AsyncFromSyncIterator::create(Realm& realm, IteratorRecord sync_iterator_record) | ||||
| { | ||||
|     return realm.heap().allocate<AsyncFromSyncIterator>(realm, realm, sync_iterator_record).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<AsyncFromSyncIterator>(realm, realm, sync_iterator_record); | ||||
| } | ||||
| 
 | ||||
| AsyncFromSyncIterator::AsyncFromSyncIterator(Realm& realm, IteratorRecord sync_iterator_record) | ||||
|  |  | |||
|  | @ -14,12 +14,12 @@ | |||
| 
 | ||||
| namespace JS { | ||||
| 
 | ||||
| ThrowCompletionOr<Value> AsyncFunctionDriverWrapper::create(Realm& realm, GeneratorObject* generator_object) | ||||
| NonnullGCPtr<Promise> AsyncFunctionDriverWrapper::create(Realm& realm, GeneratorObject* generator_object) | ||||
| { | ||||
|     auto top_level_promise = Promise::create(realm); | ||||
|     // Note: This generates a handle to itself, which it clears upon completing its execution
 | ||||
|     //       The top_level_promise is also kept alive by this Wrapper
 | ||||
|     auto wrapper = MUST_OR_THROW_OOM(realm.heap().allocate<AsyncFunctionDriverWrapper>(realm, realm, *generator_object, *top_level_promise)); | ||||
|     auto wrapper = realm.heap().allocate<AsyncFunctionDriverWrapper>(realm, 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); | ||||
|  |  | |||
|  | @ -23,7 +23,7 @@ public: | |||
|         Yes, | ||||
|     }; | ||||
| 
 | ||||
|     static ThrowCompletionOr<Value> create(Realm&, GeneratorObject*); | ||||
|     [[nodiscard]] static NonnullGCPtr<Promise> create(Realm&, GeneratorObject*); | ||||
| 
 | ||||
|     virtual ~AsyncFunctionDriverWrapper() override = default; | ||||
|     void visit_edges(Cell::Visitor&) override; | ||||
|  |  | |||
|  | @ -20,7 +20,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 = MUST_OR_THROW_OOM(realm.heap().allocate<AsyncGenerator>(realm, realm, generating_function_prototype_object, move(execution_context))); | ||||
|     auto object = realm.heap().allocate<AsyncGenerator>(realm, realm, generating_function_prototype_object, move(execution_context)); | ||||
|     object->m_generating_function = generating_function; | ||||
|     object->m_frame = move(frame); | ||||
|     object->m_previous_value = initial_value; | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ namespace JS { | |||
| 
 | ||||
| NonnullGCPtr<BigIntObject> BigIntObject::create(Realm& realm, BigInt& bigint) | ||||
| { | ||||
|     return realm.heap().allocate<BigIntObject>(realm, bigint, realm.intrinsics().bigint_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<BigIntObject>(realm, bigint, realm.intrinsics().bigint_prototype()); | ||||
| } | ||||
| 
 | ||||
| BigIntObject::BigIntObject(BigInt& bigint, Object& prototype) | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ namespace JS { | |||
| 
 | ||||
| NonnullGCPtr<BooleanObject> BooleanObject::create(Realm& realm, bool value) | ||||
| { | ||||
|     return realm.heap().allocate<BooleanObject>(realm, value, realm.intrinsics().boolean_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<BooleanObject>(realm, value, realm.intrinsics().boolean_prototype()); | ||||
| } | ||||
| 
 | ||||
| BooleanObject::BooleanObject(bool value, Object& prototype) | ||||
|  |  | |||
|  | @ -26,7 +26,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 = MUST_OR_THROW_OOM(realm.heap().allocate<BoundFunction>(realm, realm, target_function, bound_this, move(bound_arguments), prototype)); | ||||
|     auto object = realm.heap().allocate<BoundFunction>(realm, realm, target_function, bound_this, move(bound_arguments), prototype); | ||||
| 
 | ||||
|     // 10. Return obj.
 | ||||
|     return object; | ||||
|  |  | |||
|  | @ -10,7 +10,7 @@ namespace JS { | |||
| 
 | ||||
| NonnullGCPtr<DataView> DataView::create(Realm& realm, ArrayBuffer* viewed_buffer, size_t byte_length, size_t byte_offset) | ||||
| { | ||||
|     return realm.heap().allocate<DataView>(realm, viewed_buffer, byte_length, byte_offset, realm.intrinsics().data_view_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<DataView>(realm, viewed_buffer, byte_length, byte_offset, realm.intrinsics().data_view_prototype()); | ||||
| } | ||||
| 
 | ||||
| DataView::DataView(ArrayBuffer* viewed_buffer, size_t byte_length, size_t byte_offset, Object& prototype) | ||||
|  |  | |||
|  | @ -25,7 +25,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()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<Date>(realm, date_value, realm.intrinsics().date_prototype()); | ||||
| } | ||||
| 
 | ||||
| Date::Date(double date_value, Object& prototype) | ||||
|  |  | |||
|  | @ -48,12 +48,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, might_need_arguments_object, contains_direct_call_to_eval, is_arrow_function, move(class_field_initializer_name)).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     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, might_need_arguments_object, contains_direct_call_to_eval, is_arrow_function, move(class_field_initializer_name)); | ||||
| } | ||||
| 
 | ||||
| NonnullGCPtr<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& realm, DeprecatedFlyString name, Object& prototype, DeprecatedString 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, bool might_need_arguments_object, bool contains_direct_call_to_eval, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name) | ||||
| { | ||||
|     return realm.heap().allocate<ECMAScriptFunctionObject>(realm, move(name), move(source_text), ecmascript_code, move(parameters), m_function_length, move(local_variables_names), parent_environment, private_environment, prototype, kind, is_strict, might_need_arguments_object, contains_direct_call_to_eval, is_arrow_function, move(class_field_initializer_name)).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     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, might_need_arguments_object, contains_direct_call_to_eval, is_arrow_function, move(class_field_initializer_name)); | ||||
| } | ||||
| 
 | ||||
| ECMAScriptFunctionObject::ECMAScriptFunctionObject(DeprecatedFlyString name, DeprecatedString 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, bool might_need_arguments_object, bool contains_direct_call_to_eval, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name) | ||||
|  | @ -118,7 +118,7 @@ void ECMAScriptFunctionObject::initialize(Realm& realm) | |||
|         Object* prototype = nullptr; | ||||
|         switch (m_kind) { | ||||
|         case FunctionKind::Normal: | ||||
|             prototype = MUST(vm.heap().allocate<Object>(realm, realm.intrinsics().new_ordinary_function_prototype_object_shape())); | ||||
|             prototype = vm.heap().allocate<Object>(realm, realm.intrinsics().new_ordinary_function_prototype_object_shape()); | ||||
|             MUST(prototype->define_property_or_throw(vm.names.constructor, { .value = this, .writable = true, .enumerable = false, .configurable = true })); | ||||
|             break; | ||||
|         case FunctionKind::Generator: | ||||
|  | @ -1088,7 +1088,7 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body() | |||
|     // NOTE: Async functions are entirely transformed to generator functions, and wrapped in a custom driver that returns a promise
 | ||||
|     //       See AwaitExpression::generate_bytecode() for the transformation.
 | ||||
|     if (m_kind == FunctionKind::Async) | ||||
|         return { Completion::Type::Return, TRY(AsyncFunctionDriverWrapper::create(realm, generator_object)), {} }; | ||||
|         return { Completion::Type::Return, AsyncFunctionDriverWrapper::create(realm, generator_object), {} }; | ||||
| 
 | ||||
|     VERIFY(m_kind == FunctionKind::Generator); | ||||
|     return { Completion::Type::Return, generator_object, {} }; | ||||
|  |  | |||
|  | @ -32,7 +32,7 @@ SourceRange const& TracebackFrame::source_range() const | |||
| 
 | ||||
| NonnullGCPtr<Error> Error::create(Realm& realm) | ||||
| { | ||||
|     return realm.heap().allocate<Error>(realm, realm.intrinsics().error_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<Error>(realm, realm.intrinsics().error_prototype()); | ||||
| } | ||||
| 
 | ||||
| NonnullGCPtr<Error> Error::create(Realm& realm, String message) | ||||
|  | @ -119,29 +119,29 @@ ThrowCompletionOr<String> Error::stack_string(VM& vm) const | |||
|     return stack_string_builder.to_string(); | ||||
| } | ||||
| 
 | ||||
| #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType)                                                                         \ | ||||
|     NonnullGCPtr<ClassName> ClassName::create(Realm& realm)                                                                                                      \ | ||||
|     {                                                                                                                                                            \ | ||||
|         return realm.heap().allocate<ClassName>(realm, realm.intrinsics().snake_name##_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); \ | ||||
|     }                                                                                                                                                            \ | ||||
|                                                                                                                                                                  \ | ||||
|     NonnullGCPtr<ClassName> ClassName::create(Realm& realm, String message)                                                                                      \ | ||||
|     {                                                                                                                                                            \ | ||||
|         auto& vm = realm.vm();                                                                                                                                   \ | ||||
|         auto error = ClassName::create(realm);                                                                                                                   \ | ||||
|         u8 attr = Attribute::Writable | Attribute::Configurable;                                                                                                 \ | ||||
|         error->define_direct_property(vm.names.message, PrimitiveString::create(vm, move(message)), attr);                                                       \ | ||||
|         return error;                                                                                                                                            \ | ||||
|     }                                                                                                                                                            \ | ||||
|                                                                                                                                                                  \ | ||||
|     ThrowCompletionOr<NonnullGCPtr<ClassName>> ClassName::create(Realm& realm, StringView message)                                                               \ | ||||
|     {                                                                                                                                                            \ | ||||
|         return create(realm, TRY_OR_THROW_OOM(realm.vm(), String::from_utf8(message)));                                                                          \ | ||||
|     }                                                                                                                                                            \ | ||||
|                                                                                                                                                                  \ | ||||
|     ClassName::ClassName(Object& prototype)                                                                                                                      \ | ||||
|         : Error(prototype)                                                                                                                                       \ | ||||
|     {                                                                                                                                                            \ | ||||
| #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType)                   \ | ||||
|     NonnullGCPtr<ClassName> ClassName::create(Realm& realm)                                                \ | ||||
|     {                                                                                                      \ | ||||
|         return realm.heap().allocate<ClassName>(realm, realm.intrinsics().snake_name##_prototype());       \ | ||||
|     }                                                                                                      \ | ||||
|                                                                                                            \ | ||||
|     NonnullGCPtr<ClassName> ClassName::create(Realm& realm, String message)                                \ | ||||
|     {                                                                                                      \ | ||||
|         auto& vm = realm.vm();                                                                             \ | ||||
|         auto error = ClassName::create(realm);                                                             \ | ||||
|         u8 attr = Attribute::Writable | Attribute::Configurable;                                           \ | ||||
|         error->define_direct_property(vm.names.message, PrimitiveString::create(vm, move(message)), attr); \ | ||||
|         return error;                                                                                      \ | ||||
|     }                                                                                                      \ | ||||
|                                                                                                            \ | ||||
|     ThrowCompletionOr<NonnullGCPtr<ClassName>> ClassName::create(Realm& realm, StringView message)         \ | ||||
|     {                                                                                                      \ | ||||
|         return create(realm, TRY_OR_THROW_OOM(realm.vm(), String::from_utf8(message)));                    \ | ||||
|     }                                                                                                      \ | ||||
|                                                                                                            \ | ||||
|     ClassName::ClassName(Object& prototype)                                                                \ | ||||
|         : Error(prototype)                                                                                 \ | ||||
|     {                                                                                                      \ | ||||
|     } | ||||
| 
 | ||||
| JS_ENUMERATE_NATIVE_ERRORS | ||||
|  |  | |||
|  | @ -28,7 +28,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 = MUST_OR_THROW_OOM(realm.heap().allocate<GeneratorObject>(realm, realm, generating_function_prototype_object, move(execution_context))); | ||||
|     auto object = realm.heap().allocate<GeneratorObject>(realm, realm, generating_function_prototype_object, move(execution_context)); | ||||
|     object->m_generating_function = generating_function; | ||||
|     object->m_frame = move(frame); | ||||
|     object->m_previous_value = initial_value; | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ namespace JS::Intl { | |||
| 
 | ||||
| NonnullGCPtr<CollatorCompareFunction> CollatorCompareFunction::create(Realm& realm, Collator& collator) | ||||
| { | ||||
|     return realm.heap().allocate<CollatorCompareFunction>(realm, realm, collator).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<CollatorCompareFunction>(realm, realm, collator); | ||||
| } | ||||
| 
 | ||||
| CollatorCompareFunction::CollatorCompareFunction(Realm& realm, Collator& collator) | ||||
|  |  | |||
|  | @ -16,7 +16,7 @@ namespace JS::Intl { | |||
| // 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()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<DateTimeFormatFunction>(realm, date_time_format, realm.intrinsics().function_prototype()); | ||||
| } | ||||
| 
 | ||||
| DateTimeFormatFunction::DateTimeFormatFunction(DateTimeFormat& date_time_format, Object& prototype) | ||||
|  |  | |||
|  | @ -16,7 +16,7 @@ namespace JS::Intl { | |||
| 
 | ||||
| ThrowCompletionOr<NonnullGCPtr<Locale>> Locale::create(Realm& realm, ::Locale::LocaleID locale_id) | ||||
| { | ||||
|     auto locale = MUST_OR_THROW_OOM(realm.heap().allocate<Locale>(realm, realm.intrinsics().intl_locale_prototype())); | ||||
|     auto locale = realm.heap().allocate<Locale>(realm, realm.intrinsics().intl_locale_prototype()); | ||||
|     locale->set_locale(TRY_OR_THROW_OOM(realm.vm(), locale_id.to_string())); | ||||
| 
 | ||||
|     for (auto& extension : locale_id.extensions) { | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ namespace JS::Intl { | |||
| // 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()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<NumberFormatFunction>(realm, number_format, realm.intrinsics().function_prototype()); | ||||
| } | ||||
| 
 | ||||
| NumberFormatFunction::NumberFormatFunction(NumberFormat& number_format, Object& prototype) | ||||
|  |  | |||
|  | @ -19,7 +19,7 @@ NonnullGCPtr<SegmentIterator> SegmentIterator::create(Realm& realm, Segmenter& s | |||
|     // 4. Set iterator.[[IteratedString]] to string.
 | ||||
|     // 5. Set iterator.[[IteratedStringNextSegmentCodeUnitIndex]] to 0.
 | ||||
|     // 6. Return iterator.
 | ||||
|     return realm.heap().allocate<SegmentIterator>(realm, realm, segmenter, move(string), segments).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<SegmentIterator>(realm, realm, segmenter, move(string), segments); | ||||
| } | ||||
| 
 | ||||
| // 18.6 Segment Iterator Objects, https://tc39.es/ecma402/#sec-segment-iterator-objects
 | ||||
|  |  | |||
|  | @ -18,7 +18,7 @@ NonnullGCPtr<Segments> Segments::create(Realm& realm, Segmenter& segmenter, Utf1 | |||
|     // 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)).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<Segments>(realm, realm, segmenter, move(string)); | ||||
| } | ||||
| 
 | ||||
| // 18.5 Segments Objects, https://tc39.es/ecma402/#sec-segments-objects
 | ||||
|  |  | |||
|  | @ -194,27 +194,27 @@ ThrowCompletionOr<void> Intrinsics::initialize_intrinsics(Realm& realm) | |||
| 
 | ||||
| #define __JS_ENUMERATE(ClassName, snake_name) \ | ||||
|     VERIFY(!m_##snake_name##_prototype);      \ | ||||
|     m_##snake_name##_prototype = heap().allocate<ClassName##Prototype>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     m_##snake_name##_prototype = heap().allocate<ClassName##Prototype>(realm, realm); | ||||
|     JS_ENUMERATE_ITERATOR_PROTOTYPES | ||||
| #undef __JS_ENUMERATE | ||||
| 
 | ||||
|     // These must be initialized separately as they have no companion constructor
 | ||||
|     m_async_from_sync_iterator_prototype = heap().allocate<AsyncFromSyncIteratorPrototype>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     m_async_generator_prototype = heap().allocate<AsyncGeneratorPrototype>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     m_generator_prototype = heap().allocate<GeneratorPrototype>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     m_intl_segments_prototype = heap().allocate<Intl::SegmentsPrototype>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     m_wrap_for_valid_iterator_prototype = heap().allocate<WrapForValidIteratorPrototype>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     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); | ||||
| 
 | ||||
|     // 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).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     m_error_constructor = heap().allocate<ErrorConstructor>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     m_function_constructor = heap().allocate<FunctionConstructor>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     m_error_prototype = heap().allocate<ErrorPrototype>(realm, realm); | ||||
|     m_error_constructor = heap().allocate<ErrorConstructor>(realm, realm); | ||||
|     m_function_constructor = heap().allocate<FunctionConstructor>(realm, realm); | ||||
| 
 | ||||
|     // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
 | ||||
|     m_proxy_constructor = heap().allocate<ProxyConstructor>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     m_proxy_constructor = heap().allocate<ProxyConstructor>(realm, realm); | ||||
| 
 | ||||
|     // Global object functions
 | ||||
|     m_eval_function = NativeFunction::create(realm, GlobalObject::eval, 1, vm.names.eval, &realm); | ||||
|  | @ -229,7 +229,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).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     m_object_constructor = heap().allocate<ObjectConstructor>(realm, realm); | ||||
| 
 | ||||
|     // 10.2.4.1 %ThrowTypeError% ( ), https://tc39.es/ecma262/#sec-%throwtypeerror%
 | ||||
|     m_throw_type_error_function = NativeFunction::create( | ||||
|  | @ -274,52 +274,52 @@ constexpr inline bool IsTypedArrayConstructor = false; | |||
| JS_ENUMERATE_TYPED_ARRAYS | ||||
| #undef __JS_ENUMERATE | ||||
| 
 | ||||
| #define __JS_ENUMERATE_INNER(ClassName, snake_name, PrototypeName, ConstructorName, Namespace, snake_namespace)                                                                                                    \ | ||||
|     void Intrinsics::initialize_##snake_namespace##snake_name()                                                                                                                                                    \ | ||||
|     {                                                                                                                                                                                                              \ | ||||
|         auto& vm = this->vm();                                                                                                                                                                                     \ | ||||
|                                                                                                                                                                                                                    \ | ||||
|         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()).release_allocated_value_but_fixme_should_propagate_errors();                \ | ||||
|             m_##snake_namespace##snake_name##_constructor = heap().allocate<Namespace::ConstructorName>(m_realm, m_realm, *typed_array_constructor()).release_allocated_value_but_fixme_should_propagate_errors(); \ | ||||
|         } else {                                                                                                                                                                                                   \ | ||||
|             m_##snake_namespace##snake_name##_prototype = heap().allocate<Namespace::PrototypeName>(m_realm, m_realm).release_allocated_value_but_fixme_should_propagate_errors();                                 \ | ||||
|             m_##snake_namespace##snake_name##_constructor = heap().allocate<Namespace::ConstructorName>(m_realm, m_realm).release_allocated_value_but_fixme_should_propagate_errors();                             \ | ||||
|         }                                                                                                                                                                                                          \ | ||||
|                                                                                                                                                                                                                    \ | ||||
|         /* FIXME: Add these special cases to JS_ENUMERATE_NATIVE_OBJECTS */                                                                                                                                        \ | ||||
|         if constexpr (IsSame<Namespace::ConstructorName, BigIntConstructor>)                                                                                                                                       \ | ||||
|             initialize_constructor(vm, vm.names.BigInt, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype);                                                              \ | ||||
|         else if constexpr (IsSame<Namespace::ConstructorName, BooleanConstructor>)                                                                                                                                 \ | ||||
|             initialize_constructor(vm, vm.names.Boolean, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype);                                                             \ | ||||
|         else if constexpr (IsSame<Namespace::ConstructorName, FunctionConstructor>)                                                                                                                                \ | ||||
|             initialize_constructor(vm, vm.names.Function, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype);                                                            \ | ||||
|         else if constexpr (IsSame<Namespace::ConstructorName, NumberConstructor>)                                                                                                                                  \ | ||||
|             initialize_constructor(vm, vm.names.Number, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype);                                                              \ | ||||
|         else if constexpr (IsSame<Namespace::ConstructorName, RegExpConstructor>)                                                                                                                                  \ | ||||
|             initialize_constructor(vm, vm.names.RegExp, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype);                                                              \ | ||||
|         else if constexpr (IsSame<Namespace::ConstructorName, StringConstructor>)                                                                                                                                  \ | ||||
|             initialize_constructor(vm, vm.names.String, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype);                                                              \ | ||||
|         else if constexpr (IsSame<Namespace::ConstructorName, SymbolConstructor>)                                                                                                                                  \ | ||||
|             initialize_constructor(vm, vm.names.Symbol, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype);                                                              \ | ||||
|         else                                                                                                                                                                                                       \ | ||||
|             initialize_constructor(vm, vm.names.ClassName, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype);                                                           \ | ||||
|     }                                                                                                                                                                                                              \ | ||||
|                                                                                                                                                                                                                    \ | ||||
|     NonnullGCPtr<Namespace::ConstructorName> Intrinsics::snake_namespace##snake_name##_constructor()                                                                                                               \ | ||||
|     {                                                                                                                                                                                                              \ | ||||
|         if (!m_##snake_namespace##snake_name##_constructor)                                                                                                                                                        \ | ||||
|             initialize_##snake_namespace##snake_name();                                                                                                                                                            \ | ||||
|         return *m_##snake_namespace##snake_name##_constructor;                                                                                                                                                     \ | ||||
|     }                                                                                                                                                                                                              \ | ||||
|                                                                                                                                                                                                                    \ | ||||
|     NonnullGCPtr<Object> Intrinsics::snake_namespace##snake_name##_prototype()                                                                                                                                     \ | ||||
|     {                                                                                                                                                                                                              \ | ||||
|         if (!m_##snake_namespace##snake_name##_prototype)                                                                                                                                                          \ | ||||
|             initialize_##snake_namespace##snake_name();                                                                                                                                                            \ | ||||
|         return *m_##snake_namespace##snake_name##_prototype;                                                                                                                                                       \ | ||||
| #define __JS_ENUMERATE_INNER(ClassName, snake_name, PrototypeName, ConstructorName, Namespace, snake_namespace)                                          \ | ||||
|     void Intrinsics::initialize_##snake_namespace##snake_name()                                                                                          \ | ||||
|     {                                                                                                                                                    \ | ||||
|         auto& vm = this->vm();                                                                                                                           \ | ||||
|                                                                                                                                                          \ | ||||
|         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());   \ | ||||
|         } 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);                               \ | ||||
|         }                                                                                                                                                \ | ||||
|                                                                                                                                                          \ | ||||
|         /* FIXME: Add these special cases to JS_ENUMERATE_NATIVE_OBJECTS */                                                                              \ | ||||
|         if constexpr (IsSame<Namespace::ConstructorName, BigIntConstructor>)                                                                             \ | ||||
|             initialize_constructor(vm, vm.names.BigInt, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype);    \ | ||||
|         else if constexpr (IsSame<Namespace::ConstructorName, BooleanConstructor>)                                                                       \ | ||||
|             initialize_constructor(vm, vm.names.Boolean, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype);   \ | ||||
|         else if constexpr (IsSame<Namespace::ConstructorName, FunctionConstructor>)                                                                      \ | ||||
|             initialize_constructor(vm, vm.names.Function, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype);  \ | ||||
|         else if constexpr (IsSame<Namespace::ConstructorName, NumberConstructor>)                                                                        \ | ||||
|             initialize_constructor(vm, vm.names.Number, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype);    \ | ||||
|         else if constexpr (IsSame<Namespace::ConstructorName, RegExpConstructor>)                                                                        \ | ||||
|             initialize_constructor(vm, vm.names.RegExp, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype);    \ | ||||
|         else if constexpr (IsSame<Namespace::ConstructorName, StringConstructor>)                                                                        \ | ||||
|             initialize_constructor(vm, vm.names.String, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype);    \ | ||||
|         else if constexpr (IsSame<Namespace::ConstructorName, SymbolConstructor>)                                                                        \ | ||||
|             initialize_constructor(vm, vm.names.Symbol, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype);    \ | ||||
|         else                                                                                                                                             \ | ||||
|             initialize_constructor(vm, vm.names.ClassName, *m_##snake_namespace##snake_name##_constructor, m_##snake_namespace##snake_name##_prototype); \ | ||||
|     }                                                                                                                                                    \ | ||||
|                                                                                                                                                          \ | ||||
|     NonnullGCPtr<Namespace::ConstructorName> Intrinsics::snake_namespace##snake_name##_constructor()                                                     \ | ||||
|     {                                                                                                                                                    \ | ||||
|         if (!m_##snake_namespace##snake_name##_constructor)                                                                                              \ | ||||
|             initialize_##snake_namespace##snake_name();                                                                                                  \ | ||||
|         return *m_##snake_namespace##snake_name##_constructor;                                                                                           \ | ||||
|     }                                                                                                                                                    \ | ||||
|                                                                                                                                                          \ | ||||
|     NonnullGCPtr<Object> Intrinsics::snake_namespace##snake_name##_prototype()                                                                           \ | ||||
|     {                                                                                                                                                    \ | ||||
|         if (!m_##snake_namespace##snake_name##_prototype)                                                                                                \ | ||||
|             initialize_##snake_namespace##snake_name();                                                                                                  \ | ||||
|         return *m_##snake_namespace##snake_name##_prototype;                                                                                             \ | ||||
|     } | ||||
| 
 | ||||
| #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ | ||||
|  | @ -339,12 +339,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).release_allocated_value_but_fixme_should_propagate_errors(); \ | ||||
|         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 = heap().allocate<ClassName>(m_realm, m_realm); \ | ||||
|         return *m_##snake_name##_object;                                            \ | ||||
|     } | ||||
| JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS | ||||
| #undef __JS_ENUMERATE | ||||
|  |  | |||
|  | @ -15,9 +15,9 @@ | |||
| 
 | ||||
| namespace JS { | ||||
| 
 | ||||
| ThrowCompletionOr<NonnullGCPtr<Iterator>> Iterator::create(Realm& realm, Object& prototype, IteratorRecord iterated) | ||||
| NonnullGCPtr<Iterator> Iterator::create(Realm& realm, Object& prototype, IteratorRecord iterated) | ||||
| { | ||||
|     return MUST_OR_THROW_OOM(realm.heap().allocate<Iterator>(realm, prototype, move(iterated))); | ||||
|     return realm.heap().allocate<Iterator>(realm, prototype, move(iterated)); | ||||
| } | ||||
| 
 | ||||
| Iterator::Iterator(Object& prototype, IteratorRecord iterated) | ||||
|  |  | |||
|  | @ -27,7 +27,7 @@ class Iterator : public Object { | |||
|     JS_OBJECT(Iterator, Object); | ||||
| 
 | ||||
| public: | ||||
|     static ThrowCompletionOr<NonnullGCPtr<Iterator>> create(Realm&, Object& prototype, IteratorRecord iterated); | ||||
|     static NonnullGCPtr<Iterator> create(Realm&, Object& prototype, IteratorRecord iterated); | ||||
| 
 | ||||
|     IteratorRecord const& iterated() const { return m_iterated; } | ||||
| 
 | ||||
|  |  | |||
|  | @ -78,7 +78,7 @@ JS_DEFINE_NATIVE_FUNCTION(IteratorConstructor::from) | |||
| 
 | ||||
|     // 4. Let wrapper be OrdinaryObjectCreate(%WrapForValidIteratorPrototype%, « [[Iterated]] »).
 | ||||
|     // 5. Set wrapper.[[Iterated]] to iteratorRecord.
 | ||||
|     auto wrapper = MUST_OR_THROW_OOM(Iterator::create(realm, realm.intrinsics().wrap_for_valid_iterator_prototype(), move(iterator_record))); | ||||
|     auto wrapper = Iterator::create(realm, realm.intrinsics().wrap_for_valid_iterator_prototype(), move(iterator_record)); | ||||
| 
 | ||||
|     // 6. Return wrapper.
 | ||||
|     return wrapper; | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ namespace JS { | |||
| 
 | ||||
| ThrowCompletionOr<NonnullGCPtr<IteratorHelper>> IteratorHelper::create(Realm& realm, IteratorRecord underlying_iterator, Closure closure, Optional<AbruptClosure> abrupt_closure) | ||||
| { | ||||
|     return TRY(realm.heap().allocate<IteratorHelper>(realm, realm, realm.intrinsics().iterator_helper_prototype(), move(underlying_iterator), move(closure), move(abrupt_closure))); | ||||
|     return realm.heap().allocate<IteratorHelper>(realm, realm, realm.intrinsics().iterator_helper_prototype(), move(underlying_iterator), move(closure), move(abrupt_closure)); | ||||
| } | ||||
| 
 | ||||
| IteratorHelper::IteratorHelper(Realm& realm, Object& prototype, IteratorRecord underlying_iterator, Closure closure, Optional<AbruptClosure> abrupt_closure) | ||||
|  |  | |||
|  | @ -439,7 +439,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 = MUST_OR_THROW_OOM(vm.heap().allocate<FlatMapIterator>(realm)); | ||||
|     auto flat_map_iterator = vm.heap().allocate<FlatMapIterator>(realm); | ||||
| 
 | ||||
|     // 5. Let closure be a new Abstract Closure with no parameters that captures iterated and mapper and performs the following steps when called:
 | ||||
|     IteratorHelper::Closure closure = [flat_map_iterator, mapper = NonnullGCPtr { mapper.as_function() }](auto& vm, auto& iterator) mutable -> ThrowCompletionOr<Value> { | ||||
|  |  | |||
|  | @ -10,7 +10,7 @@ namespace JS { | |||
| 
 | ||||
| NonnullGCPtr<Map> Map::create(Realm& realm) | ||||
| { | ||||
|     return realm.heap().allocate<Map>(realm, realm.intrinsics().map_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<Map>(realm, realm.intrinsics().map_prototype()); | ||||
| } | ||||
| 
 | ||||
| Map::Map(Object& prototype) | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ namespace JS { | |||
| 
 | ||||
| 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()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<MapIterator>(realm, map, iteration_kind, realm.intrinsics().map_iterator_prototype()); | ||||
| } | ||||
| 
 | ||||
| MapIterator::MapIterator(Map& map, Object::PropertyKind iteration_kind, Object& prototype) | ||||
|  |  | |||
|  | @ -36,7 +36,7 @@ NonnullGCPtr<NativeFunction> NativeFunction::create(Realm& allocating_realm, Saf | |||
|     // 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, move(behaviour), prototype.value(), *realm.value()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     auto function = allocating_realm.heap().allocate<NativeFunction>(allocating_realm, move(behaviour), prototype.value(), *realm.value()); | ||||
| 
 | ||||
|     // 10. Perform SetFunctionLength(func, length).
 | ||||
|     function->set_function_length(length); | ||||
|  | @ -53,7 +53,7 @@ NonnullGCPtr<NativeFunction> NativeFunction::create(Realm& allocating_realm, Saf | |||
| 
 | ||||
| NonnullGCPtr<NativeFunction> NativeFunction::create(Realm& realm, DeprecatedFlyString const& name, SafeFunction<ThrowCompletionOr<Value>(VM&)> function) | ||||
| { | ||||
|     return realm.heap().allocate<NativeFunction>(realm, name, move(function), realm.intrinsics().function_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<NativeFunction>(realm, name, move(function), realm.intrinsics().function_prototype()); | ||||
| } | ||||
| 
 | ||||
| NativeFunction::NativeFunction(SafeFunction<ThrowCompletionOr<Value>(VM&)> native_function, Object* prototype, Realm& realm) | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ namespace JS { | |||
| 
 | ||||
| NonnullGCPtr<NumberObject> NumberObject::create(Realm& realm, double value) | ||||
| { | ||||
|     return realm.heap().allocate<NumberObject>(realm, value, realm.intrinsics().number_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<NumberObject>(realm, value, realm.intrinsics().number_prototype()); | ||||
| } | ||||
| 
 | ||||
| NumberObject::NumberObject(double value, Object& prototype) | ||||
|  |  | |||
|  | @ -29,10 +29,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()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|         return realm.heap().allocate<Object>(realm, realm.intrinsics().empty_object_shape()); | ||||
|     if (prototype == realm.intrinsics().object_prototype()) | ||||
|         return realm.heap().allocate<Object>(realm, realm.intrinsics().new_object_shape()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<Object>(realm, ConstructWithPrototypeTag::Tag, *prototype).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|         return realm.heap().allocate<Object>(realm, realm.intrinsics().new_object_shape()); | ||||
|     return realm.heap().allocate<Object>(realm, ConstructWithPrototypeTag::Tag, *prototype); | ||||
| } | ||||
| 
 | ||||
| Object::Object(GlobalObjectTag, Realm& realm) | ||||
|  |  | |||
|  | @ -44,7 +44,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()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<Promise>(realm, realm.intrinsics().promise_prototype()); | ||||
| } | ||||
| 
 | ||||
| // 27.2 Promise Objects, https://tc39.es/ecma262/#sec-promise-objects
 | ||||
|  |  | |||
|  | @ -59,7 +59,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 = TRY(vm.heap().allocate<ResolvingFunctions>(realm)); | ||||
|     auto resolving_functions = vm.heap().allocate<ResolvingFunctions>(realm); | ||||
| 
 | ||||
|     // 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> { | ||||
|  |  | |||
|  | @ -55,7 +55,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()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<PromiseAllResolveElementFunction>(realm, 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) | ||||
|  | @ -87,7 +87,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()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<PromiseAllSettledResolveElementFunction>(realm, 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) | ||||
|  | @ -128,7 +128,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()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<PromiseAllSettledRejectElementFunction>(realm, 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) | ||||
|  | @ -169,7 +169,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()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<PromiseAnyRejectElementFunction>(realm, 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) | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ namespace JS { | |||
| 
 | ||||
| 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()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<PromiseResolvingFunction>(realm, promise, already_resolved, move(function), realm.intrinsics().function_prototype()); | ||||
| } | ||||
| 
 | ||||
| PromiseResolvingFunction::PromiseResolvingFunction(Promise& promise, AlreadyResolved& already_resolved, FunctionType native_function, Object& prototype) | ||||
|  |  | |||
|  | @ -17,7 +17,7 @@ namespace JS { | |||
| 
 | ||||
| NonnullGCPtr<ProxyObject> ProxyObject::create(Realm& realm, Object& target, Object& handler) | ||||
| { | ||||
|     return realm.heap().allocate<ProxyObject>(realm, target, handler, realm.intrinsics().object_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<ProxyObject>(realm, target, handler, realm.intrinsics().object_prototype()); | ||||
| } | ||||
| 
 | ||||
| ProxyObject::ProxyObject(Object& target, Object& handler, Object& prototype) | ||||
|  |  | |||
|  | @ -132,12 +132,12 @@ ThrowCompletionOr<DeprecatedString> parse_regex_pattern(VM& vm, StringView patte | |||
| 
 | ||||
| NonnullGCPtr<RegExpObject> RegExpObject::create(Realm& realm) | ||||
| { | ||||
|     return realm.heap().allocate<RegExpObject>(realm, realm.intrinsics().regexp_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<RegExpObject>(realm, realm.intrinsics().regexp_prototype()); | ||||
| } | ||||
| 
 | ||||
| NonnullGCPtr<RegExpObject> RegExpObject::create(Realm& realm, Regex<ECMA262> regex, DeprecatedString pattern, DeprecatedString flags) | ||||
| { | ||||
|     return realm.heap().allocate<RegExpObject>(realm, move(regex), move(pattern), move(flags), realm.intrinsics().regexp_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<RegExpObject>(realm, move(regex), move(pattern), move(flags), realm.intrinsics().regexp_prototype()); | ||||
| } | ||||
| 
 | ||||
| RegExpObject::RegExpObject(Object& prototype) | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ namespace JS { | |||
| // 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).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<RegExpStringIterator>(realm, 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) | ||||
|  |  | |||
|  | @ -10,7 +10,7 @@ namespace JS { | |||
| 
 | ||||
| NonnullGCPtr<Set> Set::create(Realm& realm) | ||||
| { | ||||
|     return realm.heap().allocate<Set>(realm, realm.intrinsics().set_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<Set>(realm, realm.intrinsics().set_prototype()); | ||||
| } | ||||
| 
 | ||||
| Set::Set(Object& prototype) | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ namespace JS { | |||
| 
 | ||||
| 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()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<SetIterator>(realm, set, iteration_kind, realm.intrinsics().set_iterator_prototype()); | ||||
| } | ||||
| 
 | ||||
| SetIterator::SetIterator(Set& set, Object::PropertyKind iteration_kind, Object& prototype) | ||||
|  |  | |||
|  | @ -79,7 +79,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> StringConstructor::construct(FunctionObj | |||
| 
 | ||||
|     // 4. Return StringCreate(s, ? GetPrototypeFromConstructor(NewTarget, "%String.prototype%")).
 | ||||
|     auto* prototype = TRY(get_prototype_from_constructor(vm, new_target, &Intrinsics::string_prototype)); | ||||
|     return MUST_OR_THROW_OOM(StringObject::create(realm, *primitive_string, *prototype)); | ||||
|     return StringObject::create(realm, *primitive_string, *prototype); | ||||
| } | ||||
| 
 | ||||
| // 22.1.2.1 String.fromCharCode ( ...codeUnits ), https://tc39.es/ecma262/#sec-string.fromcharcode
 | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ namespace JS { | |||
| 
 | ||||
| NonnullGCPtr<StringIterator> StringIterator::create(Realm& realm, String string) | ||||
| { | ||||
|     return realm.heap().allocate<StringIterator>(realm, move(string), realm.intrinsics().string_iterator_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<StringIterator>(realm, move(string), realm.intrinsics().string_iterator_prototype()); | ||||
| } | ||||
| 
 | ||||
| StringIterator::StringIterator(String string, Object& prototype) | ||||
|  |  | |||
|  | @ -15,7 +15,7 @@ | |||
| namespace JS { | ||||
| 
 | ||||
| // 10.4.3.4 StringCreate ( value, prototype ), https://tc39.es/ecma262/#sec-stringcreate
 | ||||
| ThrowCompletionOr<NonnullGCPtr<StringObject>> StringObject::create(Realm& realm, PrimitiveString& primitive_string, Object& prototype) | ||||
| NonnullGCPtr<StringObject> StringObject::create(Realm& realm, PrimitiveString& primitive_string, Object& prototype) | ||||
| { | ||||
|     // 1. Let S be MakeBasicObject(« [[Prototype]], [[Extensible]], [[StringData]] »).
 | ||||
|     // 2. Set S.[[Prototype]] to prototype.
 | ||||
|  | @ -26,7 +26,7 @@ ThrowCompletionOr<NonnullGCPtr<StringObject>> StringObject::create(Realm& realm, | |||
|     // 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 MUST_OR_THROW_OOM(realm.heap().allocate<StringObject>(realm, primitive_string, prototype)); | ||||
|     return realm.heap().allocate<StringObject>(realm, primitive_string, prototype); | ||||
| } | ||||
| 
 | ||||
| StringObject::StringObject(PrimitiveString& string, Object& prototype) | ||||
|  |  | |||
|  | @ -14,7 +14,7 @@ class StringObject : public Object { | |||
|     JS_OBJECT(StringObject, Object); | ||||
| 
 | ||||
| public: | ||||
|     static ThrowCompletionOr<NonnullGCPtr<StringObject>> create(Realm&, PrimitiveString&, Object& prototype); | ||||
|     [[nodiscard]] static NonnullGCPtr<StringObject> create(Realm&, PrimitiveString&, Object& prototype); | ||||
| 
 | ||||
|     virtual void initialize(Realm&) override; | ||||
|     virtual ~StringObject() override = default; | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ namespace JS { | |||
| 
 | ||||
| NonnullGCPtr<SuppressedError> SuppressedError::create(Realm& realm) | ||||
| { | ||||
|     return realm.heap().allocate<SuppressedError>(realm, realm.intrinsics().suppressed_error_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<SuppressedError>(realm, realm.intrinsics().suppressed_error_prototype()); | ||||
| } | ||||
| 
 | ||||
| SuppressedError::SuppressedError(Object& prototype) | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ namespace JS { | |||
| 
 | ||||
| NonnullGCPtr<SymbolObject> SymbolObject::create(Realm& realm, Symbol& primitive_symbol) | ||||
| { | ||||
|     return realm.heap().allocate<SymbolObject>(realm, primitive_symbol, realm.intrinsics().symbol_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<SymbolObject>(realm, primitive_symbol, realm.intrinsics().symbol_prototype()); | ||||
| } | ||||
| 
 | ||||
| SymbolObject::SymbolObject(Symbol& symbol, Object& prototype) | ||||
|  |  | |||
|  | @ -36,7 +36,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, MUST(heap().allocate<Now>(realm, realm)), attr); | ||||
|     define_direct_property(vm.names.Now, heap().allocate<Now>(realm, 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(); }); | ||||
|  |  | |||
|  | @ -419,137 +419,137 @@ void TypedArrayBase::visit_edges(Visitor& visitor) | |||
|     visitor.visit(m_viewed_array_buffer); | ||||
| } | ||||
| 
 | ||||
| #define JS_DEFINE_TYPED_ARRAY(ClassName, snake_name, PrototypeName, ConstructorName, Type)                                                                                             \ | ||||
|     ThrowCompletionOr<NonnullGCPtr<ClassName>> ClassName::create(Realm& realm, u32 length, FunctionObject& new_target)                                                                 \ | ||||
|     {                                                                                                                                                                                  \ | ||||
|         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 MUST_OR_THROW_OOM(realm.heap().allocate<ClassName>(realm, *prototype, length, *array_buffer));                                                                          \ | ||||
|     }                                                                                                                                                                                  \ | ||||
|                                                                                                                                                                                        \ | ||||
|     ThrowCompletionOr<NonnullGCPtr<ClassName>> ClassName::create(Realm& realm, u32 length)                                                                                             \ | ||||
|     {                                                                                                                                                                                  \ | ||||
|         auto array_buffer = TRY(ArrayBuffer::create(realm, length * sizeof(UnderlyingBufferDataType)));                                                                                \ | ||||
|         return create(realm, length, *array_buffer);                                                                                                                                   \ | ||||
|     }                                                                                                                                                                                  \ | ||||
|                                                                                                                                                                                        \ | ||||
|     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).release_allocated_value_but_fixme_should_propagate_errors(); \ | ||||
|     }                                                                                                                                                                                  \ | ||||
|                                                                                                                                                                                        \ | ||||
|     ClassName::ClassName(Object& prototype, u32 length, ArrayBuffer& array_buffer)                                                                                                     \ | ||||
|         : TypedArray(prototype,                                                                                                                                                        \ | ||||
|             bit_cast<TypedArrayBase::IntrinsicConstructor>(&Intrinsics::snake_name##_constructor), length, array_buffer)                                                               \ | ||||
|     {                                                                                                                                                                                  \ | ||||
|         if constexpr (#ClassName##sv.is_one_of("BigInt64Array", "BigUint64Array"))                                                                                                     \ | ||||
|             m_content_type = ContentType::BigInt;                                                                                                                                      \ | ||||
|         else                                                                                                                                                                           \ | ||||
|             m_content_type = ContentType::Number;                                                                                                                                      \ | ||||
|     }                                                                                                                                                                                  \ | ||||
|                                                                                                                                                                                        \ | ||||
|     ClassName::~ClassName()                                                                                                                                                            \ | ||||
|     {                                                                                                                                                                                  \ | ||||
|     }                                                                                                                                                                                  \ | ||||
|                                                                                                                                                                                        \ | ||||
|     DeprecatedFlyString const& ClassName::element_name() const                                                                                                                         \ | ||||
|     {                                                                                                                                                                                  \ | ||||
|         return vm().names.ClassName.as_string();                                                                                                                                       \ | ||||
|     }                                                                                                                                                                                  \ | ||||
|                                                                                                                                                                                        \ | ||||
|     PrototypeName::PrototypeName(Object& prototype)                                                                                                                                    \ | ||||
|         : Object(ConstructWithPrototypeTag::Tag, prototype)                                                                                                                            \ | ||||
|     {                                                                                                                                                                                  \ | ||||
|     }                                                                                                                                                                                  \ | ||||
|                                                                                                                                                                                        \ | ||||
|     PrototypeName::~PrototypeName()                                                                                                                                                    \ | ||||
|     {                                                                                                                                                                                  \ | ||||
|     }                                                                                                                                                                                  \ | ||||
|                                                                                                                                                                                        \ | ||||
|     void PrototypeName::initialize(Realm& realm)                                                                                                                                       \ | ||||
|     {                                                                                                                                                                                  \ | ||||
|         auto& vm = this->vm();                                                                                                                                                         \ | ||||
|         Base::initialize(realm);                                                                                                                                                       \ | ||||
|         define_direct_property(vm.names.BYTES_PER_ELEMENT, Value((i32)sizeof(Type)), 0);                                                                                               \ | ||||
|     }                                                                                                                                                                                  \ | ||||
|                                                                                                                                                                                        \ | ||||
|     ConstructorName::ConstructorName(Realm& realm, Object& prototype)                                                                                                                  \ | ||||
|         : TypedArrayConstructor(realm.vm().names.ClassName.as_string(), prototype)                                                                                                     \ | ||||
|     {                                                                                                                                                                                  \ | ||||
|     }                                                                                                                                                                                  \ | ||||
|                                                                                                                                                                                        \ | ||||
|     ConstructorName::~ConstructorName()                                                                                                                                                \ | ||||
|     {                                                                                                                                                                                  \ | ||||
|     }                                                                                                                                                                                  \ | ||||
|                                                                                                                                                                                        \ | ||||
|     void ConstructorName::initialize(Realm& realm)                                                                                                                                     \ | ||||
|     {                                                                                                                                                                                  \ | ||||
|         auto& vm = this->vm();                                                                                                                                                         \ | ||||
|         Base::initialize(realm);                                                                                                                                                       \ | ||||
|                                                                                                                                                                                        \ | ||||
|         /* 23.2.6.2 TypedArray.prototype, https://tc39.es/ecma262/#sec-typedarray.prototype */                                                                                         \ | ||||
|         define_direct_property(vm.names.prototype, realm.intrinsics().snake_name##_prototype(), 0);                                                                                    \ | ||||
|                                                                                                                                                                                        \ | ||||
|         /* 23.2.6.1 TypedArray.BYTES_PER_ELEMENT, https://tc39.es/ecma262/#sec-typedarray.bytes_per_element */                                                                         \ | ||||
|         define_direct_property(vm.names.BYTES_PER_ELEMENT, Value((i32)sizeof(Type)), 0);                                                                                               \ | ||||
|                                                                                                                                                                                        \ | ||||
|         define_direct_property(vm.names.length, Value(3), Attribute::Configurable);                                                                                                    \ | ||||
|     }                                                                                                                                                                                  \ | ||||
|                                                                                                                                                                                        \ | ||||
|     /* 23.2.5.1 TypedArray ( ...args ), https://tc39.es/ecma262/#sec-typedarray */                                                                                                     \ | ||||
|     ThrowCompletionOr<Value> ConstructorName::call()                                                                                                                                   \ | ||||
|     {                                                                                                                                                                                  \ | ||||
|         auto& vm = this->vm();                                                                                                                                                         \ | ||||
|         return vm.throw_completion<TypeError>(ErrorType::ConstructorWithoutNew, vm.names.ClassName);                                                                                   \ | ||||
|     }                                                                                                                                                                                  \ | ||||
|                                                                                                                                                                                        \ | ||||
|     /* 23.2.5.1 TypedArray ( ...args ), https://tc39.es/ecma262/#sec-typedarray */                                                                                                     \ | ||||
|     ThrowCompletionOr<NonnullGCPtr<Object>> ConstructorName::construct(FunctionObject& new_target)                                                                                     \ | ||||
|     {                                                                                                                                                                                  \ | ||||
|         auto& vm = this->vm();                                                                                                                                                         \ | ||||
|         auto& realm = *vm.current_realm();                                                                                                                                             \ | ||||
|                                                                                                                                                                                        \ | ||||
|         if (vm.argument_count() == 0)                                                                                                                                                  \ | ||||
|             return TRY(ClassName::create(realm, 0, new_target));                                                                                                                       \ | ||||
|                                                                                                                                                                                        \ | ||||
|         auto first_argument = vm.argument(0);                                                                                                                                          \ | ||||
|         if (first_argument.is_object()) {                                                                                                                                              \ | ||||
|             auto typed_array = TRY(ClassName::create(realm, 0, new_target));                                                                                                           \ | ||||
|             if (first_argument.as_object().is_typed_array()) {                                                                                                                         \ | ||||
|                 auto& arg_typed_array = static_cast<TypedArrayBase&>(first_argument.as_object());                                                                                      \ | ||||
|                 TRY(initialize_typed_array_from_typed_array(vm, *typed_array, arg_typed_array));                                                                                       \ | ||||
|             } else if (is<ArrayBuffer>(first_argument.as_object())) {                                                                                                                  \ | ||||
|                 auto& array_buffer = static_cast<ArrayBuffer&>(first_argument.as_object());                                                                                            \ | ||||
|                 TRY(initialize_typed_array_from_array_buffer(vm, *typed_array, array_buffer,                                                                                           \ | ||||
|                     vm.argument(1), vm.argument(2)));                                                                                                                                  \ | ||||
|             } else {                                                                                                                                                                   \ | ||||
|                 auto iterator = TRY(first_argument.get_method(vm, vm.well_known_symbol_iterator()));                                                                                   \ | ||||
|                 if (iterator) {                                                                                                                                                        \ | ||||
|                     auto values = TRY(iterator_to_list(vm, TRY(get_iterator_from_method(vm, first_argument, *iterator))));                                                             \ | ||||
|                     TRY(initialize_typed_array_from_list(vm, *typed_array, values));                                                                                                   \ | ||||
|                 } else {                                                                                                                                                               \ | ||||
|                     TRY(initialize_typed_array_from_array_like(vm, *typed_array, first_argument.as_object()));                                                                         \ | ||||
|                 }                                                                                                                                                                      \ | ||||
|             }                                                                                                                                                                          \ | ||||
|             return typed_array;                                                                                                                                                        \ | ||||
|         }                                                                                                                                                                              \ | ||||
|                                                                                                                                                                                        \ | ||||
|         auto array_length_or_error = first_argument.to_index(vm);                                                                                                                      \ | ||||
|         if (array_length_or_error.is_error()) {                                                                                                                                        \ | ||||
|             auto error = array_length_or_error.release_error();                                                                                                                        \ | ||||
|             if (error.value()->is_object() && is<RangeError>(error.value()->as_object())) {                                                                                            \ | ||||
|                 /* Re-throw more specific RangeError */                                                                                                                                \ | ||||
|                 return vm.throw_completion<RangeError>(ErrorType::InvalidLength, "typed array");                                                                                       \ | ||||
|             }                                                                                                                                                                          \ | ||||
|             return error;                                                                                                                                                              \ | ||||
|         }                                                                                                                                                                              \ | ||||
|         auto array_length = array_length_or_error.release_value();                                                                                                                     \ | ||||
|         if (array_length > NumericLimits<i32>::max() / sizeof(Type))                                                                                                                   \ | ||||
|             return vm.throw_completion<RangeError>(ErrorType::InvalidLength, "typed array");                                                                                           \ | ||||
|         /* FIXME: What is the best/correct behavior here? */                                                                                                                           \ | ||||
|         if (Checked<u32>::multiplication_would_overflow(array_length, sizeof(Type)))                                                                                                   \ | ||||
|             return vm.throw_completion<RangeError>(ErrorType::InvalidLength, "typed array");                                                                                           \ | ||||
|         return TRY(ClassName::create(realm, array_length, new_target));                                                                                                                \ | ||||
| #define JS_DEFINE_TYPED_ARRAY(ClassName, snake_name, PrototypeName, ConstructorName, Type)                                  \ | ||||
|     ThrowCompletionOr<NonnullGCPtr<ClassName>> ClassName::create(Realm& realm, u32 length, FunctionObject& new_target)      \ | ||||
|     {                                                                                                                       \ | ||||
|         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);                                  \ | ||||
|     }                                                                                                                       \ | ||||
|                                                                                                                             \ | ||||
|     ThrowCompletionOr<NonnullGCPtr<ClassName>> ClassName::create(Realm& realm, u32 length)                                  \ | ||||
|     {                                                                                                                       \ | ||||
|         auto array_buffer = TRY(ArrayBuffer::create(realm, length * sizeof(UnderlyingBufferDataType)));                     \ | ||||
|         return create(realm, length, *array_buffer);                                                                        \ | ||||
|     }                                                                                                                       \ | ||||
|                                                                                                                             \ | ||||
|     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);  \ | ||||
|     }                                                                                                                       \ | ||||
|                                                                                                                             \ | ||||
|     ClassName::ClassName(Object& prototype, u32 length, ArrayBuffer& array_buffer)                                          \ | ||||
|         : TypedArray(prototype,                                                                                             \ | ||||
|             bit_cast<TypedArrayBase::IntrinsicConstructor>(&Intrinsics::snake_name##_constructor), length, array_buffer)    \ | ||||
|     {                                                                                                                       \ | ||||
|         if constexpr (#ClassName##sv.is_one_of("BigInt64Array", "BigUint64Array"))                                          \ | ||||
|             m_content_type = ContentType::BigInt;                                                                           \ | ||||
|         else                                                                                                                \ | ||||
|             m_content_type = ContentType::Number;                                                                           \ | ||||
|     }                                                                                                                       \ | ||||
|                                                                                                                             \ | ||||
|     ClassName::~ClassName()                                                                                                 \ | ||||
|     {                                                                                                                       \ | ||||
|     }                                                                                                                       \ | ||||
|                                                                                                                             \ | ||||
|     DeprecatedFlyString const& ClassName::element_name() const                                                              \ | ||||
|     {                                                                                                                       \ | ||||
|         return vm().names.ClassName.as_string();                                                                            \ | ||||
|     }                                                                                                                       \ | ||||
|                                                                                                                             \ | ||||
|     PrototypeName::PrototypeName(Object& prototype)                                                                         \ | ||||
|         : Object(ConstructWithPrototypeTag::Tag, prototype)                                                                 \ | ||||
|     {                                                                                                                       \ | ||||
|     }                                                                                                                       \ | ||||
|                                                                                                                             \ | ||||
|     PrototypeName::~PrototypeName()                                                                                         \ | ||||
|     {                                                                                                                       \ | ||||
|     }                                                                                                                       \ | ||||
|                                                                                                                             \ | ||||
|     void PrototypeName::initialize(Realm& realm)                                                                            \ | ||||
|     {                                                                                                                       \ | ||||
|         auto& vm = this->vm();                                                                                              \ | ||||
|         Base::initialize(realm);                                                                                            \ | ||||
|         define_direct_property(vm.names.BYTES_PER_ELEMENT, Value((i32)sizeof(Type)), 0);                                    \ | ||||
|     }                                                                                                                       \ | ||||
|                                                                                                                             \ | ||||
|     ConstructorName::ConstructorName(Realm& realm, Object& prototype)                                                       \ | ||||
|         : TypedArrayConstructor(realm.vm().names.ClassName.as_string(), prototype)                                          \ | ||||
|     {                                                                                                                       \ | ||||
|     }                                                                                                                       \ | ||||
|                                                                                                                             \ | ||||
|     ConstructorName::~ConstructorName()                                                                                     \ | ||||
|     {                                                                                                                       \ | ||||
|     }                                                                                                                       \ | ||||
|                                                                                                                             \ | ||||
|     void ConstructorName::initialize(Realm& realm)                                                                          \ | ||||
|     {                                                                                                                       \ | ||||
|         auto& vm = this->vm();                                                                                              \ | ||||
|         Base::initialize(realm);                                                                                            \ | ||||
|                                                                                                                             \ | ||||
|         /* 23.2.6.2 TypedArray.prototype, https://tc39.es/ecma262/#sec-typedarray.prototype */                              \ | ||||
|         define_direct_property(vm.names.prototype, realm.intrinsics().snake_name##_prototype(), 0);                         \ | ||||
|                                                                                                                             \ | ||||
|         /* 23.2.6.1 TypedArray.BYTES_PER_ELEMENT, https://tc39.es/ecma262/#sec-typedarray.bytes_per_element */              \ | ||||
|         define_direct_property(vm.names.BYTES_PER_ELEMENT, Value((i32)sizeof(Type)), 0);                                    \ | ||||
|                                                                                                                             \ | ||||
|         define_direct_property(vm.names.length, Value(3), Attribute::Configurable);                                         \ | ||||
|     }                                                                                                                       \ | ||||
|                                                                                                                             \ | ||||
|     /* 23.2.5.1 TypedArray ( ...args ), https://tc39.es/ecma262/#sec-typedarray */                                          \ | ||||
|     ThrowCompletionOr<Value> ConstructorName::call()                                                                        \ | ||||
|     {                                                                                                                       \ | ||||
|         auto& vm = this->vm();                                                                                              \ | ||||
|         return vm.throw_completion<TypeError>(ErrorType::ConstructorWithoutNew, vm.names.ClassName);                        \ | ||||
|     }                                                                                                                       \ | ||||
|                                                                                                                             \ | ||||
|     /* 23.2.5.1 TypedArray ( ...args ), https://tc39.es/ecma262/#sec-typedarray */                                          \ | ||||
|     ThrowCompletionOr<NonnullGCPtr<Object>> ConstructorName::construct(FunctionObject& new_target)                          \ | ||||
|     {                                                                                                                       \ | ||||
|         auto& vm = this->vm();                                                                                              \ | ||||
|         auto& realm = *vm.current_realm();                                                                                  \ | ||||
|                                                                                                                             \ | ||||
|         if (vm.argument_count() == 0)                                                                                       \ | ||||
|             return TRY(ClassName::create(realm, 0, new_target));                                                            \ | ||||
|                                                                                                                             \ | ||||
|         auto first_argument = vm.argument(0);                                                                               \ | ||||
|         if (first_argument.is_object()) {                                                                                   \ | ||||
|             auto typed_array = TRY(ClassName::create(realm, 0, new_target));                                                \ | ||||
|             if (first_argument.as_object().is_typed_array()) {                                                              \ | ||||
|                 auto& arg_typed_array = static_cast<TypedArrayBase&>(first_argument.as_object());                           \ | ||||
|                 TRY(initialize_typed_array_from_typed_array(vm, *typed_array, arg_typed_array));                            \ | ||||
|             } else if (is<ArrayBuffer>(first_argument.as_object())) {                                                       \ | ||||
|                 auto& array_buffer = static_cast<ArrayBuffer&>(first_argument.as_object());                                 \ | ||||
|                 TRY(initialize_typed_array_from_array_buffer(vm, *typed_array, array_buffer,                                \ | ||||
|                     vm.argument(1), vm.argument(2)));                                                                       \ | ||||
|             } else {                                                                                                        \ | ||||
|                 auto iterator = TRY(first_argument.get_method(vm, vm.well_known_symbol_iterator()));                        \ | ||||
|                 if (iterator) {                                                                                             \ | ||||
|                     auto values = TRY(iterator_to_list(vm, TRY(get_iterator_from_method(vm, first_argument, *iterator))));  \ | ||||
|                     TRY(initialize_typed_array_from_list(vm, *typed_array, values));                                        \ | ||||
|                 } else {                                                                                                    \ | ||||
|                     TRY(initialize_typed_array_from_array_like(vm, *typed_array, first_argument.as_object()));              \ | ||||
|                 }                                                                                                           \ | ||||
|             }                                                                                                               \ | ||||
|             return typed_array;                                                                                             \ | ||||
|         }                                                                                                                   \ | ||||
|                                                                                                                             \ | ||||
|         auto array_length_or_error = first_argument.to_index(vm);                                                           \ | ||||
|         if (array_length_or_error.is_error()) {                                                                             \ | ||||
|             auto error = array_length_or_error.release_error();                                                             \ | ||||
|             if (error.value()->is_object() && is<RangeError>(error.value()->as_object())) {                                 \ | ||||
|                 /* Re-throw more specific RangeError */                                                                     \ | ||||
|                 return vm.throw_completion<RangeError>(ErrorType::InvalidLength, "typed array");                            \ | ||||
|             }                                                                                                               \ | ||||
|             return error;                                                                                                   \ | ||||
|         }                                                                                                                   \ | ||||
|         auto array_length = array_length_or_error.release_value();                                                          \ | ||||
|         if (array_length > NumericLimits<i32>::max() / sizeof(Type))                                                        \ | ||||
|             return vm.throw_completion<RangeError>(ErrorType::InvalidLength, "typed array");                                \ | ||||
|         /* FIXME: What is the best/correct behavior here? */                                                                \ | ||||
|         if (Checked<u32>::multiplication_would_overflow(array_length, sizeof(Type)))                                        \ | ||||
|             return vm.throw_completion<RangeError>(ErrorType::InvalidLength, "typed array");                                \ | ||||
|         return TRY(ClassName::create(realm, array_length, new_target));                                                     \ | ||||
|     } | ||||
| 
 | ||||
| #undef __JS_ENUMERATE | ||||
|  |  | |||
|  | @ -566,7 +566,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> Value::to_object(VM& vm) const | |||
|     // String
 | ||||
|     case STRING_TAG: | ||||
|         // Return a new String object whose [[StringData]] internal slot is set to argument. See 22.1 for a description of String objects.
 | ||||
|         return MUST_OR_THROW_OOM(StringObject::create(realm, const_cast<JS::PrimitiveString&>(as_string()), realm.intrinsics().string_prototype())); | ||||
|         return StringObject::create(realm, const_cast<JS::PrimitiveString&>(as_string()), realm.intrinsics().string_prototype()); | ||||
|     // Symbol
 | ||||
|     case SYMBOL_TAG: | ||||
|         // Return a new Symbol object whose [[SymbolData]] internal slot is set to argument. See 20.4 for a description of Symbol objects.
 | ||||
|  |  | |||
|  | @ -10,7 +10,7 @@ namespace JS { | |||
| 
 | ||||
| NonnullGCPtr<WeakMap> WeakMap::create(Realm& realm) | ||||
| { | ||||
|     return realm.heap().allocate<WeakMap>(realm, realm.intrinsics().weak_map_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<WeakMap>(realm, realm.intrinsics().weak_map_prototype()); | ||||
| } | ||||
| 
 | ||||
| WeakMap::WeakMap(Object& prototype) | ||||
|  |  | |||
|  | @ -10,12 +10,12 @@ namespace JS { | |||
| 
 | ||||
| NonnullGCPtr<WeakRef> WeakRef::create(Realm& realm, Object& value) | ||||
| { | ||||
|     return realm.heap().allocate<WeakRef>(realm, value, realm.intrinsics().weak_ref_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<WeakRef>(realm, 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()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<WeakRef>(realm, value, realm.intrinsics().weak_ref_prototype()); | ||||
| } | ||||
| 
 | ||||
| WeakRef::WeakRef(Object& value, Object& prototype) | ||||
|  |  | |||
|  | @ -10,7 +10,7 @@ namespace JS { | |||
| 
 | ||||
| NonnullGCPtr<WeakSet> WeakSet::create(Realm& realm) | ||||
| { | ||||
|     return realm.heap().allocate<WeakSet>(realm, realm.intrinsics().weak_set_prototype()).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|     return realm.heap().allocate<WeakSet>(realm, realm.intrinsics().weak_set_prototype()); | ||||
| } | ||||
| 
 | ||||
| WeakSet::WeakSet(Object& prototype) | ||||
|  |  | |||
|  | @ -22,7 +22,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 = MUST_OR_THROW_OOM(vm.heap().allocate<WrappedFunction>(realm, caller_realm, target, prototype)); | ||||
|     auto wrapped = vm.heap().allocate<WrappedFunction>(realm, caller_realm, target, prototype); | ||||
| 
 | ||||
|     // 7. Let result be CopyNameAndLength(wrapped, Target).
 | ||||
|     auto result = copy_name_and_length(vm, *wrapped, target); | ||||
|  |  | |||
|  | @ -292,7 +292,7 @@ inline JSFileResult TestRunner::run_file_test(DeprecatedString const& test_path) | |||
|         *g_vm, | ||||
|         [&](JS::Realm& realm_) -> JS::GlobalObject* { | ||||
|             realm = &realm_; | ||||
|             global_object = g_vm->heap().allocate<TestRunnerGlobalObject>(*realm, *realm).release_allocated_value_but_fixme_should_propagate_errors(); | ||||
|             global_object = g_vm->heap().allocate<TestRunnerGlobalObject>(*realm, *realm); | ||||
|             return global_object; | ||||
|         }, | ||||
|         nullptr)); | ||||
|  |  | |||
|  | @ -174,7 +174,7 @@ ErrorOr<void> initialize_main_thread_vm() | |||
|                     /* .promise = */ promise, | ||||
|                     /* .reason = */ promise.result(), | ||||
|                 }; | ||||
|                 auto promise_rejection_event = HTML::PromiseRejectionEvent::create(HTML::relevant_realm(global), HTML::EventNames::rejectionhandled, event_init).release_value_but_fixme_should_propagate_errors(); | ||||
|                 auto promise_rejection_event = HTML::PromiseRejectionEvent::create(HTML::relevant_realm(global), HTML::EventNames::rejectionhandled, event_init); | ||||
|                 window.dispatch_event(promise_rejection_event); | ||||
|             }); | ||||
|             break; | ||||
|  |  | |||
|  | @ -53,7 +53,7 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> OptionConstructor::construct | |||
|     if (vm.argument_count() > 0) { | ||||
|         auto text = TRY(vm.argument(0).to_deprecated_string(vm)); | ||||
|         if (!text.is_empty()) { | ||||
|             auto new_text_node = MUST_OR_THROW_OOM(vm.heap().allocate<DOM::Text>(realm, document, text)); | ||||
|             auto new_text_node = vm.heap().allocate<DOM::Text>(realm, document, text); | ||||
|             MUST(option_element->append_child(*new_text_node)); | ||||
|         } | ||||
|     } | ||||
|  |  | |||
|  | @ -14,9 +14,9 @@ | |||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSFontFaceRule>> CSSFontFaceRule::create(JS::Realm& realm, FontFace&& font_face) | ||||
| JS::NonnullGCPtr<CSSFontFaceRule> CSSFontFaceRule::create(JS::Realm& realm, FontFace&& font_face) | ||||
| { | ||||
|     return MUST_OR_THROW_OOM(realm.heap().allocate<CSSFontFaceRule>(realm, realm, move(font_face))); | ||||
|     return realm.heap().allocate<CSSFontFaceRule>(realm, realm, move(font_face)); | ||||
| } | ||||
| 
 | ||||
| CSSFontFaceRule::CSSFontFaceRule(JS::Realm& realm, FontFace&& font_face) | ||||
|  |  | |||
|  | @ -16,7 +16,7 @@ class CSSFontFaceRule final : public CSSRule { | |||
|     WEB_PLATFORM_OBJECT(CSSFontFaceRule, CSSRule); | ||||
| 
 | ||||
| public: | ||||
|     static WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSFontFaceRule>> create(JS::Realm&, FontFace&&); | ||||
|     [[nodiscard]] static JS::NonnullGCPtr<CSSFontFaceRule> create(JS::Realm&, FontFace&&); | ||||
| 
 | ||||
|     virtual ~CSSFontFaceRule() override = default; | ||||
| 
 | ||||
|  |  | |||
|  | @ -19,10 +19,10 @@ | |||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSImportRule>> CSSImportRule::create(AK::URL url, DOM::Document& document) | ||||
| JS::NonnullGCPtr<CSSImportRule> CSSImportRule::create(AK::URL url, DOM::Document& document) | ||||
| { | ||||
|     auto& realm = document.realm(); | ||||
|     return MUST_OR_THROW_OOM(realm.heap().allocate<CSSImportRule>(realm, move(url), document)); | ||||
|     return realm.heap().allocate<CSSImportRule>(realm, move(url), document); | ||||
| } | ||||
| 
 | ||||
| CSSImportRule::CSSImportRule(AK::URL url, DOM::Document& document) | ||||
|  |  | |||
|  | @ -22,7 +22,7 @@ class CSSImportRule final | |||
|     WEB_PLATFORM_OBJECT(CSSImportRule, CSSRule); | ||||
| 
 | ||||
| public: | ||||
|     static WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSImportRule>> create(AK::URL, DOM::Document&); | ||||
|     [[nodiscard]] static JS::NonnullGCPtr<CSSImportRule> create(AK::URL, DOM::Document&); | ||||
| 
 | ||||
|     virtual ~CSSImportRule() = default; | ||||
| 
 | ||||
|  |  | |||
|  | @ -11,9 +11,9 @@ | |||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSKeyframeRule>> CSSKeyframeRule::create(JS::Realm& realm, CSS::Percentage key, Web::CSS::CSSStyleDeclaration& declarations) | ||||
| JS::NonnullGCPtr<CSSKeyframeRule> CSSKeyframeRule::create(JS::Realm& realm, CSS::Percentage key, Web::CSS::CSSStyleDeclaration& declarations) | ||||
| { | ||||
|     return MUST_OR_THROW_OOM(realm.heap().allocate<CSSKeyframeRule>(realm, realm, key, declarations)); | ||||
|     return realm.heap().allocate<CSSKeyframeRule>(realm, realm, key, declarations); | ||||
| } | ||||
| 
 | ||||
| void CSSKeyframeRule::visit_edges(Visitor& visitor) | ||||
|  |  | |||
|  | @ -20,7 +20,7 @@ class CSSKeyframeRule final : public CSSRule { | |||
|     WEB_PLATFORM_OBJECT(CSSKeyframeRule, CSSRule); | ||||
| 
 | ||||
| public: | ||||
|     static WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSKeyframeRule>> create(JS::Realm& realm, CSS::Percentage key, CSSStyleDeclaration& declarations); | ||||
|     static JS::NonnullGCPtr<CSSKeyframeRule> create(JS::Realm&, CSS::Percentage key, CSSStyleDeclaration&); | ||||
| 
 | ||||
|     virtual ~CSSKeyframeRule() = default; | ||||
| 
 | ||||
|  |  | |||
|  | @ -10,9 +10,9 @@ | |||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSKeyframesRule>> CSSKeyframesRule::create(JS::Realm& realm, AK::FlyString name, Vector<JS::NonnullGCPtr<CSSKeyframeRule>> keyframes) | ||||
| JS::NonnullGCPtr<CSSKeyframesRule> CSSKeyframesRule::create(JS::Realm& realm, AK::FlyString name, Vector<JS::NonnullGCPtr<CSSKeyframeRule>> keyframes) | ||||
| { | ||||
|     return MUST_OR_THROW_OOM(realm.heap().allocate<CSSKeyframesRule>(realm, realm, move(name), move(keyframes))); | ||||
|     return realm.heap().allocate<CSSKeyframesRule>(realm, realm, move(name), move(keyframes)); | ||||
| } | ||||
| 
 | ||||
| void CSSKeyframesRule::visit_edges(Visitor& visitor) | ||||
|  |  | |||
|  | @ -21,7 +21,7 @@ class CSSKeyframesRule final : public CSSRule { | |||
|     WEB_PLATFORM_OBJECT(CSSKeyframesRule, CSSRule); | ||||
| 
 | ||||
| public: | ||||
|     static WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSKeyframesRule>> create(JS::Realm& realm, FlyString name, Vector<JS::NonnullGCPtr<CSSKeyframeRule>> keyframes); | ||||
|     [[nodiscard]] static JS::NonnullGCPtr<CSSKeyframesRule> create(JS::Realm&, FlyString name, Vector<JS::NonnullGCPtr<CSSKeyframeRule>>); | ||||
| 
 | ||||
|     virtual ~CSSKeyframesRule() = default; | ||||
| 
 | ||||
|  |  | |||
|  | @ -12,9 +12,9 @@ | |||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSMediaRule>> CSSMediaRule::create(JS::Realm& realm, MediaList& media_queries, CSSRuleList& rules) | ||||
| JS::NonnullGCPtr<CSSMediaRule> CSSMediaRule::create(JS::Realm& realm, MediaList& media_queries, CSSRuleList& rules) | ||||
| { | ||||
|     return MUST_OR_THROW_OOM(realm.heap().allocate<CSSMediaRule>(realm, realm, media_queries, rules)); | ||||
|     return realm.heap().allocate<CSSMediaRule>(realm, realm, media_queries, rules); | ||||
| } | ||||
| 
 | ||||
| CSSMediaRule::CSSMediaRule(JS::Realm& realm, MediaList& media, CSSRuleList& rules) | ||||
|  |  | |||
|  | @ -18,7 +18,7 @@ class CSSMediaRule final : public CSSConditionRule { | |||
|     WEB_PLATFORM_OBJECT(CSSMediaRule, CSSConditionRule); | ||||
| 
 | ||||
| public: | ||||
|     static WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSMediaRule>> create(JS::Realm&, MediaList& media_queries, CSSRuleList&); | ||||
|     [[nodiscard]] static JS::NonnullGCPtr<CSSMediaRule> create(JS::Realm&, MediaList& media_queries, CSSRuleList&); | ||||
| 
 | ||||
|     virtual ~CSSMediaRule() = default; | ||||
| 
 | ||||
|  |  | |||
|  | @ -21,9 +21,9 @@ CSSNamespaceRule::CSSNamespaceRule(JS::Realm& realm, Optional<DeprecatedString> | |||
| { | ||||
| } | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSNamespaceRule>> CSSNamespaceRule::create(JS::Realm& realm, Optional<DeprecatedString> prefix, AK::StringView namespace_uri) | ||||
| JS::NonnullGCPtr<CSSNamespaceRule> CSSNamespaceRule::create(JS::Realm& realm, Optional<DeprecatedString> prefix, AK::StringView namespace_uri) | ||||
| { | ||||
|     return MUST_OR_THROW_OOM(realm.heap().allocate<CSSNamespaceRule>(realm, realm, prefix, namespace_uri)); | ||||
|     return realm.heap().allocate<CSSNamespaceRule>(realm, realm, prefix, namespace_uri); | ||||
| } | ||||
| 
 | ||||
| void CSSNamespaceRule::initialize(JS::Realm& realm) | ||||
|  |  | |||
|  | @ -14,7 +14,7 @@ class CSSNamespaceRule final : public CSSRule { | |||
|     WEB_PLATFORM_OBJECT(CSSNamespaceRule, CSSRule); | ||||
| 
 | ||||
| public: | ||||
|     static WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSNamespaceRule>> create(JS::Realm&, Optional<DeprecatedString> prefix, StringView namespace_uri); | ||||
|     [[nodiscard]] static JS::NonnullGCPtr<CSSNamespaceRule> create(JS::Realm&, Optional<DeprecatedString> prefix, StringView namespace_uri); | ||||
| 
 | ||||
|     virtual ~CSSNamespaceRule() = default; | ||||
| 
 | ||||
|  |  | |||
|  | @ -18,9 +18,9 @@ | |||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSRuleList>> CSSRuleList::create(JS::Realm& realm, JS::MarkedVector<CSSRule*> const& rules) | ||||
| JS::NonnullGCPtr<CSSRuleList> CSSRuleList::create(JS::Realm& realm, JS::MarkedVector<CSSRule*> const& rules) | ||||
| { | ||||
|     auto rule_list = MUST_OR_THROW_OOM(realm.heap().allocate<CSSRuleList>(realm, realm)); | ||||
|     auto rule_list = realm.heap().allocate<CSSRuleList>(realm, realm); | ||||
|     for (auto* rule : rules) | ||||
|         rule_list->m_rules.append(*rule); | ||||
|     return rule_list; | ||||
|  | @ -31,9 +31,9 @@ CSSRuleList::CSSRuleList(JS::Realm& realm) | |||
| { | ||||
| } | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSRuleList>> CSSRuleList::create_empty(JS::Realm& realm) | ||||
| JS::NonnullGCPtr<CSSRuleList> CSSRuleList::create_empty(JS::Realm& realm) | ||||
| { | ||||
|     return MUST_OR_THROW_OOM(realm.heap().allocate<CSSRuleList>(realm, realm)); | ||||
|     return realm.heap().allocate<CSSRuleList>(realm, realm); | ||||
| } | ||||
| 
 | ||||
| void CSSRuleList::initialize(JS::Realm& realm) | ||||
|  |  | |||
|  | @ -23,8 +23,8 @@ class CSSRuleList : public Bindings::LegacyPlatformObject { | |||
|     WEB_PLATFORM_OBJECT(CSSRuleList, Bindings::LegacyPlatformObject); | ||||
| 
 | ||||
| public: | ||||
|     static WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSRuleList>> create(JS::Realm&, JS::MarkedVector<CSSRule*> const&); | ||||
|     static WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSRuleList>> create_empty(JS::Realm&); | ||||
|     [[nodiscard]] static JS::NonnullGCPtr<CSSRuleList> create(JS::Realm&, JS::MarkedVector<CSSRule*> const&); | ||||
|     [[nodiscard]] static JS::NonnullGCPtr<CSSRuleList> create_empty(JS::Realm&); | ||||
| 
 | ||||
|     ~CSSRuleList() = default; | ||||
| 
 | ||||
|  |  | |||
|  | @ -26,9 +26,9 @@ void CSSStyleDeclaration::initialize(JS::Realm& realm) | |||
|     set_prototype(&Bindings::ensure_web_prototype<Bindings::CSSStyleDeclarationPrototype>(realm, "CSSStyleDeclaration")); | ||||
| } | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::NonnullGCPtr<PropertyOwningCSSStyleDeclaration>> PropertyOwningCSSStyleDeclaration::create(JS::Realm& realm, Vector<StyleProperty> properties, HashMap<DeprecatedString, StyleProperty> custom_properties) | ||||
| JS::NonnullGCPtr<PropertyOwningCSSStyleDeclaration> PropertyOwningCSSStyleDeclaration::create(JS::Realm& realm, Vector<StyleProperty> properties, HashMap<DeprecatedString, StyleProperty> custom_properties) | ||||
| { | ||||
|     return MUST_OR_THROW_OOM(realm.heap().allocate<PropertyOwningCSSStyleDeclaration>(realm, realm, move(properties), move(custom_properties))); | ||||
|     return realm.heap().allocate<PropertyOwningCSSStyleDeclaration>(realm, realm, move(properties), move(custom_properties)); | ||||
| } | ||||
| 
 | ||||
| PropertyOwningCSSStyleDeclaration::PropertyOwningCSSStyleDeclaration(JS::Realm& realm, Vector<StyleProperty> properties, HashMap<DeprecatedString, StyleProperty> custom_properties) | ||||
|  | @ -45,10 +45,10 @@ DeprecatedString PropertyOwningCSSStyleDeclaration::item(size_t index) const | |||
|     return CSS::string_from_property_id(m_properties[index].property_id); | ||||
| } | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::NonnullGCPtr<ElementInlineCSSStyleDeclaration>> ElementInlineCSSStyleDeclaration::create(DOM::Element& element, Vector<StyleProperty> properties, HashMap<DeprecatedString, StyleProperty> custom_properties) | ||||
| JS::NonnullGCPtr<ElementInlineCSSStyleDeclaration> ElementInlineCSSStyleDeclaration::create(DOM::Element& element, Vector<StyleProperty> properties, HashMap<DeprecatedString, StyleProperty> custom_properties) | ||||
| { | ||||
|     auto& realm = element.realm(); | ||||
|     return MUST_OR_THROW_OOM(realm.heap().allocate<ElementInlineCSSStyleDeclaration>(realm, element, move(properties), move(custom_properties))); | ||||
|     return realm.heap().allocate<ElementInlineCSSStyleDeclaration>(realm, element, move(properties), move(custom_properties)); | ||||
| } | ||||
| 
 | ||||
| ElementInlineCSSStyleDeclaration::ElementInlineCSSStyleDeclaration(DOM::Element& element, Vector<StyleProperty> properties, HashMap<DeprecatedString, StyleProperty> custom_properties) | ||||
|  |  | |||
|  | @ -53,7 +53,7 @@ class PropertyOwningCSSStyleDeclaration : public CSSStyleDeclaration { | |||
|     friend class ElementInlineCSSStyleDeclaration; | ||||
| 
 | ||||
| public: | ||||
|     static WebIDL::ExceptionOr<JS::NonnullGCPtr<PropertyOwningCSSStyleDeclaration>> | ||||
|     [[nodiscard]] static JS::NonnullGCPtr<PropertyOwningCSSStyleDeclaration> | ||||
|     create(JS::Realm&, Vector<StyleProperty>, HashMap<DeprecatedString, StyleProperty> custom_properties); | ||||
| 
 | ||||
|     virtual ~PropertyOwningCSSStyleDeclaration() override = default; | ||||
|  | @ -93,7 +93,7 @@ class ElementInlineCSSStyleDeclaration final : public PropertyOwningCSSStyleDecl | |||
|     WEB_PLATFORM_OBJECT(ElementInlineCSSStyleDeclaration, PropertyOwningCSSStyleDeclaration); | ||||
| 
 | ||||
| public: | ||||
|     static WebIDL::ExceptionOr<JS::NonnullGCPtr<ElementInlineCSSStyleDeclaration>> create(DOM::Element&, Vector<StyleProperty> properties, HashMap<DeprecatedString, StyleProperty> custom_properties); | ||||
|     [[nodiscard]] static JS::NonnullGCPtr<ElementInlineCSSStyleDeclaration> create(DOM::Element&, Vector<StyleProperty>, HashMap<DeprecatedString, StyleProperty> custom_properties); | ||||
| 
 | ||||
|     virtual ~ElementInlineCSSStyleDeclaration() override = default; | ||||
| 
 | ||||
|  |  | |||
|  | @ -12,9 +12,9 @@ | |||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSStyleRule>> CSSStyleRule::create(JS::Realm& realm, Vector<NonnullRefPtr<Web::CSS::Selector>>&& selectors, CSSStyleDeclaration& declaration) | ||||
| JS::NonnullGCPtr<CSSStyleRule> CSSStyleRule::create(JS::Realm& realm, Vector<NonnullRefPtr<Web::CSS::Selector>>&& selectors, CSSStyleDeclaration& declaration) | ||||
| { | ||||
|     return MUST_OR_THROW_OOM(realm.heap().allocate<CSSStyleRule>(realm, realm, move(selectors), declaration)); | ||||
|     return realm.heap().allocate<CSSStyleRule>(realm, realm, move(selectors), declaration); | ||||
| } | ||||
| 
 | ||||
| CSSStyleRule::CSSStyleRule(JS::Realm& realm, Vector<NonnullRefPtr<Selector>>&& selectors, CSSStyleDeclaration& declaration) | ||||
|  |  | |||
|  | @ -18,7 +18,7 @@ class CSSStyleRule final : public CSSRule { | |||
|     WEB_PLATFORM_OBJECT(CSSStyleRule, CSSRule); | ||||
| 
 | ||||
| public: | ||||
|     static WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSStyleRule>> create(JS::Realm&, Vector<NonnullRefPtr<Selector>>&&, CSSStyleDeclaration&); | ||||
|     [[nodiscard]] static JS::NonnullGCPtr<CSSStyleRule> create(JS::Realm&, Vector<NonnullRefPtr<Selector>>&&, CSSStyleDeclaration&); | ||||
| 
 | ||||
|     virtual ~CSSStyleRule() override = default; | ||||
| 
 | ||||
|  |  | |||
|  | @ -15,9 +15,9 @@ | |||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSStyleSheet>> CSSStyleSheet::create(JS::Realm& realm, CSSRuleList& rules, MediaList& media, Optional<AK::URL> location) | ||||
| JS::NonnullGCPtr<CSSStyleSheet> CSSStyleSheet::create(JS::Realm& realm, CSSRuleList& rules, MediaList& media, Optional<AK::URL> location) | ||||
| { | ||||
|     return MUST_OR_THROW_OOM(realm.heap().allocate<CSSStyleSheet>(realm, realm, rules, media, move(location))); | ||||
|     return realm.heap().allocate<CSSStyleSheet>(realm, realm, rules, media, move(location)); | ||||
| } | ||||
| 
 | ||||
| CSSStyleSheet::CSSStyleSheet(JS::Realm& realm, CSSRuleList& rules, MediaList& media, Optional<AK::URL> location) | ||||
|  |  | |||
|  | @ -23,7 +23,7 @@ class CSSStyleSheet final | |||
|     WEB_PLATFORM_OBJECT(CSSStyleSheet, StyleSheet); | ||||
| 
 | ||||
| public: | ||||
|     static WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSStyleSheet>> create(JS::Realm&, CSSRuleList& rules, MediaList& media, Optional<AK::URL> location); | ||||
|     [[nodiscard]] static JS::NonnullGCPtr<CSSStyleSheet> create(JS::Realm&, CSSRuleList&, MediaList&, Optional<AK::URL> location); | ||||
| 
 | ||||
|     virtual ~CSSStyleSheet() override = default; | ||||
| 
 | ||||
|  |  | |||
|  | @ -11,9 +11,9 @@ | |||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSSupportsRule>> CSSSupportsRule::create(JS::Realm& realm, NonnullRefPtr<Supports>&& supports, CSSRuleList& rules) | ||||
| JS::NonnullGCPtr<CSSSupportsRule> CSSSupportsRule::create(JS::Realm& realm, NonnullRefPtr<Supports>&& supports, CSSRuleList& rules) | ||||
| { | ||||
|     return MUST_OR_THROW_OOM(realm.heap().allocate<CSSSupportsRule>(realm, realm, move(supports), rules)); | ||||
|     return realm.heap().allocate<CSSSupportsRule>(realm, realm, move(supports), rules); | ||||
| } | ||||
| 
 | ||||
| CSSSupportsRule::CSSSupportsRule(JS::Realm& realm, NonnullRefPtr<Supports>&& supports, CSSRuleList& rules) | ||||
|  |  | |||
|  | @ -19,7 +19,7 @@ class CSSSupportsRule final : public CSSConditionRule { | |||
|     WEB_PLATFORM_OBJECT(CSSSupportsRule, CSSConditionRule); | ||||
| 
 | ||||
| public: | ||||
|     static WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSSupportsRule>> create(JS::Realm&, NonnullRefPtr<Supports>&&, CSSRuleList&); | ||||
|     static JS::NonnullGCPtr<CSSSupportsRule> create(JS::Realm&, NonnullRefPtr<Supports>&&, CSSRuleList&); | ||||
| 
 | ||||
|     virtual ~CSSSupportsRule() = default; | ||||
| 
 | ||||
|  |  | |||
|  | @ -13,9 +13,9 @@ | |||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::NonnullGCPtr<MediaList>> MediaList::create(JS::Realm& realm, Vector<NonnullRefPtr<MediaQuery>>&& media) | ||||
| JS::NonnullGCPtr<MediaList> MediaList::create(JS::Realm& realm, Vector<NonnullRefPtr<MediaQuery>>&& media) | ||||
| { | ||||
|     return MUST_OR_THROW_OOM(realm.heap().allocate<MediaList>(realm, realm, move(media))); | ||||
|     return realm.heap().allocate<MediaList>(realm, realm, move(media)); | ||||
| } | ||||
| 
 | ||||
| MediaList::MediaList(JS::Realm& realm, Vector<NonnullRefPtr<MediaQuery>>&& media) | ||||
|  |  | |||
|  | @ -20,7 +20,7 @@ class MediaList final : public Bindings::LegacyPlatformObject { | |||
|     WEB_PLATFORM_OBJECT(MediaList, Bindings::LegacyPlatformObject); | ||||
| 
 | ||||
| public: | ||||
|     static WebIDL::ExceptionOr<JS::NonnullGCPtr<MediaList>> create(JS::Realm&, Vector<NonnullRefPtr<MediaQuery>>&& media); | ||||
|     [[nodiscard]] static JS::NonnullGCPtr<MediaList> create(JS::Realm&, Vector<NonnullRefPtr<MediaQuery>>&&); | ||||
|     ~MediaList() = default; | ||||
| 
 | ||||
|     DeprecatedString media_text() const; | ||||
|  |  | |||
|  | @ -15,9 +15,9 @@ | |||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::NonnullGCPtr<MediaQueryList>> MediaQueryList::create(DOM::Document& document, Vector<NonnullRefPtr<MediaQuery>>&& media) | ||||
| JS::NonnullGCPtr<MediaQueryList> MediaQueryList::create(DOM::Document& document, Vector<NonnullRefPtr<MediaQuery>>&& media) | ||||
| { | ||||
|     return MUST_OR_THROW_OOM(document.heap().allocate<MediaQueryList>(document.realm(), document, move(media))); | ||||
|     return document.heap().allocate<MediaQueryList>(document.realm(), document, move(media)); | ||||
| } | ||||
| 
 | ||||
| MediaQueryList::MediaQueryList(DOM::Document& document, Vector<NonnullRefPtr<MediaQuery>>&& media) | ||||
|  |  | |||
|  | @ -17,7 +17,7 @@ class MediaQueryList final : public DOM::EventTarget { | |||
|     WEB_PLATFORM_OBJECT(MediaQueryList, DOM::EventTarget); | ||||
| 
 | ||||
| public: | ||||
|     static WebIDL::ExceptionOr<JS::NonnullGCPtr<MediaQueryList>> create(DOM::Document&, Vector<NonnullRefPtr<MediaQuery>>&&); | ||||
|     [[nodiscard]] static JS::NonnullGCPtr<MediaQueryList> create(DOM::Document&, Vector<NonnullRefPtr<MediaQuery>>&&); | ||||
| 
 | ||||
|     virtual ~MediaQueryList() override = default; | ||||
| 
 | ||||
|  |  | |||
|  | @ -10,9 +10,9 @@ | |||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::NonnullGCPtr<MediaQueryListEvent>> MediaQueryListEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, MediaQueryListEventInit const& event_init) | ||||
| JS::NonnullGCPtr<MediaQueryListEvent> MediaQueryListEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, MediaQueryListEventInit const& event_init) | ||||
| { | ||||
|     return MUST_OR_THROW_OOM(realm.heap().allocate<MediaQueryListEvent>(realm, realm, event_name, event_init)); | ||||
|     return realm.heap().allocate<MediaQueryListEvent>(realm, realm, event_name, event_init); | ||||
| } | ||||
| 
 | ||||
| MediaQueryListEvent::MediaQueryListEvent(JS::Realm& realm, FlyString const& event_name, MediaQueryListEventInit const& event_init) | ||||
|  |  | |||
|  | @ -20,7 +20,7 @@ class MediaQueryListEvent final : public DOM::Event { | |||
|     WEB_PLATFORM_OBJECT(MediaQueryListEvent, DOM::Event); | ||||
| 
 | ||||
| public: | ||||
|     static WebIDL::ExceptionOr<JS::NonnullGCPtr<MediaQueryListEvent>> construct_impl(JS::Realm&, FlyString const& event_name, MediaQueryListEventInit const& event_init = {}); | ||||
|     [[nodiscard]] static JS::NonnullGCPtr<MediaQueryListEvent> construct_impl(JS::Realm&, FlyString const& event_name, MediaQueryListEventInit const& = {}); | ||||
| 
 | ||||
|     virtual ~MediaQueryListEvent() override; | ||||
| 
 | ||||
|  |  | |||
|  | @ -18,9 +18,9 @@ namespace Web { | |||
| CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingContext const& context, StringView css, Optional<AK::URL> location) | ||||
| { | ||||
|     if (css.is_empty()) { | ||||
|         auto rule_list = CSS::CSSRuleList::create_empty(context.realm()).release_value_but_fixme_should_propagate_errors(); | ||||
|         auto media_list = CSS::MediaList::create(context.realm(), {}).release_value_but_fixme_should_propagate_errors(); | ||||
|         return CSS::CSSStyleSheet::create(context.realm(), rule_list, media_list, location).release_value_but_fixme_should_propagate_errors(); | ||||
|         auto rule_list = CSS::CSSRuleList::create_empty(context.realm()); | ||||
|         auto media_list = CSS::MediaList::create(context.realm(), {}); | ||||
|         return CSS::CSSStyleSheet::create(context.realm(), rule_list, media_list, location); | ||||
|     } | ||||
|     auto parser = CSS::Parser::Parser::create(context, css).release_value_but_fixme_should_propagate_errors(); | ||||
|     return parser.parse_as_css_stylesheet(location); | ||||
|  | @ -29,7 +29,7 @@ CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingContext const& cont | |||
| CSS::ElementInlineCSSStyleDeclaration* parse_css_style_attribute(CSS::Parser::ParsingContext const& context, StringView css, DOM::Element& element) | ||||
| { | ||||
|     if (css.is_empty()) | ||||
|         return CSS::ElementInlineCSSStyleDeclaration::create(element, {}, {}).release_value_but_fixme_should_propagate_errors(); | ||||
|         return CSS::ElementInlineCSSStyleDeclaration::create(element, {}, {}); | ||||
|     auto parser = CSS::Parser::Parser::create(context, css).release_value_but_fixme_should_propagate_errors(); | ||||
|     return parser.parse_as_style_attribute(element); | ||||
| } | ||||
|  |  | |||
|  | @ -161,9 +161,9 @@ CSSStyleSheet* Parser::parse_as_css_stylesheet(Optional<AK::URL> location) | |||
|             rules.append(rule); | ||||
|     } | ||||
| 
 | ||||
|     auto rule_list = CSSRuleList::create(m_context.realm(), rules).release_value_but_fixme_should_propagate_errors(); | ||||
|     auto media_list = MediaList::create(m_context.realm(), {}).release_value_but_fixme_should_propagate_errors(); | ||||
|     return CSSStyleSheet::create(m_context.realm(), rule_list, media_list, move(location)).release_value_but_fixme_should_propagate_errors(); | ||||
|     auto rule_list = CSSRuleList::create(m_context.realm(), rules); | ||||
|     auto media_list = MediaList::create(m_context.realm(), {}); | ||||
|     return CSSStyleSheet::create(m_context.realm(), rule_list, media_list, move(location)); | ||||
| } | ||||
| 
 | ||||
| Optional<SelectorList> Parser::parse_as_selector(SelectorParsingMode parsing_mode) | ||||
|  | @ -2360,7 +2360,7 @@ ElementInlineCSSStyleDeclaration* Parser::parse_as_style_attribute(DOM::Element& | |||
| { | ||||
|     auto declarations_and_at_rules = parse_a_list_of_declarations(m_token_stream); | ||||
|     auto [properties, custom_properties] = extract_properties(declarations_and_at_rules); | ||||
|     return ElementInlineCSSStyleDeclaration::create(element, move(properties), move(custom_properties)).release_value_but_fixme_should_propagate_errors(); | ||||
|     return ElementInlineCSSStyleDeclaration::create(element, move(properties), move(custom_properties)); | ||||
| } | ||||
| 
 | ||||
| Optional<AK::URL> Parser::parse_url_function(ComponentValue const& component_value) | ||||
|  | @ -3149,7 +3149,7 @@ CSSRule* Parser::convert_to_rule(NonnullRefPtr<Rule> rule) | |||
|             } | ||||
| 
 | ||||
|             if (url.has_value()) | ||||
|                 return CSSImportRule::create(url.value(), const_cast<DOM::Document&>(*m_context.document())).release_value_but_fixme_should_propagate_errors(); | ||||
|                 return CSSImportRule::create(url.value(), const_cast<DOM::Document&>(*m_context.document())); | ||||
|             dbgln_if(CSS_PARSER_DEBUG, "Unable to parse url from @import rule"); | ||||
|             return {}; | ||||
|         } | ||||
|  | @ -3166,9 +3166,9 @@ CSSRule* Parser::convert_to_rule(NonnullRefPtr<Rule> rule) | |||
|                 if (auto* child_rule = convert_to_rule(raw_rule)) | ||||
|                     child_rules.append(child_rule); | ||||
|             } | ||||
|             auto media_list = MediaList::create(m_context.realm(), move(media_query_list)).release_value_but_fixme_should_propagate_errors(); | ||||
|             auto rule_list = CSSRuleList::create(m_context.realm(), child_rules).release_value_but_fixme_should_propagate_errors(); | ||||
|             return CSSMediaRule::create(m_context.realm(), media_list, rule_list).release_value_but_fixme_should_propagate_errors(); | ||||
|             auto media_list = MediaList::create(m_context.realm(), move(media_query_list)); | ||||
|             auto rule_list = CSSRuleList::create(m_context.realm(), child_rules); | ||||
|             return CSSMediaRule::create(m_context.realm(), media_list, rule_list); | ||||
|         } | ||||
|         if (rule->at_rule_name().equals_ignoring_ascii_case("supports"sv)) { | ||||
|             auto supports_tokens = TokenStream { rule->prelude() }; | ||||
|  | @ -3191,8 +3191,8 @@ CSSRule* Parser::convert_to_rule(NonnullRefPtr<Rule> rule) | |||
|                     child_rules.append(child_rule); | ||||
|             } | ||||
| 
 | ||||
|             auto rule_list = CSSRuleList::create(m_context.realm(), child_rules).release_value_but_fixme_should_propagate_errors(); | ||||
|             return CSSSupportsRule::create(m_context.realm(), supports.release_nonnull(), rule_list).release_value_but_fixme_should_propagate_errors(); | ||||
|             auto rule_list = CSSRuleList::create(m_context.realm(), child_rules); | ||||
|             return CSSSupportsRule::create(m_context.realm(), supports.release_nonnull(), rule_list); | ||||
|         } | ||||
|         if (rule->at_rule_name().equals_ignoring_ascii_case("keyframes"sv)) { | ||||
|             auto prelude_stream = TokenStream { rule->prelude() }; | ||||
|  | @ -3286,7 +3286,7 @@ CSSRule* Parser::convert_to_rule(NonnullRefPtr<Rule> rule) | |||
|                     auto block_declarations = parse_a_list_of_declarations(block_stream); | ||||
|                     auto style = convert_to_style_declaration(block_declarations); | ||||
|                     for (auto& selector : selectors) { | ||||
|                         auto keyframe_rule = CSSKeyframeRule::create(m_context.realm(), selector, *style).release_value_but_fixme_should_propagate_errors(); | ||||
|                         auto keyframe_rule = CSSKeyframeRule::create(m_context.realm(), selector, *style); | ||||
|                         keyframes.append(keyframe_rule); | ||||
|                     } | ||||
|                 } else { | ||||
|  | @ -3294,7 +3294,7 @@ CSSRule* Parser::convert_to_rule(NonnullRefPtr<Rule> rule) | |||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             return CSSKeyframesRule::create(m_context.realm(), name, move(keyframes)).release_value_but_fixme_should_propagate_errors(); | ||||
|             return CSSKeyframesRule::create(m_context.realm(), name, move(keyframes)); | ||||
|         } | ||||
|         if (rule->at_rule_name().equals_ignoring_ascii_case("namespace"sv)) { | ||||
|             // https://drafts.csswg.org/css-namespaces/#syntax
 | ||||
|  | @ -3325,7 +3325,7 @@ CSSRule* Parser::convert_to_rule(NonnullRefPtr<Rule> rule) | |||
|                 return {}; | ||||
|             } | ||||
| 
 | ||||
|             return CSSNamespaceRule::create(m_context.realm(), prefix, namespace_uri).release_value_but_fixme_should_propagate_errors(); | ||||
|             return CSSNamespaceRule::create(m_context.realm(), prefix, namespace_uri); | ||||
|         } | ||||
| 
 | ||||
|         // FIXME: More at rules!
 | ||||
|  | @ -3363,7 +3363,7 @@ CSSRule* Parser::convert_to_rule(NonnullRefPtr<Rule> rule) | |||
|         return {}; | ||||
|     } | ||||
| 
 | ||||
|     return CSSStyleRule::create(m_context.realm(), move(selectors.value()), *declaration).release_value_but_fixme_should_propagate_errors(); | ||||
|     return CSSStyleRule::create(m_context.realm(), move(selectors.value()), *declaration); | ||||
| } | ||||
| 
 | ||||
| auto Parser::extract_properties(Vector<DeclarationOrAtRule> const& declarations_and_at_rules) -> PropertiesAndCustomProperties | ||||
|  | @ -3392,7 +3392,7 @@ auto Parser::extract_properties(Vector<DeclarationOrAtRule> const& declarations_ | |||
| PropertyOwningCSSStyleDeclaration* Parser::convert_to_style_declaration(Vector<DeclarationOrAtRule> const& declarations_and_at_rules) | ||||
| { | ||||
|     auto [properties, custom_properties] = extract_properties(declarations_and_at_rules); | ||||
|     return PropertyOwningCSSStyleDeclaration::create(m_context.realm(), move(properties), move(custom_properties)).release_value_but_fixme_should_propagate_errors(); | ||||
|     return PropertyOwningCSSStyleDeclaration::create(m_context.realm(), move(properties), move(custom_properties)); | ||||
| } | ||||
| 
 | ||||
| Optional<StyleProperty> Parser::convert_to_style_property(Declaration const& declaration) | ||||
|  | @ -6133,7 +6133,7 @@ CSSRule* Parser::parse_font_face_rule(TokenStream<ComponentValue>& tokens) | |||
|         unicode_range.empend(0x0u, 0x10FFFFu); | ||||
|     } | ||||
| 
 | ||||
|     return CSSFontFaceRule::create(m_context.realm(), FontFace { font_family.release_value(), weight, slope, move(src), move(unicode_range) }).release_value_but_fixme_should_propagate_errors(); | ||||
|     return CSSFontFaceRule::create(m_context.realm(), FontFace { font_family.release_value(), weight, slope, move(src), move(unicode_range) }); | ||||
| } | ||||
| 
 | ||||
| Vector<FontFace::Source> Parser::parse_font_face_src(TokenStream<ComponentValue>& component_values) | ||||
|  |  | |||
|  | @ -48,9 +48,9 @@ | |||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| WebIDL::ExceptionOr<JS::NonnullGCPtr<ResolvedCSSStyleDeclaration>> ResolvedCSSStyleDeclaration::create(DOM::Element& element) | ||||
| JS::NonnullGCPtr<ResolvedCSSStyleDeclaration> ResolvedCSSStyleDeclaration::create(DOM::Element& element) | ||||
| { | ||||
|     return MUST_OR_THROW_OOM(element.realm().heap().allocate<ResolvedCSSStyleDeclaration>(element.realm(), element)); | ||||
|     return element.realm().heap().allocate<ResolvedCSSStyleDeclaration>(element.realm(), element); | ||||
| } | ||||
| 
 | ||||
| ResolvedCSSStyleDeclaration::ResolvedCSSStyleDeclaration(DOM::Element& element) | ||||
|  |  | |||
|  | @ -14,7 +14,7 @@ class ResolvedCSSStyleDeclaration final : public CSSStyleDeclaration { | |||
|     WEB_PLATFORM_OBJECT(ResolvedCSSStyleDeclaration, CSSStyleDeclaration); | ||||
| 
 | ||||
| public: | ||||
|     static WebIDL::ExceptionOr<JS::NonnullGCPtr<ResolvedCSSStyleDeclaration>> create(DOM::Element& element); | ||||
|     [[nodiscard]] static JS::NonnullGCPtr<ResolvedCSSStyleDeclaration> create(DOM::Element&); | ||||
| 
 | ||||
|     virtual ~ResolvedCSSStyleDeclaration() override = default; | ||||
| 
 | ||||
|  |  | |||
Some files were not shown because too many files have changed in this diff Show more
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling