Changeset 264639 in webkit
- Timestamp:
- Jul 20, 2020, 5:04:06 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 7 added
- 23 edited
- 1 copied
-
JSTests/ChangeLog (modified) (1 diff)
-
JSTests/stress/intl-displaynames.js (added)
-
JSTests/stress/intl-parse-unicode-subtags.js (added)
-
JSTests/test262/config.yaml (modified) (2 diffs)
-
JSTests/test262/expectations.yaml (modified) (1 diff)
-
Source/JavaScriptCore/CMakeLists.txt (modified) (1 diff)
-
Source/JavaScriptCore/ChangeLog (modified) (1 diff)
-
Source/JavaScriptCore/DerivedSources-input.xcfilelist (modified) (1 diff)
-
Source/JavaScriptCore/DerivedSources-output.xcfilelist (modified) (1 diff)
-
Source/JavaScriptCore/DerivedSources.make (modified) (1 diff)
-
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj (modified) (7 diffs)
-
Source/JavaScriptCore/Sources.txt (modified) (1 diff)
-
Source/JavaScriptCore/runtime/CommonIdentifiers.h (modified) (1 diff)
-
Source/JavaScriptCore/runtime/IntlDisplayNames.cpp (added)
-
Source/JavaScriptCore/runtime/IntlDisplayNames.h (copied) (copied from trunk/Source/JavaScriptCore/runtime/IntlRelativeTimeFormat.h ) (4 diffs)
-
Source/JavaScriptCore/runtime/IntlDisplayNamesConstructor.cpp (added)
-
Source/JavaScriptCore/runtime/IntlDisplayNamesConstructor.h (added)
-
Source/JavaScriptCore/runtime/IntlDisplayNamesPrototype.cpp (added)
-
Source/JavaScriptCore/runtime/IntlDisplayNamesPrototype.h (added)
-
Source/JavaScriptCore/runtime/IntlLocale.cpp (modified) (1 diff)
-
Source/JavaScriptCore/runtime/IntlNumberFormat.cpp (modified) (1 diff)
-
Source/JavaScriptCore/runtime/IntlObject.cpp (modified) (4 diffs)
-
Source/JavaScriptCore/runtime/IntlObject.h (modified) (2 diffs)
-
Source/JavaScriptCore/runtime/IntlRelativeTimeFormat.h (modified) (1 diff)
-
Source/JavaScriptCore/runtime/JSGlobalObject.cpp (modified) (3 diffs)
-
Source/JavaScriptCore/runtime/JSGlobalObject.h (modified) (2 diffs)
-
Source/JavaScriptCore/runtime/OptionsList.h (modified) (1 diff)
-
Source/JavaScriptCore/runtime/VM.cpp (modified) (3 diffs)
-
Source/JavaScriptCore/runtime/VM.h (modified) (3 diffs)
-
Source/WTF/ChangeLog (modified) (1 diff)
-
Source/WTF/wtf/text/StringView.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChangeLog
r264633 r264639 1 2020-07-20 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [ECMA-402] Implement Intl.DisplayNames 4 https://bugs.webkit.org/show_bug.cgi?id=209779 5 6 Reviewed by Ross Kirsling. 7 8 * stress/intl-displaynames.js: Added. 9 (shouldBe): 10 (shouldThrow): 11 (vm.icuVersion): 12 * stress/intl-parse-unicode-subtags.js: Added. 13 (shouldBe): 14 (shouldThrow): 15 (vm.icuVersion): 16 * test262/config.yaml: 17 1 18 2020-07-20 Ross Kirsling <ross.kirsling@sony.com> 2 19 -
trunk/JSTests/test262/config.yaml
r264631 r264639 7 7 class-fields-public: usePublicClassFields 8 8 class-fields-private: usePrivateClassFields 9 Intl.DisplayNames: useIntlDisplayNames 9 10 skip: 10 11 features: … … 27 28 - Intl.DateTimeFormat-formatRange 28 29 - Intl.DateTimeFormat-fractionalSecondDigits 29 - Intl.DisplayNames30 30 - Intl.ListFormat 31 31 - Intl.NumberFormat-unified -
trunk/JSTests/test262/expectations.yaml
r264633 r264639 1576 1576 default: 'Test262Error: Expected SameValue(«h24», «h23») to be true' 1577 1577 strict mode: 'Test262Error: Expected SameValue(«h24», «h23») to be true' 1578 test/intl402/DisplayNames/length.js: 1579 default: 'Test262Error: descriptor value should be 0' 1580 strict mode: 'Test262Error: descriptor value should be 0' 1578 1581 test/intl402/Intl/getCanonicalLocales/canonicalized-tags.js: 1579 1582 default: 'Test262Error: Expected SameValue(«cmn», «zh») to be true' -
trunk/Source/JavaScriptCore/CMakeLists.txt
r264617 r264639 71 71 runtime/IntlDateTimeFormatConstructor.cpp 72 72 runtime/IntlDateTimeFormatPrototype.cpp 73 runtime/IntlDisplayNamesConstructor.cpp 74 runtime/IntlDisplayNamesPrototype.cpp 73 75 runtime/IntlLocalePrototype.cpp 74 76 runtime/IntlNumberFormatConstructor.cpp -
trunk/Source/JavaScriptCore/ChangeLog
r264635 r264639 1 2020-07-20 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [ECMA-402] Implement Intl.DisplayNames 4 https://bugs.webkit.org/show_bug.cgi?id=209779 5 6 Reviewed by Ross Kirsling. 7 8 This patch implements Intl.DisplayNames behind useIntlDisplayNames=1 flag. 9 Intl.DisplayNames can offer readable "display-name" for ICU language, script, region, currency codes. 10 For example, it can offer "United States" string for "US" region code. 11 We use ICU ULocaleDisplayNames to implement it, except for currency since ULocaleDisplayNames is not supporting 12 currency correctly: it ignores "long", "short", and "narrow" style configurations. We need to call ucurr_getName 13 directly. 14 15 This patch appropriately adds unicode-language-id parsing in IntlLocale.cpp so that we can validate language id 16 when it is passed to `Intl.DisplayNames#of` as defined in the spec. 17 18 * CMakeLists.txt: 19 * DerivedSources-input.xcfilelist: 20 * DerivedSources-output.xcfilelist: 21 * DerivedSources.make: 22 * JavaScriptCore.xcodeproj/project.pbxproj: 23 * Sources.txt: 24 * runtime/CommonIdentifiers.h: 25 * runtime/IntlDisplayNames.cpp: Added. 26 (JSC::IntlDisplayNames::create): 27 (JSC::IntlDisplayNames::createStructure): 28 (JSC::IntlDisplayNames::IntlDisplayNames): 29 (JSC::IntlDisplayNames::finishCreation): 30 (JSC::IntlDisplayNames::initializeDisplayNames): 31 (JSC::IntlDisplayNames::of const): 32 (JSC::IntlDisplayNames::resolvedOptions const): 33 (JSC::IntlDisplayNames::styleString): 34 (JSC::IntlDisplayNames::typeString): 35 (JSC::IntlDisplayNames::fallbackString): 36 * runtime/IntlDisplayNames.h: Copied from Source/JavaScriptCore/runtime/IntlRelativeTimeFormat.h. 37 * runtime/IntlDisplayNamesConstructor.cpp: Added. 38 (JSC::IntlDisplayNamesConstructor::create): 39 (JSC::IntlDisplayNamesConstructor::createStructure): 40 (JSC::IntlDisplayNamesConstructor::IntlDisplayNamesConstructor): 41 (JSC::IntlDisplayNamesConstructor::finishCreation): 42 (JSC::constructIntlDisplayNames): 43 (JSC::callIntlDisplayNames): 44 (JSC::IntlDisplayNamesConstructorSupportedLocalesOf): 45 * runtime/IntlDisplayNamesConstructor.h: Added. 46 * runtime/IntlDisplayNamesPrototype.cpp: Added. 47 (JSC::IntlDisplayNamesPrototype::create): 48 (JSC::IntlDisplayNamesPrototype::createStructure): 49 (JSC::IntlDisplayNamesPrototype::IntlDisplayNamesPrototype): 50 (JSC::IntlDisplayNamesPrototype::finishCreation): 51 (JSC::IntlDisplayNamesPrototypeFuncOf): 52 (JSC::IntlDisplayNamesPrototypeFuncResolvedOptions): 53 * runtime/IntlDisplayNamesPrototype.h: Added. 54 * runtime/IntlLocale.cpp: 55 (JSC::isUnicodeLanguageSubtag): Deleted. 56 (JSC::isUnicodeScriptSubtag): Deleted. 57 (JSC::isUnicodeRegionSubtag): Deleted. 58 * runtime/IntlNumberFormat.cpp: 59 (JSC::IntlNumberFormat::initializeNumberFormat): 60 * runtime/IntlObject.cpp: 61 (JSC::createDisplayNamesConstructor): 62 (JSC::IntlObject::finishCreation): 63 (JSC::isUnicodeLanguageSubtag): 64 (JSC::isUnicodeScriptSubtag): 65 (JSC::isUnicodeRegionSubtag): 66 (JSC::isUnicodeVariantSubtag): 67 (JSC::isUnicodeLanguageId): 68 (JSC::isWellFormedCurrencyCode): 69 * runtime/IntlObject.h: 70 (JSC::intlDisplayNamesAvailableLocales): 71 * runtime/IntlRelativeTimeFormat.h: 72 * runtime/JSGlobalObject.cpp: 73 (JSC::JSGlobalObject::init): 74 (JSC::JSGlobalObject::visitChildren): 75 * runtime/JSGlobalObject.h: 76 (JSC::JSGlobalObject::displayNamesStructure): 77 * runtime/OptionsList.h: 78 * runtime/VM.cpp: 79 (JSC::VM::VM): 80 * runtime/VM.h: 81 1 82 2020-07-20 Geoffrey Garen <ggaren@apple.com> 2 83 -
trunk/Source/JavaScriptCore/DerivedSources-input.xcfilelist
r263961 r264639 138 138 $(PROJECT_DIR)/runtime/IntlDateTimeFormatConstructor.cpp 139 139 $(PROJECT_DIR)/runtime/IntlDateTimeFormatPrototype.cpp 140 $(PROJECT_DIR)/runtime/IntlDisplayNamesConstructor.cpp 141 $(PROJECT_DIR)/runtime/IntlDisplayNamesPrototype.cpp 140 142 $(PROJECT_DIR)/runtime/IntlLocalePrototype.cpp 141 143 $(PROJECT_DIR)/runtime/IntlNumberFormatConstructor.cpp -
trunk/Source/JavaScriptCore/DerivedSources-output.xcfilelist
r261215 r264639 28 28 $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/IntlDateTimeFormatConstructor.lut.h 29 29 $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/IntlDateTimeFormatPrototype.lut.h 30 $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/IntlDisplayNamesConstructor.lut.h 31 $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/IntlDisplayNamesPrototype.lut.h 30 32 $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/IntlLocalePrototype.lut.h 31 33 $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/IntlNumberFormatConstructor.lut.h -
trunk/Source/JavaScriptCore/DerivedSources.make
r263961 r264639 159 159 IntlDateTimeFormatConstructor.lut.h \ 160 160 IntlDateTimeFormatPrototype.lut.h \ 161 IntlDisplayNamesConstructor.lut.h \ 162 IntlDisplayNamesPrototype.lut.h \ 161 163 IntlLocalePrototype.lut.h \ 162 164 IntlNumberFormatConstructor.lut.h \ -
trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r264630 r264639 1824 1824 E34F930E2322D882002B8DB4 /* JSGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = E34F930C2322D881002B8DB4 /* JSGenerator.h */; }; 1825 1825 E350708A1DC49BBF0089BCD6 /* DOMJITSignature.h in Headers */ = {isa = PBXBuildFile; fileRef = E35070891DC49BB60089BCD6 /* DOMJITSignature.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1826 E353C11D24AA4CB7003FBDF3 /* IntlDisplayNames.h in Headers */ = {isa = PBXBuildFile; fileRef = E353C11724AA4CB6003FBDF3 /* IntlDisplayNames.h */; }; 1827 E353C11E24AA4CB7003FBDF3 /* IntlDisplayNamesConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = E353C11824AA4CB6003FBDF3 /* IntlDisplayNamesConstructor.h */; }; 1828 E353C12124AA4CB7003FBDF3 /* IntlDisplayNamesPrototype.h in Headers */ = {isa = PBXBuildFile; fileRef = E353C11B24AA4CB7003FBDF3 /* IntlDisplayNamesPrototype.h */; }; 1826 1829 E354622B1B6065D100545386 /* ConstructAbility.h in Headers */ = {isa = PBXBuildFile; fileRef = E354622A1B6065D100545386 /* ConstructAbility.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1827 1830 E3555B8A1DAE03A500F36921 /* DOMJITCallDOMGetterSnippet.h in Headers */ = {isa = PBXBuildFile; fileRef = E3555B891DAE03A200F36921 /* DOMJITCallDOMGetterSnippet.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 1833 1836 E35E03601B7AB43E0073AD2A /* InspectorInstrumentationObject.h in Headers */ = {isa = PBXBuildFile; fileRef = E35E035E1B7AB43E0073AD2A /* InspectorInstrumentationObject.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1834 1837 E3637EE9236E56B00096BD0A /* LinkTimeConstant.h in Headers */ = {isa = PBXBuildFile; fileRef = E3637EE7236E56B00096BD0A /* LinkTimeConstant.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1838 E365F33A24AA623900C991B2 /* IntlDisplayNamesConstructor.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = E365F33924AA621200C991B2 /* IntlDisplayNamesConstructor.lut.h */; }; 1839 E365F33B24AA623B00C991B2 /* IntlDisplayNamesPrototype.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = E365F33824AA621100C991B2 /* IntlDisplayNamesPrototype.lut.h */; }; 1835 1840 E36B767022F8D61900D09818 /* WasmOMGForOSREntryPlan.h in Headers */ = {isa = PBXBuildFile; fileRef = E36B766F22F8D61100D09818 /* WasmOMGForOSREntryPlan.h */; }; 1836 1841 E36CC9472086314F0051FFD6 /* WasmCreationMode.h in Headers */ = {isa = PBXBuildFile; fileRef = E36CC9462086314F0051FFD6 /* WasmCreationMode.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 4996 5001 E34F930C2322D881002B8DB4 /* JSGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSGenerator.h; sourceTree = "<group>"; }; 4997 5002 E35070891DC49BB60089BCD6 /* DOMJITSignature.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMJITSignature.h; sourceTree = "<group>"; }; 5003 E353C11624AA4CB5003FBDF3 /* IntlDisplayNames.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntlDisplayNames.cpp; sourceTree = "<group>"; }; 5004 E353C11724AA4CB6003FBDF3 /* IntlDisplayNames.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntlDisplayNames.h; sourceTree = "<group>"; }; 5005 E353C11824AA4CB6003FBDF3 /* IntlDisplayNamesConstructor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntlDisplayNamesConstructor.h; sourceTree = "<group>"; }; 5006 E353C11924AA4CB6003FBDF3 /* IntlDisplayNamesPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntlDisplayNamesPrototype.cpp; sourceTree = "<group>"; }; 5007 E353C11A24AA4CB6003FBDF3 /* IntlDisplayNamesConstructor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntlDisplayNamesConstructor.cpp; sourceTree = "<group>"; }; 5008 E353C11B24AA4CB7003FBDF3 /* IntlDisplayNamesPrototype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntlDisplayNamesPrototype.h; sourceTree = "<group>"; }; 4998 5009 E354622A1B6065D100545386 /* ConstructAbility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConstructAbility.h; sourceTree = "<group>"; }; 4999 5010 E3555B891DAE03A200F36921 /* DOMJITCallDOMGetterSnippet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMJITCallDOMGetterSnippet.h; sourceTree = "<group>"; }; … … 5012 5023 E3637EE7236E56B00096BD0A /* LinkTimeConstant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LinkTimeConstant.h; sourceTree = "<group>"; }; 5013 5024 E3637EE8236E56B00096BD0A /* LinkTimeConstant.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LinkTimeConstant.cpp; sourceTree = "<group>"; }; 5025 E365F33824AA621100C991B2 /* IntlDisplayNamesPrototype.lut.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntlDisplayNamesPrototype.lut.h; sourceTree = "<group>"; }; 5026 E365F33924AA621200C991B2 /* IntlDisplayNamesConstructor.lut.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntlDisplayNamesConstructor.lut.h; sourceTree = "<group>"; }; 5014 5027 E36B480123E9573800E4A66E /* UnlinkedCodeBlockGenerator.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = UnlinkedCodeBlockGenerator.cpp; sourceTree = "<group>"; }; 5015 5028 E36B766E22F8D61100D09818 /* WasmOMGForOSREntryPlan.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WasmOMGForOSREntryPlan.cpp; sourceTree = "<group>"; }; … … 6778 6791 A1587D731B4DC1C600D69849 /* IntlDateTimeFormatConstructor.lut.h */, 6779 6792 A1587D741B4DC1C600D69849 /* IntlDateTimeFormatPrototype.lut.h */, 6793 E365F33924AA621200C991B2 /* IntlDisplayNamesConstructor.lut.h */, 6794 E365F33824AA621100C991B2 /* IntlDisplayNamesPrototype.lut.h */, 6780 6795 A125846C1B45A36000CC7F6C /* IntlNumberFormatConstructor.lut.h */, 6781 6796 A125846D1B45A36000CC7F6C /* IntlNumberFormatPrototype.lut.h */, … … 7281 7296 A1587D6B1B4DC14100D69849 /* IntlDateTimeFormatPrototype.cpp */, 7282 7297 A1587D6C1B4DC14100D69849 /* IntlDateTimeFormatPrototype.h */, 7298 E353C11624AA4CB5003FBDF3 /* IntlDisplayNames.cpp */, 7299 E353C11724AA4CB6003FBDF3 /* IntlDisplayNames.h */, 7300 E353C11A24AA4CB6003FBDF3 /* IntlDisplayNamesConstructor.cpp */, 7301 E353C11824AA4CB6003FBDF3 /* IntlDisplayNamesConstructor.h */, 7302 E353C11924AA4CB6003FBDF3 /* IntlDisplayNamesPrototype.cpp */, 7303 E353C11B24AA4CB7003FBDF3 /* IntlDisplayNamesPrototype.h */, 7283 7304 A3AFF92D245A3CFA00C9BA3B /* IntlLocale.cpp */, 7284 7305 A3AFF92B245A3CF900C9BA3B /* IntlLocale.h */, … … 9778 9799 A1587D721B4DC14100D69849 /* IntlDateTimeFormatPrototype.h in Headers */, 9779 9800 A1587D761B4DC1C600D69849 /* IntlDateTimeFormatPrototype.lut.h in Headers */, 9801 E353C11D24AA4CB7003FBDF3 /* IntlDisplayNames.h in Headers */, 9802 E353C11E24AA4CB7003FBDF3 /* IntlDisplayNamesConstructor.h in Headers */, 9803 E365F33A24AA623900C991B2 /* IntlDisplayNamesConstructor.lut.h in Headers */, 9804 E353C12124AA4CB7003FBDF3 /* IntlDisplayNamesPrototype.h in Headers */, 9805 E365F33B24AA623B00C991B2 /* IntlDisplayNamesPrototype.lut.h in Headers */, 9780 9806 A1D792FD1B43864B004516F5 /* IntlNumberFormat.h in Headers */, 9781 9807 A1D792FF1B43864B004516F5 /* IntlNumberFormatConstructor.h in Headers */, -
trunk/Source/JavaScriptCore/Sources.txt
r264617 r264639 817 817 runtime/IntlDateTimeFormatConstructor.cpp 818 818 runtime/IntlDateTimeFormatPrototype.cpp 819 runtime/IntlDisplayNames.cpp 820 runtime/IntlDisplayNamesConstructor.cpp 821 runtime/IntlDisplayNamesPrototype.cpp 819 822 runtime/IntlLocale.cpp 820 823 runtime/IntlLocaleConstructor.cpp -
trunk/Source/JavaScriptCore/runtime/CommonIdentifiers.h
r264617 r264639 35 35 macro(Date) \ 36 36 macro(DateTimeFormat) \ 37 macro(DisplayNames) \ 37 38 macro(Error) \ 38 39 macro(EvalError) \ -
trunk/Source/JavaScriptCore/runtime/IntlDisplayNames.h
r264638 r264639 1 1 /* 2 * Copyright (C) 2020 Sony Interactive Entertainment Inc.3 2 * Copyright (C) 2020 Apple Inc. All rights reserved. 4 3 * … … 28 27 29 28 #include "JSObject.h" 30 #include <unicode/ureldatefmt.h> 29 #include <unicode/uldnames.h> 30 #include <wtf/unicode/icu/ICUHelpers.h> 31 31 32 32 namespace JSC { 33 33 34 #if !defined(HAVE_ICU_U_LOCALE_DISPLAY_NAMES) 35 // We need 61 or later since part of implementation uses UCURR_NARROW_SYMBOL_NAME. 36 #if U_ICU_VERSION_MAJOR_NUM >= 61 37 #define HAVE_ICU_U_LOCALE_DISPLAY_NAMES 1 38 #endif 39 #endif 40 34 41 enum class RelevantExtensionKey : uint8_t; 35 42 36 class Intl RelativeTimeFormatfinal : public JSNonFinalObject {43 class IntlDisplayNames final : public JSNonFinalObject { 37 44 public: 38 45 using Base = JSNonFinalObject; … … 42 49 static void destroy(JSCell* cell) 43 50 { 44 static_cast<Intl RelativeTimeFormat*>(cell)->IntlRelativeTimeFormat::~IntlRelativeTimeFormat();51 static_cast<IntlDisplayNames*>(cell)->IntlDisplayNames::~IntlDisplayNames(); 45 52 } 46 53 … … 48 55 static IsoSubspace* subspaceFor(VM& vm) 49 56 { 50 return vm.intl RelativeTimeFormatSpace<mode>();57 return vm.intlDisplayNamesSpace<mode>(); 51 58 } 52 59 53 static Intl RelativeTimeFormat* create(VM&, Structure*);60 static IntlDisplayNames* create(VM&, Structure*); 54 61 static Structure* createStructure(VM&, JSGlobalObject*, JSValue); 55 62 56 63 DECLARE_INFO; 57 64 58 void initialize RelativeTimeFormat(JSGlobalObject*, JSValue locales, JSValue options);59 JSValue format(JSGlobalObject*, double, StringView unitString) const; 60 JSValue formatToParts(JSGlobalObject*, double, StringView unitString) const;65 void initializeDisplayNames(JSGlobalObject*, JSValue localesValue, JSValue optionsValue); 66 67 JSValue of(JSGlobalObject*, JSValue) const; 61 68 JSObject* resolvedOptions(JSGlobalObject*) const; 62 69 63 70 private: 64 Intl RelativeTimeFormat(VM&, Structure*);71 IntlDisplayNames(VM&, Structure*); 65 72 void finishCreation(VM&); 66 static void visitChildren(JSCell*, SlotVisitor&);67 73 68 static Vector<String> localeData(const String&, RelevantExtensionKey); 69 70 String formatInternal(JSGlobalObject*, double, StringView unit) const; 71 72 enum class Style : uint8_t { Long, Short, Narrow }; 73 74 struct URelativeDateTimeFormatterDeleter { 75 void operator()(URelativeDateTimeFormatter*) const; 76 }; 77 struct UNumberFormatDeleter { 78 void operator()(UNumberFormat*) const; 79 }; 74 enum class Style : uint8_t { Narrow, Short, Long }; 75 enum class Type : uint8_t { Language, Region, Script, Currency }; 76 enum class Fallback : uint8_t { Code, None }; 80 77 81 78 static ASCIILiteral styleString(Style); 79 static ASCIILiteral typeString(Type); 80 static ASCIILiteral fallbackString(Fallback); 82 81 83 std::unique_ptr<URelativeDateTimeFormatter, URelativeDateTimeFormatterDeleter> m_relativeDateTimeFormatter; 84 std::unique_ptr<UNumberFormat, UNumberFormatDeleter> m_numberFormat; 85 82 using ULocaleDisplayNamesDeleter = ICUDeleter<uldn_close>; 83 std::unique_ptr<ULocaleDisplayNames, ULocaleDisplayNamesDeleter> m_displayNames; 86 84 String m_locale; 87 String m_numberingSystem; 85 // FIXME: We should store it only when m_type is Currency. 86 // https://bugs.webkit.org/show_bug.cgi?id=213773 87 CString m_localeCString; 88 88 Style m_style { Style::Long }; 89 bool m_numeric { true }; 89 Type m_type { Type::Language }; 90 Fallback m_fallback { Fallback::Code }; 90 91 }; 91 92 -
trunk/Source/JavaScriptCore/runtime/IntlLocale.cpp
r264324 r264639 192 192 } 193 193 194 // unicode_language_subtag = alpha{2,3} | alpha{5,8} ;195 static bool isUnicodeLanguageSubtag(StringView string)196 {197 auto length = string.length();198 return length >= 2 && length <= 8 && length != 4 && string.isAllSpecialCharacters<isASCIIAlpha>();199 }200 201 // unicode_script_subtag = alpha{4} ;202 static bool isUnicodeScriptSubtag(StringView string)203 {204 return string.length() == 4 && string.isAllSpecialCharacters<isASCIIAlpha>();205 }206 207 // unicode_region_subtag = alpha{2} | digit{3} ;208 static bool isUnicodeRegionSubtag(StringView string)209 {210 auto length = string.length();211 return (length == 2 && string.isAllSpecialCharacters<isASCIIAlpha>())212 || (length == 3 && string.isAllSpecialCharacters<isASCIIDigit>());213 }214 215 194 // https://tc39.es/ecma402/#sec-Intl.Locale 216 195 void IntlLocale::initializeLocale(JSGlobalObject* globalObject, JSValue tagValue, JSValue optionsValue) -
trunk/Source/JavaScriptCore/runtime/IntlNumberFormat.cpp
r264537 r264639 203 203 RETURN_IF_EXCEPTION(scope, void()); 204 204 if (!currency.isNull()) { 205 if ( currency.length() != 3 || !currency.isAllSpecialCharacters<isASCIIAlpha>()) {205 if (!isWellFormedCurrencyCode(currency)) { 206 206 throwException(globalObject, scope, createRangeError(globalObject, "currency is not a well-formed currency code"_s)); 207 207 return; -
trunk/Source/JavaScriptCore/runtime/IntlObject.cpp
r264537 r264639 36 36 #include "IntlDateTimeFormatConstructor.h" 37 37 #include "IntlDateTimeFormatPrototype.h" 38 #include "IntlDisplayNames.h" 39 #include "IntlDisplayNamesConstructor.h" 40 #include "IntlDisplayNamesPrototype.h" 38 41 #include "IntlLocale.h" 39 42 #include "IntlLocaleConstructor.h" … … 79 82 } 80 83 84 static JSValue createDisplayNamesConstructor(VM& vm, JSObject* object) 85 { 86 IntlObject* intlObject = jsCast<IntlObject*>(object); 87 JSGlobalObject* globalObject = intlObject->globalObject(vm); 88 return IntlDisplayNamesConstructor::create(vm, IntlDisplayNamesConstructor::createStructure(vm, globalObject, globalObject->functionPrototype()), jsCast<IntlDisplayNamesPrototype*>(globalObject->displayNamesStructure()->storedPrototypeObject())); 89 } 90 81 91 static JSValue createLocaleConstructor(VM& vm, JSObject* object) 82 92 { … … 154 164 { 155 165 Base::finishCreation(vm); 166 #if HAVE(ICU_U_LOCALE_DISPLAY_NAMES) 167 if (Options::useIntlDisplayNames()) 168 putDirectWithoutTransition(vm, vm.propertyNames->DisplayNames, createDisplayNamesConstructor(vm, this), static_cast<unsigned>(PropertyAttribute::DontEnum)); 169 #else 170 UNUSED_PARAM(createDisplayNamesConstructor); 171 #endif 156 172 } 157 173 … … 816 832 } 817 833 834 // unicode_language_subtag = alpha{2,3} | alpha{5,8} ; 835 bool isUnicodeLanguageSubtag(StringView string) 836 { 837 auto length = string.length(); 838 return length >= 2 && length <= 8 && length != 4 && string.isAllSpecialCharacters<isASCIIAlpha>(); 839 } 840 841 // unicode_script_subtag = alpha{4} ; 842 bool isUnicodeScriptSubtag(StringView string) 843 { 844 return string.length() == 4 && string.isAllSpecialCharacters<isASCIIAlpha>(); 845 } 846 847 // unicode_region_subtag = alpha{2} | digit{3} ; 848 bool isUnicodeRegionSubtag(StringView string) 849 { 850 auto length = string.length(); 851 return (length == 2 && string.isAllSpecialCharacters<isASCIIAlpha>()) 852 || (length == 3 && string.isAllSpecialCharacters<isASCIIDigit>()); 853 } 854 855 // unicode_variant_subtag = (alphanum{5,8} | digit alphanum{3}) ; 856 bool isUnicodeVariantSubtag(StringView string) 857 { 858 auto length = string.length(); 859 if (length >= 5 && length <= 8) 860 return string.isAllSpecialCharacters<isASCIIAlphanumeric>(); 861 return length == 4 && isASCIIDigit(string[0]) && string.substring(1).isAllSpecialCharacters<isASCIIAlphanumeric>(); 862 } 863 864 // unicode_language_id, but intersection of BCP47 and UTS35. 865 // unicode_language_id = 866 // | unicode_language_subtag (sep unicode_script_subtag)? (sep unicode_region_subtag)? (sep unicode_variant_subtag)* ; 867 // https://github.com/tc39/proposal-intl-displaynames/issues/79 868 bool isUnicodeLanguageId(StringView string) 869 { 870 Vector<StringView, 4> subtags; 871 for (auto subtag : string.splitAllowingEmptyEntries('-')) 872 subtags.append(subtag); 873 874 ASSERT(subtags.size() >= 1); 875 unsigned cursor = 0; 876 if (!isUnicodeLanguageSubtag(subtags[cursor])) 877 return false; 878 ++cursor; 879 880 if (cursor == subtags.size()) 881 return true; 882 if (isUnicodeScriptSubtag(subtags[cursor])) 883 ++cursor; 884 885 if (cursor == subtags.size()) 886 return true; 887 if (isUnicodeRegionSubtag(subtags[cursor])) 888 ++cursor; 889 890 while (true) { 891 if (cursor == subtags.size()) 892 return true; 893 if (!isUnicodeVariantSubtag(subtags[cursor])) 894 return false; 895 ++cursor; 896 } 897 } 898 899 bool isWellFormedCurrencyCode(StringView currency) 900 { 901 return currency.length() == 3 && currency.isAllSpecialCharacters<isASCIIAlpha>(); 902 } 903 818 904 EncodedJSValue JSC_HOST_CALL intlObjectFuncGetCanonicalLocales(JSGlobalObject* globalObject, CallFrame* callFrame) 819 905 { -
trunk/Source/JavaScriptCore/runtime/IntlObject.h
r264537 r264639 83 83 const HashSet<String>& intlCollatorAvailableLocales(); 84 84 inline const HashSet<String>& intlDateTimeFormatAvailableLocales() { return intlAvailableLocales(); } 85 inline const HashSet<String>& intlDisplayNamesAvailableLocales() { return intlAvailableLocales(); } 85 86 inline const HashSet<String>& intlNumberFormatAvailableLocales() { return intlAvailableLocales(); } 86 87 inline const HashSet<String>& intlPluralRulesAvailableLocales() { return intlAvailableLocales(); } … … 112 113 bool isUnicodeLocaleIdentifierType(StringView); 113 114 115 bool isUnicodeLanguageSubtag(StringView); 116 bool isUnicodeScriptSubtag(StringView); 117 bool isUnicodeRegionSubtag(StringView); 118 bool isUnicodeVariantSubtag(StringView); 119 bool isUnicodeLanguageId(StringView); 120 121 bool isWellFormedCurrencyCode(StringView); 122 114 123 struct UFieldPositionIteratorDeleter { 115 124 void operator()(UFieldPositionIterator*) const; -
trunk/Source/JavaScriptCore/runtime/IntlRelativeTimeFormat.h
r264617 r264639 31 31 32 32 namespace JSC { 33 34 enum class RelevantExtensionKey : uint8_t; 33 35 34 36 enum class RelevantExtensionKey : uint8_t; -
trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp
r264617 r264639 76 76 #include "IntlDateTimeFormat.h" 77 77 #include "IntlDateTimeFormatPrototype.h" 78 #include "IntlDisplayNames.h" 79 #include "IntlDisplayNamesPrototype.h" 78 80 #include "IntlLocale.h" 79 81 #include "IntlLocalePrototype.h" … … 986 988 init.set(IntlDateTimeFormat::createStructure(init.vm, globalObject, dateTimeFormatPrototype)); 987 989 }); 990 m_displayNamesStructure.initLater( 991 [] (const Initializer<Structure>& init) { 992 JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner); 993 IntlDisplayNamesPrototype* displayNamesPrototype = IntlDisplayNamesPrototype::create(init.vm, IntlDisplayNamesPrototype::createStructure(init.vm, globalObject, globalObject->objectPrototype())); 994 init.set(IntlDisplayNames::createStructure(init.vm, globalObject, displayNamesPrototype)); 995 }); 988 996 m_localeStructure.initLater( 989 997 [] (const Initializer<Structure>& init) { … … 1837 1845 thisObject->m_collatorStructure.visit(visitor); 1838 1846 thisObject->m_dateTimeFormatStructure.visit(visitor); 1847 thisObject->m_displayNamesStructure.visit(visitor); 1839 1848 thisObject->m_numberFormatStructure.visit(visitor); 1840 1849 thisObject->m_localeStructure.visit(visitor); -
trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h
r264617 r264639 298 298 LazyProperty<JSGlobalObject, Structure> m_collatorStructure; 299 299 LazyProperty<JSGlobalObject, Structure> m_dateTimeFormatStructure; 300 LazyProperty<JSGlobalObject, Structure> m_displayNamesStructure; 300 301 LazyProperty<JSGlobalObject, Structure> m_localeStructure; 301 302 LazyProperty<JSGlobalObject, Structure> m_numberFormatStructure; … … 800 801 Structure* collatorStructure() { return m_collatorStructure.get(this); } 801 802 Structure* dateTimeFormatStructure() { return m_dateTimeFormatStructure.get(this); } 803 Structure* displayNamesStructure() { return m_displayNamesStructure.get(this); } 802 804 Structure* numberFormatStructure() { return m_numberFormatStructure.get(this); } 803 805 Structure* localeStructure() { return m_localeStructure.get(this); } -
trunk/Source/JavaScriptCore/runtime/OptionsList.h
r264617 r264639 490 490 v(Bool, useWeakRefs, false, Normal, "Expose the WeakRef constructor.") \ 491 491 v(Bool, useBigInt, true, Normal, "If true, we will enable BigInt support.") \ 492 v(Bool, useIntlDisplayNames, false, Normal, "Expose the Intl.DisplayNames constructor.") \ 492 493 v(Bool, useArrayAllocationProfiling, true, Normal, "If true, we will use our normal array allocation profiling. If false, the allocation profile will always claim to be undecided.") \ 493 494 v(Bool, forcePolyProto, false, Normal, "If true, create_this will always create an object with a poly proto structure.") \ -
trunk/Source/JavaScriptCore/runtime/VM.cpp
r264635 r264639 67 67 #include "IntlCollator.h" 68 68 #include "IntlDateTimeFormat.h" 69 #include "IntlDisplayNames.h" 69 70 #include "IntlLocale.h" 70 71 #include "IntlNumberFormat.h" … … 309 310 , intlCollatorHeapCellType(IsoHeapCellType::create<IntlCollator>()) 310 311 , intlDateTimeFormatHeapCellType(IsoHeapCellType::create<IntlDateTimeFormat>()) 312 , intlDisplayNamesHeapCellType(IsoHeapCellType::create<IntlDisplayNames>()) 311 313 , intlLocaleHeapCellType(IsoHeapCellType::create<IntlLocale>()) 312 314 , intlNumberFormatHeapCellType(IsoHeapCellType::create<IntlNumberFormat>()) … … 1513 1515 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(intlCollatorSpace, intlCollatorHeapCellType.get(), IntlCollator) 1514 1516 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(intlDateTimeFormatSpace, intlDateTimeFormatHeapCellType.get(), IntlDateTimeFormat) 1517 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(intlDisplayNamesSpace, intlDisplayNamesHeapCellType.get(), IntlDisplayNames) 1515 1518 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(intlLocaleSpace, intlLocaleHeapCellType.get(), IntlLocale) 1516 1519 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(intlNumberFormatSpace, intlNumberFormatHeapCellType.get(), IntlNumberFormat) -
trunk/Source/JavaScriptCore/runtime/VM.h
r264635 r264639 127 127 class IntlCollator; 128 128 class IntlDateTimeFormat; 129 class IntlDisplayNames; 129 130 class IntlLocale; 130 131 class IntlNumberFormat; … … 403 404 std::unique_ptr<IsoHeapCellType> intlCollatorHeapCellType; 404 405 std::unique_ptr<IsoHeapCellType> intlDateTimeFormatHeapCellType; 406 std::unique_ptr<IsoHeapCellType> intlDisplayNamesHeapCellType; 405 407 std::unique_ptr<IsoHeapCellType> intlLocaleHeapCellType; 406 408 std::unique_ptr<IsoHeapCellType> intlNumberFormatHeapCellType; … … 561 563 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(intlCollatorSpace) 562 564 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(intlDateTimeFormatSpace) 565 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(intlDisplayNamesSpace) 563 566 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(intlLocaleSpace) 564 567 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(intlNumberFormatSpace) -
trunk/Source/WTF/ChangeLog
r264630 r264639 1 2020-07-20 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [ECMA-402] Implement Intl.DisplayNames 4 https://bugs.webkit.org/show_bug.cgi?id=209779 5 6 Reviewed by Ross Kirsling. 7 8 * wtf/text/StringView.h: 9 1 10 2020-07-20 Adrian Perez de Castro <aperez@igalia.com> 2 11 -
trunk/Source/WTF/wtf/text/StringView.h
r263665 r264639 760 760 WTF_MAKE_FAST_ALLOCATED; 761 761 public: 762 using iterator_category = std::forward_iterator_tag; 763 using value_type = StringView; 764 using difference_type = ptrdiff_t; 765 using pointer = value_type*; 766 using reference = value_type&; 767 762 768 StringView operator*() const; 763 769
Note:
See TracChangeset
for help on using the changeset viewer.