Skip to content

Commit

Permalink
Cssstyledeclaration#item() now returns a string
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Oct 13, 2024
1 parent 7ef9d1a commit 21e40b0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 17 deletions.
6 changes: 6 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

<body>
<release version="4.5.0" date="xxxx, 2024" description="Chrome/Edge 129, Firefox 129, WebWorker, Bugfixes">
<action type="update" dev="rbri">
INCOMPATIBLE CHANGE: Return type of AbstractCssStyleDeclaration.item(int) has changed from Object to String.
</action>
<action type="fix" dev="rbri">
Javascript Cssstyledeclaration#item() now returns a string.
</action>
<action type="update" dev="RhinoTeam">
core-js: code cleanup; remove the unused javascript/optimizer package.
</action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,10 @@ else if (values.length > 0) {
public abstract int getLength();

/**
* Returns the item in the given index.
* @param index the index
* @return the item in the given index
* @return the name of the CSS property at the specified index
*/
public abstract Object item(int index);
public abstract String item(int index);

/**
* Returns the CSSRule that is the parent of this style block or <code>null</code> if this CSSStyleDeclaration is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ else if (AUTO.equals(value)) {
* {@inheritDoc}
*/
@Override
public Object item(final int index) {
public String item(final int index) {
return elementStyleDeclaration_.item(index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ public int getLength() {
* {@inheritDoc}
*/
@Override
public Object item(final int index) {
return cssStyleDeclarationImpl_.getProperties().get(index);
public String item(final int index) {
return cssStyleDeclarationImpl_.getProperties().get(index).toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -901,15 +901,15 @@ public int getLength() {
}

/**
* Returns the item in the given index.
* @param index the index
* @return the item in the given index
* @return a CSS property name from a CSSStyleDeclaration by index.
*/
@JsxFunction
public Object item(final int index) {
public String item(final int index) {
if (styleDeclaration_ == null) {
return null; // prototype
}

return styleDeclaration_.item(index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,19 +544,31 @@ public void selectorTextSetCaseInsensitive() throws Exception {
*/
@Test
@Alerts(DEFAULT = {"[object CSSStyleDeclaration]", "[object CSSStyleDeclaration]", "4", "[object CSSPageRule]",
"margin: 1cm;", "margin-top", "margin-right", "margin-bottom", "margin-left"},
"margin: 1cm;",
"string margin-top",
"string margin-right",
"string margin-bottom",
"string margin-left"},
FF = {"[object CSSPageDescriptors]", "[object CSSPageDescriptors]", "4", "[object CSSPageRule]",
"margin: 1cm;", "margin-top", "margin-right", "margin-bottom", "margin-left"},
"margin: 1cm;",
"string margin-top",
"string margin-right",
"string margin-bottom",
"string margin-left"},
FF_ESR = {"[object CSS2Properties]", "[object CSS2Properties]", "4", "[object CSSPageRule]",
"margin: 1cm;", "margin-top", "margin-right", "margin-bottom", "margin-left"})
"margin: 1cm;",
"string margin-top",
"string margin-right",
"string margin-bottom",
"string margin-left"})
@HtmlUnitNYI(CHROME = {"[object CSSStyleDeclaration]", "[object CSSStyleDeclaration]",
"1", "[object CSSPageRule]", "margin: 1cm;", "margin: 1cm"},
"1", "[object CSSPageRule]", "margin: 1cm;", "string margin: 1cm"},
EDGE = {"[object CSSStyleDeclaration]", "[object CSSStyleDeclaration]",
"1", "[object CSSPageRule]", "margin: 1cm;", "margin: 1cm"},
"1", "[object CSSPageRule]", "margin: 1cm;", "string margin: 1cm"},
FF = {"[object CSSStyleDeclaration]", "[object CSSStyleDeclaration]",
"1", "[object CSSPageRule]", "margin: 1cm;", "margin: 1cm"},
"1", "[object CSSPageRule]", "margin: 1cm;", "string margin: 1cm"},
FF_ESR = {"[object CSSStyleDeclaration]", "[object CSSStyleDeclaration]",
"1", "[object CSSPageRule]", "margin: 1cm;", "margin: 1cm"})
"1", "[object CSSPageRule]", "margin: 1cm;", "string margin: 1cm"})
// FIXME FF returns CSS2Properties vs. default returns CSSStyleDeclaration :(
public void style() throws Exception {
final String html
Expand All @@ -577,7 +589,7 @@ public void style() throws Exception {
+ " log(style.parentRule);\n"
+ " log(style.cssText);\n"
+ " for (var i = 0; i < style.length; i++) {\n"
+ " log(style.item(i));\n"
+ " log(typeof style.item(i) + ' ' + style.item(i));\n"
+ " }\n"
+ "</script>\n"

Expand Down

0 comments on commit 21e40b0

Please sign in to comment.