Skip to content

Commit adc3368

Browse files
committed
test: fix location object to match Location interface in WPT
The Location interface should not have a searchParams property according to the WHATWG URL spec. This commit fixes the WPT test runner to hide the searchParams property from the location object using a Proxy, ensuring that WPT tests expecting the Location interface behavior pass correctly. - Use Proxy to hide searchParams from location object in WPT runner - Remove historical.any.js from expected failures in url.json Fixes the 'searchParams on location object' test in historical.any.js
1 parent eac00fa commit adc3368

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

test/common/wpt.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,16 @@ class WPTRunner {
596596
const title = spec.getMeta().title;
597597
let { initScript } = this;
598598

599-
initScript = `${initScript}\n\n//===\nglobalThis.location = new URL("${url.href}");`;
599+
initScript = `${initScript}\n\n//===\nconst _location = new URL("${url.href}");\n` +
600+
`globalThis.location = new Proxy(_location, {\n` +
601+
` has(target, prop) { return prop !== 'searchParams' && prop in target; },\n` +
602+
` get(target, prop) { return prop === 'searchParams' ? undefined : target[prop]; },\n` +
603+
` ownKeys(target) { return Object.keys(target).filter(k => k !== 'searchParams'); },\n` +
604+
` getOwnPropertyDescriptor(target, prop) {\n` +
605+
` if (prop === 'searchParams') return undefined;\n` +
606+
` return Object.getOwnPropertyDescriptor(target, prop);\n` +
607+
` }\n` +
608+
`});`;
600609

601610
if (title) {
602611
initScript = `${initScript}\n\n//===\nglobalThis.META_TITLE = "${title}";`;

test/wpt/status/url.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@
1010
]
1111
}
1212
},
13-
"historical.any.js": {
14-
"fail": {
15-
"expected": [
16-
"searchParams on location object"
17-
]
18-
}
19-
},
2013
"javascript-urls.window.js": {
2114
"skip": "requires document.body reference"
2215
},

0 commit comments

Comments
 (0)