Skip to content

Commit

Permalink
Expose a URLHost class to JavaScript
Browse files Browse the repository at this point in the history
Also export host parser (already in use by HTML).

Fixes #274.
  • Loading branch information
annevk committed Jun 7, 2018
1 parent 6a9f7ea commit 533d5c8
Showing 1 changed file with 62 additions and 2 deletions.
64 changes: 62 additions & 2 deletions url.bs
Original file line number Diff line number Diff line change
Expand Up @@ -3208,6 +3208,65 @@ e.g., "newURL" and "oldURL".
naming. [[!HTML]]


<h3 id=urlhost-class>URLHost class</h3>

<pre class=idl>
[Constructor(USVString host),
Exposed=(Window,Worker)]
interface URLHost {
USVString unicode();
readonly attribute URLHostType type;

stringifier USVString toJSON();
};

enum URLHostType { "ipv4", "ipv6", "domain" };</pre>

<p>Each {{URLHost}} object has an associated <dfn for=URLHost>host</dfn> (a <a for=/>host</a>).

<hr>

<p>The <dfn constructor for=URLHost><code>URLHost(<var>input</var>)</code></dfn> constructor, when
invoked, must run these steps:

<ol>
<li><p>Let <var>host</var> be the result of <a>host parsing</a> <var>input</var> with true.

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

<li><p>Return a new {{URLHost}} object whose <a for=URLHost>host</a> is <var>host</var>.
</ol>

<p>The <dfn method for=URLHost><code>unicode()</code></dfn> method, when invoked, must run these
steps:

<ol>
<li><p>If <a>context object</a>'s <a for=URLHost>host</a> is not a <a>domain</a>, then <a>throw</a>
a {{TypeError}}.

<li><p>Let <var>unicodeDomain</var> be the result of running <a>domain to Unicode</a> on
<a>context object</a>'s <a for=URLHost>host</a>.

<li><p>Return <var>unicodeDomain</var>, <a lt="host serializer">serialized</a>.
</ol>

<p>The <dfn attribute for=URLHost><code>type</code></dfn> attribute's getter, must run these steps:

<ol>
<li><p>If <a>context object</a>'s <a for=URLHost>host</a> is an <a>IPv4 address</a>, then return
"<code>ipv4</code>".

<li><p>If <a>context object</a>'s <a for=URLHost>host</a> is an <a>IPv6 address</a>, then return
"<code>ipv6</code>".

<li><p>Return "<code>domain</code>".
</ol>

<p>The <dfn for=URLHost>stringification behavior</dfn> and
<dfn method for=URLHost><code>toJSON()</code></dfn> method, when invoked, must return
<a>context object</a>'s <a for=URLHost>host</a>, <a lt="host serializer">serialized</a>.



<h2 id=acknowledgments class=no-num>Acknowledgments</h2>

Expand Down Expand Up @@ -3302,8 +3361,9 @@ Trevor Rowbotham,
Valentin Gosu,
Vyacheslav Matva,
Wei Wang,
山岸和利 (Yamagishi Kazutoshi), and
成瀬ゆい (Yui Naruse)
山岸和利 (Yamagishi Kazutoshi),
成瀬ゆい (Yui Naruse), and
Zach Lym
for being awesome!

<p>This standard is written by
Expand Down

0 comments on commit 533d5c8

Please sign in to comment.