Changeset 206837 in webkit
- Timestamp:
- Oct 5, 2016 5:07:21 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r206835 r206837 1 2016-10-05 Andy VanWagoner <thetalecrafter@gmail.com> 2 3 [INTL] Implement Intl.getCanonicalLocales 4 https://bugs.webkit.org/show_bug.cgi?id=162768 5 6 Reviewed by Benjamin Poulain. 7 8 * js/intl-expected.txt: Added tests for Intl.getCanonicalLocales 9 * js/script-tests/intl.js: Added test for Intl.getCanonicalLocales 10 1 11 2016-10-05 Ryan Haddad <ryanhaddad@apple.com> 2 12 -
trunk/LayoutTests/js/intl-expected.txt
r187575 r206837 13 13 PASS delete Intl; is true 14 14 PASS 'Intl' in global() is false 15 PASS Intl.getCanonicalLocales.length is 1 16 PASS Intl.getCanonicalLocales() is an instance of Array 17 PASS Intl.getCanonicalLocales.call(null, 'en') is [ 'en' ] 18 PASS Intl.getCanonicalLocales.call({}, 'en') is [ 'en' ] 19 PASS Intl.getCanonicalLocales.call(1, 'en') is [ 'en' ] 20 PASS Intl.getCanonicalLocales(9) is [] 21 PASS Intl.getCanonicalLocales('en') is [ 'en' ] 22 PASS Intl.getCanonicalLocales({ length: 4, 1: 'en', 0: 'es', 3: 'de' }) is [ 'es', 'en', 'de' ] 23 PASS Intl.getCanonicalLocales([ 'en', 'pt', 'en', 'es' ]) is [ 'en', 'pt', 'es' ] 24 PASS Intl.getCanonicalLocales('En-laTn-us-variant2-variant1-1abc-U-ko-tRue-A-aa-aaa-x-RESERVED') is [ 'en-Latn-US-variant2-variant1-1abc-a-aa-aaa-u-ko-true-x-reserved' ] 25 PASS Intl.getCanonicalLocales('no-bok') is [ 'nb' ] 26 PASS Intl.getCanonicalLocales('X-some-thing') is [ 'x-some-thing' ] 27 PASS Intl.getCanonicalLocales(Object.create(null, { length: { get() { throw Error('a') } } })) threw exception Error: a. 28 PASS Intl.getCanonicalLocales(Object.create(null, { length: { value: 1 }, 0: { get() { throw Error('b') } } })) threw exception Error: b. 29 PASS Intl.getCanonicalLocales([ { toString() { throw Error('c') } } ]) threw exception Error: c. 30 PASS Intl.getCanonicalLocales([ 5 ]) threw exception TypeError: locale value must be a string or object. 31 PASS Intl.getCanonicalLocales('') threw exception RangeError: invalid language tag: . 32 PASS Intl.getCanonicalLocales('a') threw exception RangeError: invalid language tag: a. 33 PASS Intl.getCanonicalLocales('abcdefghij') threw exception RangeError: invalid language tag: abcdefghij. 34 PASS Intl.getCanonicalLocales('#$') threw exception RangeError: invalid language tag: #$. 35 PASS Intl.getCanonicalLocales('en-@-abc') threw exception RangeError: invalid language tag: en-@-abc. 36 PASS Intl.getCanonicalLocales('en-u') threw exception RangeError: invalid language tag: en-u. 37 PASS Intl.getCanonicalLocales('en-u-kn-true-u-ko-true') threw exception RangeError: invalid language tag: en-u-kn-true-u-ko-true. 38 PASS Intl.getCanonicalLocales('en-x') threw exception RangeError: invalid language tag: en-x. 39 PASS Intl.getCanonicalLocales('en-*') threw exception RangeError: invalid language tag: en-*. 40 PASS Intl.getCanonicalLocales('en-') threw exception RangeError: invalid language tag: en-. 41 PASS Intl.getCanonicalLocales('en--US') threw exception RangeError: invalid language tag: en--US. 42 PASS Intl.getCanonicalLocales('de') did not throw exception. 43 PASS Intl.getCanonicalLocales('de-DE') did not throw exception. 44 PASS Intl.getCanonicalLocales('DE-de') did not throw exception. 45 PASS Intl.getCanonicalLocales('cmn') did not throw exception. 46 PASS Intl.getCanonicalLocales('cmn-Hans') did not throw exception. 47 PASS Intl.getCanonicalLocales('CMN-hANS') did not throw exception. 48 PASS Intl.getCanonicalLocales('cmn-hans-cn') did not throw exception. 49 PASS Intl.getCanonicalLocales('es-419') did not throw exception. 50 PASS Intl.getCanonicalLocales('es-419-u-nu-latn-cu-bob') did not throw exception. 51 PASS Intl.getCanonicalLocales('i-klingon') did not throw exception. 52 PASS Intl.getCanonicalLocales('cmn-hans-cn-t-ca-u-ca-x-t-u') did not throw exception. 53 PASS Intl.getCanonicalLocales('enochian-enochian') did not throw exception. 54 PASS Intl.getCanonicalLocales('de-gregory-u-ca-gregory') did not throw exception. 55 PASS Intl.getCanonicalLocales('aa-a-foo-x-a-foo-bar') did not throw exception. 56 PASS Intl.getCanonicalLocales('x-en-US-12345') did not throw exception. 57 PASS Intl.getCanonicalLocales('x-12345-12345-en-US') did not throw exception. 58 PASS Intl.getCanonicalLocales('x-en-US-12345-12345') did not throw exception. 59 PASS Intl.getCanonicalLocales('x-en-u-foo') did not throw exception. 60 PASS Intl.getCanonicalLocales('x-en-u-foo-u-bar') did not throw exception. 15 61 PASS successfullyParsed is true 16 62 -
trunk/LayoutTests/js/script-tests/intl.js
r198926 r206837 31 31 Intl = __Intl; 32 32 33 // 8.2.1 Intl.getCanonicalLocales(locales) 34 35 // The value of the length property of the getCanonicalLocales method is 1. 36 shouldBe("Intl.getCanonicalLocales.length", "1"); 37 38 // Returns Locales 39 shouldBeType("Intl.getCanonicalLocales()", "Array"); 40 // Doesn't care about `this`. 41 shouldBe("Intl.getCanonicalLocales.call(null, 'en')", "[ 'en' ]"); 42 shouldBe("Intl.getCanonicalLocales.call({}, 'en')", "[ 'en' ]"); 43 shouldBe("Intl.getCanonicalLocales.call(1, 'en')", "[ 'en' ]"); 44 // Ignores non-object, non-string list. 45 shouldBe("Intl.getCanonicalLocales(9)", "[]"); 46 // Makes an array of tags. 47 shouldBe("Intl.getCanonicalLocales('en')", "[ 'en' ]"); 48 // Handles array-like objects with holes. 49 shouldBe("Intl.getCanonicalLocales({ length: 4, 1: 'en', 0: 'es', 3: 'de' })", "[ 'es', 'en', 'de' ]"); 50 // Deduplicates tags. 51 shouldBe("Intl.getCanonicalLocales([ 'en', 'pt', 'en', 'es' ])", "[ 'en', 'pt', 'es' ]"); 52 // Canonicalizes tags. 53 shouldBe("Intl.getCanonicalLocales('En-laTn-us-variant2-variant1-1abc-U-ko-tRue-A-aa-aaa-x-RESERVED')", "[ 'en-Latn-US-variant2-variant1-1abc-a-aa-aaa-u-ko-true-x-reserved' ]"); 54 // Replaces outdated tags. 55 shouldBe("Intl.getCanonicalLocales('no-bok')", "[ 'nb' ]"); 56 // Canonicalizes private tags. 57 shouldBe("Intl.getCanonicalLocales('X-some-thing')", "[ 'x-some-thing' ]"); 58 // Throws on problems with length, get, or toString. 59 shouldThrow("Intl.getCanonicalLocales(Object.create(null, { length: { get() { throw Error('a') } } }))", "'Error: a'"); 60 shouldThrow("Intl.getCanonicalLocales(Object.create(null, { length: { value: 1 }, 0: { get() { throw Error('b') } } }))", "'Error: b'"); 61 shouldThrow("Intl.getCanonicalLocales([ { toString() { throw Error('c') } } ])", "'Error: c'"); 62 // Throws on bad tags. 63 shouldThrow("Intl.getCanonicalLocales([ 5 ])", "'TypeError: locale value must be a string or object'"); 64 shouldThrow("Intl.getCanonicalLocales('')", "'RangeError: invalid language tag: '"); 65 shouldThrow("Intl.getCanonicalLocales('a')", "'RangeError: invalid language tag: a'"); 66 shouldThrow("Intl.getCanonicalLocales('abcdefghij')", "'RangeError: invalid language tag: abcdefghij'"); 67 shouldThrow("Intl.getCanonicalLocales('#$')", "'RangeError: invalid language tag: #$'"); 68 shouldThrow("Intl.getCanonicalLocales('en-@-abc')", "'RangeError: invalid language tag: en-@-abc'"); 69 shouldThrow("Intl.getCanonicalLocales('en-u')", "'RangeError: invalid language tag: en-u'"); 70 shouldThrow("Intl.getCanonicalLocales('en-u-kn-true-u-ko-true')", "'RangeError: invalid language tag: en-u-kn-true-u-ko-true'"); 71 shouldThrow("Intl.getCanonicalLocales('en-x')", "'RangeError: invalid language tag: en-x'"); 72 shouldThrow("Intl.getCanonicalLocales('en-*')", "'RangeError: invalid language tag: en-*'"); 73 shouldThrow("Intl.getCanonicalLocales('en-')", "'RangeError: invalid language tag: en-'"); 74 shouldThrow("Intl.getCanonicalLocales('en--US')", "'RangeError: invalid language tag: en--US'"); 75 // Accepts valid tags 76 var validLanguageTags = [ 77 "de", // ISO 639 language code 78 "de-DE", // + ISO 3166-1 country code 79 "DE-de", // tags are case-insensitive 80 "cmn", // ISO 639 language code 81 "cmn-Hans", // + script code 82 "CMN-hANS", // tags are case-insensitive 83 "cmn-hans-cn", // + ISO 3166-1 country code 84 "es-419", // + UN M.49 region code 85 "es-419-u-nu-latn-cu-bob", // + Unicode locale extension sequence 86 "i-klingon", // grandfathered tag 87 "cmn-hans-cn-t-ca-u-ca-x-t-u", // singleton subtags can also be used as private use subtags 88 "enochian-enochian", // language and variant subtags may be the same 89 "de-gregory-u-ca-gregory", // variant and extension subtags may be the same 90 "aa-a-foo-x-a-foo-bar", // variant subtags can also be used as private use subtags 91 "x-en-US-12345", // anything goes in private use tags 92 "x-12345-12345-en-US", 93 "x-en-US-12345-12345", 94 "x-en-u-foo", 95 "x-en-u-foo-u-bar" 96 ]; 97 for (var validLanguageTag of validLanguageTags) { 98 shouldNotThrow("Intl.getCanonicalLocales('" + validLanguageTag + "')"); 99 } 100 -
trunk/Source/JavaScriptCore/ChangeLog
r206836 r206837 1 2016-10-05 Andy VanWagoner <thetalecrafter@gmail.com> 2 3 [INTL] Implement Intl.getCanonicalLocales 4 https://bugs.webkit.org/show_bug.cgi?id=162768 5 6 Reviewed by Benjamin Poulain. 7 8 Implement Intl.getCanonicalLocales from ECMA 402 (3rd edition) 9 http://ecma-international.org/ecma-402/3.0/index.html#sec-intl.getcanonicallocales 10 11 Reuse canonicalizeLocaleList and copy the results into a new JSArray. 12 13 * runtime/IntlObject.cpp: 14 (JSC::IntlObject::finishCreation): 15 (JSC::intlObjectFuncGetCanonicalLocales): 16 1 17 2016-10-05 Michael Saboff <msaboff@apple.com> 2 18 -
trunk/Source/JavaScriptCore/runtime/IntlObject.cpp
r206386 r206837 57 57 STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(IntlObject); 58 58 59 static EncodedJSValue JSC_HOST_CALL intlObjectFuncGetCanonicalLocales(ExecState*); 60 59 61 } 60 62 … … 111 113 putDirectWithoutTransition(vm, vm.propertyNames->NumberFormat, numberFormatConstructor, DontEnum); 112 114 putDirectWithoutTransition(vm, vm.propertyNames->DateTimeFormat, dateTimeFormatConstructor, DontEnum); 115 116 // 8.2 Function Properties of the Intl Object 117 // https://tc39.github.io/ecma402/#sec-function-properties-of-the-intl-object 118 putDirectNativeFunction(vm, globalObject, Identifier::fromString(&vm, "getCanonicalLocales"), 1, intlObjectFuncGetCanonicalLocales, NoIntrinsic, DontEnum); 113 119 } 114 120 … … 1011 1017 } 1012 1018 1019 EncodedJSValue JSC_HOST_CALL intlObjectFuncGetCanonicalLocales(ExecState* state) 1020 { 1021 VM& vm = state->vm(); 1022 auto scope = DECLARE_THROW_SCOPE(vm); 1023 // https://tc39.github.io/ecma402/#sec-intl.getcanonicallocales 1024 // 8.2.1 Intl.getCanonicalLocales(locales) (ECMA-402 4.0) 1025 1026 // 1. Let ll be ? CanonicalizeLocaleList(locales). 1027 Vector<String> localeList = canonicalizeLocaleList(*state, state->argument(0)); 1028 RETURN_IF_EXCEPTION(scope, encodedJSValue()); 1029 1030 // 2. Return CreateArrayFromList(ll). 1031 JSGlobalObject* globalObject = state->callee()->globalObject(); 1032 JSArray* localeArray = JSArray::tryCreateUninitialized(vm, globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous), localeList.size()); 1033 if (!localeArray) { 1034 throwOutOfMemoryError(state, scope); 1035 return encodedJSValue(); 1036 } 1037 1038 auto length = localeList.size(); 1039 for (size_t i = 0; i < length; ++i) { 1040 localeArray->initializeIndex(vm, i, jsString(state, localeList[i])); 1041 RETURN_IF_EXCEPTION(scope, encodedJSValue()); 1042 } 1043 return JSValue::encode(localeArray); 1044 } 1045 1013 1046 } // namespace JSC 1014 1047
Note: See TracChangeset
for help on using the changeset viewer.