Skip to content

Commit 9b549da

Browse files
committed
[JSC] Update Intl.DurationFormat#resolvedOptions to the latest spec
https://bugs.webkit.org/show_bug.cgi?id=279940 Reviewed by Yusuke Suzuki. This patch makes the following changes to update `Intl.DurationFormat.prototype.resolvedOptions` to the latest spec: - Does not put `fractionalDigits` when it is `undefined`[1] - Put `numberingSystem` before `style`[2] [1]: tc39/proposal-intl-duration-format#167 [2]: tc39/proposal-intl-duration-format#172 * Source/JavaScriptCore/runtime/IntlDurationFormat.cpp: (JSC::IntlDurationFormat::resolvedOptions const): * JSTests/test262/expectations.yaml: * JSTests/stress/intl-durationformat.js: (test): Canonical link: https://commits.webkit.org/283901@main
1 parent 98862c0 commit 9b549da

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

JSTests/stress/intl-durationformat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ function test() {
168168
shouldThrow(() => df.format(null), TypeError);
169169
shouldThrow(() => df.format(undefined), TypeError);
170170
shouldThrow(() => df.format([null]), TypeError);
171-
shouldBe(JSON.stringify(df.resolvedOptions()), `{"locale":"en","style":"long","years":"long","yearsDisplay":"auto","months":"long","monthsDisplay":"auto","weeks":"long","weeksDisplay":"auto","days":"long","daysDisplay":"auto","hours":"long","hoursDisplay":"auto","minutes":"long","minutesDisplay":"auto","seconds":"long","secondsDisplay":"auto","milliseconds":"long","millisecondsDisplay":"auto","microseconds":"long","microsecondsDisplay":"auto","nanoseconds":"long","nanosecondsDisplay":"auto","numberingSystem":"latn"}`);
171+
shouldBe(JSON.stringify(df.resolvedOptions()), `{"locale":"en","numberingSystem":"latn","style":"long","years":"long","yearsDisplay":"auto","months":"long","monthsDisplay":"auto","weeks":"long","weeksDisplay":"auto","days":"long","daysDisplay":"auto","hours":"long","hoursDisplay":"auto","minutes":"long","minutesDisplay":"auto","seconds":"long","secondsDisplay":"auto","milliseconds":"long","millisecondsDisplay":"auto","microseconds":"long","microsecondsDisplay":"auto","nanoseconds":"long","nanosecondsDisplay":"auto"}`);
172172
shouldBe(JSON.stringify(Reflect.getOwnPropertyDescriptor(Intl.DurationFormat.prototype, Symbol.toStringTag)), `{"value":"Intl.DurationFormat","writable":false,"enumerable":false,"configurable":true}`);
173173
}
174174
{

JSTests/test262/expectations.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,15 +1522,9 @@ test/intl402/DateTimeFormat/timezone-legacy-non-iana.js:
15221522
test/intl402/DateTimeFormat/timezone-not-canonicalized.js:
15231523
default: 'Test262Error: Expected SameValue(«Asia/Calcutta», «Asia/Kolkata») to be true'
15241524
strict mode: 'Test262Error: Expected SameValue(«Asia/Calcutta», «Asia/Kolkata») to be true'
1525-
test/intl402/DurationFormat/constructor-option-read-order.js:
1526-
default: 'Test262Error: Expected [numberingSystem, style, years, yearsDisplay, months, monthsDisplay, weeks, weeksDisplay, days, daysDisplay, hours, hoursDisplay, minutes, minutesDisplay, seconds, secondsDisplay, milliseconds, millisecondsDisplay, microseconds, microsecondsDisplay, nanoseconds, nanosecondsDisplay, fractionalDigits] and [numberingSystem, style, years, yearsDisplay, months, monthsDisplay, weeks, weeksDisplay, days, daysDisplay, hours, hoursDisplay, minutes, minutesDisplay, seconds, secondsDisplay, milliseconds, millisecondsDisplay, microseconds, microsecondsDisplay, nanoseconds, nanosecondsDisplay] to have the same contents. '
1527-
strict mode: 'Test262Error: Expected [numberingSystem, style, years, yearsDisplay, months, monthsDisplay, weeks, weeksDisplay, days, daysDisplay, hours, hoursDisplay, minutes, minutesDisplay, seconds, secondsDisplay, milliseconds, millisecondsDisplay, microseconds, microsecondsDisplay, nanoseconds, nanosecondsDisplay, fractionalDigits] and [numberingSystem, style, years, yearsDisplay, months, monthsDisplay, weeks, weeksDisplay, days, daysDisplay, hours, hoursDisplay, minutes, minutesDisplay, seconds, secondsDisplay, milliseconds, millisecondsDisplay, microseconds, microsecondsDisplay, nanoseconds, nanosecondsDisplay] to have the same contents. '
15281525
test/intl402/DurationFormat/prototype/format/precision-exact-mathematical-values.js:
15291526
default: 'Test262Error: Duration is {"seconds":10000000,"nanoseconds":1} Expected SameValue(«0:00:10,000,000.000000002», «0:00:10,000,000.000000001») to be true'
15301527
strict mode: 'Test262Error: Duration is {"seconds":10000000,"nanoseconds":1} Expected SameValue(«0:00:10,000,000.000000002», «0:00:10,000,000.000000001») to be true'
1531-
test/intl402/DurationFormat/prototype/resolvedOptions/return-keys-order-default.js:
1532-
default: 'Test262Error: Expected [locale, style, years, yearsDisplay, months, monthsDisplay, weeks, weeksDisplay, days, daysDisplay, hours, hoursDisplay, minutes, minutesDisplay, seconds, secondsDisplay, milliseconds, millisecondsDisplay, microseconds, microsecondsDisplay, nanoseconds, nanosecondsDisplay, fractionalDigits, numberingSystem] and [locale, numberingSystem, style, years, yearsDisplay, months, monthsDisplay, weeks, weeksDisplay, days, daysDisplay, hours, hoursDisplay, minutes, minutesDisplay, seconds, secondsDisplay, milliseconds, millisecondsDisplay, microseconds, microsecondsDisplay, nanoseconds, nanosecondsDisplay] to have the same contents. '
1533-
strict mode: 'Test262Error: Expected [locale, style, years, yearsDisplay, months, monthsDisplay, weeks, weeksDisplay, days, daysDisplay, hours, hoursDisplay, minutes, minutesDisplay, seconds, secondsDisplay, milliseconds, millisecondsDisplay, microseconds, microsecondsDisplay, nanoseconds, nanosecondsDisplay, fractionalDigits, numberingSystem] and [locale, numberingSystem, style, years, yearsDisplay, months, monthsDisplay, weeks, weeksDisplay, days, daysDisplay, hours, hoursDisplay, minutes, minutesDisplay, seconds, secondsDisplay, milliseconds, millisecondsDisplay, microseconds, microsecondsDisplay, nanoseconds, nanosecondsDisplay] to have the same contents. '
15341528
test/intl402/Locale/extensions-grandfathered.js:
15351529
default: 'Test262Error: Expected SameValue(«fr-Cyrl-FR-gaulish-u-nu-latn», «fr-Cyrl-FR-u-nu-latn») to be true'
15361530
strict mode: 'Test262Error: Expected SameValue(«fr-Cyrl-FR-gaulish-u-nu-latn», «fr-Cyrl-FR-u-nu-latn») to be true'

Source/JavaScriptCore/runtime/IntlDurationFormat.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ JSObject* IntlDurationFormat::resolvedOptions(JSGlobalObject* globalObject) cons
761761
VM& vm = globalObject->vm();
762762
JSObject* options = constructEmptyObject(globalObject);
763763
options->putDirect(vm, vm.propertyNames->locale, jsString(vm, m_locale));
764+
options->putDirect(vm, vm.propertyNames->numberingSystem, jsString(vm, m_numberingSystem));
764765
options->putDirect(vm, vm.propertyNames->style, jsNontrivialString(vm, styleString(m_style)));
765766

766767
for (unsigned index = 0; index < numberOfTemporalUnits; ++index) {
@@ -770,8 +771,8 @@ JSObject* IntlDurationFormat::resolvedOptions(JSGlobalObject* globalObject) cons
770771
options->putDirect(vm, displayName(vm, unit), jsNontrivialString(vm, displayString(unitData.display())));
771772
}
772773

773-
options->putDirect(vm, vm.propertyNames->fractionalDigits, m_fractionalDigits == fractionalDigitsUndefinedValue ? jsUndefined() : jsNumber(m_fractionalDigits));
774-
options->putDirect(vm, vm.propertyNames->numberingSystem, jsString(vm, m_numberingSystem));
774+
if (m_fractionalDigits != fractionalDigitsUndefinedValue)
775+
options->putDirect(vm, vm.propertyNames->fractionalDigits, jsNumber(m_fractionalDigits));
775776
return options;
776777
}
777778

0 commit comments

Comments
 (0)