Skip to content

Commit 816cf66

Browse files
committed
Add URL.parse()
Tests: web-platform-tests/wpt#45248. Fixes #372.
1 parent ffee2e2 commit 816cf66

File tree

1 file changed

+41
-12
lines changed

1 file changed

+41
-12
lines changed

url.bs

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3327,6 +3327,7 @@ are encouraged to use an API suitable to their needs, which might not be this on
33273327
interface URL {
33283328
constructor(USVString url, optional USVString base);
33293329

3330+
static URL? parse(USVString url, optional USVString base);
33303331
static boolean canParse(USVString url, optional USVString base);
33313332

33323333
stringifier attribute USVString href;
@@ -3389,8 +3390,28 @@ null-or-<a>scalar value string</a> <var>base</var> (default null), and then runs
33893390
<var>parsedBase</var>.
33903391
</ol>
33913392

3393+
<div algorithm>
3394+
<p>To <dfn for=URL>initialize</dfn> a {{URL}} object <var>url</var> with a <a for=/>URL</var>
3395+
<var>urlRecord</var>:
3396+
3397+
<li><p>Let <var>query</var> be <var>urlRecord</var>'s <a for=url>query</a>, if that is non-null;
3398+
otherwise the empty string.
3399+
3400+
<li><p>Set <var>url</var>'s <a for=URL>URL</a> to <var>urlRecord</var>.
3401+
3402+
<li><p>Set <var>url</var>'s <a for=URL>query object</a> to a new {{URLSearchParams}} object.
3403+
3404+
<li><p><a for=URLSearchParams>Initialize</a> <var>url</var>'s <a for=URL>query object</a> with
3405+
<var>query</var>.
3406+
3407+
<li><p>Set <var>url</var>'s <a for=URL>query object</a>'s <a for=URLSearchParams>URL object</a> to
3408+
<var>url</var>.
3409+
</ol>
3410+
</div>
3411+
33923412
<hr>
33933413

3414+
<div algorithm>
33943415
<p id=constructors>The
33953416
<dfn constructor for=URL lt="URL(url, base)"><code>new URL(<var>url</var>, <var>base</var>)</code></dfn>
33963417
constructor steps are:
@@ -3401,19 +3422,9 @@ constructor steps are:
34013422

34023423
<li><p>If <var>parsedURL</var> is failure, then <a>throw</a> a {{TypeError}}.
34033424

3404-
<li><p>Let <var>query</var> be <var>parsedURL</var>'s <a for=url>query</a>, if that is non-null,
3405-
and the empty string otherwise.
3406-
3407-
<li><p>Set <a>this</a>'s <a for=URL>URL</a> to <var>parsedURL</var>.
3408-
3409-
<li><p>Set <a>this</a>'s <a for=URL>query object</a> to a new {{URLSearchParams}} object.
3410-
3411-
<li><p><a for=URLSearchParams>Initialize</a> <a>this</a>'s <a for=URL>query object</a> with
3412-
<var>query</var>.
3413-
3414-
<li><p>Set <a>this</a>'s <a for=URL>query object</a>'s <a for=URLSearchParams>URL object</a> to
3415-
<a>this</a>.
3425+
<li><p><a for=URL>Initialize</a> <a>this</a> with <var>parsedURL</var>.
34163426
</ol>
3427+
</div>
34173428

34183429
<div class=example id=example-5434421b>
34193430
<p>To <a lt="basic URL parser">parse</a> a string into a <a for=/>URL</a> without using a
@@ -3450,6 +3461,24 @@ url.pathname // "/%F0%9F%8F%B3%EF%B8%8F%E2%80%8D%F0%9F%8C%88"</code></pre>
34503461

34513462
<hr>
34523463

3464+
<div algorithm>
3465+
<p>The static <dfn method for=URL><code>parse(<var>url</var>, <var>base</var>)</code></dfn> method
3466+
steps are:
3467+
3468+
<ol>
3469+
<li><p>Let <var>parsedURL</var> be the result of running the <a>API URL parser</a> on
3470+
<var>url</var> with <var>base</var>, if given.
3471+
3472+
<li><p>If <var>parsedURL</var> is failure, then return null.
3473+
3474+
<li><p>Let <var>url</var> be a new <code>URL</code> object.
3475+
3476+
<li><p><a for=URL>Initialize</a> <var>url</var> with <var>parsedURL</var>.
3477+
3478+
<li><p>Return <var>url</var>.
3479+
</ol>
3480+
</div>
3481+
34533482
<p>The static <dfn method for=URL><code>canParse(<var>url</var>, <var>base</var>)</code></dfn>
34543483
method steps are:
34553484

0 commit comments

Comments
 (0)