⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 264639 in webkit


Ignore:
Timestamp:
Jul 20, 2020, 5:04:06 PM (6 years ago)
Author:
ysuzuki@apple.com
Message:

[ECMA-402] Implement Intl.DisplayNames
​https://bugs.webkit.org/show_bug.cgi?id=209779

Reviewed by Ross Kirsling.

JSTests:

  • stress/intl-displaynames.js: Added.

(shouldBe):
(shouldThrow):
(vm.icuVersion):

  • stress/intl-parse-unicode-subtags.js: Added.

(shouldBe):
(shouldThrow):
(vm.icuVersion):

  • test262/config.yaml:

Source/JavaScriptCore:

This patch implements Intl.DisplayNames behind useIntlDisplayNames=1 flag.
Intl.DisplayNames can offer readable "display-name" for ICU language, script, region, currency codes.
For example, it can offer "United States" string for "US" region code.
We use ICU ULocaleDisplayNames to implement it, except for currency since ULocaleDisplayNames is not supporting
currency correctly: it ignores "long", "short", and "narrow" style configurations. We need to call ucurr_getName
directly.

This patch appropriately adds unicode-language-id parsing in IntlLocale.cpp so that we can validate language id
when it is passed to Intl.DisplayNames#of as defined in the spec.

  • CMakeLists.txt:
  • DerivedSources-input.xcfilelist:
  • DerivedSources-output.xcfilelist:
  • DerivedSources.make:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • Sources.txt:
  • runtime/CommonIdentifiers.h:
  • runtime/IntlDisplayNames.cpp: Added.

(JSC::IntlDisplayNames::create):
(JSC::IntlDisplayNames::createStructure):
(JSC::IntlDisplayNames::IntlDisplayNames):
(JSC::IntlDisplayNames::finishCreation):
(JSC::IntlDisplayNames::initializeDisplayNames):
(JSC::IntlDisplayNames::of const):
(JSC::IntlDisplayNames::resolvedOptions const):
(JSC::IntlDisplayNames::styleString):
(JSC::IntlDisplayNames::typeString):
(JSC::IntlDisplayNames::fallbackString):

  • runtime/IntlDisplayNames.h: Copied from Source/JavaScriptCore/runtime/IntlRelativeTimeFormat.h.
  • runtime/IntlDisplayNamesConstructor.cpp: Added.

(JSC::IntlDisplayNamesConstructor::create):
(JSC::IntlDisplayNamesConstructor::createStructure):
(JSC::IntlDisplayNamesConstructor::IntlDisplayNamesConstructor):
(JSC::IntlDisplayNamesConstructor::finishCreation):
(JSC::constructIntlDisplayNames):
(JSC::callIntlDisplayNames):
(JSC::IntlDisplayNamesConstructorSupportedLocalesOf):

  • runtime/IntlDisplayNamesConstructor.h: Added.
  • runtime/IntlDisplayNamesPrototype.cpp: Added.

(JSC::IntlDisplayNamesPrototype::create):
(JSC::IntlDisplayNamesPrototype::createStructure):
(JSC::IntlDisplayNamesPrototype::IntlDisplayNamesPrototype):
(JSC::IntlDisplayNamesPrototype::finishCreation):
(JSC::IntlDisplayNamesPrototypeFuncOf):
(JSC::IntlDisplayNamesPrototypeFuncResolvedOptions):

  • runtime/IntlDisplayNamesPrototype.h: Added.
  • runtime/IntlLocale.cpp:

(JSC::isUnicodeLanguageSubtag): Deleted.
(JSC::isUnicodeScriptSubtag): Deleted.
(JSC::isUnicodeRegionSubtag): Deleted.

  • runtime/IntlNumberFormat.cpp:

(JSC::IntlNumberFormat::initializeNumberFormat):

  • runtime/IntlObject.cpp:

(JSC::createDisplayNamesConstructor):
(JSC::IntlObject::finishCreation):
(JSC::isUnicodeLanguageSubtag):
(JSC::isUnicodeScriptSubtag):
(JSC::isUnicodeRegionSubtag):
(JSC::isUnicodeVariantSubtag):
(JSC::isUnicodeLanguageId):
(JSC::isWellFormedCurrencyCode):

  • runtime/IntlObject.h:

(JSC::intlDisplayNamesAvailableLocales):

  • runtime/IntlRelativeTimeFormat.h:
  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildren):

  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::displayNamesStructure):

  • runtime/OptionsList.h:
  • runtime/VM.cpp:

(JSC::VM::VM):

  • runtime/VM.h:

Source/WTF:

  • wtf/text/StringView.h:
Location:
trunk
Files:
7 added
23 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r264633 r264639  
     12020-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
    1182020-07-20  Ross Kirsling  <ross.kirsling@sony.com>
    219
  • trunk/JSTests/test262/config.yaml

    r264631 r264639  
    77  class-fields-public: usePublicClassFields
    88  class-fields-private: usePrivateClassFields
     9  Intl.DisplayNames: useIntlDisplayNames
    910skip:
    1011  features:
    … …  
    2728    - Intl.DateTimeFormat-formatRange
    2829    - Intl.DateTimeFormat-fractionalSecondDigits
    29     - Intl.DisplayNames
    3030    - Intl.ListFormat
    3131    - Intl.NumberFormat-unified
  • trunk/JSTests/test262/expectations.yaml

    r264633 r264639  
    15761576  default: 'Test262Error: Expected SameValue(«h24», «h23») to be true'
    15771577  strict mode: 'Test262Error: Expected SameValue(«h24», «h23») to be true'
     1578test/intl402/DisplayNames/length.js:
     1579  default: 'Test262Error: descriptor value should be 0'
     1580  strict mode: 'Test262Error: descriptor value should be 0'
    15781581test/intl402/Intl/getCanonicalLocales/canonicalized-tags.js:
    15791582  default: 'Test262Error: Expected SameValue(«cmn», «zh») to be true'
  • trunk/Source/JavaScriptCore/CMakeLists.txt

    r264617 r264639  
    7171    runtime/IntlDateTimeFormatConstructor.cpp
    7272    runtime/IntlDateTimeFormatPrototype.cpp
     73    runtime/IntlDisplayNamesConstructor.cpp
     74    runtime/IntlDisplayNamesPrototype.cpp
    7375    runtime/IntlLocalePrototype.cpp
    7476    runtime/IntlNumberFormatConstructor.cpp
  • trunk/Source/JavaScriptCore/ChangeLog

    r264635 r264639  
     12020-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
    1822020-07-20  Geoffrey Garen  <ggaren@apple.com>
    283
  • trunk/Source/JavaScriptCore/DerivedSources-input.xcfilelist

    r263961 r264639  
    138138$(PROJECT_DIR)/runtime/IntlDateTimeFormatConstructor.cpp
    139139$(PROJECT_DIR)/runtime/IntlDateTimeFormatPrototype.cpp
     140$(PROJECT_DIR)/runtime/IntlDisplayNamesConstructor.cpp
     141$(PROJECT_DIR)/runtime/IntlDisplayNamesPrototype.cpp
    140142$(PROJECT_DIR)/runtime/IntlLocalePrototype.cpp
    141143$(PROJECT_DIR)/runtime/IntlNumberFormatConstructor.cpp
  • trunk/Source/JavaScriptCore/DerivedSources-output.xcfilelist

    r261215 r264639  
    2828$(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/IntlDateTimeFormatConstructor.lut.h
    2929$(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
    3032$(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/IntlLocalePrototype.lut.h
    3133$(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/IntlNumberFormatConstructor.lut.h
  • trunk/Source/JavaScriptCore/DerivedSources.make

    r263961 r264639  
    159159    IntlDateTimeFormatConstructor.lut.h \
    160160    IntlDateTimeFormatPrototype.lut.h \
     161    IntlDisplayNamesConstructor.lut.h \
     162    IntlDisplayNamesPrototype.lut.h \
    161163    IntlLocalePrototype.lut.h \
    162164    IntlNumberFormatConstructor.lut.h \
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r264630 r264639  
    18241824                E34F930E2322D882002B8DB4 /* JSGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = E34F930C2322D881002B8DB4 /* JSGenerator.h */; };
    18251825                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 */; };
    18261829                E354622B1B6065D100545386 /* ConstructAbility.h in Headers */ = {isa = PBXBuildFile; fileRef = E354622A1B6065D100545386 /* ConstructAbility.h */; settings = {ATTRIBUTES = (Private, ); }; };
    18271830                E3555B8A1DAE03A500F36921 /* DOMJITCallDOMGetterSnippet.h in Headers */ = {isa = PBXBuildFile; fileRef = E3555B891DAE03A200F36921 /* DOMJITCallDOMGetterSnippet.h */; settings = {ATTRIBUTES = (Private, ); }; };
    … …  
    18331836                E35E03601B7AB43E0073AD2A /* InspectorInstrumentationObject.h in Headers */ = {isa = PBXBuildFile; fileRef = E35E035E1B7AB43E0073AD2A /* InspectorInstrumentationObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
    18341837                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 */; };
    18351840                E36B767022F8D61900D09818 /* WasmOMGForOSREntryPlan.h in Headers */ = {isa = PBXBuildFile; fileRef = E36B766F22F8D61100D09818 /* WasmOMGForOSREntryPlan.h */; };
    18361841                E36CC9472086314F0051FFD6 /* WasmCreationMode.h in Headers */ = {isa = PBXBuildFile; fileRef = E36CC9462086314F0051FFD6 /* WasmCreationMode.h */; settings = {ATTRIBUTES = (Private, ); }; };
    … …  
    49965001                E34F930C2322D881002B8DB4 /* JSGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSGenerator.h; sourceTree = "<group>"; };
    49975002                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>"; };
    49985009                E354622A1B6065D100545386 /* ConstructAbility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConstructAbility.h; sourceTree = "<group>"; };
    49995010                E3555B891DAE03A200F36921 /* DOMJITCallDOMGetterSnippet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMJITCallDOMGetterSnippet.h; sourceTree = "<group>"; };
    … …  
    50125023                E3637EE7236E56B00096BD0A /* LinkTimeConstant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LinkTimeConstant.h; sourceTree = "<group>"; };
    50135024                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>"; };
    50145027                E36B480123E9573800E4A66E /* UnlinkedCodeBlockGenerator.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = UnlinkedCodeBlockGenerator.cpp; sourceTree = "<group>"; };
    50155028                E36B766E22F8D61100D09818 /* WasmOMGForOSREntryPlan.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WasmOMGForOSREntryPlan.cpp; sourceTree = "<group>"; };
    … …  
    67786791                                A1587D731B4DC1C600D69849 /* IntlDateTimeFormatConstructor.lut.h */,
    67796792                                A1587D741B4DC1C600D69849 /* IntlDateTimeFormatPrototype.lut.h */,
     6793                                E365F33924AA621200C991B2 /* IntlDisplayNamesConstructor.lut.h */,
     6794                                E365F33824AA621100C991B2 /* IntlDisplayNamesPrototype.lut.h */,
    67806795                                A125846C1B45A36000CC7F6C /* IntlNumberFormatConstructor.lut.h */,
    67816796                                A125846D1B45A36000CC7F6C /* IntlNumberFormatPrototype.lut.h */,
    … …  
    72817296                                A1587D6B1B4DC14100D69849 /* IntlDateTimeFormatPrototype.cpp */,
    72827297                                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 */,
    72837304                                A3AFF92D245A3CFA00C9BA3B /* IntlLocale.cpp */,
    72847305                                A3AFF92B245A3CF900C9BA3B /* IntlLocale.h */,
    … …  
    97789799                                A1587D721B4DC14100D69849 /* IntlDateTimeFormatPrototype.h in Headers */,
    97799800                                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 */,
    97809806                                A1D792FD1B43864B004516F5 /* IntlNumberFormat.h in Headers */,
    97819807                                A1D792FF1B43864B004516F5 /* IntlNumberFormatConstructor.h in Headers */,
  • trunk/Source/JavaScriptCore/Sources.txt

    r264617 r264639  
    817817runtime/IntlDateTimeFormatConstructor.cpp
    818818runtime/IntlDateTimeFormatPrototype.cpp
     819runtime/IntlDisplayNames.cpp
     820runtime/IntlDisplayNamesConstructor.cpp
     821runtime/IntlDisplayNamesPrototype.cpp
    819822runtime/IntlLocale.cpp
    820823runtime/IntlLocaleConstructor.cpp
  • trunk/Source/JavaScriptCore/runtime/CommonIdentifiers.h

    r264617 r264639  
    3535    macro(Date) \
    3636    macro(DateTimeFormat) \
     37    macro(DisplayNames) \
    3738    macro(Error) \
    3839    macro(EvalError) \
  • trunk/Source/JavaScriptCore/runtime/IntlDisplayNames.h

    r264638 r264639  
    11/*
    2  * Copyright (C) 2020 Sony Interactive Entertainment Inc.
    32 * Copyright (C) 2020 Apple Inc. All rights reserved.
    43 *
    … …  
    2827
    2928#include "JSObject.h"
    30 #include <unicode/ureldatefmt.h>
     29#include <unicode/uldnames.h>
     30#include <wtf/unicode/icu/ICUHelpers.h>
    3131
    3232namespace JSC {
    3333
     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
    3441enum class RelevantExtensionKey : uint8_t;
    3542
    36 class IntlRelativeTimeFormat final : public JSNonFinalObject {
     43class IntlDisplayNames final : public JSNonFinalObject {
    3744public:
    3845    using Base = JSNonFinalObject;
    … …  
    4249    static void destroy(JSCell* cell)
    4350    {
    44         static_cast<IntlRelativeTimeFormat*>(cell)->IntlRelativeTimeFormat::~IntlRelativeTimeFormat();
     51        static_cast<IntlDisplayNames*>(cell)->IntlDisplayNames::~IntlDisplayNames();
    4552    }
    4653
    … …  
    4855    static IsoSubspace* subspaceFor(VM& vm)
    4956    {
    50         return vm.intlRelativeTimeFormatSpace<mode>();
     57        return vm.intlDisplayNamesSpace<mode>();
    5158    }
    5259
    53     static IntlRelativeTimeFormat* create(VM&, Structure*);
     60    static IntlDisplayNames* create(VM&, Structure*);
    5461    static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
    5562
    5663    DECLARE_INFO;
    5764
    58     void initializeRelativeTimeFormat(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;
    6168    JSObject* resolvedOptions(JSGlobalObject*) const;
    6269
    6370private:
    64     IntlRelativeTimeFormat(VM&, Structure*);
     71    IntlDisplayNames(VM&, Structure*);
    6572    void finishCreation(VM&);
    66     static void visitChildren(JSCell*, SlotVisitor&);
    6773
    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 };
    8077
    8178    static ASCIILiteral styleString(Style);
     79    static ASCIILiteral typeString(Type);
     80    static ASCIILiteral fallbackString(Fallback);
    8281
    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;
    8684    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;
    8888    Style m_style { Style::Long };
    89     bool m_numeric { true };
     89    Type m_type { Type::Language };
     90    Fallback m_fallback { Fallback::Code };
    9091};
    9192
  • trunk/Source/JavaScriptCore/runtime/IntlLocale.cpp

    r264324 r264639  
    192192}
    193193
    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 
    215194// https://tc39.es/ecma402/#sec-Intl.Locale
    216195void IntlLocale::initializeLocale(JSGlobalObject* globalObject, JSValue tagValue, JSValue optionsValue)
  • trunk/Source/JavaScriptCore/runtime/IntlNumberFormat.cpp

    r264537 r264639  
    203203    RETURN_IF_EXCEPTION(scope, void());
    204204    if (!currency.isNull()) {
    205         if (currency.length() != 3 || !currency.isAllSpecialCharacters<isASCIIAlpha>()) {
     205        if (!isWellFormedCurrencyCode(currency)) {
    206206            throwException(globalObject, scope, createRangeError(globalObject, "currency is not a well-formed currency code"_s));
    207207            return;
  • trunk/Source/JavaScriptCore/runtime/IntlObject.cpp

    r264537 r264639  
    3636#include "IntlDateTimeFormatConstructor.h"
    3737#include "IntlDateTimeFormatPrototype.h"
     38#include "IntlDisplayNames.h"
     39#include "IntlDisplayNamesConstructor.h"
     40#include "IntlDisplayNamesPrototype.h"
    3841#include "IntlLocale.h"
    3942#include "IntlLocaleConstructor.h"
    … …  
    7982}
    8083
     84static 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
    8191static JSValue createLocaleConstructor(VM& vm, JSObject* object)
    8292{
    … …  
    154164{
    155165    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
    156172}
    157173
    … …  
    816832}
    817833
     834// unicode_language_subtag = alpha{2,3} | alpha{5,8} ;
     835bool 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} ;
     842bool isUnicodeScriptSubtag(StringView string)
     843{
     844    return string.length() == 4 && string.isAllSpecialCharacters<isASCIIAlpha>();
     845}
     846
     847// unicode_region_subtag = alpha{2} | digit{3} ;
     848bool 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}) ;
     856bool 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
     868bool 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
     899bool isWellFormedCurrencyCode(StringView currency)
     900{
     901    return currency.length() == 3 && currency.isAllSpecialCharacters<isASCIIAlpha>();
     902}
     903
    818904EncodedJSValue JSC_HOST_CALL intlObjectFuncGetCanonicalLocales(JSGlobalObject* globalObject, CallFrame* callFrame)
    819905{
  • trunk/Source/JavaScriptCore/runtime/IntlObject.h

    r264537 r264639  
    8383const HashSet<String>& intlCollatorAvailableLocales();
    8484inline const HashSet<String>& intlDateTimeFormatAvailableLocales() { return intlAvailableLocales(); }
     85inline const HashSet<String>& intlDisplayNamesAvailableLocales() { return intlAvailableLocales(); }
    8586inline const HashSet<String>& intlNumberFormatAvailableLocales() { return intlAvailableLocales(); }
    8687inline const HashSet<String>& intlPluralRulesAvailableLocales() { return intlAvailableLocales(); }
    … …  
    112113bool isUnicodeLocaleIdentifierType(StringView);
    113114
     115bool isUnicodeLanguageSubtag(StringView);
     116bool isUnicodeScriptSubtag(StringView);
     117bool isUnicodeRegionSubtag(StringView);
     118bool isUnicodeVariantSubtag(StringView);
     119bool isUnicodeLanguageId(StringView);
     120
     121bool isWellFormedCurrencyCode(StringView);
     122
    114123struct UFieldPositionIteratorDeleter {
    115124    void operator()(UFieldPositionIterator*) const;
  • trunk/Source/JavaScriptCore/runtime/IntlRelativeTimeFormat.h

    r264617 r264639  
    3131
    3232namespace JSC {
     33
     34enum class RelevantExtensionKey : uint8_t;
    3335
    3436enum class RelevantExtensionKey : uint8_t;
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp

    r264617 r264639  
    7676#include "IntlDateTimeFormat.h"
    7777#include "IntlDateTimeFormatPrototype.h"
     78#include "IntlDisplayNames.h"
     79#include "IntlDisplayNamesPrototype.h"
    7880#include "IntlLocale.h"
    7981#include "IntlLocalePrototype.h"
    … …  
    986988            init.set(IntlDateTimeFormat::createStructure(init.vm, globalObject, dateTimeFormatPrototype));
    987989        });
     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        });
    988996    m_localeStructure.initLater(
    989997        [] (const Initializer<Structure>& init) {
    … …  
    18371845    thisObject->m_collatorStructure.visit(visitor);
    18381846    thisObject->m_dateTimeFormatStructure.visit(visitor);
     1847    thisObject->m_displayNamesStructure.visit(visitor);
    18391848    thisObject->m_numberFormatStructure.visit(visitor);
    18401849    thisObject->m_localeStructure.visit(visitor);
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r264617 r264639  
    298298    LazyProperty<JSGlobalObject, Structure> m_collatorStructure;
    299299    LazyProperty<JSGlobalObject, Structure> m_dateTimeFormatStructure;
     300    LazyProperty<JSGlobalObject, Structure> m_displayNamesStructure;
    300301    LazyProperty<JSGlobalObject, Structure> m_localeStructure;
    301302    LazyProperty<JSGlobalObject, Structure> m_numberFormatStructure;
    … …  
    800801    Structure* collatorStructure() { return m_collatorStructure.get(this); }
    801802    Structure* dateTimeFormatStructure() { return m_dateTimeFormatStructure.get(this); }
     803    Structure* displayNamesStructure() { return m_displayNamesStructure.get(this); }
    802804    Structure* numberFormatStructure() { return m_numberFormatStructure.get(this); }
    803805    Structure* localeStructure() { return m_localeStructure.get(this); }
  • trunk/Source/JavaScriptCore/runtime/OptionsList.h

    r264617 r264639  
    490490    v(Bool, useWeakRefs, false, Normal, "Expose the WeakRef constructor.") \
    491491    v(Bool, useBigInt, true, Normal, "If true, we will enable BigInt support.") \
     492    v(Bool, useIntlDisplayNames, false, Normal, "Expose the Intl.DisplayNames constructor.") \
    492493    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.") \
    493494    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  
    6767#include "IntlCollator.h"
    6868#include "IntlDateTimeFormat.h"
     69#include "IntlDisplayNames.h"
    6970#include "IntlLocale.h"
    7071#include "IntlNumberFormat.h"
    … …  
    309310    , intlCollatorHeapCellType(IsoHeapCellType::create<IntlCollator>())
    310311    , intlDateTimeFormatHeapCellType(IsoHeapCellType::create<IntlDateTimeFormat>())
     312    , intlDisplayNamesHeapCellType(IsoHeapCellType::create<IntlDisplayNames>())
    311313    , intlLocaleHeapCellType(IsoHeapCellType::create<IntlLocale>())
    312314    , intlNumberFormatHeapCellType(IsoHeapCellType::create<IntlNumberFormat>())
    … …  
    15131515DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(intlCollatorSpace, intlCollatorHeapCellType.get(), IntlCollator)
    15141516DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(intlDateTimeFormatSpace, intlDateTimeFormatHeapCellType.get(), IntlDateTimeFormat)
     1517DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(intlDisplayNamesSpace, intlDisplayNamesHeapCellType.get(), IntlDisplayNames)
    15151518DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(intlLocaleSpace, intlLocaleHeapCellType.get(), IntlLocale)
    15161519DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(intlNumberFormatSpace, intlNumberFormatHeapCellType.get(), IntlNumberFormat)
  • trunk/Source/JavaScriptCore/runtime/VM.h

    r264635 r264639  
    127127class IntlCollator;
    128128class IntlDateTimeFormat;
     129class IntlDisplayNames;
    129130class IntlLocale;
    130131class IntlNumberFormat;
    … …  
    403404    std::unique_ptr<IsoHeapCellType> intlCollatorHeapCellType;
    404405    std::unique_ptr<IsoHeapCellType> intlDateTimeFormatHeapCellType;
     406    std::unique_ptr<IsoHeapCellType> intlDisplayNamesHeapCellType;
    405407    std::unique_ptr<IsoHeapCellType> intlLocaleHeapCellType;
    406408    std::unique_ptr<IsoHeapCellType> intlNumberFormatHeapCellType;
    … …  
    561563    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(intlCollatorSpace)
    562564    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(intlDateTimeFormatSpace)
     565    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(intlDisplayNamesSpace)
    563566    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(intlLocaleSpace)
    564567    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(intlNumberFormatSpace)
  • trunk/Source/WTF/ChangeLog

    r264630 r264639  
     12020-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
    1102020-07-20  Adrian Perez de Castro  <aperez@igalia.com>
    211
  • trunk/Source/WTF/wtf/text/StringView.h

    r263665 r264639  
    760760    WTF_MAKE_FAST_ALLOCATED;
    761761public:
     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
    762768    StringView operator*() const;
    763769
Note: See TracChangeset for help on using the changeset viewer.