Commit a5797756 authored by Hwanseung Lee's avatar Hwanseung Lee Committed by Commit Bot

[css-typed-om] CSSUnitValue.unit should be readonly

CSSUnitValue.unit should be immutable to prevent cyclic references

Bug: 803687
Change-Id: I35f79ec2491277fcb2d02ce85a2e9c6ecd8c3a07
Reviewed-on: https://chromium-review.googlesource.com/897177Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Commit-Queue: Hwanseung Lee <hs1217.lee@samsung.com>
Cr-Commit-Position: refs/heads/master@{#534237}
parent 89e777f7
...@@ -34,22 +34,10 @@ test(() => { ...@@ -34,22 +34,10 @@ test(() => {
assert_equals(result.toString(), '3.14px'); assert_equals(result.toString(), '3.14px');
}, 'CSSKeywordValue from DOMString modified by "value" setter serializes correctly'); }, 'CSSKeywordValue from DOMString modified by "value" setter serializes correctly');
test(() => {
let result = CSSStyleValue.parse('width', '1px');
result.unit = 's';
assert_equals(result.toString(), '1s');
}, 'CSSKeywordValue from DOMString modified by "unit" setter serializes correctly');
test(t => { test(t => {
let result = createInlineStyleMap(t, 'width: 1px').get('width'); let result = createInlineStyleMap(t, 'width: 1px').get('width');
result.value = 3.14; result.value = 3.14;
assert_equals(result.toString(), '3.14px'); assert_equals(result.toString(), '3.14px');
}, 'CSSKeywordValue from CSSOM modified by "value" setter serializes correctly'); }, 'CSSKeywordValue from CSSOM modified by "value" setter serializes correctly');
test(t => {
let result = createInlineStyleMap(t, 'width: 1px').get('width');
result.unit = 's';
assert_equals(result.toString(), '1s');
}, 'CSSKeywordValue from CSSOM modified by "unit" setter serializes correctly');
</script> </script>
This is a testharness.js-based test. This is a testharness.js-based test.
Found 72 tests; 62 PASS, 10 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS Constructing CSSUnitValue with an empty string as the unit throws a TypeError PASS Constructing CSSUnitValue with an empty string as the unit throws a TypeError
PASS Constructing CSSUnitValue with an invalid unit as the unit throws a TypeError PASS Constructing CSSUnitValue with an invalid unit as the unit throws a TypeError
PASS Updating CSSUnitValue.unit with an empty string throws a TypeError
PASS Updating CSSUnitValue.unit with an invalid unit throws a TypeError
PASS CSSUnitValue can be constructed with number PASS CSSUnitValue can be constructed with number
PASS CSSUnitValue.unit can be updated to number
PASS CSSUnitValue can be constructed with percent PASS CSSUnitValue can be constructed with percent
PASS CSSUnitValue.unit can be updated to percent
PASS CSSUnitValue can be constructed with em PASS CSSUnitValue can be constructed with em
PASS CSSUnitValue.unit can be updated to em
PASS CSSUnitValue can be constructed with ex PASS CSSUnitValue can be constructed with ex
PASS CSSUnitValue.unit can be updated to ex
PASS CSSUnitValue can be constructed with ch PASS CSSUnitValue can be constructed with ch
PASS CSSUnitValue.unit can be updated to ch
FAIL CSSUnitValue can be constructed with ic Failed to construct 'CSSUnitValue': Invalid unit: ic FAIL CSSUnitValue can be constructed with ic Failed to construct 'CSSUnitValue': Invalid unit: ic
FAIL CSSUnitValue.unit can be updated to ic Failed to set the 'unit' property on 'CSSUnitValue': Invalid unit: ic
PASS CSSUnitValue can be constructed with rem PASS CSSUnitValue can be constructed with rem
PASS CSSUnitValue.unit can be updated to rem
FAIL CSSUnitValue can be constructed with lh Failed to construct 'CSSUnitValue': Invalid unit: lh FAIL CSSUnitValue can be constructed with lh Failed to construct 'CSSUnitValue': Invalid unit: lh
FAIL CSSUnitValue.unit can be updated to lh Failed to set the 'unit' property on 'CSSUnitValue': Invalid unit: lh
FAIL CSSUnitValue can be constructed with rlh Failed to construct 'CSSUnitValue': Invalid unit: rlh FAIL CSSUnitValue can be constructed with rlh Failed to construct 'CSSUnitValue': Invalid unit: rlh
FAIL CSSUnitValue.unit can be updated to rlh Failed to set the 'unit' property on 'CSSUnitValue': Invalid unit: rlh
PASS CSSUnitValue can be constructed with vw PASS CSSUnitValue can be constructed with vw
PASS CSSUnitValue.unit can be updated to vw
PASS CSSUnitValue can be constructed with vh PASS CSSUnitValue can be constructed with vh
PASS CSSUnitValue.unit can be updated to vh
FAIL CSSUnitValue can be constructed with vi Failed to construct 'CSSUnitValue': Invalid unit: vi FAIL CSSUnitValue can be constructed with vi Failed to construct 'CSSUnitValue': Invalid unit: vi
FAIL CSSUnitValue.unit can be updated to vi Failed to set the 'unit' property on 'CSSUnitValue': Invalid unit: vi
FAIL CSSUnitValue can be constructed with vb Failed to construct 'CSSUnitValue': Invalid unit: vb FAIL CSSUnitValue can be constructed with vb Failed to construct 'CSSUnitValue': Invalid unit: vb
FAIL CSSUnitValue.unit can be updated to vb Failed to set the 'unit' property on 'CSSUnitValue': Invalid unit: vb
PASS CSSUnitValue can be constructed with vmin PASS CSSUnitValue can be constructed with vmin
PASS CSSUnitValue.unit can be updated to vmin
PASS CSSUnitValue can be constructed with vmax PASS CSSUnitValue can be constructed with vmax
PASS CSSUnitValue.unit can be updated to vmax
PASS CSSUnitValue can be constructed with cm PASS CSSUnitValue can be constructed with cm
PASS CSSUnitValue.unit can be updated to cm
PASS CSSUnitValue can be constructed with mm PASS CSSUnitValue can be constructed with mm
PASS CSSUnitValue.unit can be updated to mm
PASS CSSUnitValue can be constructed with Q PASS CSSUnitValue can be constructed with Q
PASS CSSUnitValue.unit can be updated to Q
PASS CSSUnitValue can be constructed with in PASS CSSUnitValue can be constructed with in
PASS CSSUnitValue.unit can be updated to in
PASS CSSUnitValue can be constructed with pt PASS CSSUnitValue can be constructed with pt
PASS CSSUnitValue.unit can be updated to pt
PASS CSSUnitValue can be constructed with pc PASS CSSUnitValue can be constructed with pc
PASS CSSUnitValue.unit can be updated to pc
PASS CSSUnitValue can be constructed with px PASS CSSUnitValue can be constructed with px
PASS CSSUnitValue.unit can be updated to px
PASS CSSUnitValue can be constructed with deg PASS CSSUnitValue can be constructed with deg
PASS CSSUnitValue.unit can be updated to deg
PASS CSSUnitValue can be constructed with grad PASS CSSUnitValue can be constructed with grad
PASS CSSUnitValue.unit can be updated to grad
PASS CSSUnitValue can be constructed with rad PASS CSSUnitValue can be constructed with rad
PASS CSSUnitValue.unit can be updated to rad
PASS CSSUnitValue can be constructed with turn PASS CSSUnitValue can be constructed with turn
PASS CSSUnitValue.unit can be updated to turn
PASS CSSUnitValue can be constructed with s PASS CSSUnitValue can be constructed with s
PASS CSSUnitValue.unit can be updated to s
PASS CSSUnitValue can be constructed with ms PASS CSSUnitValue can be constructed with ms
PASS CSSUnitValue.unit can be updated to ms
PASS CSSUnitValue can be constructed with Hz PASS CSSUnitValue can be constructed with Hz
PASS CSSUnitValue.unit can be updated to Hz
PASS CSSUnitValue can be constructed with kHz PASS CSSUnitValue can be constructed with kHz
PASS CSSUnitValue.unit can be updated to kHz
PASS CSSUnitValue can be constructed with dpi PASS CSSUnitValue can be constructed with dpi
PASS CSSUnitValue.unit can be updated to dpi
PASS CSSUnitValue can be constructed with dpcm PASS CSSUnitValue can be constructed with dpcm
PASS CSSUnitValue.unit can be updated to dpcm
PASS CSSUnitValue can be constructed with dppx PASS CSSUnitValue can be constructed with dppx
PASS CSSUnitValue.unit can be updated to dppx
PASS CSSUnitValue can be constructed with fr PASS CSSUnitValue can be constructed with fr
PASS CSSUnitValue.unit can be updated to fr
Harness: the test ran to completion. Harness: the test ran to completion.
...@@ -19,26 +19,12 @@ for (const {unit, desc} of gInvalidTestUnits) { ...@@ -19,26 +19,12 @@ for (const {unit, desc} of gInvalidTestUnits) {
}, 'Constructing CSSUnitValue with ' + desc + ' as the unit throws a TypeError'); }, 'Constructing CSSUnitValue with ' + desc + ' as the unit throws a TypeError');
} }
for (const {unit, desc} of gInvalidTestUnits) {
test(() => {
let result = new CSSUnitValue(0, 'px');
assert_throws(new TypeError(), () => result.unit = unit);
assert_equals(result.unit, 'px');
}, 'Updating CSSUnitValue.unit with ' + desc + ' throws a TypeError');
}
for (const unit of gValidUnits) { for (const unit of gValidUnits) {
test(() => { test(() => {
const result = new CSSUnitValue(-3.14, unit); const result = new CSSUnitValue(-3.14, unit);
assert_equals(result.value, -3.14); assert_equals(result.value, -3.14);
assert_equals(result.unit, unit.toLowerCase()); assert_equals(result.unit, unit.toLowerCase());
}, 'CSSUnitValue can be constructed with ' + unit); }, 'CSSUnitValue can be constructed with ' + unit);
test(() => {
let result = new CSSUnitValue(-3.14, 'px');
result.unit = unit
assert_equals(result.unit, unit.toLowerCase());
}, 'CSSUnitValue.unit can be updated to ' + unit);
} }
</script> </script>
...@@ -124,7 +124,6 @@ CONSOLE MESSAGE: line 147: interface CSSUnitValue : CSSNumericValue ...@@ -124,7 +124,6 @@ CONSOLE MESSAGE: line 147: interface CSSUnitValue : CSSNumericValue
CONSOLE MESSAGE: line 147: getter unit CONSOLE MESSAGE: line 147: getter unit
CONSOLE MESSAGE: line 147: getter value CONSOLE MESSAGE: line 147: getter value
CONSOLE MESSAGE: line 147: method constructor CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter unit
CONSOLE MESSAGE: line 147: setter value CONSOLE MESSAGE: line 147: setter value
CONSOLE MESSAGE: line 147: interface CSSUnparsedValue : CSSStyleValue CONSOLE MESSAGE: line 147: interface CSSUnparsedValue : CSSStyleValue
CONSOLE MESSAGE: line 147: getter length CONSOLE MESSAGE: line 147: getter length
...@@ -412,7 +411,6 @@ CONSOLE MESSAGE: line 147: interface CSSUnitValue : CSSNumericValue ...@@ -412,7 +411,6 @@ CONSOLE MESSAGE: line 147: interface CSSUnitValue : CSSNumericValue
CONSOLE MESSAGE: line 147: getter unit CONSOLE MESSAGE: line 147: getter unit
CONSOLE MESSAGE: line 147: getter value CONSOLE MESSAGE: line 147: getter value
CONSOLE MESSAGE: line 147: method constructor CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter unit
CONSOLE MESSAGE: line 147: setter value CONSOLE MESSAGE: line 147: setter value
CONSOLE MESSAGE: line 147: interface CSSUnparsedValue : CSSStyleValue CONSOLE MESSAGE: line 147: interface CSSUnparsedValue : CSSStyleValue
CONSOLE MESSAGE: line 147: getter length CONSOLE MESSAGE: line 147: getter length
......
...@@ -857,7 +857,6 @@ interface CSSUnitValue : CSSNumericValue ...@@ -857,7 +857,6 @@ interface CSSUnitValue : CSSNumericValue
getter unit getter unit
getter value getter value
method constructor method constructor
setter unit
setter value setter value
interface CSSUnparsedValue : CSSStyleValue interface CSSUnparsedValue : CSSStyleValue
attribute @@toStringTag attribute @@toStringTag
......
...@@ -61,17 +61,6 @@ CSSUnitValue* CSSUnitValue::FromCSSValue(const CSSPrimitiveValue& value) { ...@@ -61,17 +61,6 @@ CSSUnitValue* CSSUnitValue::FromCSSValue(const CSSPrimitiveValue& value) {
return new CSSUnitValue(value.GetDoubleValue(), unit); return new CSSUnitValue(value.GetDoubleValue(), unit);
} }
void CSSUnitValue::setUnit(const String& unit_name,
ExceptionState& exception_state) {
CSSPrimitiveValue::UnitType unit = UnitFromName(unit_name);
if (!IsValidUnit(unit)) {
exception_state.ThrowTypeError("Invalid unit: " + unit_name);
return;
}
unit_ = unit;
}
String CSSUnitValue::unit() const { String CSSUnitValue::unit() const {
if (unit_ == CSSPrimitiveValue::UnitType::kNumber) if (unit_ == CSSPrimitiveValue::UnitType::kNumber)
return "number"; return "number";
......
...@@ -31,7 +31,6 @@ class CORE_EXPORT CSSUnitValue final : public CSSNumericValue { ...@@ -31,7 +31,6 @@ class CORE_EXPORT CSSUnitValue final : public CSSNumericValue {
// Setters and getters for attributes defined in the IDL. // Setters and getters for attributes defined in the IDL.
void setValue(double new_value) { value_ = new_value; } void setValue(double new_value) { value_ = new_value; }
double value() const { return value_; } double value() const { return value_; }
void setUnit(const String& new_unit, ExceptionState&);
String unit() const; String unit() const;
// Internal methods. // Internal methods.
......
...@@ -12,5 +12,5 @@ ...@@ -12,5 +12,5 @@
RuntimeEnabled=CSSTypedOM RuntimeEnabled=CSSTypedOM
] interface CSSUnitValue : CSSNumericValue { ] interface CSSUnitValue : CSSNumericValue {
[EnforceRange] attribute double value; [EnforceRange] attribute double value;
[RaisesException=Setter] attribute DOMString unit; readonly attribute DOMString unit;
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment