mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibWeb: Get the length property from collection through standard getters
DOMTokenList and FileList do not have the 'length' own property - their prototypes have this property instead. So we must go through [[Get]] to retrieve this property, which will consider the prototype.
This commit is contained in:
parent
627eb90086
commit
3d0bbb4bcf
Notes:
github-actions[bot]
2024-11-03 17:08:57 +00:00
Author: https://github.com/trflynn89
Commit: 3d0bbb4bcf
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2137
1 changed files with 7 additions and 7 deletions
|
@ -187,19 +187,20 @@ static ErrorOr<JsonValue, ExecuteScriptResultType> clone_an_object(JS::Realm& re
|
||||||
auto& vm = realm.vm();
|
auto& vm = realm.vm();
|
||||||
|
|
||||||
// 1. Let result be the value of the first matching statement, matching on value:
|
// 1. Let result be the value of the first matching statement, matching on value:
|
||||||
auto get_result = [&]() -> ErrorOr<Variant<JsonArray, JsonObject>, ExecuteScriptResultType> {
|
auto result = TRY(([&]() -> ErrorOr<Variant<JsonArray, JsonObject>, ExecuteScriptResultType> {
|
||||||
// -> a collection
|
// -> a collection
|
||||||
if (is_collection(value)) {
|
if (is_collection(value)) {
|
||||||
// A new Array which length property is equal to the result of getting the property length of value.
|
// A new Array which length property is equal to the result of getting the property length of value.
|
||||||
auto length_property = TRY_OR_JS_ERROR(value.internal_get_own_property(vm.names.length));
|
auto length_property = TRY_OR_JS_ERROR(value.get(vm.names.length));
|
||||||
if (!length_property->value.has_value())
|
|
||||||
return ExecuteScriptResultType::JavaScriptError;
|
auto length = TRY_OR_JS_ERROR(length_property.to_length(vm));
|
||||||
auto length = TRY_OR_JS_ERROR(length_property->value->to_length(vm));
|
|
||||||
if (length > NumericLimits<u32>::max())
|
if (length > NumericLimits<u32>::max())
|
||||||
return ExecuteScriptResultType::JavaScriptError;
|
return ExecuteScriptResultType::JavaScriptError;
|
||||||
|
|
||||||
auto array = JsonArray {};
|
auto array = JsonArray {};
|
||||||
for (size_t i = 0; i < length; ++i)
|
for (size_t i = 0; i < length; ++i)
|
||||||
array.must_append(JsonValue {});
|
array.must_append(JsonValue {});
|
||||||
|
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
// -> Otherwise
|
// -> Otherwise
|
||||||
|
@ -207,8 +208,7 @@ static ErrorOr<JsonValue, ExecuteScriptResultType> clone_an_object(JS::Realm& re
|
||||||
// A new Object.
|
// A new Object.
|
||||||
return JsonObject {};
|
return JsonObject {};
|
||||||
}
|
}
|
||||||
};
|
}()));
|
||||||
auto result = TRY(get_result());
|
|
||||||
|
|
||||||
// 2. For each enumerable own property in value, run the following substeps:
|
// 2. For each enumerable own property in value, run the following substeps:
|
||||||
for (auto& key : MUST(value.Object::internal_own_property_keys())) {
|
for (auto& key : MUST(value.Object::internal_own_property_keys())) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue