From 29484f130bccc829fcf5de3305706b5398e2e862 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 31 Mar 2017 15:31:06 +0200 Subject: [PATCH] Expose a URLHost class to JavaScript Also export host parser (already in use by HTML). Fixes #274. --- url.bs | 89 ++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 74 insertions(+), 15 deletions(-) diff --git a/url.bs b/url.bs index c3a5a435..9e2d5f40 100644 --- a/url.bs +++ b/url.bs @@ -354,8 +354,8 @@ requires context to be distinguished.

Host parsing

-

The host parser takes a string input, a boolean -isSpecial, and then runs these steps: +

The host parser takes a +string input with a boolean isSpecial, and then runs these steps:

  1. @@ -1725,8 +1725,8 @@ string input, optionally with a base URL base, opti
  2. If buffer is the empty string, validation error, return failure. -

  3. Let host be the result of host parsing - buffer with url is special. +

  4. Let host be the result of host parsing buffer with + url is special.

  5. If host is failure, then return failure. @@ -1757,8 +1757,8 @@ string input, optionally with a base URL base, opti string, and either url includes credentials or url's port is non-null, validation error, return. -

  6. Let host be the result of host parsing - buffer with url is special. +

  7. Let host be the result of host parsing buffer with + url is special.

  8. If host is failure, then return failure. @@ -1962,8 +1962,8 @@ string input, optionally with a base URL base, opti

    Otherwise, run these steps:

      -
    1. Let host be the result of host parsing - buffer with url is special. +

    2. Let host be the result of host parsing buffer with + url is special.

    3. If host is failure, then return failure. @@ -2609,14 +2609,13 @@ URLPath would be a subclassed Array? -->

    4. Let parsedBase be the result of running the basic URL parser on base. -

    5. If parsedBase is failure, then throw a TypeError exception. +

    6. If parsedBase is failure, then throw a {{TypeError}}.

  9. Let parsedURL be the result of running the basic URL parser on url with parsedBase. -

  10. If parsedURL is failure, throw a TypeError - exception. +

  11. If parsedURL is failure, throw a {{TypeError}}.

  12. Let query be parsedURL's query, if that is non-null, and the empty string otherwise. @@ -2677,7 +2676,7 @@ url.pathname // "/%F0%9F%8F%B3%EF%B8%8F%E2%80%8D%F0%9F%8C%88"

  13. Let parsedURL be the result of running the basic URL parser on the given value. -

  14. If parsedURL is failure, throw a TypeError exception. +

  15. If parsedURL is failure, throw a {{TypeError}}.

  16. Set context object's url to parsedURL. @@ -3066,7 +3065,7 @@ these steps: list name-value pairs with the key being the name and the value being the value. -

    The stringification behavior must return the +

    The stringification behavior must return the serialization of the {{URLSearchParams}} object's list. @@ -3090,6 +3089,65 @@ e.g., "newURL" and "oldURL". naming. [[!HTML]] +

    URLHost class

    + +
    +[Constructor(USVString host),
    + Exposed=(Window,Worker)]
    +interface URLHost {
    +  USVString unicode();
    +  readonly attribute URLHostType type;
    +
    +  stringifier USVString toJSON();
    +};
    +
    +enum URLHostType { "ipv4", "ipv6", "domain" };
    + +

    Each {{URLHost}} object has an associated host (a host). + +


    + +

    The URLHost(input) constructor, when +invoked, must run these steps: + +

      +
    1. Let host be the result of host parsing input with true. + +

    2. If host is failure, then throw a {{TypeError}}. + +

    3. Return a new {{URLHost}} object whose host is host. +

    + +

    The unicode() method, when invoked, must run these +steps: + +

      +
    1. If context object's host is not a domain, then throw + a {{TypeError}}. + +

    2. Let unicodeDomain be the result of running domain to Unicode on + context object's host. + +

    3. Return unicodeDomain, serialized. +

    + +

    The type attribute's getter, must run these steps: + +

      +
    1. If context object's host is an IPv4 address, then return + "ipv4". + +

    2. If context object's host is an IPv6 address, then return + "ipv6". + +

    3. Return "domain". +

    + +

    The stringification behavior and +toJSON() method, when invoked, must return +context object's host, serialized. + +

    Acknowledgments

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

    This standard is written by