From 279347675e4b641c500629e4d2bacd2bda028ddc Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 1 Oct 2015 14:35:32 +0200 Subject: [PATCH] Inline URLUtils for a and area elements See https://github.com/whatwg/url/issues/62 for the background. This defines a mixin used by both a and area elements to define their IDL members previously defined by the URL standard. It also fixes a small error in the WorkerLocation text. --- source | 589 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 540 insertions(+), 49 deletions(-) diff --git a/source b/source index 1b0e8bbfe09..76171459c27 100644 --- a/source +++ b/source @@ -2685,7 +2685,26 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
  • Absolute URL
  • Relative URL
  • Relative schemes -
  • The URL parser +
  • + The URL parser and basic URL parser as + well as these parser states: +
  • Parsed URL
  • The scheme component of a parsed URL
  • The scheme data component of a parsed URL @@ -2696,6 +2715,7 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
  • The path component of a parsed URL
  • The query component of a parsed URL
  • The fragment component of a parsed URL +
  • non-relative flag
  • Parse errors from the URL parser
  • The URL serialiser
  • The host serialiser @@ -2705,6 +2725,8 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
  • UTF-8 percent encode
  • Percent decode
  • Decoder error +
  • set the username +
  • set the password
  • The domain to ASCII algorithm
  • The domain to Unicode algorithm
  • URLUtils interface @@ -17423,7 +17445,7 @@ included with Exhibit B. attribute DOMString text; }; -HTMLAnchorElement implements URLUtils; +HTMLAnchorElement implements HTMLHyperlinkElementUtils; @@ -17568,28 +17590,6 @@ included with Exhibit B. same value as the textContent IDL attribute on the element, and on setting, must act as if the textContent IDL attribute on the element had been set to the new value.

    -
    - -

    The a element also supports the URLUtils interface.

    - -

    When the element is created, and whenever the element's href content attribute is set, changed, or removed, the user - agent must invoke the element's URLUtils interface's set the input algorithm with the value of the href content attribute, if any, or the null value otherwise, - as the given value.

    - -

    The element's URLUtils interface's get the - base algorithm must simply return the element's base URL.

    - -

    The element's URLUtils interface's query - encoding is the document's character encoding.

    - -

    When the element's URLUtils interface invokes its update steps with a string value, the user - agent must set the element's href content attribute to - the string value.

    - @@ -20510,8 +20510,520 @@ document.body.appendChild(wbr); type.

    +

    API for a and area elements

    + +
    [NoInterfaceObject, Exposed=Window]
    +interface HTMLHyperlinkElementUtils {
    +  stringifier attribute USVString href;
    +           attribute USVString origin;
    +           attribute USVString protocol;
    +           attribute USVString username;
    +           attribute USVString password;
    +           attribute USVString host;
    +           attribute USVString hostname;
    +           attribute USVString port;
    +           attribute USVString pathname;
    +           attribute USVString search;
    +           attribute USVString hash;
    +};
    + +
    + +
    hyperlink . toString()
    +
    hyperlink . href
    +
    +

    Returns the hyperlink's URL.

    +

    Can be set, to change the URL.

    +
    + +
    hyperlink . origin
    +
    +

    Returns the hyperlink's URL's origin.

    +
    + +
    hyperlink . protocol
    +
    +

    Returns the hyperlink's URL's scheme.

    +

    Can be set, to change the URL's scheme.

    +
    + +
    hyperlink . username
    +
    +

    Returns the hyperlink's URL's username.

    +

    Can be set, to change the URL's username.

    +
    + + +
    hyperlink . password
    +
    +

    Returns the hyperlink's URL's password.

    +

    Can be set, to change the URL's password.

    +
    + + +
    hyperlink . host
    +
    +

    Returns the hyperlink's URL's host and port (if different from the default port for the + scheme).

    +

    Can be set, to change the URL's host and port.

    +
    + +
    hyperlink . hostname
    +
    +

    Returns the hyperlink's URL's host.

    +

    Can be set, to change the URL's host.

    +
    + +
    hyperlink . port
    +
    +

    Returns the hyperlink's URL's port.

    +

    Can be set, to change the URL's port.

    +
    + +
    hyperlink . pathname
    +
    +

    Returns the hyperlink's URL's path.

    +

    Can be set, to change the URL's path.

    +
    + +
    hyperlink . search
    +
    +

    Returns the hyperlink's URL's query (includes leading "?" if + non-empty).

    +

    Can be set, to change the URL's query (ignores leading "?").

    +
    + +
    hyperlink . hash
    +
    +

    Returns the hyperlink's URL's fragment (includes leading "#" if + non-empty).

    +

    Can be set, to change the URL's fragment (ignores leading "#").

    +
    +
    +
    +

    An element implementing the HTMLHyperlinkElementUtils mixin has an associated url (null or a URL). It is initially null. + +

    An element implementing the HTMLHyperlinkElementUtils mixin has an associated set the url algorithm, which sets this + element's url to the resulting parsed URL + of resolving this element's href content attribute value relative to this element. If + resolving was aborted with an error, set this element's url to null.

    + +

    When elements implementing the HTMLHyperlinkElementUtils mixin are created, and + whenever those elements have their href content + attribute set, changed, or removed, the user agent must set the url.

    + +

    This is only observable for blob: URLs as parsing them involves the + structured clone algorithm.

    + +

    An element implementing the HTMLHyperlinkElementUtils mixin has an associated reinitialise url algorithm, which runs these steps:

    + +
      +
    1. If element's url is null or its + non-relative flag is set, terminate these steps.

    2. + +
    3. Set the url.

    4. +
    + +

    To update href, set the element's href content attribute's value to the element's url, serialised.

    + +
    + +

    The href attribute's getter must run these + steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. Let url be this element's url.

    4. + +
    5. If url is null and this element has no href content attribute, return the empty string. + +

    6. Otherwise, if url is null, return this element's href content attribute's value.

    7. + +
    8. Return url, serialised.

    9. +
    + +

    The href attribute's setter must set this element's + href content attribute's value to the given value. + +

    The origin attribute's getter must run + these steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. If this element's url is null, return the + empty string.

    4. + +
    5. Return the Unicode serialization + of this element's url's origin.

    6. +
    + +

    It returns the Unicode rather than the ASCII serialisation for + compatibility with MessageEvent.

    + +

    The protocol attribute's getter must + run these steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. If this element's url is null, return ":".

    4. + +
    5. Return this element's url's scheme, followed by ":".

    6. +
    + +

    The protocol attribute's setter must run these + steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. If this element's url is null, terminate these + steps.

    4. + +
    5. Basic URL parse the given value, followed by :", with this element's url as + url and scheme start state as state override.

    6. + +
    7. Update href.

    8. +
    + +

    The username attribute's getter must + run these steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. If this element's url is null, return the + empty string.

    4. + +
    5. Return this element's url's username.

    6. +
    + +

    The username attribute's setter must run these + steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. Let url be this element's url.

    4. + +
    5. If url or url's host is null, + or url's non-relative flag is set, terminate these steps.

    6. + +
    7. Set the username, given url and the given value.

    8. + +
    9. Update href.

    10. +
    + +

    The password attribute's getter must + run these steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. Let url be this element's url.

    4. + +
    5. If url or url's password + is null, return the empty string.

    6. + +
    7. Return url's password.

    8. +
    + +

    The password attribute's setter must run these + steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. Let url be this element's url.

    4. + +
    5. If url or url's host is null, + or url's non-relative flag is set, terminate these steps.

    6. + +
    7. Set the password, given url and the given value.

    8. + +
    9. Update href.

    10. +
    + +

    The host attribute's getter must run these + steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. Let url be this element's url.

    4. + +
    5. If url or url's host is null, + return the empty string.

    6. + +
    7. If url's port is null, return + url's host, serialised.

    8. + +
    9. Return url's host, serialised, followed by ":" and url's port, serialised.

    10. +
    + +

    The host attribute's setter must run these steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. Let url be this element's url.

    4. + +
    5. If url is null or url's non-relative flag is set, + terminate these steps.

    6. + +
    7. Basic URL parse the given value, with + url as url and host state as state + override.

    8. + +
    9. Update href.

    10. +
    + +

    The hostname attribute's getter must + run these steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. Let url be this element's url.

    4. + +
    5. If url or url's host is null, + return the empty string.

    6. + +
    7. Return url's host, serialised.

    8. +
    + +

    The hostname attribute's setter must run these + steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. Let url be this element's url.

    4. + +
    5. If url is null or url's non-relative flag is set, + terminate these steps.

    6. + +
    7. Basic URL parse the given value, with + url as url and hostname state as state + override.

    8. + +
    9. Update href.

    10. +
    + +

    The port attribute's getter must run these + steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. Let url be this element's url.

    4. + +
    5. If url or url's port is null, + return the empty string.

    6. + +
    7. Return url's port, serialised.

    8. +
    + +

    The port attribute's setter must run these steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. Let url be this element's url.

    4. + +
    5. If url or url's host is null, + url's non-relative flag is set, or url's scheme is "file", terminate these + steps.

    6. + +
    7. Basic URL parse the given value, with + url as url and port state as state + override.

    8. + +
    9. Update href.

    10. +
    + +

    The pathname attribute's getter must + run these steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. Let url be this element's url.

    4. + +
    5. If url is null, return the empty string.

    6. + +
    7. If url's non-relative flag is set, return the first string in + url's path.

    8. + +
    9. Return "/", followed by the strings in url's path (including empty strings), separated from each other by + "/".

    10. +
    + +

    The pathname attribute's setter must run these + steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. Let url be this element's url.

    4. + +
    5. If url is null or url's non-relative flag is set, + terminate these steps.

    6. + +
    7. Set url's path to the empty + list.

    8. + +
    9. Basic URL parse the given value, with + url as url and path start state as state + override.

    10. + +
    11. Update href.

    12. +
    + +

    The search attribute's getter must run + these steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. Let url be this element's url.

    4. + +
    5. If url is null, or url's query is either null or the empty string, return the empty + string.

    6. + +
    7. Return "?", followed by url's query.

    8. +
    + +

    The search attribute's setter must run these + steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. Let url be this element's url.

    4. + +
    5. If url is null, terminate these steps.

    6. + +
    7. If the given value is the empty string, set url's query to null. + +

    8. +

      Otherwise, run these substeps:

      + +
        +
      1. Let input be the given value with a single leading "?" + removed, if any.

      2. + +
      3. Set url's query to the empty + string.

      4. + +
      5. Basic URL parse input, with + url as url and query state as state override, and + this element's node document's document's character encoding as + encoding override.

      6. +
      +
    9. + +
    10. Update href.

    11. +
    + +

    The hash attribute's getter must run these + steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. Let url be this element's url.

    4. + +
    5. If url is null, or url's fragment is either null or the empty string, return the + empty string.

    6. + +
    7. Return "#", followed by url's fragment.

    8. +
    + +

    The hash attribute's setter must run these steps:

    + +
      +
    1. Reinitialise url.

    2. + +
    3. Let url be this element's url.

    4. + +
    5. If url is null or url's scheme is "javascript", terminate these + steps.

    6. + +
    7. If the given value is the empty string, set url's fragment to null. + +

    8. +

      Otherwise, run these substeps:

      + +
        +
      1. Let input be the given value with a single leading "#" + removed, if any.

      2. + +
      3. Set url's fragment to the empty + string.

      4. + +
      5. Basic URL parse input, with + url as url and fragment state as state + override.

      6. +
      +
    9. + +
    10. Update href.

    11. +
    + +

    Following hyperlinks

    When a user follows a hyperlink created by an element @@ -36269,7 +36781,7 @@ dictionary TrackEventInit : EventInit { attribute DOMString hreflang; attribute DOMString type; }; -HTMLAreaElement implements URLUtils; +HTMLAreaElement implements HTMLHyperlinkElementUtils; @@ -36447,28 +36959,6 @@ dictionary TrackEventInit : EventInit {

    The IDL attribute relList must reflect the rel content attribute.

    -
    - -

    The area element also supports the URLUtils interface.

    - -

    When the element is created, and whenever the element's href content attribute is set, changed, or removed, the user - agent must invoke the element's URLUtils interface's set the input algorithm with the value of the href content attribute, if any, or the null value otherwise, - as the given value.

    - -

    The element's URLUtils interface's get the - base algorithm must simply return the element's base URL.

    - -

    The element's URLUtils interface's query - encoding is the document's character encoding.

    - -

    When the element's URLUtils interface invokes its update steps with a string value, the user - agent must set the element's href content attribute to - the string value.

    -
    @@ -96247,8 +96737,9 @@ interface WorkerLocation { these steps:

      -
    1. Let port be the WorkerGlobalScope object's url's

      Let port be the associated WorkerGlobalScope object's + url's port.

    2. If port is null, return the empty string.