mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +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: https://github.com/LadybirdBrowser/ladybird/commit/3d0bbb4bcf4 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();
|
||||
|
||||
// 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
|
||||
if (is_collection(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));
|
||||
if (!length_property->value.has_value())
|
||||
return ExecuteScriptResultType::JavaScriptError;
|
||||
auto length = TRY_OR_JS_ERROR(length_property->value->to_length(vm));
|
||||
auto length_property = TRY_OR_JS_ERROR(value.get(vm.names.length));
|
||||
|
||||
auto length = TRY_OR_JS_ERROR(length_property.to_length(vm));
|
||||
if (length > NumericLimits<u32>::max())
|
||||
return ExecuteScriptResultType::JavaScriptError;
|
||||
|
||||
auto array = JsonArray {};
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
array.must_append(JsonValue {});
|
||||
|
||||
return array;
|
||||
}
|
||||
// -> Otherwise
|
||||
|
@ -207,8 +208,7 @@ static ErrorOr<JsonValue, ExecuteScriptResultType> clone_an_object(JS::Realm& re
|
|||
// A new Object.
|
||||
return JsonObject {};
|
||||
}
|
||||
};
|
||||
auto result = TRY(get_result());
|
||||
}()));
|
||||
|
||||
// 2. For each enumerable own property in value, run the following substeps:
|
||||
for (auto& key : MUST(value.Object::internal_own_property_keys())) {
|
||||
|
|
Loading…
Reference in a new issue