@@ -727,7 +727,8 @@ The following are the arithmetic operations you can perform on dimensions:
727
727
728
728
<div algorithm="CSSNumericValue.to()">
729
729
The <dfn method for=CSSNumericValue>to(|unit|)</dfn> method converts an existing {{CSSNumericValue}} |this|
730
- into another one with the specified |unit|.
730
+ into another one with the specified |unit|,
731
+ if possible.
731
732
When called, it must perform the following steps:
732
733
733
734
1. Let |type| be the result of [=creating a type=] from |unit|.
@@ -740,24 +741,46 @@ The following are the arithmetic operations you can perform on dimensions:
740
741
741
742
3. If |sum| has more than one [=list/item=] ,
742
743
[=throw=] a {{TypeError}} .
743
- Otherwise, let |item| be the sole [=list/item=] in |sum|.
744
-
745
- 4. If |item| has more than one [=map/value=] in its [=sum value/unit map=] ,
746
- or that single [=map/value=] ’s value is anything other than `1`,
744
+ Otherwise, let |item| be the result of [=create a CSSUnitValue from a sum value item|creating a CSSUnitValue=]
745
+ from the sole [=list/item=] in |sum|.
746
+ If |item| is failure,
747
747
[=throw=] a {{TypeError}} .
748
- Otherwise, let |item unit| be the sole [=map/key=] in the [=sum value/unit map=] ,
749
- and |item value| be |item|’s [=sum value/value=] .
750
748
751
- 5 . If |unit| and |item unit| are not [=compatible units=] ,
749
+ 4 . If |unit| and |item|’s {{CSSUnitValue/ unit}} internal slot are not [=compatible units=] ,
752
750
[=throw=] a {{TypeError}} .
753
751
754
- 6. Return a new {{CSSUnitValue}}
752
+ 5. If |unit| is not equal to |item|’s {{CSSUnitValue/unit}} internal slot,
753
+ multiply |item|’s {{CSSUnitValue/value}} internal slot
754
+ by the conversion ratio between the two units,
755
+ and set its {{CSSUnitValue/unit}} internal slot
756
+ to |unit|.
757
+
758
+ 6. Return |item|.
759
+ </div>
760
+
761
+ <div algorithm>
762
+ When asked to <dfn export>create a CSSUnitValue from a sum value item</dfn> |item|,
763
+ perform the following steps:
764
+
765
+ 1. If |item| has more than one [=map/entry=] in its [=sum value/unit map=] ,
766
+ return failure.
767
+
768
+ 2. If |item| has no [=map/entries=] in its [=sum value/unit map=] ,
769
+ return a new {{CSSUnitValue}}
770
+ whose {{CSSUnitValue/unit}} internal slot
771
+ is set to "number",
772
+ and whose {{CSSUnitValue/value}} internal slot
773
+ is set to |item|’s [=sum value/value=] .
774
+
775
+ 3. Otherwise, |item| has a single [=map/entry=] in its [=sum value/unit map=] .
776
+ If that [=map/entry’s=] [=map/value=] is anything other than `1`,
777
+ return failure.
778
+
779
+ 4. Otherwise, return a new {{CSSUnitValue}}
755
780
whose {{CSSUnitValue/unit}} internal slot
756
- is set to |unit| ,
781
+ is set to that [=map/entry’s=] [=map/key=] ,
757
782
and whose {{CSSUnitValue/value}} internal slot
758
- is set to |item value|
759
- multiplied by the conversion ratio between |item unit|
760
- and |unit|.
783
+ is set to |item|’s [=sum value/value=] .
761
784
</div>
762
785
763
786
<div algorithm="sum value">
@@ -1251,17 +1274,16 @@ are represented as {{CSSUnitValue}}s.
1251
1274
</div>
1252
1275
1253
1276
<div algorithm>
1254
- When asked to <dfn export local-lt="new unit value">create a new unit value</dfn>
1255
- from a numeric value |num|,
1277
+ When asked to <dfn export>create a CSSUnitValue from a string</dfn> |str|,
1256
1278
return a new {{CSSUnitValue}} object
1257
1279
with its {{CSSUnitValue/value}} internal slot
1258
- set to the numeric portion of |num| ,
1280
+ set to the numeric portion of |str| parsed into a number ,
1259
1281
and its {{CSSUnitValue/unit}} internal slot
1260
- set to the unit portion of |num |,
1261
- or "number" or "percent" if |num | is a plain number or percent.
1282
+ set to the unit portion of |str |,
1283
+ or "number" or "percent" if |str | is a plain number or percent.
1262
1284
1263
1285
<div class=example>
1264
- For example, creating a [=new unit value =] from ''5px''
1286
+ For example, [=create a CSSUnitValue from a string|creating a CSSUnitValue =] from ''5px''
1265
1287
creates an object equivalent to
1266
1288
<code> new CSSUnitValue(5, "px")</code> .
1267
1289
</div>
0 commit comments