LibWeb/HTML: Set correct name for cross-origin wrapper functions

This commit is contained in:
Shannon Booth
2026-01-12 23:17:37 +01:00
committed by Jelle Raaijmakers
parent d49939e230
commit 399c62933a
Notes: github-actions[bot] 2026-01-13 09:12:50 +00:00
4 changed files with 98 additions and 6 deletions

View File

@@ -0,0 +1,34 @@
"use strict";
const crossOriginWindowMethods = [
{key: "close", length: 0},
{key: "focus", length: 0},
{key: "blur", length: 0},
{key: "postMessage", length: 1},
];
const crossOriginWindowAccessors = [
"window",
"self",
"location",
"closed",
"frames",
"length",
"top",
"opener",
"parent",
].map(key => ({key}));
const makeCrossOriginWindow = t => {
const iframe = document.createElement("iframe");
const path = location.pathname.slice(0, location.pathname.lastIndexOf("/")) + "/frame.html";
iframe.src = get_host_info().HTTP_REMOTE_ORIGIN + path;
return new Promise((resolve, reject) => {
iframe.onload = () => { resolve(iframe.contentWindow); };
iframe.onerror = reject;
document.body.append(iframe);
t.add_cleanup(() => { iframe.remove(); });
});
};

View File

@@ -0,0 +1,45 @@
<!doctype html>
<meta charset=utf-8>
<title>Cross-origin methods and accessors are created with correct 'name' property</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/browsers.html#crossorigingetownpropertyhelper-(-o,-p-)">
<script src="../../../../resources/testharness.js"></script>
<script src="../../../../resources/testharnessreport.js"></script>
<script src="../../../../common/get-host-info.sub.js"></script>
<script src="cross-origin-objects-function-common.js"></script>
<div id=log></div>
<script>
"use strict";
promise_test(async t => {
const w = await makeCrossOriginWindow(t);
for (const {key} of crossOriginWindowMethods) {
assert_equals(w[key].name, key, `w.${key} via [[Get]]`);
const desc = Object.getOwnPropertyDescriptor(w, key);
assert_equals(desc.value.name, key, `w.${key} via [[GetOwnProperty]]`);
}
}, "Cross-origin Window methods have correct 'name'");
promise_test(async t => {
const w = await makeCrossOriginWindow(t);
for (const {key} of crossOriginWindowAccessors) {
const desc = Object.getOwnPropertyDescriptor(w, key);
assert_equals(desc.get.name, `get ${key}`);
if (key === "location") {
assert_equals(desc.set.name, `set ${key}`);
}
}
}, "Cross-origin Window accessors have correct 'name'");
promise_test(async t => {
const w = await makeCrossOriginWindow(t);
assert_equals(w.location.replace.name, "replace");
const desc = Object.getOwnPropertyDescriptor(w.location, "replace");
assert_equals(desc.value.name, "replace");
}, "Cross-origin Location `replace` method has correct 'name'");
promise_test(async t => {
const w = await makeCrossOriginWindow(t);
const desc = Object.getOwnPropertyDescriptor(w.location, "href");
assert_equals(desc.set.name, "set href");
}, "Cross-origin Location `href` setter has correct 'name'");
</script>