From a653b60e49e8b57058bf11410dd9581162eb952b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 25 Jul 2023 15:07:13 +0200 Subject: [PATCH] LibWeb: Implement basic support for window[number] This fixes an assertion on https://amazon.com/ since WindowProxy would advertise "0" as an own property key, but then act like it was a bogus property when actually queried for it directly. --- .../Text/expected/window-proxy-numeric-own-property.txt | 3 +++ .../Text/input/window-proxy-numeric-own-property.html | 9 +++++++++ Userland/Libraries/LibWeb/HTML/WindowProxy.cpp | 7 ++++++- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/window-proxy-numeric-own-property.txt create mode 100644 Tests/LibWeb/Text/input/window-proxy-numeric-own-property.html diff --git a/Tests/LibWeb/Text/expected/window-proxy-numeric-own-property.txt b/Tests/LibWeb/Text/expected/window-proxy-numeric-own-property.txt new file mode 100644 index 0000000000..d20b210c6c --- /dev/null +++ b/Tests/LibWeb/Text/expected/window-proxy-numeric-own-property.txt @@ -0,0 +1,3 @@ + true +[object Window] +false diff --git a/Tests/LibWeb/Text/input/window-proxy-numeric-own-property.html b/Tests/LibWeb/Text/input/window-proxy-numeric-own-property.html new file mode 100644 index 0000000000..ae61ba3cad --- /dev/null +++ b/Tests/LibWeb/Text/input/window-proxy-numeric-own-property.html @@ -0,0 +1,9 @@ + + + diff --git a/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp b/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp index 4554c0157a..3887b75f78 100644 --- a/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp +++ b/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp @@ -80,7 +80,12 @@ JS::ThrowCompletionOr> WindowProxy::internal_ge // 4. If maxProperties is greater than 0 and index is less than maxProperties, then set value to the WindowProxy object of the indexth document-tree child browsing context of W's browsing context, sorted in the order that their browsing context container elements were most recently inserted into W's associated Document, the WindowProxy object of the most recently inserted browsing context container's nested browsing context being last. if (max_properties > 0 && index < max_properties) { - // FIXME: Implement this. + JS::MarkedVector browsing_contexts { vm.heap() }; + m_window->browsing_context()->for_each_child([&](BrowsingContext& child) { + if (child.container() && child.container()->in_a_document_tree()) + browsing_contexts.append(&child); + }); + value = JS::Value(browsing_contexts[index]->window_proxy()); } // 5. If value is undefined, then: