Skip to content

Commit 97bfa00

Browse files
mikewestchromium-wpt-export-bot
authored andcommitted
[Origin API] .from() should throw on <a> and <area>.
When extracting an origin from `<a>` and `<area>` elements without an `href` attribute, we're currently returning an opaque `Origin`. We should throw instead, as there's not an origin to extract from these elements (see [1]). Thanks to @annevk for pointing this out in [2]. [1]: https://html.spec.whatwg.org/multipage/links.html#api-for-a-and-area-elements:extract-an-origin [2]: whatwg/url#892 (comment) Bug: 434131026 Change-Id: I136cc0ff24355e29418e060ab384938f3615a60e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7231346 Commit-Queue: Mike West <[email protected]> Reviewed-by: Antonio Sartori <[email protected]> Cr-Commit-Position: refs/heads/main@{#1554582}
1 parent 7d60204 commit 97bfa00

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

html/browsers/origin/api/origin-from-htmlhyperlinkelementutils.window.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
// META: title=`Origin.from(HTMLHyperlinkElementUtils)`
22
// META: script=resources/serializations.js
33

4+
test(t => {
5+
const invalid = document.createElement("a");
6+
assert_throws_js(TypeError, _ => Origin.from(invalid));
7+
}, `Origin.from(<a>) throws.`);
8+
9+
test(t => {
10+
const invalid = document.createElement("area");
11+
assert_throws_js(TypeError, _ => Origin.from(invalid));
12+
}, `Origin.from(<area>) throws.`);
13+
414
for (const opaque of urls.opaque) {
515
// <a>
616
test(t => {

0 commit comments

Comments
 (0)