WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
158188
[INTL] Implement the caseFirst option for Intl.Collator
https://bugs.webkit.org/show_bug.cgi?id=158188
Summary
[INTL] Implement the caseFirst option for Intl.Collator
Sukolsak Sakshuwong
Reported
2016-05-29 01:33:21 PDT
The caseFirst option lets users specify whether upper case or lower case should sort first when using Intl.Collator.prototype.compare. For example, new Intl.Collator('en', {caseFirst: 'upper'}).compare('a', 'A'); // returns 1 new Intl.Collator('en', {caseFirst: 'lower'}).compare('a', 'A'); // returns -1 According to the ECMAScript 2015 Internationalization API Specification (ECMA-402 2nd edition), implementations are not required to support caseFirst. But it would be a nice feature to have. Currently, only Chrome seems to supports this.
http://www.ecma-international.org/ecma-402/2.0/
Attachments
Patch
(19.72 KB, patch)
2016-05-29 01:38 PDT
,
Sukolsak Sakshuwong
no flags
Details
Formatted Diff
Diff
Archive of layout-test-results from ews103 for mac-yosemite
(1.11 MB, application/zip)
2016-05-29 02:14 PDT
,
Build Bot
no flags
Details
Patch
(19.68 KB, patch)
2016-05-30 08:58 PDT
,
Sukolsak Sakshuwong
no flags
Details
Formatted Diff
Diff
Patch
(19.51 KB, patch)
2017-04-27 21:45 PDT
,
Andy VanWagoner
no flags
Details
Formatted Diff
Diff
Show Obsolete
(2)
View All
Add attachment
proposed patch, testcase, etc.
Sukolsak Sakshuwong
Comment 1
2016-05-29 01:38:31 PDT
Created
attachment 280056
[details]
Patch
Build Bot
Comment 2
2016-05-29 02:14:44 PDT
Comment on
attachment 280056
[details]
Patch
Attachment 280056
[details]
did not pass mac-ews (mac): Output:
http://webkit-queues.webkit.org/results/1400967
Number of test failures exceeded the failure limit.
Build Bot
Comment 3
2016-05-29 02:14:47 PDT
Created
attachment 280057
[details]
Archive of layout-test-results from ews103 for mac-yosemite The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews103 Port: mac-yosemite Platform: Mac OS X 10.10.5
Sukolsak Sakshuwong
Comment 4
2016-05-30 08:58:55 PDT
Created
attachment 280100
[details]
Patch Resubmit
Darin Adler
Comment 5
2016-05-30 20:52:53 PDT
Comment on
attachment 280100
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=280100&action=review
> Source/JavaScriptCore/runtime/IntlCollator.cpp:289 > m_numeric = (result.get(ASCIILiteral("kn")) == "true");
I’d like how this reads better without the parentheses.
> Source/JavaScriptCore/runtime/IntlCollator.cpp:290 > + const String& caseFirst = result.get(ASCIILiteral("kf"));
As with the cases below, I think it’s nicer to have the translation from string to CaseFirst be in a helper function. It can be inlined if we like.
> Source/JavaScriptCore/runtime/IntlCollator.cpp:296 > + ASSERT(caseFirst == "false");
Why can we assert this? What prevents invalid values?
> Source/JavaScriptCore/runtime/IntlCollator.cpp:389 > + UColAttributeValue caseFirst; > + switch (m_caseFirst) { > + case CaseFirst::Upper: > + caseFirst = UCOL_UPPER_FIRST; > + break; > + case CaseFirst::Lower: > + caseFirst = UCOL_LOWER_FIRST; > + break; > + case CaseFirst::False: > + caseFirst = UCOL_OFF; > + break; > + default: > + ASSERT_NOT_REACHED(); > + }
It’s a better idiom to put this kind of translation into a helper function that takes a CaseFirst and returns a UColAttributeValue. Then we can use return inside the switch cases, so we can put the ASSERT_NOT_REACHED outside the switch instead of in a default case, and the compiler will give us a warning if we ever leave a case out. It also makes the main code flow easier to read and helps us spot if we made a mistake. This would be similar to the caseFirstString function. It can be inlined if we like. Only trick might be using the UColAttributeValue type in the class header without including ICU headers.
> Source/JavaScriptCore/runtime/IntlCollator.cpp:451 > +const char* IntlCollator::caseFirstString(CaseFirst caseFirst)
I think we should probably mark this function inline.
> Source/JavaScriptCore/runtime/IntlCollator.cpp:462 > + return nullptr;
I think we should return "false" here instead of nullptr.
Sukolsak Sakshuwong
Comment 6
2016-05-30 22:05:06 PDT
Thanks. (In reply to
comment #5
)
> Comment on
attachment 280100
[details]
> Patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=280100&action=review
> > > Source/JavaScriptCore/runtime/IntlCollator.cpp:289 > > m_numeric = (result.get(ASCIILiteral("kn")) == "true"); > > I’d like how this reads better without the parentheses.
Will fix.
> > Source/JavaScriptCore/runtime/IntlCollator.cpp:290 > > + const String& caseFirst = result.get(ASCIILiteral("kf")); > > As with the cases below, I think it’s nicer to have the translation from > string to CaseFirst be in a helper function. It can be inlined if we like.
Will do. Do you have any name suggestion for the helper function? caseFirstString(CaseFirst) <-> caseFirstFromString(const String&)?
> > Source/JavaScriptCore/runtime/IntlCollator.cpp:296 > > + ASSERT(caseFirst == "false"); > > Why can we assert this? What prevents invalid values?
The HashMap "result" which we get the caseFirst value from is sanitized by resolveLocale(...). We test invalid values in the tests.
> > Source/JavaScriptCore/runtime/IntlCollator.cpp:451 > > +const char* IntlCollator::caseFirstString(CaseFirst caseFirst) > > I think we should probably mark this function inline.
Will do.
> > Source/JavaScriptCore/runtime/IntlCollator.cpp:462 > > + return nullptr; > > I think we should return "false" here instead of nullptr.
Why is that? Is it so that the compiler can optimize out the "case CaseFirst::False:" branch?
Andy VanWagoner
Comment 7
2017-04-27 21:45:59 PDT
Created
attachment 308501
[details]
Patch
Andy VanWagoner
Comment 8
2017-04-27 21:50:10 PDT
Comment on
attachment 308501
[details]
Patch Only small changes from what Sukolsak submitted a year ago. The code matches the existing patterns in these files. Larger changes to clean up or optimize I'd suggest should be in a future patch.
Geoffrey Garen
Comment 9
2017-04-27 21:53:22 PDT
Comment on
attachment 308501
[details]
Patch r=me
WebKit Commit Bot
Comment 10
2017-04-27 23:00:23 PDT
Comment on
attachment 308501
[details]
Patch Clearing flags on attachment: 308501 Committed
r215921
: <
http://trac.webkit.org/changeset/215921
>
WebKit Commit Bot
Comment 11
2017-04-27 23:00:25 PDT
All reviewed patches have been landed. Closing bug.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug