From 3d0bbb4bcf42627d0e5f9314922ffc8ac44fa770 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 2 Nov 2024 11:40:31 -0400 Subject: [PATCH] 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. --- .../Libraries/LibWeb/WebDriver/ExecuteScript.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp b/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp index c88cf279414..747ccfa0b67 100644 --- a/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp +++ b/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp @@ -187,19 +187,20 @@ static ErrorOr 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, ExecuteScriptResultType> { + auto result = TRY(([&]() -> ErrorOr, 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::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 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())) {