Skip to content

Commit 7517023

Browse files
committed
[GR-49756] Recent normative changes affecting NumberFormat.
PullRequest: js/2963
2 parents 540b35d + 6efb119 commit 7517023

File tree

7 files changed

+26
-63
lines changed

7 files changed

+26
-63
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ public Object setNumberFormatDigitOptions(JSNumberFormat.BasicInternalState intl
101101
Object mnsdValue = getMinSignificantDigitsOption.getValue(options);
102102
Object mxsdValue = getMaxSignificantDigitsOption.getValue(options);
103103
intlObj.setMinimumIntegerDigits(mnid);
104-
String roundingPriority = getRoundingPriorityOption.executeValue(options);
105104

106105
int roundingIncrement = getRoundingIncrementOption.executeInt(options, 1, 5000, 1);
107106
if (!isValidRoundingIncrement(roundingIncrement)) {
@@ -110,6 +109,7 @@ public Object setNumberFormatDigitOptions(JSNumberFormat.BasicInternalState intl
110109
}
111110

112111
String roundingMode = getRoundingModeOption.executeValue(options);
112+
String roundingPriority = getRoundingPriorityOption.executeValue(options);
113113
String trailingZeroDisplay = getTrailingZeroDisplayOption.executeValue(options);
114114

115115
int mxfdDefault = (roundingIncrement == 1) ? mxfdDefaultParam : mnfdDefault;
@@ -136,8 +136,8 @@ public Object setNumberFormatDigitOptions(JSNumberFormat.BasicInternalState intl
136136
}
137137
if (needFd) {
138138
if (hasFd) {
139-
int mnfd = getMnfdDNO.executeInt(mnfdValue, 0, 20, -1);
140-
int mxfd = getMxfdDNO.executeInt(mxfdValue, 0, 20, -1);
139+
int mnfd = getMnfdDNO.executeInt(mnfdValue, 0, 100, -1);
140+
int mxfd = getMxfdDNO.executeInt(mxfdValue, 0, 100, -1);
141141
if (mnfd == -1) {
142142
mnfd = Math.min(mnfdDefault, mxfd);
143143
} else if (mxfd == -1) {

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ protected Number doLong(long value) {
9898
@TruffleBoundary
9999
@Specialization
100100
protected Number doString(TruffleString value) {
101-
return parseStringNumericLiteral(Strings.toJavaString(value));
101+
return parseStringNumericLiteral(Strings.toJavaString(JSRuntime.trimJSWhiteSpace(value)));
102102
}
103103

104104
@Specialization
@@ -134,12 +134,11 @@ protected Number doGeneric(Object value,
134134
private static final BigDecimal SIXTEEN = BigDecimal.valueOf(16);
135135

136136
private static Number parseStringNumericLiteral(String s) {
137-
String trimmed = s.trim();
138-
if (trimmed.isEmpty()) {
137+
if (s.isEmpty()) {
139138
return BigDecimal.ZERO;
140139
}
141140
try {
142-
Number result = parseStrNumericLiteral(trimmed);
141+
Number result = parseStrNumericLiteral(s);
143142
return (result == null) ? Double.NaN : result;
144143
} catch (ArithmeticException | NumberFormatException ex) {
145144
return Double.NaN;
@@ -281,11 +280,7 @@ private static Number parseStrUnsignedDecimalLiteral(String s) {
281280
if (exponentIndex != -1) {
282281
String exponentPart = s.substring(exponentIndex + 1);
283282
int exponent = parseSignedInteger(exponentPart);
284-
if (exponent > 0) {
285-
result = result.movePointRight(exponent);
286-
} else {
287-
result = result.movePointLeft(exponent);
288-
}
283+
result = result.movePointRight(exponent);
289284
}
290285

291286
return result;

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ private static Number toInternalNumberRepresentation(Object o) {
707707
}
708708
}
709709

710-
public static class BasicInternalState {
710+
public abstract static class BasicInternalState {
711711
private UnlocalizedNumberFormatter unlocalizedFormatter;
712712

713713
private Locale javaLocale;
@@ -730,7 +730,9 @@ JSObject toResolvedOptionsObject(JSContext context, JSRealm realm) {
730730
return resolvedOptions;
731731
}
732732

733-
void fillResolvedOptions(@SuppressWarnings("unused") JSContext context, @SuppressWarnings("unused") JSRealm realm, JSDynamicObject result) {
733+
abstract void fillResolvedOptions(JSContext context, JSRealm realm, JSDynamicObject result);
734+
735+
void fillBasicResolvedOptions(JSDynamicObject result) {
734736
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_MINIMUM_INTEGER_DIGITS, minimumIntegerDigits, JSAttributes.getDefault());
735737
if (minimumFractionDigits != null) {
736738
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_MINIMUM_FRACTION_DIGITS, minimumFractionDigits, JSAttributes.getDefault());
@@ -744,8 +746,15 @@ void fillResolvedOptions(@SuppressWarnings("unused") JSContext context, @Suppres
744746
if (maximumSignificantDigits != null) {
745747
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_MAXIMUM_SIGNIFICANT_DIGITS, maximumSignificantDigits, JSAttributes.getDefault());
746748
}
747-
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_ROUNDING_MODE, Strings.fromJavaString(roundingMode), JSAttributes.getDefault());
749+
}
750+
751+
void fillRoundingResolvedOptions(JSDynamicObject result) {
748752
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_ROUNDING_INCREMENT, roundingIncrement, JSAttributes.getDefault());
753+
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_ROUNDING_MODE, Strings.fromJavaString(roundingMode), JSAttributes.getDefault());
754+
755+
String resolvedRoundingType = (IntlUtil.MORE_PRECISION.equals(roundingType) || IntlUtil.LESS_PRECISION.equals(roundingType)) ? roundingType : IntlUtil.AUTO;
756+
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_ROUNDING_PRIORITY, Strings.fromJavaString(resolvedRoundingType), JSAttributes.getDefault());
757+
749758
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_TRAILING_ZERO_DISPLAY, Strings.fromJavaString(trailingZeroDisplay), JSAttributes.getDefault());
750759
}
751760

@@ -940,7 +949,9 @@ void fillResolvedOptions(JSContext context, JSRealm realm, JSDynamicObject resul
940949
if (unitDisplay != null) {
941950
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_UNIT_DISPLAY, Strings.fromJavaString(unitDisplay), JSAttributes.getDefault());
942951
}
943-
super.fillResolvedOptions(context, realm, result);
952+
953+
fillBasicResolvedOptions(result);
954+
944955
Object resolvedUseGrouping = useGrouping;
945956
if (useGrouping instanceof String && context.getEcmaScriptVersion() < JSConfig.ECMAScript2023) {
946957
resolvedUseGrouping = true;
@@ -953,9 +964,7 @@ void fillResolvedOptions(JSContext context, JSRealm realm, JSDynamicObject resul
953964
}
954965
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_SIGN_DISPLAY, Strings.fromJavaString(signDisplay), JSAttributes.getDefault());
955966

956-
String roundingType = getRoundingType();
957-
String resolvedRoundingType = (IntlUtil.MORE_PRECISION.equals(roundingType) || IntlUtil.LESS_PRECISION.equals(roundingType)) ? roundingType : IntlUtil.AUTO;
958-
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_ROUNDING_PRIORITY, Strings.fromJavaString(resolvedRoundingType), JSAttributes.getDefault());
967+
fillRoundingResolvedOptions(result);
959968
}
960969

961970
@TruffleBoundary

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,9 @@ public static class InternalState extends JSNumberFormat.BasicInternalState {
160160
void fillResolvedOptions(JSContext context, JSRealm realm, JSDynamicObject result) {
161161
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_LOCALE, Strings.fromJavaString(getLocale()), JSAttributes.getDefault());
162162
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_TYPE, Strings.fromJavaString(type), JSAttributes.getDefault());
163-
super.fillResolvedOptions(context, realm, result);
163+
super.fillBasicResolvedOptions(result);
164164
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_PLURAL_CATEGORIES, JSRuntime.createArrayFromList(realm.getContext(), realm, pluralCategories), JSAttributes.getDefault());
165-
String roundingType = getRoundingType();
166-
String resolvedRoundingType = (IntlUtil.MORE_PRECISION.equals(roundingType) || IntlUtil.LESS_PRECISION.equals(roundingType)) ? roundingType : IntlUtil.AUTO;
167-
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_ROUNDING_PRIORITY, Strings.fromJavaString(resolvedRoundingType), JSAttributes.getDefault());
165+
super.fillRoundingResolvedOptions(result);
168166
}
169167

170168
@TruffleBoundary

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
import com.oracle.truffle.js.runtime.builtins.JSFunctionObject;
7171
import com.oracle.truffle.js.runtime.builtins.JSNonProxy;
7272
import com.oracle.truffle.js.runtime.builtins.JSObjectFactory;
73-
import com.oracle.truffle.js.runtime.builtins.JSOrdinary;
7473
import com.oracle.truffle.js.runtime.builtins.PrototypeSupplier;
7574
import com.oracle.truffle.js.runtime.objects.JSAttributes;
7675
import com.oracle.truffle.js.runtime.objects.JSDynamicObject;
@@ -199,13 +198,11 @@ public static class InternalState extends JSNumberFormat.BasicInternalState {
199198
private String numeric;
200199

201200
@Override
202-
JSObject toResolvedOptionsObject(JSContext context, JSRealm realm) {
203-
JSObject result = JSOrdinary.create(context, realm);
201+
void fillResolvedOptions(JSContext context, JSRealm realm, JSDynamicObject result) {
204202
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_LOCALE, Strings.fromJavaString(getLocale()), JSAttributes.getDefault());
205203
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_STYLE, Strings.fromJavaString(style), JSAttributes.getDefault());
206204
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_NUMERIC, Strings.fromJavaString(numeric), JSAttributes.getDefault());
207205
JSObjectUtil.putDataProperty(result, IntlUtil.KEY_NUMBERING_SYSTEM, Strings.fromJavaString(getNumberingSystem()), JSAttributes.getDefault());
208-
return result;
209206
}
210207

211208
@TruffleBoundary

graal-js/test/test262.json

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10524,30 +10524,6 @@
1052410524
"filePath" : "intl402/Locale/prototype/minimize/removing-likely-subtags-first-adds-likely-subtags.js",
1052510525
"status" : "FAIL",
1052610526
"comment" : "new failures 2013-06-28"
10527-
}, {
10528-
"filePath" : "intl402/NumberFormat/constructor-option-read-order.js",
10529-
"status" : "FAIL",
10530-
"comment" : "new failures 2023-10-09"
10531-
}, {
10532-
"filePath" : "intl402/NumberFormat/prototype/resolvedOptions/return-keys-order-default.js",
10533-
"status" : "FAIL",
10534-
"comment" : "new failures 2023-10-09"
10535-
}, {
10536-
"filePath" : "intl402/NumberFormat/throws-for-maximumFractionDigits-over-limit.js",
10537-
"status" : "FAIL",
10538-
"comment" : "new failures 2023-10-09"
10539-
}, {
10540-
"filePath" : "intl402/NumberFormat/throws-for-minimumFractionDigits-over-limit.js",
10541-
"status" : "FAIL",
10542-
"comment" : "new failures 2023-10-09"
10543-
}, {
10544-
"filePath" : "intl402/PluralRules/constructor-option-read-order.js",
10545-
"status" : "FAIL",
10546-
"comment" : "new failures 2023-10-09"
10547-
}, {
10548-
"filePath" : "intl402/PluralRules/prototype/resolvedOptions/return-keys-order-default.js",
10549-
"status" : "FAIL",
10550-
"comment" : "new failures 2023-10-09"
1055110527
}, {
1055210528
"filePath" : "intl402/Temporal/Calendar/calendar-case-insensitive.js",
1055310529
"status" : "FAIL",

graal-js/test/testV8.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,6 @@
210210
"filePath" : "intl/localematcher/bestfit-supplemental-files.js",
211211
"status" : "FAIL",
212212
"comment" : "localeMatcher best fit"
213-
}, {
214-
"filePath" : "intl/number-format/check-digit-ranges.js",
215-
"status" : "FAIL",
216-
"comment" : "new failures 2023-10-09"
217-
}, {
218-
"filePath" : "intl/number-format/format-range-string.js",
219-
"status" : "FAIL",
220-
"comment" : "V8 test update 2022-08-10"
221-
}, {
222-
"filePath" : "intl/number-format/format-string.js",
223-
"status" : "FAIL",
224-
"comment" : "V8 test update 2022-08-10"
225213
}, {
226214
"filePath" : "intl/number-format/resolved-options-order.js",
227215
"status" : "FAIL",

0 commit comments

Comments
 (0)