Skip to content

Commit a653b60

Browse files
committed
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.
1 parent c431167 commit a653b60

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
true
2+
[object Window]
3+
false
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script src="include.js"></script>
2+
<iframe src="about:blank"></iframe>
3+
<script>
4+
test(() => {
5+
println(0 in window)
6+
println(window[0])
7+
println(1 in window)
8+
});
9+
</script>

Userland/Libraries/LibWeb/HTML/WindowProxy.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> WindowProxy::internal_ge
8080

8181
// 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.
8282
if (max_properties > 0 && index < max_properties) {
83-
// FIXME: Implement this.
83+
JS::MarkedVector<BrowsingContext*> browsing_contexts { vm.heap() };
84+
m_window->browsing_context()->for_each_child([&](BrowsingContext& child) {
85+
if (child.container() && child.container()->in_a_document_tree())
86+
browsing_contexts.append(&child);
87+
});
88+
value = JS::Value(browsing_contexts[index]->window_proxy());
8489
}
8590

8691
// 5. If value is undefined, then:

0 commit comments

Comments
 (0)