- Revision
- 200358
- Author
- [email protected]
- Date
- 2016-05-02 19:52:19 -0700 (Mon, 02 May 2016)
Log Message
Indexing CSSStyleDeclaration object with out-of-range index should return undefined
https://bugs.webkit.org/show_bug.cgi?id=157283
Reviewed by Darin Adler.
Source/WebCore:
Indexing CSSStyleDeclaration object with out-of-range index should return undefined,
as per:
- http://heycam.github.io/webidl/#idl-indexed-properties
- http://heycam.github.io/webidl/#getownproperty-guts
WebKit was incorrectly returning the empty string in this case. We however, still
return the empty string if calling the indexed property getter via item(), as is
expected.
The new behavior matches Firefox and the Web IDL specification. Chrome returns the
empty string in this case though.
Test: fast/dom/indexed-getters-returning-string.html
* css/CSSComputedStyleDeclaration.cpp:
(WebCore::CSSComputedStyleDeclaration::item):
* css/PropertySetCSSStyleDeclaration.cpp:
(WebCore::PropertySetCSSStyleDeclaration::item):
LayoutTests:
Rebaseline a couple of existing tests due to the slight behavior change.
Also add a new layout test for more extensive testing.
* fast/dom/CSSStyleDeclaration/css-computed-style-item-expected.txt:
* fast/dom/CSSStyleDeclaration/css-style-item-expected.txt:
* fast/dom/CSSStyleDeclaration/script-tests/css-computed-style-item.js:
* fast/dom/CSSStyleDeclaration/script-tests/css-style-item.js:
* fast/dom/indexed-getters-returning-string-expected.txt: Added.
* fast/dom/indexed-getters-returning-string.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (200357 => 200358)
--- trunk/LayoutTests/ChangeLog 2016-05-03 02:25:31 UTC (rev 200357)
+++ trunk/LayoutTests/ChangeLog 2016-05-03 02:52:19 UTC (rev 200358)
@@ -1,3 +1,20 @@
+2016-05-02 Chris Dumez <[email protected]>
+
+ Indexing CSSStyleDeclaration object with out-of-range index should return undefined
+ https://bugs.webkit.org/show_bug.cgi?id=157283
+
+ Reviewed by Darin Adler.
+
+ Rebaseline a couple of existing tests due to the slight behavior change.
+ Also add a new layout test for more extensive testing.
+
+ * fast/dom/CSSStyleDeclaration/css-computed-style-item-expected.txt:
+ * fast/dom/CSSStyleDeclaration/css-style-item-expected.txt:
+ * fast/dom/CSSStyleDeclaration/script-tests/css-computed-style-item.js:
+ * fast/dom/CSSStyleDeclaration/script-tests/css-style-item.js:
+ * fast/dom/indexed-getters-returning-string-expected.txt: Added.
+ * fast/dom/indexed-getters-returning-string.html: Added.
+
2016-05-02 Antoine Quint <[email protected]>
Specifying a longhand property should not serialize to a shorthand property
Modified: trunk/LayoutTests/fast/dom/CSSStyleDeclaration/css-computed-style-item-expected.txt (200357 => 200358)
--- trunk/LayoutTests/fast/dom/CSSStyleDeclaration/css-computed-style-item-expected.txt 2016-05-03 02:25:31 UTC (rev 200357)
+++ trunk/LayoutTests/fast/dom/CSSStyleDeclaration/css-computed-style-item-expected.txt 2016-05-03 02:52:19 UTC (rev 200358)
@@ -4,7 +4,8 @@
PASS typeof computedStyle.length is "number"
-PASS computedStyle[computedStyle.length] is ""
+PASS computedStyle.item(computedStyle.length) is ""
+PASS computedStyle[computedStyle.length] is undefined.
PASS computedStyle[-1] is undefined.
PASS successfullyParsed is true
Modified: trunk/LayoutTests/fast/dom/CSSStyleDeclaration/css-style-item-expected.txt (200357 => 200358)
--- trunk/LayoutTests/fast/dom/CSSStyleDeclaration/css-style-item-expected.txt 2016-05-03 02:25:31 UTC (rev 200357)
+++ trunk/LayoutTests/fast/dom/CSSStyleDeclaration/css-style-item-expected.txt 2016-05-03 02:52:19 UTC (rev 200358)
@@ -5,7 +5,8 @@
PASS style.length is 1
PASS style[0] is "color"
-PASS style[1] is ""
+PASS style.item(1) is ""
+PASS style[1] is undefined.
PASS style[-1] is undefined.
PASS successfullyParsed is true
Modified: trunk/LayoutTests/fast/dom/CSSStyleDeclaration/script-tests/css-computed-style-item.js (200357 => 200358)
--- trunk/LayoutTests/fast/dom/CSSStyleDeclaration/script-tests/css-computed-style-item.js 2016-05-03 02:25:31 UTC (rev 200357)
+++ trunk/LayoutTests/fast/dom/CSSStyleDeclaration/script-tests/css-computed-style-item.js 2016-05-03 02:52:19 UTC (rev 200358)
@@ -6,7 +6,8 @@
var computedStyle = window.getComputedStyle(element, null);
shouldBeEqualToString('typeof computedStyle.length', 'number');
-shouldBeEqualToString('computedStyle[computedStyle.length]', '');
+shouldBeEqualToString('computedStyle.item(computedStyle.length)', '');
+shouldBeUndefined('computedStyle[computedStyle.length]');
shouldBeUndefined('computedStyle[-1]')
document.documentElement.removeChild(element);
Modified: trunk/LayoutTests/fast/dom/CSSStyleDeclaration/script-tests/css-style-item.js (200357 => 200358)
--- trunk/LayoutTests/fast/dom/CSSStyleDeclaration/script-tests/css-style-item.js 2016-05-03 02:25:31 UTC (rev 200357)
+++ trunk/LayoutTests/fast/dom/CSSStyleDeclaration/script-tests/css-style-item.js 2016-05-03 02:52:19 UTC (rev 200358)
@@ -7,7 +7,8 @@
shouldEvaluateTo('style.length', 1);
shouldBeEqualToString('style[0]', 'color');
-shouldBeEqualToString('style[1]', '');
+shouldBeEqualToString('style.item(1)', '');
+shouldBeUndefined('style[1]');
shouldBeUndefined('style[-1]')
document.documentElement.removeChild(element);
Added: trunk/LayoutTests/fast/dom/indexed-getters-returning-string-expected.txt (0 => 200358)
--- trunk/LayoutTests/fast/dom/indexed-getters-returning-string-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/indexed-getters-returning-string-expected.txt 2016-05-03 02:52:19 UTC (rev 200358)
@@ -0,0 +1,27 @@
+Tests the behavior of indexed property getters returning a DOMString with regards to out-of-bounds access
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+* Indexed property getters returning a non-nullable DOMString
+DOMTokenList.item()
+PASS document.body.classList.item(666) is null
+PASS document.body.classList[666] is undefined.
+DOMStringList.item()
+PASS location.ancestorOrigins.item(666) is null
+PASS location.ancestorOrigins[666] is undefined.
+Storage.getItem()
+PASS localStorage.getItem(666) is null
+PASS localStorage[666] is undefined.
+MediaList.item()
+PASS stylesheet.media.item(666) is null
+PASS stylesheet.media[666] is undefined.
+
+* Indexed property getters returning a non-nullable DOMString
+CSSStyleDeclaration.item()
+PASS document.body.style.item(666) is ""
+PASS document.body.style[666] is undefined.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/dom/indexed-getters-returning-string.html (0 => 200358)
--- trunk/LayoutTests/fast/dom/indexed-getters-returning-string.html (rev 0)
+++ trunk/LayoutTests/fast/dom/indexed-getters-returning-string.html 2016-05-03 02:52:19 UTC (rev 200358)
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<head>
+<style id="style" media="screen"></style>
+</head>
+<body>
+<script src=""
+<script>
+description("Tests the behavior of indexed property getters returning a DOMString with regards to out-of-bounds access");
+
+debug("* Indexed property getters returning a non-nullable DOMString");
+debug("DOMTokenList.item()");
+shouldBeNull("document.body.classList.item(666)");
+shouldBeUndefined("document.body.classList[666]");
+debug("DOMStringList.item()");
+shouldBeNull("location.ancestorOrigins.item(666)");
+shouldBeUndefined("location.ancestorOrigins[666]");
+debug("Storage.getItem()");
+shouldBeNull("localStorage.getItem(666)");
+shouldBeUndefined("localStorage[666]");
+debug("MediaList.item()");
+var stylesheet = document.getElementById("style").sheet;
+shouldBeNull("stylesheet.media.item(666)");
+shouldBeUndefined("stylesheet.media[666]");
+
+debug("");
+debug("* Indexed property getters returning a non-nullable DOMString");
+debug("CSSStyleDeclaration.item()");
+shouldBeEmptyString("document.body.style.item(666)");
+shouldBeUndefined("document.body.style[666]");
+
+</script>
+<script src=""
+</body>
Modified: trunk/Source/WebCore/ChangeLog (200357 => 200358)
--- trunk/Source/WebCore/ChangeLog 2016-05-03 02:25:31 UTC (rev 200357)
+++ trunk/Source/WebCore/ChangeLog 2016-05-03 02:52:19 UTC (rev 200358)
@@ -1,3 +1,29 @@
+2016-05-02 Chris Dumez <[email protected]>
+
+ Indexing CSSStyleDeclaration object with out-of-range index should return undefined
+ https://bugs.webkit.org/show_bug.cgi?id=157283
+
+ Reviewed by Darin Adler.
+
+ Indexing CSSStyleDeclaration object with out-of-range index should return undefined,
+ as per:
+ - http://heycam.github.io/webidl/#idl-indexed-properties
+ - http://heycam.github.io/webidl/#getownproperty-guts
+
+ WebKit was incorrectly returning the empty string in this case. We however, still
+ return the empty string if calling the indexed property getter via item(), as is
+ expected.
+
+ The new behavior matches Firefox and the Web IDL specification. Chrome returns the
+ empty string in this case though.
+
+ Test: fast/dom/indexed-getters-returning-string.html
+
+ * css/CSSComputedStyleDeclaration.cpp:
+ (WebCore::CSSComputedStyleDeclaration::item):
+ * css/PropertySetCSSStyleDeclaration.cpp:
+ (WebCore::PropertySetCSSStyleDeclaration::item):
+
2016-05-02 Antoine Quint <[email protected]>
Specifying a longhand property should not serialize to a shorthand property
Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (200357 => 200358)
--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp 2016-05-03 02:25:31 UTC (rev 200357)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp 2016-05-03 02:52:19 UTC (rev 200358)
@@ -3873,24 +3873,24 @@
String CSSComputedStyleDeclaration::item(unsigned i) const
{
if (i >= length())
- return emptyString();
+ return String();
if (i < numComputedProperties)
return getPropertyNameString(computedProperties[i]);
Node* node = m_node.get();
if (!node)
- return emptyString();
+ return String();
auto* style = node->computedStyle(m_pseudoElementSpecifier);
if (!style)
- return emptyString();
+ return String();
unsigned index = i - numComputedProperties;
const auto& customProperties = style->customProperties();
if (index >= customProperties.size())
- return emptyString();
+ return String();
Vector<String, 4> results;
copyKeysToVector(customProperties, results);
Modified: trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp (200357 => 200358)
--- trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp 2016-05-03 02:25:31 UTC (rev 200357)
+++ trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp 2016-05-03 02:52:19 UTC (rev 200358)
@@ -137,7 +137,7 @@
String PropertySetCSSStyleDeclaration::item(unsigned i) const
{
if (i >= m_propertySet->propertyCount())
- return "";
+ return String();
return m_propertySet->propertyAt(i).cssName();
}