From ff4f0e8bf0a1ef5829411fc5988f94a75118f73b Mon Sep 17 00:00:00 2001 From: Yoav Weiss Date: Thu, 3 Dec 2015 14:42:37 +0100 Subject: [PATCH] Close #123: remove feature detection from add() and add supports() This change replaces the feature detection method for DOMTokenLists: * It removes references to "validation steps" from add(), toggle(), replace() and object creation. * It adds supports() as discussed. * When associated attribute has no supported tokens, TypeError is thrown (by "validation steps"). --- dom.bs | 54 +++++++++++++++++++++++++++--------------------------- dom.html | 48 +++++++++++++++++++++++++----------------------- 2 files changed, 52 insertions(+), 50 deletions(-) diff --git a/dom.bs b/dom.bs index 448ab6d43..406436ad9 100644 --- a/dom.bs +++ b/dom.bs @@ -8531,10 +8531,11 @@ interface DOMTokenList { readonly attribute unsigned long length; getter DOMString? item(unsigned long index); boolean contains(DOMString token); - boolean add(DOMString... tokens); + void add(DOMString... tokens); void remove(DOMString... tokens); boolean toggle(DOMString token, optional boolean force); void replace(DOMString token, DOMString newToken); + boolean supports(DOMString token); stringifier; iterable<DOMString>; }; @@ -8556,7 +8557,7 @@ associated attribute's local name.
  1. If the associated attribute's local name does not define - supported tokens, return true. + supported tokens, throw a TypeError.

  2. Let lowercase token be a copy of token, converted to ASCII lowercase. @@ -8591,16 +8592,8 @@ are to: associated attribute's local name attribute or associated element's associated attribute's local name attribute is -set, run these substeps: - -

      -
    1. Let temporary tokens be the new value, - parsed. - -

    2. For each token in temporary tokens, run - validation steps with token. If the return value is true, append token - to tokens. -

    +set, set tokens to the new value, +parsed.

    When an associated element's associated attribute's local name attribute is @@ -8623,11 +8616,10 @@ associated element's

    tokenlist . add(tokens…)
    -

    Adds all valid arguments passed, except those already present. +

    Adds all arguments passed, except those already present.

    Throws a {{SyntaxError}} exception if one if the arguments is the empty string.

    Throws an {{InvalidCharacterError}} exception if one of the arguments contains any ASCII whitespace. -

    Returns false if any invalid arguments passed, true otherwise.

    tokenlist . remove(tokens…)
    @@ -8639,8 +8631,8 @@ associated element's
    tokenlist . toggle(token [, force])

    If force is not given, "toggles" token, removing it if it's present and - adding it if it's not present and is valid. If force is true, adds token - if it is valid (same as {{add()}}). If force is false, removes token (same + adding it if it's not present. If force is true, adds token + (same as {{add()}}). If force is false, removes token (same as {{DOMTokenList/remove()}}).

    Returns true if token is now present, and false otherwise.

    Throws a {{SyntaxError}} exception if token is empty. @@ -8652,6 +8644,12 @@ associated element's

    Throws a {{SyntaxError}} exception if one if the arguments is the empty string.

    Throws an {{InvalidCharacterError}} exception if one of the arguments contains any ASCII whitespace. + +

    tokenlist . supports(token) +
    +

    Returns true if token is in the associated attribute's supported tokens. Returns + false otherwise. +

    Throws a TypeError exception if the associated attribute has no supported tokens defined.

    The length attribute' getter must return the @@ -8698,15 +8696,10 @@ method, when invoked, must run these steps: {{InvalidCharacterError}} exception.

-
  • Let valid be true. -
  • For each token in tokens, in given order, that is not in - tokens, run validation steps with token. If the return value is false, - set valid to false. Otherwise, append token to tokens. + tokens, append token to tokens.

  • Run the update steps. - -

  • Return valid.

    The @@ -8754,9 +8747,6 @@ method, when invoked, must run these steps:

    1. If force is passed and is false, return false. -

    2. Otherwise, run validation steps with token. If the return value is - false, return false. -

    3. Otherwise, append token to tokens, run the update steps, and return true.

    @@ -8774,14 +8764,24 @@ method, when invoked, must run these steps:
  • If either token or newToken contains any ASCII whitespace, throw an {{InvalidCharacterError}} exception. -

  • If token is not in tokens or running the validation steps for - newToken return false, terminate these steps. +

  • If token is not in tokens, terminate these steps.

  • Replace token in tokens with newToken.

  • Run the update steps. +

    The +supports(token…) +method, when invoked, must run these steps: + +

      +
    1. Let result be the return value of validation steps called with + token. Rethrow any exceptions. + +

    2. Return result. +

    +

    The stringification behavior must return the result of running context object's serialize steps. diff --git a/dom.html b/dom.html index 86f0b3a28..4e27ff701 100644 --- a/dom.html +++ b/dom.html @@ -69,7 +69,7 @@

    DOM

    -

    Living Standard — Last Updated

    +

    Living Standard — Last Updated

    Participate: @@ -4074,10 +4074,11 @@

    length; getter DOMString? item(unsigned long index); boolean contains(DOMString token); - boolean add(DOMString... tokens); + void add(DOMString... tokens); void remove(DOMString... tokens); boolean toggle(DOMString token, optional boolean force); void replace(DOMString token, DOMString newToken); + boolean supports(DOMString token); stringifier; iterable<DOMString>; }; @@ -4089,7 +4090,7 @@

    A DOMTokenList object’s validation steps for a given token are:

    1. -

      If the associated attribute’s local name does not define supported tokens, return true.

      +

      If the associated attribute’s local name does not define supported tokens, throw a TypeError.

    2. Let lowercase token be a copy of token, converted to ASCII lowercase.

    3. @@ -4110,13 +4111,7 @@


      When a DOMTokenList object is created and its associated element has an associated attribute’s local name attribute or -associated element’s associated attribute’s local name attribute is set, run these substeps:

      -
        -
      1. -

        Let temporary tokens be the new value, parsed.

        -
      2. -

        For each token in temporary tokens, run validation steps with token. If the return value is true, append token to tokens.

        -
      +associated element’s associated attribute’s local name attribute is set, set tokens to the new value, parsed.

      When an associated element’s associated attribute’s local name attribute is removed, set tokens to the empty set.

      tokenlist . length @@ -4133,10 +4128,9 @@

      Throws an InvalidCharacterError exception if token contains any ASCII whitespace.

      tokenlist . add(tokens…)
      -

      Adds all valid arguments passed, except those already present.

      +

      Adds all arguments passed, except those already present.

      Throws a SyntaxError exception if one if the arguments is the empty string.

      Throws an InvalidCharacterError exception if one of the arguments contains any ASCII whitespace.

      -

      Returns false if any invalid arguments passed, true otherwise.

      tokenlist . remove(tokens…)

      Removes arguments passed, if they are present.

      @@ -4145,7 +4139,7 @@

      tokenlist . toggle(token [, force])

      If force is not given, "toggles" token, removing it if it’s present and - adding it if it’s not present and is valid. If force is true, adds token if it is valid (same as add()). If force is false, removes token (same + adding it if it’s not present. If force is true, adds token (same as add()). If force is false, removes token (same as remove()).

      Returns true if token is now present, and false otherwise.

      Throws a SyntaxError exception if token is empty.

      @@ -4155,6 +4149,11 @@

      Replaces token with newToken.

      Throws a SyntaxError exception if one if the arguments is the empty string.

      Throws an InvalidCharacterError exception if one of the arguments contains any ASCII whitespace.

      +
      tokenlist . supports(token) +
      +

      Returns true if token is in the associated attribute’s supported tokens. Returns + false otherwise.

      +

      Throws a TypeError exception if the associated attribute has no supported tokens defined.

      The length attribute' getter must return the number of tokens in the tokens.

      @@ -4189,14 +4188,10 @@

      If token contains any ASCII whitespace, throw an InvalidCharacterError exception.

    -
  • Let valid be true.
  • -

    For each token in tokens, in given order, that is not in tokens, run validation steps with token. If the return value is false, - set valid to false. Otherwise, append token to tokens.

    +

    For each token in tokens, in given order, that is not in tokens, append token to tokens.

  • Run the update steps.

    -
  • -

    Return valid.

    The remove(tokens…) method, when invoked, must run these steps:

      @@ -4232,9 +4227,6 @@

    1. If force is passed and is false, return false.

      -
    2. -

      Otherwise, run validation steps with token. If the return value is - false, return false.

    3. Otherwise, append token to tokens, run the update steps, and return true.

      @@ -4247,12 +4239,19 @@

      If either token or newToken contains any ASCII whitespace, throw an InvalidCharacterError exception.

    4. -

      If token is not in tokens or running the validation steps for newToken return false, terminate these steps.

      +

      If token is not in tokens, terminate these steps.

    5. Replace token in tokens with newToken.

    6. Run the update steps.

    +

    The supports(token…) method, when invoked, must run these steps:

    +
      +
    1. +

      Let result be the return value of validation steps called with token. Rethrow any exceptions.

      +
    2. +

      Return result.

      +

    The stringification behavior must return the result of running context object’s serialize steps.

    7.2. Interface DOMSettableTokenList

    interface DOMSettableTokenList : DOMTokenList {
    @@ -5395,6 +5394,7 @@ 

    substringData(offset, count), in §4.9
  • subtree, in §4.3.1
  • supported tokens, in §7.1 +
  • supports(token), in §7.1
  • surroundContents(newParent), in §5.2
  • systemId @@ -5434,6 +5434,7 @@

    argument for DOMTokenList/contains(token), in §7.1
  • argument for DOMTokenList/toggle(token, force), DOMTokenList/toggle(token), in §7.1
  • argument for DOMTokenList/replace(token, newToken), in §7.1 +
  • argument for DOMTokenList/supports(token), in §7.1
  • tokens @@ -6052,10 +6053,11 @@

    IDL Inde readonly attribute unsigned long length; getter DOMString? item(unsigned long index); boolean contains(DOMString token); - boolean add(DOMString... tokens); + void add(DOMString... tokens); void remove(DOMString... tokens); boolean toggle(DOMString token, optional boolean force); void replace(DOMString token, DOMString newToken); + boolean supports(DOMString token); stringifier; iterable<DOMString>; };