Fix issue 325 by adding algo for equals()#412
Conversation
| when called on a {{CSSNumericValue}} |this|, | ||
| must perform the following steps: | ||
|
|
||
| 1. If the |value| item is the same type as the {{CSSNumericValue}} the method is being called on continue to step 2, else return false. |
There was a problem hiding this comment.
You don't need to continue on to step 2 as this happens automatically. Maybe rewrite as 'If |value| is of different type to |this|, return false.'
There was a problem hiding this comment.
Also we need to define what 'different type' means.
| The <dfn for=CSSNumericValue method>equals(...|value|)</dfn> method, | ||
| when called on a {{CSSNumericValue}} |this|, | ||
| must perform the following steps: | ||
|
|
There was a problem hiding this comment.
Will need to either explicitly iterate over |value| (change to values?) or just restrict this to take a single value.
There was a problem hiding this comment.
And by "or" Shane means "do the first thing", because all the other methods take multiple values too.
There was a problem hiding this comment.
Had done the first thing. Commit 3 should make equals accept an array.
|
|
||
| 1. If the |value| item is the same type as the {{CSSNumericValue}} the method is being called on continue to step 2, else return false. | ||
|
|
||
| 2. If the |value| item has the same type as the {{CSSNumericValue}} continue to the next step, else return false. |
There was a problem hiding this comment.
Isn't this the same as step 1?
There was a problem hiding this comment.
This was supposed to be class.
| 2. If the |value| item has the same type as the {{CSSNumericValue}} continue to the next step, else return false. | ||
|
|
||
| 3. If the |value| item has the same unit as the {{CSSNumericValue}} return true, else return false. | ||
|
|
< 10BC0 /div>
There was a problem hiding this comment.
Also need to handle calc values, etc.
| <div class=issue> | ||
| Define {{CSSNumericValue/equals()}}. | ||
| <div algorithm="CSSNumericValue.equals(...|value|)"> | ||
| The <dfn for=CSSNumericValue method>equals(...|value|)</dfn> method, |
There was a problem hiding this comment.
Note that .equals() is variadic; you have to check that all the values are equal to each other/this.
| when called on a {{CSSNumericValue}} |this|, | ||
| must perform the following steps: | ||
|
|
||
| 1. If the |value| item is the same type as the {{CSSNumericValue}} the method is being called on continue to step 2, else return false. |
There was a problem hiding this comment.
- Just reverse this conditional and return false. No need to explicitly say to go to the next step; that's implied by the list.
- Be clear what you mean by "type" - you use the exact same word in the second step, but clearly mean something different. I suspect here you're talking about the interface type.
- "the CSSNumericValue the method is being called on" is already stored in the
|this|variable, so you just refer to it that way.
|
|
||
| 1. If the |value| item is the same type as the {{CSSNumericValue}} the method is being called on continue to step 2, else return false. | ||
|
|
||
| 2. If the |value| item has the same type as the {{CSSNumericValue}} continue to the next step, else return false. |
There was a problem hiding this comment.
- Same concerns as about the structure; reverse the conditional and just return false.
- I think you mean "value" here? Refer to
|this|’s {{CSSUnitValue/value}} internal slotthen (and same for |value|).
|
|
||
| 2. If the |value| item has the same type as the {{CSSNumericValue}} continue to the next step, else return false. | ||
|
|
||
| 3. If the |value| item has the same unit as the {{CSSNumericValue}} return true, else return false. |
There was a problem hiding this comment.
Use {{CSSUnitValue/unit}} internal slot.
| <div algorithm="CSSNumericValue.equals(...|value|)"> | ||
| The <dfn for=CSSNumericValue method>equals(...|value|)</dfn> method, | ||
| when called on a {{CSSNumericValue}} |this|, | ||
| must perform the following steps: |
There was a problem hiding this comment.
The algo claims to be defined for CSSNumericValue, but the steps assume that you're looking at a CSSUnitValue. It needs to work for all the CSSMathValue subtypes too.
|
Whoops, I still had this page up from earlier, and it hadn't updated with Shane's comments. Sorry for doubling up. ^_^ |
|
I suck at Github but I have added a new commit. Hopefully that addresses both @shans and @tabatkins comments. |
nainar
left a comment
There was a problem hiding this comment.
Commit 3 makes equals accept an array of values instead of just one value. Take a look?
| <div algorithm="CSSNumericValue.equals(...|value|)"> | ||
| The <dfn for=CSSNumericValue method>equals(...|value|)</dfn> method, | ||
| when called on a {{CSSNumericValue}} |this|, | ||
| must perform the following steps: |
| The <dfn for=CSSNumericValue method>equals(...|value|)</dfn> method, | ||
| when called on a {{CSSNumericValue}} |this|, | ||
| must perform the following steps: | ||
| E776 |
|
There was a problem hiding this comment.
Had done the first thing. Commit 3 should make equals accept an array.
| 2. If the |value| item has the same type as the {{CSSNumericValue}} continue to the next step, else return false. | ||
|
|
||
| 3. If the |value| item has the same unit as the {{CSSNumericValue}} return true, else return false. | ||
|
|
| when called on a {{CSSNumericValue}} |this|, | ||
| must perform the following steps: | ||
|
|
||
| 1. If the |value| item is the same type as the {{CSSNumericValue}} the method is being called on continue to step 2, else return false. |
|
|
||
| 1. If the |value| item is the same type as the {{CSSNumericValue}} the method is being called on continue to step 2, else return false. | ||
|
|
||
| 2. If the |value| item has the same type as the {{CSSNumericValue}} continue to the next step, else return false. |
|
|
||
| 2. If the |value| item has the same type as the {{CSSNumericValue}} continue to the next step, else return false. | ||
|
|
||
| 3. If the |value| item has the same unit as the {{CSSNumericValue}} return true, else return false. |
tabatkins
left a comment
There was a problem hiding this comment.
Looking much better overall, just some nits left.
|
|
||
| 1. [=list/If all=] |item|s of |thisAndValues| do not belong to the same class return false. Example: all items in |thisAndValues| must be {{CSSUnitValue}}. | ||
|
|
||
| 2. [=list/If all=] |item|s in |thisAndValues| are {{CSSUnitValue}s and have the same {{CSSUnitValue/value}} return true. |
|
|
||
| 2. [=list/If all=] |item|s in |thisAndValues| are {{CSSUnitValue}s and have the same {{CSSUnitValue/value}} return true. | ||
|
|
||
| 4. =list/If all=] |item|s in |thisAndValues| are {{CSSMathValue}s : |
| 2. [=list/If all=] |item|s in |thisAndValues| are {{CSSUnitValue}s and have the same {{CSSUnitValue/value}} return true. | ||
|
|
||
| 4. =list/If all=] |item|s in |thisAndValues| are {{CSSMathValue}s : | ||
| 1. If the {{CSSMathValue/operator}} are not equal for all {{CSSMathValues}} in |thisAndValues| return false. |
There was a problem hiding this comment.
This is already covered by "same class" earlier, so you can drop this.
| 1. If the {{CSSMathValue/operator}} are not equal for all {{CSSMathValues}} in |thisAndValues| return false. | ||
| 2. If |thisAndValues| are all either {{CSSMathSum}}, {{CSSMathProduct}}, {{CSSMathMin}} or {{CSSMathMax}}, iterate over the {{CSSNumericArray}}s on |thisAndValues|, | ||
| 1. For each {{CSSUnitValue}} in each of the {{CSSNumericArray}}s go back to step 1 to check that the {{CSSUnitValue}}s on all items in |thisAndValue| are equal. | ||
| 3. If |this| and |value| are both either {{CSSMathNegate}} or {{CSSMathInvert}}: |
There was a problem hiding this comment.
Do you mean CSSMathProduct? Cause that is dealt with in the above step. Or do you mean the case where values in |thisAndValues| are not all of the same type? If the latter in that case we should return a false right?
|
@tabatkins took a stab at equals take a look? |
nainar
left a comment
There was a problem hiding this comment.
@tabatkins made the changes and had a follow up question.
|
|
||
| 1. [=list/If all=] |item|s of |thisAndValues| do not belong to the same class return false. Example: all items in |thisAndValues| must be {{CSSUnitValue}}. | ||
|
|
||
| 2. [=list/If all=] |item|s in |thisAndValues| are {{CSSUnitValue}s and have the same {{CSSUnitValue/value}} return true. |
|
|
||
| 2. [=list/If all=] |item|s in |thisAndValues| are {{CSSUnitValue}s and have the same {{CSSUnitValue/value}} return true. | ||
|
|
||
| 4. =list/If all=] |item|s in |thisAndValues| are {{CSSMathValue}s : |
| 2. [=list/If all=] |item|s in |thisAndValues| are {{CSSUnitValue}s and have the same {{CSSUnitValue/value}} return true. | ||
|
|
||
| 4. =list/If all=] |item|s in |thisAndValues| are {{CSSMathValue}s : | ||
| 1. If the {{CSSMathValue/operator}} are not equal for all {{CSSMathValues}} in |thisAndValues| return false. |
| 1. If the {{CSSMathValue/operator}} are not equal for all {{CSSMathValues}} in |thisAndValues| return false. | ||
| 2. If |thisAndValues| are all either {{CSSMathSum}}, {{CSSMathProduct}}, {{CSSMathMin}} or {{CSSMathMax}}, iterate over the {{CSSNumericArray}}s on |thisAndValues|, | ||
| 1. For each {{CSSUnitValue}} in each of the {{CSSNumericArray}}s go back to step 1 to check that the {{CSSUnitValue}}s on all items in |thisAndValue| are equal. | ||
| 3. If |this| and |value| are both either {{CSSMathNegate}} or {{CSSMathInvert}}: |
There was a problem hiding this comment.
Do you mean CSSMathProduct? Cause that is dealt with in the above step. Or do you mean the case where values in |thisAndValues| are not all of the same type? If the latter in that case we should return a false right?
Gonna go ahead and merge and fix things up myself.
@shans could you take a look, took a stab at writing up the algo for .equals()