clarify and test interactions with indexed access

This commit is contained in:
Delan Azabani 2023-03-21 14:06:05 +08:00
parent fb2acb0b02
commit c831a136b2
2 changed files with 53 additions and 4 deletions

View file

@ -117,14 +117,14 @@ unsafe extern "C" fn get_own_property_descriptor(
jsstr_to_string(*cx, id.to_string())
} else if id.is_int() {
// If the property key is an integer index, convert it to a String too.
// TODO(delan) will this interfere with indexed access on the Window object
// (window[index]), which should only return document-tree child navigables?
// https://html.spec.whatwg.org/multipage/#accessing-other-browsing-contexts
// For indexed access on the window object, which may shadow this, see
// the getOwnPropertyDescriptor trap in dom/windowproxy.rs.
id.to_int().to_string()
} else if id.is_symbol() {
// Symbol properties were already handled above.
unreachable!()
} else {
unreachable!()
unimplemented!()
};
if s.is_empty() {
return true;

View file

@ -0,0 +1,49 @@
<!doctype html>
<meta charset=utf-8>
<title>Interactions between indexed and named access on the Window object</title>
<link rel="author" title="Delan Azabani" href="dazabani@igalia.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#accessing-other-browsing-contexts">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#named-access-on-the-window-object">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=0></div>
<div id=3></div>
<iframe name=2></iframe>
<iframe name=1></iframe>
<script>
const divs = document.querySelectorAll("div");
const iframes = document.querySelectorAll("iframe");
const wp = Object.getPrototypeOf(window);
test(function() {
assert_equals(window[0], iframes[0].contentWindow);
assert_equals(window["0"], iframes[0].contentWindow);
}, "WindowProxy: document-tree child navigable with index 0 (indexed access)");
test(function() {
assert_equals(window[1], iframes[1].contentWindow);
assert_equals(window["1"], iframes[1].contentWindow);
}, "WindowProxy: document-tree child navigable with index 1 (indexed access)");
test(function() {
assert_equals(window[2], iframes[0].contentWindow);
assert_equals(window["2"], iframes[0].contentWindow);
}, "WindowProxy: document-tree child navigable with target name 2 (named access)");
test(function() {
assert_equals(window[3], divs[1]);
assert_equals(window["3"], divs[1]);
}, "WindowProxy: element with id 3 (named access)");
test(function() {
assert_equals(wp[0], divs[0]);
assert_equals(wp["0"], divs[0]);
}, "Window prototype: element with id 0 (named access)");
test(function() {
assert_equals(wp[1], iframes[1].contentWindow);
assert_equals(wp["1"], iframes[1].contentWindow);
}, "Window prototype: document-tree child navigable with target name 1 (named access)");
test(function() {
assert_equals(wp[2], iframes[0].contentWindow);
assert_equals(wp["2"], iframes[0].contentWindow);
}, "Window prototype: document-tree child navigable with target name 2 (named access)");
test(function() {
assert_equals(wp[3], divs[1]);
assert_equals(wp["3"], divs[1]);
}, "Window prototype: element with id 3 (named access)");
</script>