Bug 162768

Summary: [INTL] Implement Intl.getCanonicalLocales
Product: WebKit Reporter: Andy VanWagoner <andy>
Component: JavaScriptCoreAssignee: Andy VanWagoner <andy>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, commit-queue, keith_miller, mark.lam, msaboff, saam
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch for landing none

Andy VanWagoner
Reported 2016-09-29 21:24:40 PDT
[INTL] Implement Intl.getCanonicalLocales
Attachments
Patch (12.64 KB, patch)
2016-09-29 21:33 PDT, Andy VanWagoner
no flags
Patch (12.64 KB, patch)
2016-09-30 07:07 PDT, Andy VanWagoner
no flags
Patch (12.67 KB, patch)
2016-10-05 14:51 PDT, Andy VanWagoner
no flags
Patch for landing (12.38 KB, patch)
2016-10-05 16:36 PDT, Benjamin Poulain
no flags
Andy VanWagoner
Comment 1 2016-09-29 21:33:46 PDT
Geoffrey Garen
Comment 2 2016-09-29 22:41:10 PDT
Comment on attachment 290292 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=290292&action=review r=me > Source/JavaScriptCore/runtime/IntlObject.cpp:59 > +static EncodedJSValue JSC_HOST_CALL IntlObjectFuncGetCanonicalLocales(ExecState*); First letter should be lower case.
Andy VanWagoner
Comment 3 2016-09-30 07:07:59 PDT
Benjamin Poulain
Comment 4 2016-10-05 12:29:52 PDT
Comment on attachment 290330 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=290330&action=review > Source/JavaScriptCore/runtime/IntlObject.cpp:1032 > + JSArray* localeArray = JSArray::tryCreateUninitialized(vm, globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithUndecided), 0); You could create an array of shape ArrayWithContiguous and the initial size already set to localeList.size(). That way you avoid growing the butterfly dynamically on push(). > Source/JavaScriptCore/runtime/IntlObject.cpp:1040 > + auto len = localeList.size(); > + for (size_t i = 0; i < len; ++i) { > + localeArray->push(state, jsString(state, localeList[i])); If you use push instead of setting the element at index, you can use the for-in loop of C++11: for (const String& locale : localeList) { ...
Andy VanWagoner
Comment 5 2016-10-05 14:51:28 PDT
Andy VanWagoner
Comment 6 2016-10-05 14:54:04 PDT
Comment on attachment 290330 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=290330&action=review >> Source/JavaScriptCore/runtime/IntlObject.cpp:1032 >> + JSArray* localeArray = JSArray::tryCreateUninitialized(vm, globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithUndecided), 0); > > You could create an array of shape ArrayWithContiguous and the initial size already set to localeList.size(). > That way you avoid growing the butterfly dynamically on push(). done. >> Source/JavaScriptCore/runtime/IntlObject.cpp:1040 >> + localeArray->push(state, jsString(state, localeList[i])); > > If you use push instead of setting the element at index, you can use the for-in loop of C++11: > for (const String& locale : localeList) { > ... Setting the initial size required this to switch to initializeIndex, which needs the index number.
Benjamin Poulain
Comment 7 2016-10-05 15:01:02 PDT
Comment on attachment 290751 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=290751&action=review > Source/JavaScriptCore/runtime/IntlObject.cpp:118 > + putDirectNativeFunction(vm, globalObject, Identifier::fromString(&vm, ASCIILiteral("getCanonicalLocales")), 1, intlObjectFuncGetCanonicalLocales, NoIntrinsic, DontEnum); Identifier has a constructor taking a static string, you do not have to use ASCIILiteral with them. > Source/JavaScriptCore/runtime/IntlObject.cpp:1039 > + auto len = localeList.size(); > + for (size_t i = 0; i < len; ++i) { In WebKit, we avoid shortening names. "len" should be "length".
Benjamin Poulain
Comment 8 2016-10-05 16:36:28 PDT
Created attachment 290762 [details] Patch for landing
WebKit Commit Bot
Comment 9 2016-10-05 17:09:50 PDT
Comment on attachment 290762 [details] Patch for landing Clearing flags on attachment: 290762 Committed r206837: <http://trac.webkit.org/changeset/206837>
WebKit Commit Bot
Comment 10 2016-10-05 17:09:54 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.