LibJS: Convert Array::create{,_from}() to NonnullGCPtr

This commit is contained in:
Linus Groh 2022-12-13 20:49:49 +00:00
parent 0c50751c13
commit 91b0123eaf
Notes: sideshowbarker 2024-07-17 08:42:05 +09:00
25 changed files with 60 additions and 60 deletions

View file

@ -1429,7 +1429,7 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString
auto& sequence_generic_type = verify_cast<IDL::ParameterizedType>(type);
scoped_generator.append(R"~~~(
auto* new_array@recursion_depth@ = MUST(JS::Array::create(realm, 0));
auto new_array@recursion_depth@ = MUST(JS::Array::create(realm, 0));
)~~~");
if (!type.is_nullable()) {

View file

@ -3571,7 +3571,7 @@ Completion ArrayExpression::execute(Interpreter& interpreter) const
auto& realm = *vm.current_realm();
// 1. Let array be ! ArrayCreate(0).
auto* array = MUST(Array::create(realm, 0));
auto array = MUST(Array::create(realm, 0));
// 2. Perform ? ArrayAccumulation of ElementList with arguments array and 0.
@ -3736,10 +3736,10 @@ ThrowCompletionOr<Value> TaggedTemplateLiteral::get_template_object(Interpreter&
// 8. Let template be ! ArrayCreate(count).
// NOTE: We don't set count since we push the values using append which
// would then append after count. Same for 9.
auto* template_ = MUST(Array::create(realm, 0));
auto template_ = MUST(Array::create(realm, 0));
// 9. Let rawObj be ! ArrayCreate(count).
auto* raw_obj = MUST(Array::create(realm, 0));
auto raw_obj = MUST(Array::create(realm, 0));
// 10. Let index be 0.
// 11. Repeat, while index < count,
@ -3775,7 +3775,7 @@ ThrowCompletionOr<Value> TaggedTemplateLiteral::get_template_object(Interpreter&
MUST(template_->set_integrity_level(Object::IntegrityLevel::Frozen));
// 15. Append the Record { [[Site]]: templateLiteral, [[Array]]: template } to templateRegistry.
m_cached_values.set(&realm, make_handle(template_));
m_cached_values.set(&realm, make_handle(template_.ptr()));
// 16. Return template.
return template_;

View file

@ -176,7 +176,7 @@ ThrowCompletionOr<void> NewBigInt::execute_impl(Bytecode::Interpreter& interpret
ThrowCompletionOr<void> NewArray::execute_impl(Bytecode::Interpreter& interpreter) const
{
auto* array = MUST(Array::create(interpreter.realm(), 0));
auto array = MUST(Array::create(interpreter.realm(), 0));
for (size_t i = 0; i < m_element_count; i++) {
auto& value = interpreter.reg(Register(m_elements[0].index() + i));
array->indexed_properties().put(i, value, default_attributes);
@ -273,7 +273,7 @@ ThrowCompletionOr<void> IteratorToArray::execute_impl(Bytecode::Interpreter& int
auto iterator_object = TRY(interpreter.accumulator().to_object(vm));
auto iterator = object_to_iterator(vm, *iterator_object);
auto* array = MUST(Array::create(interpreter.realm(), 0));
auto array = MUST(Array::create(interpreter.realm(), 0));
size_t index = 0;
while (true) {

View file

@ -17,7 +17,7 @@
namespace JS {
// 10.4.2.2 ArrayCreate ( length [ , proto ] ), https://tc39.es/ecma262/#sec-arraycreate
ThrowCompletionOr<Array*> Array::create(Realm& realm, u64 length, Object* prototype)
ThrowCompletionOr<NonnullGCPtr<Array>> Array::create(Realm& realm, u64 length, Object* prototype)
{
auto& vm = realm.vm();
@ -38,14 +38,14 @@ ThrowCompletionOr<Array*> Array::create(Realm& realm, u64 length, Object* protot
MUST(array->internal_define_own_property(vm.names.length, { .value = Value(length), .writable = true, .enumerable = false, .configurable = false }));
// 7. Return A.
return array;
return NonnullGCPtr { *array };
}
// 7.3.18 CreateArrayFromList ( elements ), https://tc39.es/ecma262/#sec-createarrayfromlist
Array* Array::create_from(Realm& realm, Vector<Value> const& elements)
NonnullGCPtr<Array> Array::create_from(Realm& realm, Vector<Value> const& elements)
{
// 1. Let array be ! ArrayCreate(0).
auto* array = MUST(Array::create(realm, 0));
auto array = MUST(Array::create(realm, 0));
// 2. Let n be 0.
// 3. For each element e of elements, do

View file

@ -21,11 +21,11 @@ class Array : public Object {
JS_OBJECT(Array, Object);
public:
static ThrowCompletionOr<Array*> create(Realm&, u64 length, Object* prototype = nullptr);
static Array* create_from(Realm&, Vector<Value> const&);
static ThrowCompletionOr<NonnullGCPtr<Array>> create(Realm&, u64 length, Object* prototype = nullptr);
static NonnullGCPtr<Array> create_from(Realm&, Vector<Value> const&);
// Non-standard but equivalent to CreateArrayFromList.
template<typename T>
static Array* create_from(Realm& realm, Span<T const> elements, Function<Value(T const&)> map_fn)
static NonnullGCPtr<Array> create_from(Realm& realm, Span<T const> elements, Function<Value(T const&)> map_fn)
{
auto values = MarkedVector<Value> { realm.heap() };
values.ensure_capacity(elements.size());

View file

@ -55,11 +55,11 @@ ThrowCompletionOr<Object*> ArrayConstructor::construct(FunctionObject& new_targe
auto* proto = TRY(get_prototype_from_constructor(vm, new_target, &Intrinsics::array_prototype));
if (vm.argument_count() == 0)
return MUST(Array::create(realm, 0, proto));
return MUST(Array::create(realm, 0, proto)).ptr();
if (vm.argument_count() == 1) {
auto length = vm.argument(0);
auto* array = MUST(Array::create(realm, 0, proto));
auto array = MUST(Array::create(realm, 0, proto));
size_t int_length;
if (!length.is_number()) {
MUST(array->create_data_property_or_throw(0, length));
@ -70,15 +70,15 @@ ThrowCompletionOr<Object*> ArrayConstructor::construct(FunctionObject& new_targe
return vm.throw_completion<RangeError>(ErrorType::InvalidLength, "array");
}
TRY(array->set(vm.names.length, Value(int_length), Object::ShouldThrowExceptions::Yes));
return array;
return array.ptr();
}
auto* array = TRY(Array::create(realm, vm.argument_count(), proto));
auto array = TRY(Array::create(realm, vm.argument_count(), proto));
for (size_t k = 0; k < vm.argument_count(); ++k)
MUST(array->create_data_property_or_throw(k, vm.argument(k)));
return array;
return array.ptr();
}
// 23.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] ), https://tc39.es/ecma262/#sec-array.from

View file

@ -120,7 +120,7 @@ static ThrowCompletionOr<Object*> array_species_create(VM& vm, Object& original_
auto is_array = TRY(Value(&original_array).is_array(vm));
if (!is_array)
return TRY(Array::create(realm, length));
return TRY(Array::create(realm, length)).ptr();
auto constructor = TRY(original_array.get(vm.names.constructor));
if (constructor.is_constructor()) {
@ -140,7 +140,7 @@ static ThrowCompletionOr<Object*> array_species_create(VM& vm, Object& original_
}
if (constructor.is_undefined())
return TRY(Array::create(realm, length));
return TRY(Array::create(realm, length)).ptr();
if (!constructor.is_constructor())
return vm.throw_completion<TypeError>(ErrorType::NotAConstructor, constructor.to_string_without_side_effects());
@ -796,7 +796,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group)
// 8. For each Record { [[Key]], [[Elements]] } g of groups, do
for (auto& group : groups) {
// a. Let elements be CreateArrayFromList(g.[[Elements]]).
auto* elements = Array::create_from(realm, group.value);
auto elements = Array::create_from(realm, group.value);
// b. Perform ! CreateDataPropertyOrThrow(obj, g.[[Key]], elements).
MUST(object->create_data_property_or_throw(group.key, elements));
@ -868,7 +868,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group_to_map)
// 8. For each Record { [[Key]], [[Elements]] } g of groups, do
for (auto& group : groups) {
// a. Let elements be CreateArrayFromList(g.[[Elements]]).
auto* elements = Array::create_from(realm, group.value);
auto elements = Array::create_from(realm, group.value);
// b. Let entry be the Record { [[Key]]: g.[[Key]], [[Value]]: elements }.
// c. Append entry as the last element of map.[[MapData]].
@ -1758,7 +1758,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_reversed)
auto length = TRY(length_of_array_like(vm, *object));
// 3. Let A be ? ArrayCreate(𝔽(len)).
auto* array = TRY(Array::create(realm, length));
auto array = TRY(Array::create(realm, length));
// 4. Let k be 0.
// 5. Repeat, while k < len,
@ -1800,7 +1800,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_sorted)
auto length = TRY(length_of_array_like(vm, *object));
// 4. Let A be ? ArrayCreate(𝔽(len)).
auto* array = TRY(Array::create(realm, length));
auto array = TRY(Array::create(realm, length));
// 5. Let SortCompare be a new Abstract Closure with parameters (x, y) that captures comparefn and performs the following steps when called:
Function<ThrowCompletionOr<double>(Value, Value)> sort_compare = [&](auto x, auto y) -> ThrowCompletionOr<double> {
@ -1893,7 +1893,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_spliced)
auto new_length = static_cast<u64>(new_length_double);
// 13. Let A be ? ArrayCreate(𝔽(newLen)).
auto* array = TRY(Array::create(realm, new_length));
auto array = TRY(Array::create(realm, new_length));
// 14. Let i be 0.
size_t i = 0;
@ -2047,7 +2047,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::with)
return vm.throw_completion<RangeError>(ErrorType::IndexOutOfRange, actual_index, length);
// 7. Let A be ? ArrayCreate(𝔽(len)).
auto* array = TRY(Array::create(realm, length));
auto array = TRY(Array::create(realm, length));
// 8. Let k be 0.
// 9. Repeat, while k < len,

View file

@ -441,7 +441,7 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
[&](auto const& param) -> ThrowCompletionOr<void> {
Value argument_value;
if (parameter.is_rest) {
auto* array = MUST(Array::create(realm, 0));
auto array = MUST(Array::create(realm, 0));
for (size_t rest_index = i; rest_index < execution_context_arguments.size(); ++rest_index)
array->indexed_properties().append(execution_context_arguments[rest_index]);
argument_value = array;

View file

@ -589,7 +589,7 @@ ThrowCompletionOr<Array*> supported_locales(VM& vm, Vector<DeprecatedString> con
}
// 5. Return CreateArrayFromList(supportedLocales).
return Array::create_from<DeprecatedString>(realm, supported_locales, [&vm](auto& locale) { return PrimitiveString::create(vm, locale); });
return Array::create_from<DeprecatedString>(realm, supported_locales, [&vm](auto& locale) { return PrimitiveString::create(vm, locale); }).ptr();
}
// 9.2.12 CoerceOptionsToObject ( options ), https://tc39.es/ecma402/#sec-coerceoptionstoobject

View file

@ -857,7 +857,7 @@ ThrowCompletionOr<Array*> format_date_time_to_parts(VM& vm, DateTimeFormat& date
auto parts = TRY(partition_date_time_pattern(vm, date_time_format, time));
// 2. Let result be ! ArrayCreate(0).
auto* result = MUST(Array::create(realm, 0));
auto result = MUST(Array::create(realm, 0));
// 3. Let n be 0.
size_t n = 0;
@ -881,7 +881,7 @@ ThrowCompletionOr<Array*> format_date_time_to_parts(VM& vm, DateTimeFormat& date
}
// 5. Return result.
return result;
return result.ptr();
}
template<typename Callback>
@ -1173,7 +1173,7 @@ ThrowCompletionOr<Array*> format_date_time_range_to_parts(VM& vm, DateTimeFormat
auto parts = TRY(partition_date_time_range_pattern(vm, date_time_format, start, end));
// 2. Let result be ! ArrayCreate(0).
auto* result = MUST(Array::create(realm, 0));
auto result = MUST(Array::create(realm, 0));
// 3. Let n be 0.
size_t n = 0;
@ -1200,7 +1200,7 @@ ThrowCompletionOr<Array*> format_date_time_range_to_parts(VM& vm, DateTimeFormat
}
// 5. Return result.
return result;
return result.ptr();
}
// 11.5.13 ToLocalTime ( epochNs, calendar, timeZone ), https://tc39.es/ecma402/#sec-tolocaltime

View file

@ -82,7 +82,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
auto parts = partition_duration_format_pattern(vm, *duration_format, record);
// 6. Let result be ! ArrayCreate(0).
auto* result = MUST(Array::create(realm, 0));
auto result = MUST(Array::create(realm, 0));
// 7. Let n be 0.
// 8. For each { [[Type]], [[Value]] } part in parts, do

View file

@ -209,7 +209,7 @@ Array* format_list_to_parts(VM& vm, ListFormat const& list_format, Vector<Deprec
auto parts = create_parts_from_list(list_format, list);
// 2. Let result be ! ArrayCreate(0).
auto* result = MUST(Array::create(realm, 0));
auto result = MUST(Array::create(realm, 0));
// 3. Let n be 0.
size_t n = 0;

View file

@ -914,7 +914,7 @@ Array* format_numeric_to_parts(VM& vm, NumberFormat& number_format, Mathematical
auto parts = partition_number_pattern(vm, number_format, move(number));
// 2. Let result be ! ArrayCreate(0).
auto* result = MUST(Array::create(realm, 0));
auto result = MUST(Array::create(realm, 0));
// 3. Let n be 0.
size_t n = 0;
@ -1824,7 +1824,7 @@ ThrowCompletionOr<Array*> format_numeric_range_to_parts(VM& vm, NumberFormat& nu
auto parts = TRY(partition_number_range_pattern(vm, number_format, move(start), move(end)));
// 2. Let result be ! ArrayCreate(0).
auto* result = MUST(Array::create(realm, 0));
auto result = MUST(Array::create(realm, 0));
// 3. Let n be 0.
size_t n = 0;
@ -1851,7 +1851,7 @@ ThrowCompletionOr<Array*> format_numeric_range_to_parts(VM& vm, NumberFormat& nu
}
// 5. Return result.
return result;
return result.ptr();
}
}

View file

@ -108,7 +108,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
// 5. Let pluralCategories be a List of Strings containing all possible results of PluralRuleSelect for the selected locale pr.[[Locale]].
auto available_categories = ::Locale::available_plural_categories(plural_rules->locale(), plural_rules->type());
auto* plural_categories = Array::create_from<::Locale::PluralCategory>(realm, available_categories, [&](auto category) {
auto plural_categories = Array::create_from<::Locale::PluralCategory>(realm, available_categories, [&](auto category) {
return PrimitiveString::create(vm, ::Locale::plural_category_to_string(category));
});

View file

@ -249,7 +249,7 @@ ThrowCompletionOr<Array*> format_relative_time_to_parts(VM& vm, RelativeTimeForm
auto parts = TRY(partition_relative_time_pattern(vm, relative_time_format, value, unit));
// 2. Let result be ! ArrayCreate(0).
auto* result = MUST(Array::create(realm, 0));
auto result = MUST(Array::create(realm, 0));
// 3. Let n be 0.
size_t n = 0;
@ -279,7 +279,7 @@ ThrowCompletionOr<Array*> format_relative_time_to_parts(VM& vm, RelativeTimeForm
}
// 5. Return result.
return result;
return result.ptr();
}
}

View file

@ -441,7 +441,7 @@ Object* JSONObject::parse_json_object(VM& vm, JsonObject const& json_object)
Array* JSONObject::parse_json_array(VM& vm, JsonArray const& json_array)
{
auto& realm = *vm.current_realm();
auto* array = MUST(Array::create(realm, 0));
auto array = MUST(Array::create(realm, 0));
size_t index = 0;
json_array.for_each([&](auto& value) {
array->define_direct_property(index++, parse_json_value(vm, value), default_attributes);

View file

@ -121,7 +121,7 @@ static ThrowCompletionOr<Value> perform_promise_all(VM& vm, Iterator& iterator_r
vm, iterator_record, constructor, result_capability, promise_resolve,
[&](PromiseValueList& values) -> ThrowCompletionOr<Value> {
// 1. Let valuesArray be CreateArrayFromList(values).
auto* values_array = Array::create_from(realm, values.values());
auto values_array = Array::create_from(realm, values.values());
// 2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »).
TRY(call(vm, *result_capability.resolve(), js_undefined(), values_array));
@ -154,7 +154,7 @@ static ThrowCompletionOr<Value> perform_promise_all_settled(VM& vm, Iterator& it
return perform_promise_common(
vm, iterator_record, constructor, result_capability, promise_resolve,
[&](PromiseValueList& values) -> ThrowCompletionOr<Value> {
auto* values_array = Array::create_from(realm, values.values());
auto values_array = Array::create_from(realm, values.values());
TRY(call(vm, *result_capability.resolve(), js_undefined(), values_array));
@ -201,7 +201,7 @@ static ThrowCompletionOr<Value> perform_promise_any(VM& vm, Iterator& iterator_r
auto error = AggregateError::create(realm);
// 2. Perform ! DefinePropertyOrThrow(error, "errors", PropertyDescriptor { [[Configurable]]: true, [[Enumerable]]: false, [[Writable]]: true, [[Value]]: CreateArrayFromList(errors) }).
auto* errors_array = Array::create_from(realm, errors.values());
auto errors_array = Array::create_from(realm, errors.values());
MUST(error->define_property_or_throw(vm.names.errors, { .value = errors_array, .writable = true, .enumerable = false, .configurable = true }));
// 3. Return ThrowCompletion(error).

View file

@ -75,7 +75,7 @@ ThrowCompletionOr<Value> PromiseAllResolveElementFunction::resolve_element()
// 10. If remainingElementsCount.[[Value]] is 0, then
if (--m_remaining_elements.value == 0) {
// a. Let valuesArray be CreateArrayFromList(values).
auto* values_array = Array::create_from(realm, m_values.values());
auto values_array = Array::create_from(realm, m_values.values());
// b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).
return JS::call(vm, *m_capability->resolve(), js_undefined(), values_array);
@ -116,7 +116,7 @@ ThrowCompletionOr<Value> PromiseAllSettledResolveElementFunction::resolve_elemen
// 14. If remainingElementsCount.[[Value]] is 0, then
if (--m_remaining_elements.value == 0) {
// a. Let valuesArray be CreateArrayFromList(values).
auto* values_array = Array::create_from(realm, m_values.values());
auto values_array = Array::create_from(realm, m_values.values());
// b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).
return JS::call(vm, *m_capability->resolve(), js_undefined(), values_array);
@ -157,7 +157,7 @@ ThrowCompletionOr<Value> PromiseAllSettledRejectElementFunction::resolve_element
// 14. If remainingElementsCount.[[Value]] is 0, then
if (--m_remaining_elements.value == 0) {
// a. Let valuesArray be CreateArrayFromList(values).
auto* values_array = Array::create_from(realm, m_values.values());
auto values_array = Array::create_from(realm, m_values.values());
// b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).
return JS::call(vm, *m_capability->resolve(), js_undefined(), values_array);
@ -192,7 +192,7 @@ ThrowCompletionOr<Value> PromiseAnyRejectElementFunction::resolve_element()
auto error = AggregateError::create(realm);
// b. Perform ! DefinePropertyOrThrow(error, "errors", PropertyDescriptor { [[Configurable]]: true, [[Enumerable]]: false, [[Writable]]: true, [[Value]]: CreateArrayFromList(errors) }).
auto* errors_array = Array::create_from(realm, m_values.values());
auto errors_array = Array::create_from(realm, m_values.values());
MUST(error->define_property_or_throw(vm.names.errors, { .value = errors_array, .writable = true, .enumerable = false, .configurable = true }));
// c. Return ? Call(promiseCapability.[[Reject]], undefined, « error »).

View file

@ -767,7 +767,7 @@ ThrowCompletionOr<Value> ProxyObject::internal_call(Value this_argument, MarkedV
}
// 7. Let argArray be CreateArrayFromList(argumentsList).
auto* arguments_array = Array::create_from(realm, arguments_list);
auto arguments_array = Array::create_from(realm, arguments_list);
// 8. Return ? Call(trap, handler, « target, thisArgument, argArray »).
return call(vm, trap, &m_handler, &m_target, this_argument, arguments_array);
@ -812,7 +812,7 @@ ThrowCompletionOr<Object*> ProxyObject::internal_construct(MarkedVector<Value> a
}
// 8. Let argArray be CreateArrayFromList(argumentsList).
auto* arguments_array = Array::create_from(realm, arguments_list);
auto arguments_array = Array::create_from(realm, arguments_list);
// 9. Let newObj be ? Call(trap, handler, « target, argArray, newTarget »).
auto new_object = TRY(call(vm, trap, &m_handler, &m_target, arguments_array, &new_target));

View file

@ -121,7 +121,7 @@ static Value make_match_indices_index_pair_array(VM& vm, Utf16View const& string
// 4. NOTE: The groupNames List contains elements aligned with the indices List starting at indices[1].
// 5. Set A to ! ArrayCreate(n).
auto* array = MUST(Array::create(realm, indices.size()));
auto array = MUST(Array::create(realm, indices.size()));
// 6. If hasGroups is true, then
// a. Let groups be ! ObjectCreate(null).
@ -253,7 +253,7 @@ static ThrowCompletionOr<Value> regexp_builtin_exec(VM& vm, RegExpObject& regexp
VERIFY(result.n_named_capture_groups < NumericLimits<u32>::max());
// 19. Let A be ! ArrayCreate(n + 1).
auto* array = MUST(Array::create(realm, result.n_named_capture_groups + 1));
auto array = MUST(Array::create(realm, result.n_named_capture_groups + 1));
// 20. Assert: The mathematical value of A's "length" property is n + 1.
@ -546,7 +546,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match)
TRY(regexp_object->set(vm.names.lastIndex, Value(0), Object::ShouldThrowExceptions::Yes));
// c. Let A be ! ArrayCreate(0).
auto* array = MUST(Array::create(realm, 0));
auto array = MUST(Array::create(realm, 0));
// d. Let n be 0.
size_t n = 0;
@ -926,7 +926,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split)
auto* splitter = TRY(construct(vm, *constructor, regexp_object, PrimitiveString::create(vm, move(new_flags))));
// 11. Let A be ! ArrayCreate(0).
auto* array = MUST(Array::create(realm, 0));
auto array = MUST(Array::create(realm, 0));
// 12. Let lengthA be 0.
size_t array_length = 0;

View file

@ -757,7 +757,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::split)
auto string = TRY(object.to_utf16_string(vm));
auto* array = MUST(Array::create(realm, 0));
auto array = MUST(Array::create(realm, 0));
size_t array_length = 0;
auto limit = NumericLimits<u32>::max();

View file

@ -431,7 +431,7 @@ ThrowCompletionOr<void> VM::iterator_binding_initialization(BindingPattern const
VERIFY(i == binding.entries.size() - 1);
// 2. Let A be ! ArrayCreate(0).
auto* array = MUST(Array::create(realm, 0));
auto array = MUST(Array::create(realm, 0));
// 3. Let n be 0.
// 4. Repeat,

View file

@ -443,7 +443,7 @@ void queue_mutation_observer_microtask(DOM::Document& document)
auto& callback = mutation_observer->callback();
auto& realm = callback.callback_context.realm();
auto* wrapped_records = MUST(JS::Array::create(realm, 0));
auto wrapped_records = MUST(JS::Array::create(realm, 0));
for (size_t i = 0; i < records.size(); ++i) {
auto& record = records.at(i);
auto property_index = JS::PropertyKey { i };

View file

@ -57,7 +57,7 @@ JS::ThrowCompletionOr<JS::Object*> HeadersIterator::next()
case JS::Object::PropertyKind::Value:
return create_iterator_result_object(vm(), JS::PrimitiveString::create(vm(), StringView { pair.value }), false);
case JS::Object::PropertyKind::KeyAndValue: {
auto* array = JS::Array::create_from(realm(), { JS::PrimitiveString::create(vm(), StringView { pair.name }), JS::PrimitiveString::create(vm(), StringView { pair.value }) });
auto array = JS::Array::create_from(realm(), { JS::PrimitiveString::create(vm(), StringView { pair.name }), JS::PrimitiveString::create(vm(), StringView { pair.value }) });
return create_iterator_result_object(vm(), array, false);
}
default:

View file

@ -109,7 +109,7 @@ JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalEnvironmentExtensions::$$_function)
return element->query_selector_all(selector);
}));
auto* array = TRY(JS::Array::create(*vm.current_realm(), node_list->length()));
auto array = TRY(JS::Array::create(*vm.current_realm(), node_list->length()));
for (auto i = 0u; i < node_list->length(); ++i) {
TRY(array->create_data_property_or_throw(i, node_list->item_value(i)));
}