Skip to content

Commit b6e66d6

Browse files
committed
Fix the type handling of .add(), and make .sub() just reuse that algorithm.
1 parent aa26a41 commit b6e66d6

File tree

1 file changed

+14
-39
lines changed

1 file changed

+14
-39
lines changed

css-typed-om/Overview.bs

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -613,27 +613,25 @@ The following are the arithmetic operations you can perform on dimensions:
613613
1. Replace each [=list/item=] of |values|
614614
with the result of [=rectifying a numberish value=] for the [=list/item=].
615615

616-
2. Prepend |this| to |values|.
617-
618-
3. If there are at least two different [=strong types=]
619-
among the [=list/items=] in |values|,
620-
[=throw=] a {{TypeError}}.
616+
2. If |this| is a {{CSSMathSum}} object,
617+
[=list/prepend=] the [=list/items=] in |this|’s {{CSSMathSum/values}} internal slot
618+
to |values|.
619+
Otherwise,
620+
prepend |this| to |values|.
621621

622-
4. If all of the [=list/items=] in |values| are {{CSSUnitValue}}s
622+
3. If all of the [=list/items=] in |values| are {{CSSUnitValue}}s
623623
and have the same {{CSSUnitValue/unit}},
624624
return a new {{CSSUnitValue}}
625625
whose {{CSSUnitValue/unit}} internal slot is set to |this|’s {{CSSUnitValue/unit}} internal slot,
626626
and {{CSSUnitValue/value}} internal slot is set to the sum of
627627
the {{CSSUnitValue/value}} internal slots
628628
of the [=list/items=] in |values|.
629629

630-
5. If |this| is a {{CSSMathSum}} object,
631-
remove |this| from |values|,
632-
and then [=list/append=] the remaining |values|
633-
to |this|’s {{CSSMathSum/values}} internal slot.
630+
4. Let |type| be the result of [=adding=] the [=types=] of every [=list/item=] in |values|.
631+
If |type| is failure,
632+
[=throw=] a {{TypeError}}.
634633

635-
6. Otherwise,
636-
return a new {{CSSMathSum}} object
634+
5. Return a new {{CSSMathSum}} object
637635
whose {{CSSMathSum/values}} internal slot
638636
is set to |values|.
639637
</div>
@@ -644,34 +642,11 @@ The following are the arithmetic operations you can perform on dimensions:
644642
must perform the following steps:
645643

646644
1. Replace each [=list/item=] of |values|
647-
with the result of [=rectifying a numberish value=] for the [=list/item=].
645+
with the result of [=rectifying a numberish value=] for the [=list/item=],
646+
then [=CSSMath/negating=] the value.
648647

649-
2. Let |thisAndValues| be |this| prepended to |values|.
650-
651-
3. If there are at least two different [=strong types=]
652-
among the [=list/items=] in |thisAndValues|,
653-
[=throw=] a {{TypeError}}.
654-
655-
4. If all of the [=list/items=] in |thisAndValues| are {{CSSUnitValue}}s
656-
and have the same {{CSSUnitValue/unit}},
657-
return a new {{CSSUnitValue}}
658-
whose {{CSSUnitValue/unit}} internal slot is set to |this|’s {{CSSUnitValue/unit}} internal slot,
659-
and {{CSSUnitValue/value}} internal slot is set to
660-
the value of |this|’s {{CSSUnitValue/value}} internal slot
661-
minus the sum of the {{CSSUnitValue/value}} internal slots
662-
of the [=list/items=] in |values|.
663-
664-
5. [=CSSMath/Negate=] all of the [=list/items=] in |values|.
665-
666-
6. If |this| is a {{CSSMathSum}} object,
667-
[=list/append=] |values|
668-
to |this|’s {{CSSMathSum/values}} internal slot.
669-
670-
7. Otherwise,
671-
prepend |this| to |values|,
672-
then return a new {{CSSMathSum}} object
673-
whose {{CSSMathSum/values}} internal slot
674-
is set to |values|.
648+
2. Return the result of calling the {{CSSNumericValue/add()}} internal algorithm
649+
with |this| and |values|.
675650
</div>
676651

677652
<div algorithm>

0 commit comments

Comments
 (0)