Skip to content

Commit 4bf3dbd

Browse files
committed
Window.top has no setter
1 parent 8f89e69 commit 4bf3dbd

5 files changed

Lines changed: 113 additions & 54 deletions

File tree

src/changes/changes.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88

99
<body>
1010
<release version="4.17.0" date="September xx, 2025" description="Chrome/Edge 140, Firefox 142, Bugfixes">
11+
<action type="fix" dev="RhinoTeam">
12+
core-js: 'eval'of a function is now undefined
13+
</action>
14+
<action type="fix" dev="RhinoTeam">
15+
core-js: duplicate properties in object literal now allowed
16+
</action>
17+
<action type="fix" dev="rbri">
18+
Window.top has no setter.
19+
</action>
1120
<action type="update" dev="rbri">
1221
Upgrade Apache commons-lang3 to 3.19.0.
1322
</action>

src/main/java/org/htmlunit/javascript/host/Window.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ public class Window extends EventTarget implements WindowOrWorkerGlobalScope, Au
204204
private Map<Class<? extends Scriptable>, Scriptable> prototypes_ = new HashMap<>();
205205
private Object controllers_;
206206
private Object opener_;
207-
private final Object top_ = NOT_FOUND; // top can be set from JS to any value!
208207
private Crypto crypto_;
209208
private Scriptable performance_;
210209

@@ -838,23 +837,10 @@ public void initialize() {
838837
*/
839838
@JsxGetter
840839
public Object getTop() {
841-
if (top_ != NOT_FOUND) {
842-
return top_;
843-
}
844-
845840
final WebWindow top = getWebWindow().getTopWindow();
846841
return top.getScriptableObject();
847842
}
848843

849-
/**
850-
* Sets the value of the {@code top} property.
851-
* @param o the new value
852-
*/
853-
@JsxSetter
854-
public void setTop(final Object o) {
855-
// ignore
856-
}
857-
858844
/**
859845
* Returns the value of the {@code opener} property.
860846
* @return the value of the {@code opener}, or {@code null} for a top level window

src/test/java/org/htmlunit/general/ElementOwnPropertiesTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ public void event() throws Exception {
986986
+ "performance[GSCE],PERSISTENT[E],postMessage(),print(),prompt(),releaseEvents(),"
987987
+ "requestAnimationFrame(),resizeBy(),resizeTo(),screen[GCE],scroll(),scrollBy(),scrollTo(),"
988988
+ "scrollX[GCE],scrollY[GCE],self[GCE],sessionStorage[GCE],setInterval(),setTimeout(),"
989-
+ "speechSynthesis[GCE],status[GSCE],stop(),styleMedia[GCE],TEMPORARY[E],top[GSCE],window[GCE]",
989+
+ "speechSynthesis[GCE],status[GSCE],stop(),styleMedia[GCE],TEMPORARY[E],top[GCE],window[GCE]",
990990
EDGE = "alert(),atob(),blur(),btoa(),cancelAnimationFrame(),captureEvents(),clearInterval(),"
991991
+ "clearTimeout(),clientInformation[GSCE],close(),closed[GCE],confirm(),constructor(),crypto[GCE],"
992992
+ "devicePixelRatio[GCE],document[GCE],event[GCE],external[GCE],find(),focus(),frameElement[GCE],"
@@ -1017,7 +1017,7 @@ public void event() throws Exception {
10171017
+ "performance[GSCE],PERSISTENT[E],postMessage(),print(),prompt(),releaseEvents(),"
10181018
+ "requestAnimationFrame(),resizeBy(),resizeTo(),screen[GCE],scroll(),scrollBy(),scrollTo(),"
10191019
+ "scrollX[GCE],scrollY[GCE],self[GCE],sessionStorage[GCE],setInterval(),setTimeout(),"
1020-
+ "speechSynthesis[GCE],status[GSCE],stop(),styleMedia[GCE],TEMPORARY[E],top[GSCE],window[GCE]",
1020+
+ "speechSynthesis[GCE],status[GSCE],stop(),styleMedia[GCE],TEMPORARY[E],top[GCE],window[GCE]",
10211021
FF = "alert(),atob(),blur(),btoa(),cancelAnimationFrame(),captureEvents(),"
10221022
+ "clearInterval(),clearTimeout(),clientInformation[GSCE],close(),closed[GCE],confirm(),constructor(),"
10231023
+ "controllers[GSCE],"
@@ -1044,7 +1044,7 @@ public void event() throws Exception {
10441044
+ "pageXOffset[GCE],pageYOffset[GCE],parent[GCE],performance[GSCE],postMessage(),print(),prompt(),"
10451045
+ "releaseEvents(),requestAnimationFrame(),resizeBy(),resizeTo(),screen[GCE],scroll(),scrollBy(),"
10461046
+ "scrollByLines(),scrollByPages(),scrollTo(),scrollX[GCE],scrollY[GCE],self[GCE],sessionStorage[GCE],"
1047-
+ "setInterval(),setTimeout(),status[GSCE],stop(),top[GSCE],window[GCE]",
1047+
+ "setInterval(),setTimeout(),status[GSCE],stop(),top[GCE],window[GCE]",
10481048
FF_ESR = "alert(),atob(),blur(),btoa(),cancelAnimationFrame(),captureEvents(),"
10491049
+ "clearInterval(),clearTimeout(),clientInformation[GCE],close(),closed[GCE],confirm(),constructor(),"
10501050
+ "controllers[GSCE],"
@@ -1071,7 +1071,7 @@ public void event() throws Exception {
10711071
+ "pageXOffset[GCE],pageYOffset[GCE],parent[GCE],performance[GSCE],postMessage(),print(),prompt(),"
10721072
+ "releaseEvents(),requestAnimationFrame(),resizeBy(),resizeTo(),screen[GCE],scroll(),scrollBy(),"
10731073
+ "scrollByLines(),scrollByPages(),scrollTo(),scrollX[GCE],scrollY[GCE],self[GCE],sessionStorage[GCE],"
1074-
+ "setInterval(),setTimeout(),status[GSCE],stop(),top[GSCE],window[GCE]")
1074+
+ "setInterval(),setTimeout(),status[GSCE],stop(),top[GCE],window[GCE]")
10751075
public void window() throws Exception {
10761076
testString("", "window");
10771077
}

src/test/java/org/htmlunit/javascript/host/Window2Test.java

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3398,4 +3398,104 @@ public void setIntervallProceeds() throws Exception {
33983398
loadPage2(content);
33993399
verifyTitle2(DEFAULT_WAIT_TIME, getWebDriver(), getExpectedAlerts());
34003400
}
3401+
3402+
/**
3403+
* @throws Exception if an error occurs
3404+
*/
3405+
@Test
3406+
@Alerts(DEFAULT = {"true",
3407+
"function get opener() { [native code] }",
3408+
"function set opener() { [native code] }",
3409+
"undefined", "true", "true"},
3410+
FF = {"true",
3411+
"function opener() { [native code] }",
3412+
"function opener() { [native code] }",
3413+
"undefined", "true", "true"},
3414+
FF_ESR = {"true",
3415+
"function opener() { [native code] }",
3416+
"function opener() { [native code] }",
3417+
"undefined", "true", "true"})
3418+
@HtmlUnitNYI(
3419+
CHROME = {"false",
3420+
"function opener() { [native code] }", "function opener() { [native code] }",
3421+
"undefined", "true", "true"},
3422+
EDGE = {"false",
3423+
"function opener() { [native code] }", "function opener() { [native code] }",
3424+
"undefined", "true", "true"},
3425+
FF = {"false",
3426+
"function opener() { [native code] }", "function opener() { [native code] }",
3427+
"undefined", "true", "true"},
3428+
FF_ESR = {"false",
3429+
"function opener() { [native code] }", "function opener() { [native code] }",
3430+
"undefined", "true", "true"})
3431+
public void openerProperty() throws Exception {
3432+
final String html = DOCTYPE_HTML
3433+
+ "<html><body><script>\n"
3434+
+ LOG_TITLE_FUNCTION
3435+
+ " let desc = Object.getOwnPropertyDescriptor(Window.prototype, 'opener');\n"
3436+
+ " log(desc === undefined);\n"
3437+
3438+
+ " desc = Object.getOwnPropertyDescriptor(window, 'opener');\n"
3439+
+ " log(desc.get);\n"
3440+
+ " log(desc.set);\n"
3441+
+ " log(desc.writable);\n"
3442+
+ " log(desc.configurable);\n"
3443+
+ " log(desc.enumerable);\n"
3444+
+ "</script></body></html>";
3445+
3446+
loadPageVerifyTitle2(html);
3447+
}
3448+
3449+
/**
3450+
* @throws Exception if an error occurs
3451+
*/
3452+
@Test
3453+
@Alerts(DEFAULT = {"true", "function get top() { [native code] }", "undefined", "undefined", "false", "true"},
3454+
FF = {"true", "function top() { [native code] }", "undefined", "undefined", "false", "true"},
3455+
FF_ESR = {"true", "function top() { [native code] }", "undefined", "undefined", "false", "true"})
3456+
@HtmlUnitNYI(
3457+
CHROME = {"false", "function top() { [native code] }", "undefined", "undefined", "true", "true"},
3458+
EDGE = {"false", "function top() { [native code] }", "undefined", "undefined", "true", "true"},
3459+
FF = {"false", "function top() { [native code] }", "undefined", "undefined", "true", "true"},
3460+
FF_ESR = {"false", "function top() { [native code] }", "undefined", "undefined", "true", "true"})
3461+
public void topProperty() throws Exception {
3462+
final String html = DOCTYPE_HTML
3463+
+ "<html><body><script>\n"
3464+
+ LOG_TITLE_FUNCTION
3465+
+ " let desc = Object.getOwnPropertyDescriptor(Window.prototype, 'top');\n"
3466+
+ " log(desc === undefined);\n"
3467+
3468+
+ " desc = Object.getOwnPropertyDescriptor(window, 'top');\n"
3469+
+ " log(desc.get);\n"
3470+
+ " log(desc.set);\n"
3471+
+ " log(desc.writable);\n"
3472+
+ " log(desc.configurable);\n"
3473+
+ " log(desc.enumerable);\n"
3474+
+ "</script></body></html>";
3475+
3476+
loadPageVerifyTitle2(html);
3477+
}
3478+
3479+
/**
3480+
* @throws Exception if an error occurs
3481+
*/
3482+
@Test
3483+
@Alerts({"true", "[object Window]", "[object Window]", "[object Window]", "[object Window]"})
3484+
public void overwriteProperty_top() throws Exception {
3485+
final String html = DOCTYPE_HTML
3486+
+ "<html><body><script>\n"
3487+
+ LOG_SESSION_STORAGE_FUNCTION
3488+
+ " log(window.top === this);\n"
3489+
+ " var top = 123;\n"
3490+
+ " log(top);\n"
3491+
+ " log(window.top);\n"
3492+
3493+
+ " window.top = 123;\n"
3494+
+ " log(top);\n"
3495+
+ " log(window.top);\n"
3496+
+ "</script></body></html>";
3497+
3498+
final WebDriver driver = loadPage2(html);
3499+
verifySessionStorage2(driver, getExpectedAlerts());
3500+
}
34013501
}

src/test/java/org/htmlunit/javascript/host/WindowTest.java

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,42 +1349,6 @@ public void showModelessDialog() throws Exception {
13491349
}
13501350
}
13511351

1352-
/**
1353-
* @throws Exception if an error occurs
1354-
*/
1355-
@Test
1356-
@Alerts({"true", "[object Window]", "[object Window]"})
1357-
public void overwriteProperty_top() throws Exception {
1358-
final String html = DOCTYPE_HTML
1359-
+ "<html><body><script>\n"
1360-
+ " alert(window.top == this);\n"
1361-
+ " var top = 123;\n"
1362-
+ " alert(top);\n"
1363-
+ " alert(window.top);\n"
1364-
+ "</script></body></html>";
1365-
// this can't be tested using WebDriver currently (i.e. using loadPageWithAlerts2)
1366-
// because the hack currently used to capture alerts needs reference to property "top".
1367-
loadPageWithAlerts(html);
1368-
}
1369-
1370-
/**
1371-
* @throws Exception if an error occurs
1372-
*/
1373-
@Test
1374-
@Alerts({"true", "[object Window]", "[object Window]"})
1375-
public void overwriteProperty_top2() throws Exception {
1376-
final String html = DOCTYPE_HTML
1377-
+ "<html><body><script>\n"
1378-
+ " alert(window.top == this);\n"
1379-
+ " window.top = 123;\n"
1380-
+ " alert(top);\n"
1381-
+ " alert(window.top);\n"
1382-
+ "</script></body></html>";
1383-
// this can't be tested using WebDriver currently (i.e. using loadPageWithAlerts2)
1384-
// because the hack currently used to capture alerts needs reference to property "top".
1385-
loadPageWithAlerts(html);
1386-
}
1387-
13881352
/**
13891353
* Download of next page is done first after onbeforeunload is done.
13901354
* @throws Exception if an error occurs

0 commit comments

Comments
 (0)