From 9c8351ba541da03eeae747dc054e7a5a912f154d Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Fri, 29 Jun 2018 18:44:59 +0100 Subject: [PATCH 1/3] Simplify boolean logic for toggleAttribute() --- dom.bs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/dom.bs b/dom.bs index ad8b27a3c..a07501fea 100644 --- a/dom.bs +++ b/dom.bs @@ -6606,20 +6606,25 @@ method, when invoked, must run these steps:

If attribute is null, then:

    -
  1. If force is not given or is true, create an attribute whose +

  2. If force is given and is false, return false. + +

  3. Create an attribute whose local name is qualifiedName, value is the empty string, and node document is the context object's - node document, then append this attribute - to the context object, and then return true. + node document. + +

  4. Append this attribute + to the context object. -
  5. Return false. +

  6. Return true.
-
  • Otherwise, if force is not given or is false, - remove an attribute given qualifiedName and the - context object, and then return false. +

  • Otherwise, if force is given and is true, return true. -

  • Return true. +

  • Remove an attribute given qualifiedName and the + context object. + +

  • Return false.

    The From 63a9c3e9766ad197b428eff5cff4e0a92997cb80 Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Fri, 29 Jun 2018 20:45:52 +0100 Subject: [PATCH 2/3] Abstract away comon logic in toggleAttribute() and setAttribute() to be simpler --- dom.bs | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/dom.bs b/dom.bs index a07501fea..1e19e00b6 100644 --- a/dom.bs +++ b/dom.bs @@ -6189,6 +6189,24 @@ in an element element, run these steps:


    +To get a valid attribute by name +given a qualifiedName, and element element, run these steps: + +
      +
    1. If qualifiedName does not match the Name production in + XML, then throw an "{{InvalidCharacterError!!exception}}" {{DOMException}}. + +

    2. If element is in the HTML namespace and its node document + is an HTML document, then set qualifiedName to qualifiedName in + ASCII lowercase. + + +

    3. Let attribute be the first attribute in element's attribute list + whose qualified name is qualifiedName, and null otherwise. + +

    4. Return qualifiedName, and attribute. +
    + To get an attribute by name given a qualifiedName and element element, run these steps: @@ -6528,17 +6546,7 @@ method, when invoked, must these steps: method, when invoked, must run these steps:
      -
    1. If qualifiedName does not match the Name production in - XML, then throw an "{{InvalidCharacterError!!exception}}" {{DOMException}}. - -

    2. If the context object is in the HTML namespace and its - node document is an HTML document, then set qualifiedName to - qualifiedName in ASCII lowercase. - -

    3. Let attribute be the first attribute in context object's - attribute list whose qualified name is qualifiedName, - and null otherwise. - +

    4. Let qualifiedName and attribute be the result of running get a valid attribute by name given the qualifiedName and context object

    5. If attribute is null, create an attribute whose local name is qualifiedName, value is @@ -6590,17 +6598,7 @@ when invoked, must run these steps: method, when invoked, must run these steps:

        -
      1. If qualifiedName does not match the Name production in - XML, then throw an "{{InvalidCharacterError!!exception}}" {{DOMException}}. - -

      2. If the context object is in the HTML namespace and its - node document is an HTML document, then set qualifiedName to - qualifiedName in ASCII lowercase. - -

      3. Let attribute be the first attribute in the context object's - attribute list whose qualified name is qualifiedName, - and null otherwise. - +

      4. Let qualifiedName and attribute be the result of running get a valid attribute by name given the qualifiedName and context object

      5. If attribute is null, then: From 543336cbb36a6a2aa93a883f38048b604cff9f6c Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Sat, 30 Jun 2018 00:10:20 +0100 Subject: [PATCH 3/3] Abstract away creating an attribute from toggleAttribute() and setAttribute() --- dom.bs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/dom.bs b/dom.bs index 1e19e00b6..97898fb10 100644 --- a/dom.bs +++ b/dom.bs @@ -6189,6 +6189,22 @@ in an element element, run these steps:


        + +To create an attribute by value +given a qualifiedName, value and element element, run these steps: + +
          +
        1. Create an attribute whose + local name is qualifiedName, value is + value, and node document is context object's + node document. + +

        2. Append this attribute to + element + +
        3. Return. +
        + To get a valid attribute by name given a qualifiedName, and element element, run these steps: @@ -6548,11 +6564,8 @@ method, when invoked, must run these steps:
        1. Let qualifiedName and attribute be the result of running get a valid attribute by name given the qualifiedName and context object -

        2. If attribute is null, create an attribute whose - local name is qualifiedName, value is - value, and node document is context object's - node document, then append this attribute to - context object, and then return. + +

        3. If attribute is null, run create an attribute by value given the qualifiedName, value and context object, and then return.

        4. Change attribute from context object to value. @@ -6606,13 +6619,7 @@ method, when invoked, must run these steps:

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

          2. Create an attribute whose - local name is qualifiedName, value is the empty - string, and node document is the context object's - node document. - -

          3. Append this attribute - to the context object. +
          4. Run create an attribute by value given the qualifiedName, the empty string and context object.

          5. Return true.