Skip to content

Commit c85b105

Browse files
committed
fix toString result for Intl.Collator, Intl.DateTimeFormat, Intl.NumberFormat, and Intl.v8BreakIterator
fix v8BreakIterator ctor to accept langage-region
1 parent bee1587 commit c85b105

8 files changed

Lines changed: 79 additions & 3 deletions

File tree

src/changes/changes.xml

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

99
<body>
1010
<release version="5.0.0" date="April 31, 2026" description="jdk17, Bugfixes">
11+
<action type="fix" dev="rbri">
12+
Fix toString result for Intl.Collator, Intl.DateTimeFormat, Intl.NumberFormat, and Intl.v8BreakIterator.
13+
</action>
14+
<action type="fix" dev="rbri">
15+
Fix v8BreakIterator ctor to accept langage-region.
16+
</action>
1117
<action type="fix" dev="Lai Quang Duong">
1218
Fix DomNode.insertBefore(DomNode) to dissolve DocumentFragment into its children before insertion.
1319
</action>

src/main/java/org/htmlunit/javascript/host/intl/Collator.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,12 @@ public static Scriptable jsConstructor(final Context cx, final Scriptable scope,
7070
format.setPrototype(((FunctionObject) ctorObj).getClassPrototype());
7171
return format;
7272
}
73+
74+
@Override
75+
public Object getDefaultValue(final Class<?> hint) {
76+
if (String.class.equals(hint) || hint == null) {
77+
return "[object Intl.Collator]";
78+
}
79+
return super.getDefaultValue(hint);
80+
}
7381
}

src/main/java/org/htmlunit/javascript/host/intl/DateTimeFormat.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,14 @@ public static Scriptable supportedLocalesOf(final Scriptable localesArgument, fi
324324
return Intl.supportedLocalesOf(localesArgument);
325325
}
326326

327+
@Override
328+
public Object getDefaultValue(final Class<?> hint) {
329+
if (String.class.equals(hint) || hint == null) {
330+
return "[object Intl.DateTimeFormat]";
331+
}
332+
return super.getDefaultValue(hint);
333+
}
334+
327335
/**
328336
* Helper.
329337
*/

src/main/java/org/htmlunit/javascript/host/intl/NumberFormat.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,14 @@ public static Scriptable supportedLocalesOf(final Scriptable localesArgument, fi
228228
return Intl.supportedLocalesOf(localesArgument);
229229
}
230230

231+
@Override
232+
public Object getDefaultValue(final Class<?> hint) {
233+
if (String.class.equals(hint) || hint == null) {
234+
return "[object Intl.NumberFormat]";
235+
}
236+
return super.getDefaultValue(hint);
237+
}
238+
231239
/**
232240
* Helper.
233241
*/

src/main/java/org/htmlunit/javascript/host/intl/V8BreakIterator.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ public static Scriptable jsConstructor(final Context cx, final Scriptable scope,
6363
final Object locales = args[0];
6464
if (locales instanceof NativeArray array) {
6565
if (array.getLength() != 0) {
66-
locale = new Locale.Builder().setLanguage(array.get(0).toString()).build();
66+
locale = new Locale.Builder().setLanguageTag(array.get(0).toString()).build();
6767
}
6868
}
6969
else if (locales instanceof String) {
70-
locale = new Locale.Builder().setLanguage(locales.toString()).build();
70+
locale = new Locale.Builder().setLanguageTag(locales.toString()).build();
7171
}
7272
else if (!JavaScriptEngine.isUndefined(locales)) {
7373
throw JavaScriptEngine.throwAsScriptRuntimeEx(
@@ -108,7 +108,10 @@ else if ("sentence".equals(obj)) {
108108
*/
109109
@Override
110110
public Object getDefaultValue(final Class<?> hint) {
111-
return getClassName();
111+
if (String.class.equals(hint) || hint == null) {
112+
return "[object Object]";
113+
}
114+
return super.getDefaultValue(hint);
112115
}
113116

114117
/**

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4390,6 +4390,17 @@ public void intl_NumberFormat() throws Exception {
43904390
test("Intl.NumberFormat");
43914391
}
43924392

4393+
/**
4394+
* @throws Exception if the test fails
4395+
*/
4396+
@Test
4397+
@Alerts(DEFAULT = "undefined",
4398+
CHROME = "function v8BreakIterator() { [native code] }",
4399+
EDGE = "function v8BreakIterator() { [native code] }")
4400+
public void intl_v8BreakIterator() throws Exception {
4401+
test("Intl.v8BreakIterator");
4402+
}
4403+
43934404
/**
43944405
* @throws Exception if the test fails
43954406
*/

src/test/java/org/htmlunit/javascript/host/intl/IntlTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import org.htmlunit.WebDriverTestCase;
1818
import org.htmlunit.junit.annotation.Alerts;
19+
import org.htmlunit.junit.annotation.HtmlUnitNYI;
1920
import org.junit.jupiter.api.Test;
2021

2122
/**
@@ -93,6 +94,11 @@ public void locale() throws Exception {
9394
@Alerts({"de",
9495
"function Locale() { [native code] }",
9596
"TypeError"})
97+
@HtmlUnitNYI(
98+
CHROME = {"de", "function Locale() { [native code] }", "[object Locale]"},
99+
EDGE = {"de", "function Locale() { [native code] }", "[object Locale]"},
100+
FF = {"de", "function Locale() { [native code] }", "[object Locale]"},
101+
FF_ESR = {"de", "function Locale() { [native code] }", "[object Locale]"})
96102
public void localeCtor() throws Exception {
97103
testCtor("new Intl.Locale('de')");
98104
}

src/test/java/org/htmlunit/javascript/host/intl/V8BreakIteratorTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,32 @@ public void v8BreakIterator() throws Exception {
5959
loadPageVerifyTitle2(html);
6060
}
6161

62+
/**
63+
* @throws Exception if the test fails
64+
*/
65+
@Test
66+
@Alerts(DEFAULT = "no support",
67+
CHROME = "true",
68+
EDGE = "true")
69+
public void v8BreakIterator2() throws Exception {
70+
final String html = DOCTYPE_HTML
71+
+ "<html><head>\n"
72+
+ "<script>\n"
73+
+ LOG_TITLE_FUNCTION
74+
+ " function test() {\n"
75+
+ " if (window.Intl && window.Intl.v8BreakIterator) {\n"
76+
+ " var iterator = Intl.v8BreakIterator('de-DE');\n"
77+
+ " log(iterator instanceof Intl.v8BreakIterator);\n"
78+
+ " } else { log('no support'); }\n"
79+
+ " }\n"
80+
+ "</script>\n"
81+
+ "</head>\n"
82+
+ "<body onload='test()'>\n"
83+
+ "</body></html>";
84+
85+
loadPageVerifyTitle2(html);
86+
}
87+
6288
/**
6389
* @throws Exception if the test fails
6490
*/

0 commit comments

Comments
 (0)