Skip to content

Commit b906fae

Browse files
committed
clarify and test interactions with indexed access
1 parent ed3e37b commit b906fae

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

components/script/window_named_properties.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ unsafe extern "C" fn get_own_property_descriptor(
117117
jsstr_to_string(*cx, id.to_string())
118118
} else if id.is_int() {
119119
// If the property key is an integer index, convert it to a String too.
120-
// TODO(delan) will this interfere with indexed access on the Window object
121-
// (window[index]), which should only return document-tree child navigables?
122-
// https://html.spec.whatwg.org/multipage/#accessing-other-browsing-contexts
120+
// For indexed access on the window object, which may shadow this, see
121+
// the getOwnPropertyDescriptor trap in dom/windowproxy.rs.
123122
id.to_int().to_string()
124123
} else if id.is_symbol() {
124+
// Symbol properties were already handled above.
125125
unreachable!()
126126
} else {
127-
unreachable!()
127+
unimplemented!()
128128
};
129129
if s.is_empty() {
130130
return true;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!doctype html>
2+
<meta charset=utf-8>
3+
<title>Interactions between indexed and named access on the Window object</title>
4+
<link rel="author" title="Delan Azabani" href="[email protected]">
5+
<link rel="help" href="https://html.spec.whatwg.org/multipage/#accessing-other-browsing-contexts">
6+
<link rel="help" href="https://html.spec.whatwg.org/multipage/#named-access-on-the-window-object">
7+
<script src="/resources/testharness.js"></script>
8+
<script src="/resources/testharnessreport.js"></script>
9+
<div id=0></div>
10+
<div id=3></div>
11+
<iframe name=2></iframe>
12+
<iframe name=1></iframe>
13+
<script>
14+
const divs = document.querySelectorAll("div");
15+
const iframes = document.querySelectorAll("iframe");
16+
const wp = Object.getPrototypeOf(window);
17+
test(function() {
18+
assert_equals(window[0], iframes[0].contentWindow);
19+
assert_equals(window["0"], iframes[0].contentWindow);
20+
}, "WindowProxy: document-tree child navigable with index 0 (indexed access)");
21+
test(function() {
22+
assert_equals(window[1], iframes[1].contentWindow);
23+
assert_equals(window["1"], iframes[1].contentWindow);
24+
}, "WindowProxy: document-tree child navigable with index 1 (indexed access)");
25+
test(function() {
26+
assert_equals(window[2], iframes[0].contentWindow);
27+
assert_equals(window["2"], iframes[0].contentWindow);
28+
}, "WindowProxy: document-tree child navigable with target name 2 (named access)");
29+
test(function() {
30+
assert_equals(window[3], divs[1]);
31+
assert_equals(window["3"], divs[1]);
32+
}, "WindowProxy: element with id 3 (named access)");
33+
test(function() {
34+
assert_equals(wp[0], divs[0]);
35+
assert_equals(wp["0"], divs[0]);
36+
}, "Window prototype: element with id 0 (named access)");
37+
test(function() {
38+
assert_equals(wp[1], iframes[1].contentWindow);
39+
assert_equals(wp["1"], iframes[1].contentWindow);
40+
}, "Window prototype: document-tree child navigable with target name 1 (named access)");
41+
test(function() {
42+
assert_equals(wp[2], iframes[0].contentWindow);
43+
assert_equals(wp["2"], iframes[0].contentWindow);
44+
}, "Window prototype: document-tree child navigable with target name 2 (named access)");
45+
test(function() {
46+
assert_equals(wp[3], divs[1]);
47+
assert_equals(wp["3"], divs[1]);
48+
}, "Window prototype: element with id 3 (named access)");
49+
</script>

0 commit comments

Comments
 (0)