Skip to content

Commit 3d03e03

Browse files
committed
make NativeDate.toLocaleString() behave more like real browsers
1 parent 6689d9d commit 3d03e03

File tree

3 files changed

+10
-42
lines changed

3 files changed

+10
-42
lines changed

src/changes/changes.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
</properties>
88

99
<body>
10-
<release version="5.0.0" date="April 01, 2026" description="jdk17, Bugfixes">
10+
<release version="5.0.0" date="April 31, 2026" description="jdk17, Bugfixes">
11+
<action type="update" dev="Lai Quang Duong">
12+
core-js: Make NativeDate.toLocaleString() behave more like real browsers.
13+
</action>
14+
<action type="update" dev="RhinoTeam">
15+
core-js: Major refactoring to separate top level scope and 'globalThis'.
16+
</action>
1117
<action type="update" dev="rbri">
1218
core-js: Improve 'caller' handling depending on strict mode.
1319
</action>

src/main/java/org/htmlunit/javascript/host/dom/XPathEvaluator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.htmlunit.corejs.javascript.Function;
1919
import org.htmlunit.corejs.javascript.NativeFunction;
2020
import org.htmlunit.corejs.javascript.Scriptable;
21+
import org.htmlunit.corejs.javascript.TopLevel;
2122
import org.htmlunit.html.DomNode;
2223
import org.htmlunit.javascript.HtmlUnitScriptable;
2324
import org.htmlunit.javascript.JavaScriptEngine;
@@ -140,7 +141,8 @@ else if (resolver instanceof NativeFunction nativeFunction) {
140141

141142
try {
142143
final String xpath = JavaScriptEngine.toString(args[0]);
143-
final DomNode doc = ((Window) scope).getDocument().getDocumentElement().getDomNodeOrDie();
144+
final Window window = (Window) ((TopLevel) scope).getGlobalThis();
145+
final DomNode doc = window.getDocument().getDocumentElement().getDomNodeOrDie();
144146
final XPathExpression xPathExpression = new XPathExpression(xpath, prefixResolver, doc);
145147
xPathExpression.setParentScope(evaluator.getParentScope());
146148
xPathExpression.setPrototype(evaluator.getPrototype(xPathExpression.getClass()));

src/test/java/org/htmlunit/javascript/NativeDate2Test.java

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,6 @@ public void ctorDouble() throws Exception {
422422
*/
423423
@Test
424424
@Alerts("12/18/2021, 10:23:00 PM")
425-
@HtmlUnitNYI(CHROME = "12/18/21, 10:23 PM",
426-
EDGE = "12/18/21, 10:23 PM",
427-
FF = "12/18/21, 10:23 PM",
428-
FF_ESR = "12/18/21, 10:23 PM")
429425
public void toLocaleEnUs() throws Exception {
430426
toLocale("new Date('2021-12-18T22:23').toLocaleString('en-US')");
431427
}
@@ -435,10 +431,6 @@ public void toLocaleEnUs() throws Exception {
435431
*/
436432
@Test
437433
@Alerts("12/18/2021")
438-
@HtmlUnitNYI(CHROME = "12/18/21",
439-
EDGE = "12/18/21",
440-
FF = "12/18/21",
441-
FF_ESR = "12/18/21")
442434
public void toLocaleEnUsDate() throws Exception {
443435
toLocale("new Date('2021-12-18T22:23').toLocaleDateString('en-US')");
444436
}
@@ -448,10 +440,6 @@ public void toLocaleEnUsDate() throws Exception {
448440
*/
449441
@Test
450442
@Alerts("10:23:00 PM")
451-
@HtmlUnitNYI(CHROME = "10:23 PM",
452-
EDGE = "10:23 PM",
453-
FF = "10:23 PM",
454-
FF_ESR = "10:23 PM")
455443
public void toLocaleEnUsTime() throws Exception {
456444
toLocale("new Date('2021-12-18T22:23').toLocaleTimeString('en-US')");
457445
}
@@ -461,10 +449,6 @@ public void toLocaleEnUsTime() throws Exception {
461449
*/
462450
@Test
463451
@Alerts("18.12.2021, 22:23:00")
464-
@HtmlUnitNYI(CHROME = "18.12.21, 22:23",
465-
EDGE = "18.12.21, 22:23",
466-
FF = "18.12.21, 22:23",
467-
FF_ESR = "18.12.21, 22:23")
468452
public void toLocaleDeDe() throws Exception {
469453
toLocale("new Date('2021-12-18T22:23').toLocaleString('de-DE')");
470454
}
@@ -474,10 +458,6 @@ public void toLocaleDeDe() throws Exception {
474458
*/
475459
@Test
476460
@Alerts("18.12.2021")
477-
@HtmlUnitNYI(CHROME = "18.12.21",
478-
EDGE = "18.12.21",
479-
FF = "18.12.21",
480-
FF_ESR = "18.12.21")
481461
public void toLocaleDeDeDate() throws Exception {
482462
toLocale("new Date('2021-12-18T22:23').toLocaleDateString('de-DE')");
483463
}
@@ -487,10 +467,6 @@ public void toLocaleDeDeDate() throws Exception {
487467
*/
488468
@Test
489469
@Alerts("22:23:00")
490-
@HtmlUnitNYI(CHROME = "22:23",
491-
EDGE = "22:23",
492-
FF = "22:23",
493-
FF_ESR = "22:23")
494470
public void toLocaleDeDeTime() throws Exception {
495471
toLocale("new Date('2021-12-18T22:23').toLocaleTimeString('de-DE')");
496472
}
@@ -500,10 +476,6 @@ public void toLocaleDeDeTime() throws Exception {
500476
*/
501477
@Test
502478
@Alerts("2021/12/18 22:23:00")
503-
@HtmlUnitNYI(CHROME = "2021/12/18 22:23",
504-
EDGE = "2021/12/18 22:23",
505-
FF = "2021/12/18 22:23",
506-
FF_ESR = "2021/12/18 22:23")
507479
public void toLocaleJaJp() throws Exception {
508480
toLocale("new Date('2021-12-18T22:23').toLocaleString('ja-JP')");
509481
}
@@ -522,10 +494,6 @@ public void toLocaleJaJpDate() throws Exception {
522494
*/
523495
@Test
524496
@Alerts("22:23:00")
525-
@HtmlUnitNYI(CHROME = "22:23",
526-
EDGE = "22:23",
527-
FF = "22:23",
528-
FF_ESR = "22:23")
529497
public void toLocaleJaJpTime() throws Exception {
530498
toLocale("new Date('2021-12-18T22:23').toLocaleTimeString('ja-JP')");
531499
}
@@ -535,10 +503,6 @@ public void toLocaleJaJpTime() throws Exception {
535503
*/
536504
@Test
537505
@Alerts("2021/12/18 22:23:00")
538-
@HtmlUnitNYI(CHROME = "2021/12/18 22:23",
539-
EDGE = "2021/12/18 22:23",
540-
FF = "2021/12/18 22:23",
541-
FF_ESR = "2021/12/18 22:23")
542506
public void toLocaleArray() throws Exception {
543507
toLocale("new Date('2021-12-18T22:23').toLocaleString(['foo', 'ja-JP', 'en-US'])");
544508
}
@@ -557,10 +521,6 @@ public void toLocaleArrayDate() throws Exception {
557521
*/
558522
@Test
559523
@Alerts("22:23:00")
560-
@HtmlUnitNYI(CHROME = "22:23",
561-
EDGE = "22:23",
562-
FF = "22:23",
563-
FF_ESR = "22:23")
564524
public void toLocaleArrayTime() throws Exception {
565525
toLocale("new Date('2021-12-18T22:23').toLocaleTimeString(['foo', 'ja-JP', 'en-US'])");
566526
}

0 commit comments

Comments
 (0)