Skip to content

Commit 5d379b1

Browse files
committed
[GR-65312] Support for 'notation' option in Intl.PluralRules.
PullRequest: js/3522
2 parents 8dfdeac + dbc2097 commit 5d379b1

File tree

6 files changed

+64
-35
lines changed

6 files changed

+64
-35
lines changed

graal-js/mx.graal-js/mx_graal_js.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
TEST262_REPO = "https://" + "github.com/tc39/test262.git"
5454

5555
# Git revision of Test262 to checkout
56-
TEST262_REV = "93d63969bccbf8b4471b7c7fadc875099b7668d3"
56+
TEST262_REV = "3316c0aaf676d657f5a6b33364fa7e579c78ac7f"
5757

5858
# Git repository of V8
5959
TESTV8_REPO = "https://" + "github.com/v8/v8.git"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
6+
*/
7+
8+
/**
9+
* Checks that Intl.PluralRules.prototype.selectRange respects the value of notation option.
10+
*/
11+
12+
load('../assert.js');
13+
14+
assertSame('one', new Intl.PluralRules('ru', { notation: 'standard' }).selectRange(1, 1000001));
15+
assertSame('many', new Intl.PluralRules('ru', { notation: 'compact' }).selectRange(1, 1000001));

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/intl/InitializePluralRulesNode.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -58,6 +58,7 @@
5858
public abstract class InitializePluralRulesNode extends JavaScriptBaseNode {
5959

6060
private static final List<String> TYPE_OPTION_VALUES = List.of(IntlUtil.CARDINAL, IntlUtil.ORDINAL);
61+
private static final List<String> NOTATION_OPTION_VALUES = List.of(IntlUtil.STANDARD, IntlUtil.SCIENTIFIC, IntlUtil.ENGINEERING, IntlUtil.COMPACT);
6162

6263
private final JSContext context;
6364

@@ -69,6 +70,7 @@ public abstract class InitializePluralRulesNode extends JavaScriptBaseNode {
6970
@Child SetNumberFormatDigitOptionsNode setNumberFormatDigitOptions;
7071

7172
@Child GetStringOptionNode getTypeOption;
73+
@Child GetStringOptionNode getNotationOption;
7274
private final BranchProfile errorBranch = BranchProfile.create();
7375

7476
protected InitializePluralRulesNode(JSContext context) {
@@ -77,6 +79,7 @@ protected InitializePluralRulesNode(JSContext context) {
7779
this.coerceOptionsToObjectNode = CoerceOptionsToObjectNodeGen.create(context);
7880
this.getLocaleMatcherOption = GetStringOptionNode.create(context, IntlUtil.KEY_LOCALE_MATCHER, GetStringOptionNode.LOCALE_MATCHER_OPTION_VALUES, IntlUtil.BEST_FIT);
7981
this.getTypeOption = GetStringOptionNode.create(context, IntlUtil.KEY_TYPE, TYPE_OPTION_VALUES, IntlUtil.CARDINAL);
82+
this.getNotationOption = GetStringOptionNode.create(context, IntlUtil.KEY_NOTATION, NOTATION_OPTION_VALUES, IntlUtil.STANDARD);
8083
this.setNumberFormatDigitOptions = SetNumberFormatDigitOptionsNode.create(context);
8184
}
8285

@@ -98,9 +101,11 @@ public JSPluralRulesObject initializePluralRules(JSPluralRulesObject pluralRules
98101

99102
getLocaleMatcherOption.executeValue(options);
100103
String optType = getTypeOption.executeValue(options);
101-
102104
state.setType(optType);
103105

106+
String notation = getNotationOption.executeValue(options);
107+
state.setNotation(notation);
108+
104109
state.resolveLocaleAndNumberingSystem(context, locales, null);
105110
setNumberFormatDigitOptions.execute(state, options, 0, 3, false);
106111

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/runtime/builtins/intl/JSNumberFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private static JSNumberFormatObject create(JSObjectFactory factory, JSRealm real
199199
return factory.trackAllocation(newObj);
200200
}
201201

202-
private static Notation notationToICUNotation(String notation, String compactDisplay) {
202+
static Notation notationToICUNotation(String notation, String compactDisplay) {
203203
Notation icuNotation;
204204
switch (notation) {
205205
case IntlUtil.STANDARD:

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/runtime/builtins/intl/JSPluralRules.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -49,6 +49,7 @@
4949
import org.graalvm.shadowed.com.ibm.icu.number.LocalizedNumberFormatter;
5050
import org.graalvm.shadowed.com.ibm.icu.number.LocalizedNumberRangeFormatter;
5151
import org.graalvm.shadowed.com.ibm.icu.number.NumberRangeFormatter;
52+
import org.graalvm.shadowed.com.ibm.icu.number.UnlocalizedNumberFormatter;
5253
import org.graalvm.shadowed.com.ibm.icu.text.PluralRules;
5354
import org.graalvm.shadowed.com.ibm.icu.text.PluralRules.PluralType;
5455

@@ -150,13 +151,15 @@ public static class InternalState extends JSNumberFormat.BasicInternalState {
150151
private LocalizedNumberRangeFormatter numberRangeFormatter;
151152

152153
private String type;
154+
private String notation;
153155
private PluralRules pluralRules;
154156
private final List<TruffleString> pluralCategories = new LinkedList<>();
155157

156158
@Override
157159
void fillResolvedOptions(JSContext context, JSRealm realm, JSDynamicObject result) {
158160
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_LOCALE, Strings.fromJavaString(getLocale()), JSAttributes.getDefault());
159161
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_TYPE, Strings.fromJavaString(type), JSAttributes.getDefault());
162+
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_NOTATION, Strings.fromJavaString(notation), JSAttributes.getDefault());
160163
super.fillBasicResolvedOptions(result);
161164
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_PLURAL_CATEGORIES, JSRuntime.createArrayFromList(realm.getContext(), realm, pluralCategories), JSAttributes.getDefault());
162165
super.fillRoundingResolvedOptions(result);
@@ -177,8 +180,10 @@ public void initializePluralRules() {
177180
@TruffleBoundary
178181
public void initializeNumberFormatter() {
179182
super.initializeNumberFormatter();
180-
numberFormatter = getUnlocalizedFormatter().locale(getJavaLocale());
181-
numberRangeFormatter = NumberRangeFormatter.withLocale(getJavaLocale()).numberFormatterBoth(getUnlocalizedFormatter());
183+
UnlocalizedNumberFormatter formatter = getUnlocalizedFormatter();
184+
formatter = formatter.notation(JSNumberFormat.notationToICUNotation(notation, IntlUtil.LONG));
185+
numberFormatter = formatter.locale(getJavaLocale());
186+
numberRangeFormatter = NumberRangeFormatter.withLocale(getJavaLocale()).numberFormatterBoth(formatter);
182187
}
183188

184189
public PluralRules getPluralRules() {
@@ -196,6 +201,10 @@ public LocalizedNumberRangeFormatter getNumberRangeFormatter() {
196201
public void setType(String type) {
197202
this.type = type;
198203
}
204+
205+
public void setNotation(String notation) {
206+
this.notation = notation;
207+
}
199208
}
200209

201210
@TruffleBoundary

graal-js/test/test262.json

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,10 +2043,6 @@
20432043
"filePath" : "intl402/DateTimeFormat/prototype/format/numbering-system.js",
20442044
"status" : "FAIL",
20452045
"comment" : "Problematic test - expects AM suffix with a plain (not narrow) space, see https://github.com/tc39/test262/pull/4276#issuecomment-2544146574"
2046-
}, {
2047-
"filePath" : "intl402/DateTimeFormat/prototype/format/temporal-objects-formatting.js",
2048-
"status" : "FAIL",
2049-
"comment" : "new failures 2025-05-08"
20502046
}, {
20512047
"filePath" : "intl402/DateTimeFormat/prototype/format/temporal-objects-not-overlapping-options.js",
20522048
"status" : "FAIL",
@@ -2055,6 +2051,26 @@
20552051
"filePath" : "intl402/DateTimeFormat/prototype/format/temporal-objects-resolved-time-zone.js",
20562052
"status" : "FAIL",
20572053
"comment" : "Temporal failures"
2054+
}, {
2055+
"filePath" : "intl402/DateTimeFormat/prototype/format/temporal-plaindate-formatting-datetime-style.js",
2056+
"status" : "FAIL",
2057+
"comment" : "new failures 2025-05-25"
2058+
}, {
2059+
"filePath" : "intl402/DateTimeFormat/prototype/format/temporal-plaindatetime-formatting-datetime-style.js",
2060+
"status" : "FAIL",
2061+
"comment" : "new failures 2025-05-25"
2062+
}, {
2063+
"filePath" : "intl402/DateTimeFormat/prototype/format/temporal-plainmonthday-formatting-datetime-style.js",
2064+
"status" : "FAIL",
2065+
"comment" : "new failures 2025-05-25"
2066+
}, {
2067+
"filePath" : "intl402/DateTimeFormat/prototype/format/temporal-plaintime-formatting-datetime-style.js",
2068+
"status" : "FAIL",
2069+
"comment" : "new failures 2025-05-25"
2070+
}, {
2071+
"filePath" : "intl402/DateTimeFormat/prototype/format/temporal-plainyearmonth-formatting-datetime-style.js",
2072+
"status" : "FAIL",
2073+
"comment" : "new failures 2025-05-25"
20582074
}, {
20592075
"filePath" : "intl402/DateTimeFormat/prototype/formatRange/temporal-objects-not-overlapping-options.js",
20602076
"status" : "FAIL",
@@ -2123,6 +2139,14 @@
21232139
"COMPILE_IMMEDIATELY" : "SKIP"
21242140
},
21252141
"comment" : "Long-running in compile mode"
2142+
}, {
2143+
"filePath" : "intl402/PluralRules/prototype/constructor/notation.js",
2144+
"status" : "FAIL",
2145+
"comment" : "Incorrect test, compares strings and string objects using ==="
2146+
}, {
2147+
"filePath" : "intl402/PluralRules/prototype/select/notation.js",
2148+
"status" : "FAIL",
2149+
"comment" : "Expects suspicious results for 'sl' locale (not matching ICU results)"
21262150
}, {
21272151
"filePath" : "intl402/Temporal/Duration/prototype/round/relativeto-infinity-throws-rangeerror.js",
21282152
"status" : "FAIL",
@@ -2255,10 +2279,6 @@
22552279
"filePath" : "intl402/Temporal/PlainDate/prototype/until/until-across-lunisolar-leap-months.js",
22562280
"status" : "FAIL",
22572281
"comment" : "new failures 2024-08-09"
2258-
}, {
2259-
"filePath" : "intl402/Temporal/PlainDate/prototype/weekOfYear/gregory-iso-weekofyear.js",
2260-
"status" : "FAIL",
2261-
"comment" : "new failures 2024-03-15"
22622282
}, {
22632283
"filePath" : "intl402/Temporal/PlainDate/prototype/weekOfYear/non-iso-week-of-year.js",
22642284
"status" : "FAIL",
@@ -2283,10 +2303,6 @@
22832303
"filePath" : "intl402/Temporal/PlainDate/prototype/withCalendar/canonicalize-calendar.js",
22842304
"status" : "FAIL",
22852305
"comment" : "new failures 2024-08-09"
2286-
}, {
2287-
"filePath" : "intl402/Temporal/PlainDate/prototype/yearOfWeek/gregory-iso-weekofyear.js",
2288-
"status" : "FAIL",
2289-
"comment" : "new failures 2024-03-15"
22902306
}, {
22912307
"filePath" : "intl402/Temporal/PlainDate/prototype/yearOfWeek/non-iso-week-of-year.js",
22922308
"status" : "FAIL",
@@ -2387,10 +2403,6 @@
23872403
"filePath" : "intl402/Temporal/PlainDateTime/prototype/until/infinity-throws-rangeerror.js",
23882404
"status" : "FAIL",
23892405
"comment" : "Temporal failures"
2390-
}, {
2391-
"filePath" : "intl402/Temporal/PlainDateTime/prototype/weekOfYear/gregory-iso-weekofyear.js",
2392-
"status" : "FAIL",
2393-
"comment" : "new failures 2024-03-15"
23942406
}, {
23952407
"filePath" : "intl402/Temporal/PlainDateTime/prototype/weekOfYear/non-iso-week-of-year.js",
23962408
"status" : "FAIL",
@@ -2403,10 +2415,6 @@
24032415
"filePath" : "intl402/Temporal/PlainDateTime/prototype/withCalendar/canonicalize-calendar.js",
24042416
"status" : "FAIL",
24052417
"comment" : "new failures 2024-08-09"
2406-
}, {
2407-
"filePath" : "intl402/Temporal/PlainDateTime/prototype/yearOfWeek/gregory-iso-weekofyear.js",
2408-
"status" : "FAIL",
2409-
"comment" : "new failures 2024-03-15"
24102418
}, {
24112419
"filePath" : "intl402/Temporal/PlainDateTime/prototype/yearOfWeek/non-iso-week-of-year.js",
24122420
"status" : "FAIL",
@@ -2799,10 +2807,6 @@
27992807
"filePath" : "intl402/Temporal/ZonedDateTime/prototype/until/infinity-throws-rangeerror.js",
28002808
"status" : "FAIL",
28012809
"comment" : "Temporal failures"
2802-
}, {
2803-
"filePath" : "intl402/Temporal/ZonedDateTime/prototype/weekOfYear/gregory-iso-weekofyear.js",
2804-
"status" : "FAIL",
2805-
"comment" : "new failures 2024-03-15"
28062810
}, {
28072811
"filePath" : "intl402/Temporal/ZonedDateTime/prototype/weekOfYear/non-iso-week-of-year.js",
28082812
"status" : "FAIL",
@@ -2819,10 +2823,6 @@
28192823
"filePath" : "intl402/Temporal/ZonedDateTime/prototype/withPlainTime/dst-skipped-cross-midnight.js",
28202824
"status" : "FAIL",
28212825
"comment" : "new failures 2024-10-16"
2822-
}, {
2823-
"filePath" : "intl402/Temporal/ZonedDateTime/prototype/yearOfWeek/gregory-iso-weekofyear.js",
2824-
"status" : "FAIL",
2825-
"comment" : "new failures 2024-03-15"
28262826
}, {
28272827
"filePath" : "intl402/Temporal/ZonedDateTime/prototype/yearOfWeek/non-iso-week-of-year.js",
28282828
"status" : "FAIL",

0 commit comments

Comments
 (0)