Commit 138fde45 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[css-typed-om] Allow mutations of CSSUnparsedValue.

This patch allows CSSUnparsedValue items to be mutated/appended.
See https://github.com/w3c/css-houdini-drafts/issues/664

Bug: 812919
Change-Id: I3e3c1d91fa9bfaa3a1a4adde45202c36c9bdb37f
Reviewed-on: https://chromium-review.googlesource.com/923670Reviewed-by: default avatarnainar <nainar@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537691}
parent b7086194
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
<meta name="assert" content="Test CSSUnparsedValue constructor and members"> <meta name="assert" content="Test CSSUnparsedValue constructor and members">
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="../resources/testhelper.js"></script>
<body> <body>
<div id="log"> <div id="log">
<script> <script>
...@@ -47,4 +48,44 @@ for (const {args, description} of gTestArguments) { ...@@ -47,4 +48,44 @@ for (const {args, description} of gTestArguments) {
}, 'CSSUnparsedValue can be constructed from ' + description); }, 'CSSUnparsedValue can be constructed from ' + description);
} }
test(() => {
let result = new CSSUnparsedValue([new CSSVariableReferenceValue('--foo')]);
result[0] = 'A';
assert_equals(result[0], 'A', 'Item should be updated to new value');
}, 'Can update item in CSSUnparsedValue to a string');
test(() => {
let result = new CSSUnparsedValue(['foo']);
result[0] = new CSSVariableReferenceValue('--A');
assert_style_value_equals(result[0], new CSSVariableReferenceValue('--A'),
'Item should be updated to new value');
}, 'Can update item in CSSUnparsedValue to a variable reference');
test(() => {
let result = new CSSUnparsedValue([]);
result[0] = new CSSVariableReferenceValue('--A');
assert_equals(result.length, 1,
'Length of CSSUnparsedValue should have increased');
assert_style_value_equals(result[0], new CSSVariableReferenceValue('--A'),
'New item should be appended');
result[1] = 'foo';
assert_equals(result.length, 2,
'Length of CSSUnparsedValue should have increased');
assert_equals(result[1], 'foo', 'New item should be appended');
}, 'Can append items to CSSUnparsedValue');
test(() => {
const result = new CSSUnparsedValue(['foo', 'bar']);
assert_equals(result[3], undefined);
}, 'Getting invalid index in CSSUnparsedValue returns undefined');
test(() => {
let result = new CSSUnparsedValue(['foo', 'bar']);
assert_throws(new RangeError(), () => result[3] = 'foo');
}, 'Setting invalid index in CSSUnparsedValue throws RangeError');
</script> </script>
...@@ -73,6 +73,34 @@ CSSUnparsedValue* CSSUnparsedValue::FromCSSValue(const CSSVariableData& value) { ...@@ -73,6 +73,34 @@ CSSUnparsedValue* CSSUnparsedValue::FromCSSValue(const CSSVariableData& value) {
return CSSUnparsedValue::Create(ParserTokenRangeToTokens(value.TokenRange())); return CSSUnparsedValue::Create(ParserTokenRangeToTokens(value.TokenRange()));
} }
CSSUnparsedSegment CSSUnparsedValue::AnonymousIndexedGetter(
unsigned index,
ExceptionState& exception_state) {
if (index < tokens_.size())
return tokens_[index];
return {};
}
bool CSSUnparsedValue::AnonymousIndexedSetter(unsigned index,
const CSSUnparsedSegment& segment,
ExceptionState& exception_state) {
if (index < tokens_.size()) {
tokens_[index] = segment;
return true;
}
if (index == tokens_.size()) {
tokens_.push_back(segment);
return true;
}
exception_state.ThrowRangeError(
ExceptionMessages::IndexOutsideRange<unsigned>(
"index", index, 0, ExceptionMessages::kInclusiveBound, tokens_.size(),
ExceptionMessages::kInclusiveBound));
return false;
}
const CSSValue* CSSUnparsedValue::ToCSSValue() const { const CSSValue* CSSUnparsedValue::ToCSSValue() const {
if (tokens_.IsEmpty()) { if (tokens_.IsEmpty()) {
return CSSVariableReferenceValue::Create(CSSVariableData::Create()); return CSSVariableReferenceValue::Create(CSSVariableData::Create());
......
...@@ -36,13 +36,10 @@ class CORE_EXPORT CSSUnparsedValue final : public CSSStyleValue { ...@@ -36,13 +36,10 @@ class CORE_EXPORT CSSUnparsedValue final : public CSSStyleValue {
StyleValueType GetType() const override { return kUnparsedType; } StyleValueType GetType() const override { return kUnparsedType; }
CSSUnparsedSegment AnonymousIndexedGetter( CSSUnparsedSegment AnonymousIndexedGetter(unsigned, ExceptionState&);
unsigned index, bool AnonymousIndexedSetter(unsigned,
ExceptionState& exception_state) const { const CSSUnparsedSegment&,
if (index < tokens_.size()) ExceptionState&);
return tokens_[index];
return {};
}
size_t length() const { return tokens_.size(); } size_t length() const { return tokens_.size(); }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
iterable<CSSUnparsedSegment>; iterable<CSSUnparsedSegment>;
readonly attribute unsigned long length; readonly attribute unsigned long length;
[RaisesException] getter CSSUnparsedSegment (unsigned long index); [RaisesException] getter CSSUnparsedSegment (unsigned long index);
[RaisesException] setter CSSUnparsedSegment (unsigned long index, CSSUnparsedSegment val);
}; };
typedef (DOMString or CSSVariableReferenceValue) CSSUnparsedSegment; typedef (DOMString or CSSVariableReferenceValue) CSSUnparsedSegment;
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