-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JSC] Implement Intl.DurationFormat #4589
[JSC] Implement Intl.DurationFormat #4589
Conversation
EWS run on previous version of this PR (hash fab2b91) |
fab2b91
to
fc3ee47
Compare
EWS run on previous version of this PR (hash fc3ee47) |
fc3ee47
to
cfea900
Compare
EWS run on previous version of this PR (hash cfea900) |
cfea900
to
8515478
Compare
EWS run on previous version of this PR (hash 8515478) |
8515478
to
5407f68
Compare
EWS run on previous version of this PR (hash 5407f68) |
5407f68
to
3c368e2
Compare
EWS run on previous version of this PR (hash 3c368e2) |
3c368e2
to
d2703af
Compare
EWS run on previous version of this PR (hash d2703af) |
d2703af
to
4b4a4e0
Compare
EWS run on previous version of this PR (hash 4b4a4e0) |
4b4a4e0
to
6f72813
Compare
EWS run on previous version of this PR (hash 6f72813) |
6f72813
to
9b7d100
Compare
EWS run on previous version of this PR (hash 9b7d100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me with comments
class UnitData { | ||
public: | ||
UnitData() = default; | ||
UnitData(UnitStyle style, Display display) | ||
: m_style(style) | ||
, m_display(display) | ||
{ | ||
} | ||
|
||
UnitStyle style() const { return m_style; } | ||
Display display() const { return m_display; } | ||
|
||
private: | ||
UnitStyle m_style : 7 { UnitStyle::Long }; | ||
Display m_display : 1 { Display::Always }; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just a struct?
class UnitData { | |
public: | |
UnitData() = default; | |
UnitData(UnitStyle style, Display display) | |
: m_style(style) | |
, m_display(display) | |
{ | |
} | |
UnitStyle style() const { return m_style; } | |
Display display() const { return m_display; } | |
private: | |
UnitStyle m_style : 7 { UnitStyle::Long }; | |
Display m_display : 1 { Display::Always }; | |
}; | |
struct UnitData { | |
UnitStyle style : 7 { UnitStyle::Long }; | |
Display display : 1 { Display::Always }; | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine. Changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, it causes some compile error.
/Users/yusukesuzuki/dev/OpenSource/Source/JavaScriptCore/runtime/IntlDurationFormat.cpp:237:25: error: non-const reference cannot bind to bit-field 'm_style'
prevStyle = unitData.m_style;
I'll just use the current class.
// 1. Let availableLocales be %DurationFormat%.[[availableLocales]]. | ||
const auto& availableLocales = intlDurationFormatAvailableLocales(); | ||
|
||
// 2. Let requestedLocales be CanonicalizeLocaleList(locales). | ||
Vector<String> requestedLocales = canonicalizeLocaleList(globalObject, callFrame->argument(0)); | ||
RETURN_IF_EXCEPTION(scope, encodedJSValue()); | ||
|
||
// 3. Return SupportedLocales(availableLocales, requestedLocales, options). | ||
RELEASE_AND_RETURN(scope, JSValue::encode(supportedLocales(globalObject, availableLocales, requestedLocales, callFrame->argument(1)))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm not really sure the step-by-step comments are helping in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is currently aligned to the rest of Intl code.
IntlDurationFormat::UnitStyle style = styleValue.value_or(IntlDurationFormat::UnitStyle::Long); | ||
if (!styleValue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems weird to use value_or
if we're guaranteed not to use the default value.
IntlDurationFormat::UnitStyle style = styleValue.value_or(IntlDurationFormat::UnitStyle::Long); | |
if (!styleValue) { | |
IntlDurationFormat::UnitStyle style; | |
if (styleValue) | |
style = styleValue.value(); | |
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
#if HAVE(ICU_U_LIST_FORMATTER) | ||
if (Options::useIntlDurationFormat()) | ||
putDirectWithoutTransition(vm, vm.propertyNames->DurationFormat, createDurationFormatConstructor(vm, this), static_cast<unsigned>(PropertyAttribute::DontEnum)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems inconsistent that we're using #if HAVE(ICU_U_LIST_FORMATTER)
to guard both specific places in the implementation and Intl.DurationFormat
's whole existence.
I guess ListFormat is similar, but I think it's weird to design errors that can never be thrown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is just for reducing compile time errors. We do not want to scatter this ifdefs outside of IntlDurationFormat.cpp as much as possible. So we confine them in that cpp file and this place by doing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess what I was thinking is that you could #if the whole IntlDurationFormat implementation instead of specific parts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes LUT table generation etc. hard to maintain on non-build platforms (and we need to put ifdefs in IntlDurationPrototype.cpp etc. too), so, this is avoiding that.
} | ||
|
||
#if HAVE(ICU_U_LIST_FORMATTER) | ||
class ListFormatInput { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not share this with IntlListFormat
? It seems the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merged.
9b7d100
to
e71a4f8
Compare
EWS run on current version of this PR (hash e71a4f8) |
EWS run on current version of this PR (hash e71a4f8) |
The failure is unrelated flaky test |
https://bugs.webkit.org/show_bug.cgi?id=214794 <rdar://66436701> Reviewed by Ross Kirsling. This patch implements Intl.DurationFormat[1], which is now stage-3 feature. It is decoupled from Temporal now: it can take an object with `hours` etc. properties, and generate formatted string for duration. In the future, it will accept Temporal.Duration too. 1. We add new microsecond and nanosecond units because they are necessary to DurationFormat[2]. 2. Implement Intl.DurationFormat with UNumberFormatter and UListFormatter. [1]: https://github.com/tc39/proposal-intl-duration-format [2]: tc39/ecma402#708 * JSTests/stress/intl-durationformat-basic.js: Added. (shouldBe): (shouldBeOneOf): (shouldBeForICUVersion): (shouldNotThrow): (shouldThrow): * JSTests/stress/intl-durationformat-digital.js: Added. (shouldBe): (throw.new.Error): * JSTests/stress/intl-durationformat-format-to-parts.js: Added. (shouldBe): (shouldBeOneOf): (shouldBeForICUVersion): (shouldNotThrow): (shouldThrow): (throw.new.Error): * JSTests/stress/intl-durationformat.js: Added. (shouldBe): (shouldNotThrow): (shouldThrow): (test.DerivedDurationFormat): (test.get shouldThrow): (test): * JSTests/stress/intl-enumeration.js: * JSTests/test262/config.yaml: * JSTests/test262/expectations.yaml: * Source/JavaScriptCore/CMakeLists.txt: * Source/JavaScriptCore/DerivedSources-input.xcfilelist: * Source/JavaScriptCore/DerivedSources-output.xcfilelist: * Source/JavaScriptCore/DerivedSources.make: * Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj: * Source/JavaScriptCore/Sources.txt: * Source/JavaScriptCore/heap/Heap.cpp: (JSC::Heap::Heap): * Source/JavaScriptCore/heap/Heap.h: * Source/JavaScriptCore/heap/HeapSubspaceTypes.h: * Source/JavaScriptCore/runtime/CommonIdentifiers.h: * Source/JavaScriptCore/runtime/IntlDurationFormat.cpp: Added. (JSC::IntlDurationFormat::create): (JSC::IntlDurationFormat::createStructure): (JSC::IntlDurationFormat::IntlDurationFormat): (JSC::IntlDurationFormat::finishCreation): (JSC::intlDurationUnitOptions): (JSC::displayName): (JSC::IntlDurationFormat::initializeDurationFormat): (JSC::ListFormatInput::ListFormatInput): (JSC::ListFormatInput::size const): (JSC::ListFormatInput::stringPointers const): (JSC::ListFormatInput::stringLengths const): (JSC::retrieveSeparator): (JSC::collectElements): (JSC::IntlDurationFormat::format const): (JSC::IntlDurationFormat::formatToParts const): (JSC::IntlDurationFormat::resolvedOptions const): (JSC::IntlDurationFormat::styleString): (JSC::IntlDurationFormat::unitStyleString): (JSC::IntlDurationFormat::displayString): * Source/JavaScriptCore/runtime/IntlDurationFormat.h: Added. * Source/JavaScriptCore/runtime/IntlDurationFormatConstructor.cpp: Added. (JSC::IntlDurationFormatConstructor::create): (JSC::IntlDurationFormatConstructor::createStructure): (JSC::IntlDurationFormatConstructor::IntlDurationFormatConstructor): (JSC::IntlDurationFormatConstructor::finishCreation): (JSC::JSC_DEFINE_HOST_FUNCTION): * Source/JavaScriptCore/runtime/IntlDurationFormatConstructor.h: Added. * Source/JavaScriptCore/runtime/IntlDurationFormatPrototype.cpp: Added. (JSC::IntlDurationFormatPrototype::create): (JSC::IntlDurationFormatPrototype::createStructure): (JSC::IntlDurationFormatPrototype::IntlDurationFormatPrototype): (JSC::IntlDurationFormatPrototype::finishCreation): (JSC::JSC_DEFINE_HOST_FUNCTION): * Source/JavaScriptCore/runtime/IntlDurationFormatPrototype.h: Added. * Source/JavaScriptCore/runtime/IntlObject.cpp: (JSC::createDurationFormatConstructor): (JSC::IntlObject::finishCreation): * Source/JavaScriptCore/runtime/IntlObject.h: (JSC::intlDurationFormatAvailableLocales): * Source/JavaScriptCore/runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::init): * Source/JavaScriptCore/runtime/JSGlobalObject.h: (JSC::JSGlobalObject::durationFormatStructure): Canonical link: https://commits.webkit.org/254791@main
e71a4f8
to
0a14082
Compare
Committed 254791@main (0a14082): https://commits.webkit.org/254791@main Reviewed commits have been landed. Closing PR #4589 and removing active labels. |
0a14082
e71a4f8
🛠 mac-debug🧪 mac-wk1🛠 🧪 merge