Skip to content

Commit 5036ac6

Browse files
committed
Intl: fix toStringSymbol for Intl, Collator, DateTimeFormat, Locale, and NumberFormat
1 parent e158a67 commit 5036ac6

7 files changed

Lines changed: 73 additions & 0 deletions

File tree

src/changes/changes.xml

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

99
<body>
1010
<release version="5.0.0" date="April 01, 2026" description="jdk17, Bugfixes">
11+
<action type="fix" dev="rbri">
12+
Intl: fix toStringSymbol for Intl, Collator, DateTimeFormat, Locale, and NumberFormat.
13+
</action>
1114
<action type="add" dev="Lai Quang Duong">
1215
Intl: supportedLocalesOf() implementation added to DateTimeFormat and NumberFormat.
1316
</action>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.htmlunit.javascript.JavaScriptEngine;
2424
import org.htmlunit.javascript.configuration.JsxClass;
2525
import org.htmlunit.javascript.configuration.JsxConstructor;
26+
import org.htmlunit.javascript.configuration.JsxSymbolConstant;
2627

2728
/**
2829
* A JavaScript object for Intl.Collator.
@@ -32,6 +33,10 @@
3233
@JsxClass
3334
public class Collator extends HtmlUnitScriptable {
3435

36+
/** Symbol.toStringTag support. */
37+
@JsxSymbolConstant
38+
public static final String TO_STRING_TAG = "Intl.Collator";
39+
3540
/**
3641
* JavaScript constructor.
3742
* @param cx the current context

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.htmlunit.javascript.configuration.JsxConstructor;
3939
import org.htmlunit.javascript.configuration.JsxFunction;
4040
import org.htmlunit.javascript.configuration.JsxStaticFunction;
41+
import org.htmlunit.javascript.configuration.JsxSymbolConstant;
4142
import org.htmlunit.javascript.host.Window;
4243
import org.htmlunit.util.StringUtils;
4344

@@ -51,6 +52,10 @@
5152
@JsxClass
5253
public class DateTimeFormat extends HtmlUnitScriptable {
5354

55+
/** Symbol.toStringTag support. */
56+
@JsxSymbolConstant
57+
public static final String TO_STRING_TAG = "Intl.DateTimeFormat";
58+
5459
private static final ConcurrentHashMap<String, String> CHROME_FORMATS_ = new ConcurrentHashMap<>();
5560
private static final ConcurrentHashMap<String, String> EDGE_FORMATS_ = new ConcurrentHashMap<>();
5661
private static final ConcurrentHashMap<String, String> FF_FORMATS_ = new ConcurrentHashMap<>();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.htmlunit.corejs.javascript.NativeArray;
3333
import org.htmlunit.corejs.javascript.Scriptable;
3434
import org.htmlunit.corejs.javascript.ScriptableObject;
35+
import org.htmlunit.corejs.javascript.SymbolKey;
3536
import org.htmlunit.corejs.javascript.TopLevel;
3637
import org.htmlunit.javascript.HtmlUnitScriptable;
3738
import org.htmlunit.javascript.JavaScriptEngine;
@@ -59,6 +60,7 @@ public static void init(final Scriptable scope, final ScriptableObject globalThi
5960
final BrowserVersion browserVersion) {
6061
final Intl intl = new Intl();
6162
intl.setParentScope(scope);
63+
intl.defineProperty(SymbolKey.TO_STRING_TAG, "Intl", ScriptableObject.DONTENUM | ScriptableObject.READONLY);
6264
intl.defineProperties(scope, browserVersion);
6365

6466
// Configure static functions (getCanonicalLocales)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.htmlunit.javascript.configuration.JsxConstructor;
3030
import org.htmlunit.javascript.configuration.JsxFunction;
3131
import org.htmlunit.javascript.configuration.JsxGetter;
32+
import org.htmlunit.javascript.configuration.JsxSymbolConstant;
3233

3334
/**
3435
* A JavaScript object for Intl.Locale.
@@ -38,6 +39,10 @@
3839
@JsxClass
3940
public class Locale extends HtmlUnitScriptable {
4041

42+
/** Symbol.toStringTag support. */
43+
@JsxSymbolConstant
44+
public static final String TO_STRING_TAG = "Intl.Locale";
45+
4146
private static final List<String> ALLOWED_HOUR_CYCLES = List.of("h11", "h12", "h23", "h24");
4247
private static final List<String> ALLOWED_CASE_FIRSTS = List.of("upper", "lower", "false");
4348

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.htmlunit.javascript.configuration.JsxConstructor;
3434
import org.htmlunit.javascript.configuration.JsxFunction;
3535
import org.htmlunit.javascript.configuration.JsxStaticFunction;
36+
import org.htmlunit.javascript.configuration.JsxSymbolConstant;
3637
import org.htmlunit.javascript.host.Window;
3738
import org.htmlunit.util.StringUtils;
3839

@@ -46,6 +47,10 @@
4647
@JsxClass
4748
public class NumberFormat extends HtmlUnitScriptable {
4849

50+
/** Symbol.toStringTag support. */
51+
@JsxSymbolConstant
52+
public static final String TO_STRING_TAG = "Intl.NumberFormat";
53+
4954
private static final ConcurrentHashMap<String, String> CHROME_FORMATS_ = new ConcurrentHashMap<>();
5055
private static final ConcurrentHashMap<String, String> EDGE_FORMATS_ = new ConcurrentHashMap<>();
5156
private static final ConcurrentHashMap<String, String> FF_FORMATS_ = new ConcurrentHashMap<>();

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3463,4 +3463,52 @@ public void notification() throws Exception {
34633463
public void console() throws Exception {
34643464
testInstanceString("", "console");
34653465
}
3466+
3467+
/**
3468+
* @throws Exception if the test fails
3469+
*/
3470+
@Test
3471+
@Alerts(CHROME = "Symbol(Symbol.toStringTag) [C] [Intl]",
3472+
EDGE = "Symbol(Symbol.toStringTag) [C] [Intl]",
3473+
FF = "Symbol(Symbol.toStringTag) [C] [Intl]",
3474+
FF_ESR = "Symbol(Symbol.toStringTag) [C] [Intl]")
3475+
public void intl() throws Exception {
3476+
testString("", "Intl", false);
3477+
}
3478+
3479+
/**
3480+
* @throws Exception if the test fails
3481+
*/
3482+
@Test
3483+
@Alerts(CHROME = "Symbol(Symbol.toStringTag) [C] [Intl.Collator]",
3484+
EDGE = "Symbol(Symbol.toStringTag) [C] [Intl.Collator]",
3485+
FF = "Symbol(Symbol.toStringTag) [C] [Intl.Collator]",
3486+
FF_ESR = "Symbol(Symbol.toStringTag) [C] [Intl.Collator]")
3487+
public void intl_Collator() throws Exception {
3488+
testString("", "new Intl.Collator('de')");
3489+
}
3490+
3491+
/**
3492+
* @throws Exception if the test fails
3493+
*/
3494+
@Test
3495+
@Alerts(CHROME = "Symbol(Symbol.toStringTag) [C] [Intl.DateTimeFormat]",
3496+
EDGE = "Symbol(Symbol.toStringTag) [C] [Intl.DateTimeFormat]",
3497+
FF = "Symbol(Symbol.toStringTag) [C] [Intl.DateTimeFormat]",
3498+
FF_ESR = "Symbol(Symbol.toStringTag) [C] [Intl.DateTimeFormat]")
3499+
public void intl_DateTimeFormat() throws Exception {
3500+
testString("", "new Intl.DateTimeFormat('en-US')");
3501+
}
3502+
3503+
/**
3504+
* @throws Exception if the test fails
3505+
*/
3506+
@Test
3507+
@Alerts(CHROME = "Symbol(Symbol.toStringTag) [C] [Intl.NumberFormat]",
3508+
EDGE = "Symbol(Symbol.toStringTag) [C] [Intl.NumberFormat]",
3509+
FF = "Symbol(Symbol.toStringTag) [C] [Intl.NumberFormat]",
3510+
FF_ESR = "Symbol(Symbol.toStringTag) [C] [Intl.NumberFormat]")
3511+
public void intl_NumberFormat() throws Exception {
3512+
testString("", "new Intl.NumberFormat('de-DE')");
3513+
}
34663514
}

0 commit comments

Comments
 (0)