Changeset 281788 in webkit


Ignore:
Timestamp:
Aug 30, 2021 6:56:19 PM (11 months ago)
Author:
ysuzuki@apple.com
Message:

[JSC] Implement Temporal.Calendar
https://bugs.webkit.org/show_bug.cgi?id=229651

Reviewed by Ross Kirsling.

JSTests:

  • stress/temporal-calendar.js: Added.

(shouldBe):
(shouldThrow):
(new.Temporal.Calendar):

Source/JavaScriptCore:

This patch implements Temporal.Calendar's simple part. Currently, we do not implement many part of Temporal.Calendar since
we do not have Temporal Date-like structures yet, but this patch implemented core part of Temporal.Calendar: keeping calendar
identifier.

We also defer implementing Temporal.Calendar.from's calendar ID parsing part since it requires full-fledged ISO 8601 parser,
which will be implemented in a separate patch.

We use unsigned for CalendarID, and this id corresponds to the array index of intlAvailableCalendars, which returns array
of String from ICU.

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

(JSC::intlAvailableCalendars):
(JSC::iso8601CalendarIDSlow):
(JSC::availableCalendars):
(JSC::createArrayFromStringVector): Deleted.

  • runtime/IntlObject.h:

(JSC::iso8601CalendarID):

  • runtime/IntlObjectInlines.h:

(JSC::createArrayFromStringVector):

  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildrenImpl):

  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::calendarStructure):

  • runtime/TemporalCalendar.cpp: Added.

(JSC::TemporalCalendar::create):
(JSC::TemporalCalendar::createStructure):
(JSC::TemporalCalendar::TemporalCalendar):
(JSC::TemporalCalendar::isBuiltinCalendar):
(JSC::parseTemporalCalendarString):
(JSC::TemporalCalendar::from):

  • runtime/TemporalCalendar.h: Added.
  • runtime/TemporalCalendarConstructor.cpp: Added.

(JSC::TemporalCalendarConstructor::create):
(JSC::TemporalCalendarConstructor::createStructure):
(JSC::TemporalCalendarConstructor::TemporalCalendarConstructor):
(JSC::TemporalCalendarConstructor::finishCreation):
(JSC::JSC_DEFINE_HOST_FUNCTION):

  • runtime/TemporalCalendarConstructor.h: Added.
  • runtime/TemporalCalendarPrototype.cpp: Added.

(JSC::TemporalCalendarPrototype::create):
(JSC::TemporalCalendarPrototype::createStructure):
(JSC::TemporalCalendarPrototype::TemporalCalendarPrototype):
(JSC::TemporalCalendarPrototype::finishCreation):
(JSC::JSC_DEFINE_CUSTOM_GETTER):
(JSC::JSC_DEFINE_HOST_FUNCTION):
(JSC::defaultMergeFields):

  • runtime/TemporalCalendarPrototype.h: Added.
  • runtime/TemporalObject.cpp:

(JSC::createCalendarConstructor):

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

Source/WTF:

Add UChar version of createStaticStringImpl to make immortal thread-safe StringImpl with UChar.

  • wtf/text/StringImpl.cpp:

(WTF::StringImpl::createStaticStringImpl):

  • wtf/text/StringImpl.h:

(WTF::StringImpl::createStaticStringImpl):

Location:
trunk
Files:
7 added
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r281748 r281788  
     12021-08-30  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Implement Temporal.Calendar
     4        https://bugs.webkit.org/show_bug.cgi?id=229651
     5
     6        Reviewed by Ross Kirsling.
     7
     8        * stress/temporal-calendar.js: Added.
     9        (shouldBe):
     10        (shouldThrow):
     11        (new.Temporal.Calendar):
     12
    1132021-08-29  Yusuke Suzuki  <ysuzuki@apple.com>
    214
  • trunk/Source/JavaScriptCore/CMakeLists.txt

    r281757 r281788  
    108108    runtime/SymbolConstructor.cpp
    109109    runtime/SymbolPrototype.cpp
     110    runtime/TemporalCalendarConstructor.cpp
     111    runtime/TemporalCalendarPrototype.cpp
    110112    runtime/TemporalObject.cpp
    111113
  • trunk/Source/JavaScriptCore/ChangeLog

    r281776 r281788  
     12021-08-30  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Implement Temporal.Calendar
     4        https://bugs.webkit.org/show_bug.cgi?id=229651
     5
     6        Reviewed by Ross Kirsling.
     7
     8        This patch implements Temporal.Calendar's simple part. Currently, we do not implement many part of Temporal.Calendar since
     9        we do not have Temporal Date-like structures yet, but this patch implemented core part of Temporal.Calendar: keeping calendar
     10        identifier.
     11
     12        We also defer implementing Temporal.Calendar.from's calendar ID parsing part since it requires full-fledged ISO 8601 parser,
     13        which will be implemented in a separate patch.
     14
     15        We use `unsigned` for CalendarID, and this id corresponds to the array index of intlAvailableCalendars, which returns array
     16        of String from ICU.
     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/IntlObject.cpp:
     26        (JSC::intlAvailableCalendars):
     27        (JSC::iso8601CalendarIDSlow):
     28        (JSC::availableCalendars):
     29        (JSC::createArrayFromStringVector): Deleted.
     30        * runtime/IntlObject.h:
     31        (JSC::iso8601CalendarID):
     32        * runtime/IntlObjectInlines.h:
     33        (JSC::createArrayFromStringVector):
     34        * runtime/JSGlobalObject.cpp:
     35        (JSC::JSGlobalObject::init):
     36        (JSC::JSGlobalObject::visitChildrenImpl):
     37        * runtime/JSGlobalObject.h:
     38        (JSC::JSGlobalObject::calendarStructure):
     39        * runtime/TemporalCalendar.cpp: Added.
     40        (JSC::TemporalCalendar::create):
     41        (JSC::TemporalCalendar::createStructure):
     42        (JSC::TemporalCalendar::TemporalCalendar):
     43        (JSC::TemporalCalendar::isBuiltinCalendar):
     44        (JSC::parseTemporalCalendarString):
     45        (JSC::TemporalCalendar::from):
     46        * runtime/TemporalCalendar.h: Added.
     47        * runtime/TemporalCalendarConstructor.cpp: Added.
     48        (JSC::TemporalCalendarConstructor::create):
     49        (JSC::TemporalCalendarConstructor::createStructure):
     50        (JSC::TemporalCalendarConstructor::TemporalCalendarConstructor):
     51        (JSC::TemporalCalendarConstructor::finishCreation):
     52        (JSC::JSC_DEFINE_HOST_FUNCTION):
     53        * runtime/TemporalCalendarConstructor.h: Added.
     54        * runtime/TemporalCalendarPrototype.cpp: Added.
     55        (JSC::TemporalCalendarPrototype::create):
     56        (JSC::TemporalCalendarPrototype::createStructure):
     57        (JSC::TemporalCalendarPrototype::TemporalCalendarPrototype):
     58        (JSC::TemporalCalendarPrototype::finishCreation):
     59        (JSC::JSC_DEFINE_CUSTOM_GETTER):
     60        (JSC::JSC_DEFINE_HOST_FUNCTION):
     61        (JSC::defaultMergeFields):
     62        * runtime/TemporalCalendarPrototype.h: Added.
     63        * runtime/TemporalObject.cpp:
     64        (JSC::createCalendarConstructor):
     65        * runtime/VM.cpp:
     66        * runtime/VM.h:
     67
    1682021-08-30  Ross Kirsling  <ross.kirsling@sony.com>
    269
  • trunk/Source/JavaScriptCore/DerivedSources-input.xcfilelist

    r279638 r281788  
    170170$(PROJECT_DIR)/runtime/SymbolConstructor.cpp
    171171$(PROJECT_DIR)/runtime/SymbolPrototype.cpp
     172$(PROJECT_DIR)/runtime/TemporalCalendarConstructor.cpp
     173$(PROJECT_DIR)/runtime/TemporalCalendarPrototype.cpp
    172174$(PROJECT_DIR)/runtime/TemporalObject.cpp
    173175$(PROJECT_DIR)/ucd/CaseFolding.txt
  • trunk/Source/JavaScriptCore/DerivedSources-output.xcfilelist

    r279638 r281788  
    6767$(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/SymbolConstructor.lut.h
    6868$(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/SymbolPrototype.lut.h
     69$(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/TemporalCalendarConstructor.lut.h
     70$(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/TemporalCalendarPrototype.lut.h
    6971$(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/TemporalObject.lut.h
    7072$(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/UnicodePatternTables.h
  • trunk/Source/JavaScriptCore/DerivedSources.make

    r279630 r281788  
    192192    SymbolConstructor.lut.h \
    193193    SymbolPrototype.lut.h \
     194    TemporalCalendarConstructor.lut.h \
     195    TemporalCalendarPrototype.lut.h \
    194196    TemporalObject.lut.h \
    195197    WebAssemblyCompileErrorConstructor.lut.h \
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r281684 r281788  
    18481848                E32AB2441DCD75F400D7533A /* MacroAssemblerHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = E380A76B1DCD7195000F89E6 /* MacroAssemblerHelpers.h */; settings = {ATTRIBUTES = (Private, ); }; };
    18491849                E32C3C6923E94C1E00BC97C0 /* UnlinkedCodeBlockGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = E32C3C6823E94C1E00BC97C0 /* UnlinkedCodeBlockGenerator.h */; };
     1850                E32D4DE726DAFD4300D4533A /* TemporalCalendarPrototype.h in Headers */ = {isa = PBXBuildFile; fileRef = E32D4DE126DAFD4200D4533A /* TemporalCalendarPrototype.h */; };
     1851                E32D4DE926DAFD4300D4533A /* TemporalCalendar.h in Headers */ = {isa = PBXBuildFile; fileRef = E32D4DE326DAFD4300D4533A /* TemporalCalendar.h */; };
     1852                E32D4DEA26DAFD4300D4533A /* TemporalCalendarConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = E32D4DE426DAFD4300D4533A /* TemporalCalendarConstructor.h */; };
    18501853                E33095DD23210A1B00EB7856 /* JSInternalFieldObjectImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = E33095DC23210A1400EB7856 /* JSInternalFieldObjectImpl.h */; settings = {ATTRIBUTES = (Private, ); }; };
    18511854                E334CBB521FD96A9000EB178 /* RegExpGlobalData.h in Headers */ = {isa = PBXBuildFile; fileRef = E334CBB321FD96A9000EB178 /* RegExpGlobalData.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    19031906                E39D45F51D39005600B3B377 /* InterpreterInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = E39D9D841D39000600667282 /* InterpreterInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
    19041907                E39D8B2E23021E2600265852 /* WasmOperations.h in Headers */ = {isa = PBXBuildFile; fileRef = E39D8B2D23021E1E00265852 /* WasmOperations.h */; };
     1908                E39DA1DA26DB5E4C00100437 /* TemporalCalendarPrototype.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = E3C4630626DB5DE900896336 /* TemporalCalendarPrototype.lut.h */; };
     1909                E39DA1DB26DB5E5100100437 /* TemporalCalendarConstructor.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = E3C4630526DB5DE900896336 /* TemporalCalendarConstructor.lut.h */; };
    19051910                E39DA4A71B7E8B7C0084F33A /* JSModuleRecord.h in Headers */ = {isa = PBXBuildFile; fileRef = E39DA4A51B7E8B7C0084F33A /* JSModuleRecord.h */; settings = {ATTRIBUTES = (Private, ); }; };
    19061911                E39EEAF322812450008474F4 /* CachedSpecialPropertyAdaptiveStructureWatchpoint.h in Headers */ = {isa = PBXBuildFile; fileRef = E39EEAF22281244C008474F4 /* CachedSpecialPropertyAdaptiveStructureWatchpoint.h */; };
     
    50885093                E3282BBA1FE930A400EDAF71 /* YarrErrorCode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = YarrErrorCode.h; path = yarr/YarrErrorCode.h; sourceTree = "<group>"; };
    50895094                E32C3C6823E94C1E00BC97C0 /* UnlinkedCodeBlockGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnlinkedCodeBlockGenerator.h; sourceTree = "<group>"; };
     5095                E32D4DE026DAFD4200D4533A /* TemporalCalendar.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TemporalCalendar.cpp; sourceTree = "<group>"; };
     5096                E32D4DE126DAFD4200D4533A /* TemporalCalendarPrototype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TemporalCalendarPrototype.h; sourceTree = "<group>"; };
     5097                E32D4DE226DAFD4200D4533A /* TemporalCalendarPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TemporalCalendarPrototype.cpp; sourceTree = "<group>"; };
     5098                E32D4DE326DAFD4300D4533A /* TemporalCalendar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TemporalCalendar.h; sourceTree = "<group>"; };
     5099                E32D4DE426DAFD4300D4533A /* TemporalCalendarConstructor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TemporalCalendarConstructor.h; sourceTree = "<group>"; };
     5100                E32D4DE526DAFD4300D4533A /* TemporalCalendarConstructor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TemporalCalendarConstructor.cpp; sourceTree = "<group>"; };
    50905101                E3305FB020B0F78700CEB82B /* InByVariant.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InByVariant.cpp; sourceTree = "<group>"; };
    50915102                E3305FB120B0F78800CEB82B /* InByVariant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InByVariant.h; sourceTree = "<group>"; };
     
    52035214                E3BFD0BA1DAF807C0065DEA2 /* AccessCaseSnippetParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccessCaseSnippetParams.h; sourceTree = "<group>"; };
    52045215                E3C295DC1ED2CBAA00D3016F /* ObjectPropertyChangeAdaptiveWatchpoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectPropertyChangeAdaptiveWatchpoint.h; sourceTree = "<group>"; };
     5216                E3C4630526DB5DE900896336 /* TemporalCalendarConstructor.lut.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TemporalCalendarConstructor.lut.h; sourceTree = "<group>"; };
     5217                E3C4630626DB5DE900896336 /* TemporalCalendarPrototype.lut.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TemporalCalendarPrototype.lut.h; sourceTree = "<group>"; };
    52055218                E3C694B123026873006FBE42 /* WasmOSREntryData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WasmOSREntryData.h; sourceTree = "<group>"; };
    52065219                E3C694B223026874006FBE42 /* WasmTierUpCount.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WasmTierUpCount.cpp; sourceTree = "<group>"; };
     
    70107023                                996B73131BD9FA2C00331B84 /* SymbolConstructor.lut.h */,
    70117024                                996B73141BD9FA2C00331B84 /* SymbolPrototype.lut.h */,
     7025                                E3C4630526DB5DE900896336 /* TemporalCalendarConstructor.lut.h */,
     7026                                E3C4630626DB5DE900896336 /* TemporalCalendarPrototype.lut.h */,
    70127027                                F6F150202693D450004B98EF /* TemporalObject.lut.h */,
    70137028                                533B15DE1DC7F463004D500A /* WasmOps.h */,
     
    79547969                                BDB4B5E099CD4C1BB3C1CF05 /* TemplateObjectDescriptor.cpp */,
    79557970                                70ECA6041AFDBEA200449739 /* TemplateObjectDescriptor.h */,
     7971                                E32D4DE026DAFD4200D4533A /* TemporalCalendar.cpp */,
     7972                                E32D4DE326DAFD4300D4533A /* TemporalCalendar.h */,
     7973                                E32D4DE526DAFD4300D4533A /* TemporalCalendarConstructor.cpp */,
     7974                                E32D4DE426DAFD4300D4533A /* TemporalCalendarConstructor.h */,
     7975                                E32D4DE226DAFD4200D4533A /* TemporalCalendarPrototype.cpp */,
     7976                                E32D4DE126DAFD4200D4533A /* TemporalCalendarPrototype.h */,
    79567977                                F6F1501B2693D33E004B98EF /* TemporalNow.cpp */,
    79577978                                F6F150182693D33D004B98EF /* TemporalNow.h */,
     
    1065010671                                DC7997831CDE9FA0004D4A09 /* TagRegistersMode.h in Headers */,
    1065110672                                70ECA6091AFDBEA200449739 /* TemplateObjectDescriptor.h in Headers */,
     10673                                E32D4DE926DAFD4300D4533A /* TemporalCalendar.h in Headers */,
     10674                                E32D4DEA26DAFD4300D4533A /* TemporalCalendarConstructor.h in Headers */,
     10675                                E39DA1DB26DB5E5100100437 /* TemporalCalendarConstructor.lut.h in Headers */,
     10676                                E32D4DE726DAFD4300D4533A /* TemporalCalendarPrototype.h in Headers */,
     10677                                E39DA1DA26DB5E4C00100437 /* TemporalCalendarPrototype.lut.h in Headers */,
    1065210678                                F6F150212693D450004B98EF /* TemporalObject.lut.h in Headers */,
    1065310679                                0F24E54F17EE274900ABB217 /* TempRegisterSet.h in Headers */,
  • trunk/Source/JavaScriptCore/Sources.txt

    r281757 r281788  
    10111011runtime/SymbolTable.cpp
    10121012runtime/TemplateObjectDescriptor.cpp
     1013runtime/TemporalCalendar.cpp
     1014runtime/TemporalCalendarConstructor.cpp
     1015runtime/TemporalCalendarPrototype.cpp
    10131016runtime/TemporalNow.cpp
    10141017runtime/TemporalObject.cpp
  • trunk/Source/JavaScriptCore/runtime/CommonIdentifiers.h

    r281375 r281788  
    111111    macro(enumerable) \
    112112    macro(era) \
     113    macro(eraYear) \
    113114    macro(errors) \
    114115    macro(eval) \
     
    170171    macro(minute) \
    171172    macro(month) \
     173    macro(monthCode) \
    172174    macro(multiline) \
    173175    macro(name) \
  • trunk/Source/JavaScriptCore/runtime/IntlObject.cpp

    r281776 r281788  
    15761576}
    15771577
     1578const Vector<String>& intlAvailableCalendars()
     1579{
     1580    static LazyNeverDestroyed<Vector<String>> availableCalendars;
     1581    static std::once_flag initializeOnce;
     1582    std::call_once(initializeOnce, [&] {
     1583        availableCalendars.construct();
     1584        ASSERT(availableCalendars->isEmpty());
     1585
     1586        UErrorCode status = U_ZERO_ERROR;
     1587        auto enumeration = std::unique_ptr<UEnumeration, ICUDeleter<uenum_close>>(ucal_getKeywordValuesForLocale("calendars", "und", false, &status));
     1588        ASSERT(U_SUCCESS(status));
     1589
     1590        int32_t count = uenum_count(enumeration.get(), &status);
     1591        ASSERT(U_SUCCESS(status));
     1592        availableCalendars->reserveInitialCapacity(count);
     1593
     1594        auto createImmortalThreadSafeString = [&](String&& string) {
     1595            if (string.is8Bit())
     1596                return StringImpl::createStaticStringImpl(string.characters8(), string.length());
     1597            return StringImpl::createStaticStringImpl(string.characters16(), string.length());
     1598        };
     1599
     1600        for (int32_t index = 0; index < count; ++index) {
     1601            int32_t length = 0;
     1602            const char* pointer = uenum_next(enumeration.get(), &length, &status);
     1603            ASSERT(U_SUCCESS(status));
     1604            String calendar(pointer, length);
     1605            if (auto mapped = mapICUCalendarKeywordToBCP47(calendar))
     1606                availableCalendars->append(createImmortalThreadSafeString(WTFMove(mapped.value())));
     1607            else
     1608                availableCalendars->append(createImmortalThreadSafeString(WTFMove(calendar)));
     1609        }
     1610
     1611        // The AvailableCalendars abstract operation returns a List, ordered as if an Array of the same
     1612        // values had been sorted using %Array.prototype.sort% using undefined as comparefn
     1613        std::sort(availableCalendars->begin(), availableCalendars->end(),
     1614            [](const String& a, const String& b) {
     1615                return WTF::codePointCompare(a, b) < 0;
     1616            });
     1617    });
     1618    return availableCalendars;
     1619}
     1620
     1621CalendarID iso8601CalendarIDStorage { std::numeric_limits<CalendarID>::max() };
     1622CalendarID iso8601CalendarIDSlow()
     1623{
     1624    static std::once_flag initializeOnce;
     1625    std::call_once(initializeOnce, [&] {
     1626        const auto& calendars = intlAvailableCalendars();
     1627        for (unsigned index = 0; index < calendars.size(); ++index) {
     1628            if (calendars[index] == "iso8601"_s) {
     1629                iso8601CalendarIDStorage = index;
     1630                return;
     1631            }
     1632        }
     1633        RELEASE_ASSERT_NOT_REACHED();
     1634    });
     1635    return iso8601CalendarIDStorage;
     1636}
     1637
    15781638// https://tc39.es/proposal-intl-enumeration/#sec-availablecalendars
    15791639static JSArray* availableCalendars(JSGlobalObject* globalObject)
    15801640{
    1581     VM& vm = globalObject->vm();
    1582     auto scope = DECLARE_THROW_SCOPE(vm);
    1583 
    1584     UErrorCode status = U_ZERO_ERROR;
    1585     auto enumeration = std::unique_ptr<UEnumeration, ICUDeleter<uenum_close>>(ucal_getKeywordValuesForLocale("calendars", "und", false, &status));
    1586     if (U_FAILURE(status)) {
    1587         throwTypeError(globalObject, scope, "failed to enumerate available calendars"_s);
    1588         return { };
    1589     }
    1590 
    1591     int32_t count = uenum_count(enumeration.get(), &status);
    1592     if (U_FAILURE(status)) {
    1593         throwTypeError(globalObject, scope, "failed to enumerate available calendars"_s);
    1594         return { };
    1595     }
    1596 
    1597     Vector<String, 1> elements;
    1598     elements.reserveInitialCapacity(count);
    1599     for (int32_t index = 0; index < count; ++index) {
    1600         int32_t length = 0;
    1601         const char* pointer = uenum_next(enumeration.get(), &length, &status);
    1602         if (U_FAILURE(status)) {
    1603             throwTypeError(globalObject, scope, "failed to enumerate available calendars"_s);
    1604             return { };
    1605         }
    1606         String calendar(pointer, length);
    1607         if (auto mapped = mapICUCalendarKeywordToBCP47(calendar))
    1608             elements.append(WTFMove(mapped.value()));
    1609         else
    1610             elements.append(WTFMove(calendar));
    1611     }
    1612 
    1613     // The AvailableCalendars abstract operation returns a List, ordered as if an Array of the same
    1614     // values had been sorted using %Array.prototype.sort% using undefined as comparefn
    1615     std::sort(elements.begin(), elements.end(),
    1616         [](const String& a, const String& b) {
    1617             return WTF::codePointCompare(a, b) < 0;
    1618         });
    1619 
    1620     RELEASE_AND_RETURN(scope, createArrayFromStringVector(globalObject, WTFMove(elements)));
     1641    return createArrayFromStringVector(globalObject, intlAvailableCalendars());
    16211642}
    16221643
     
    18661887}
    18671888
    1868 JSArray* createArrayFromStringVector(JSGlobalObject* globalObject, Vector<String, 1>&& elements)
    1869 {
    1870     VM& vm = globalObject->vm();
    1871     auto scope = DECLARE_THROW_SCOPE(vm);
    1872 
    1873     JSArray* result = JSArray::tryCreate(vm, globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous), elements.size());
    1874     if (!result) {
    1875         throwOutOfMemoryError(globalObject, scope);
    1876         return nullptr;
    1877     }
    1878     for (unsigned index = 0; index < elements.size(); ++index) {
    1879         result->putDirectIndex(globalObject, index, jsString(vm, WTFMove(elements[index])));
    1880         RETURN_IF_EXCEPTION(scope, { });
    1881     }
    1882     return result;
    1883 }
    1884 
    18851889} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/IntlObject.h

    r281513 r281788  
    102102inline const LocaleSet& intlListFormatAvailableLocales() { return intlAvailableLocales(); }
    103103
     104using CalendarID = unsigned;
     105const Vector<String>& intlAvailableCalendars();
     106
     107extern CalendarID iso8601CalendarIDStorage;
     108CalendarID iso8601CalendarIDSlow();
     109inline CalendarID iso8601CalendarID()
     110{
     111    unsigned value = iso8601CalendarIDStorage;
     112    if (value == std::numeric_limits<CalendarID>::max())
     113        return iso8601CalendarIDSlow();
     114    return value;
     115}
     116
    104117TriState intlBooleanOption(JSGlobalObject*, JSObject* options, PropertyName);
    105118String intlStringOption(JSGlobalObject*, JSObject* options, PropertyName, std::initializer_list<const char*> values, const char* notFound, const char* fallback);
     
    149162std::optional<String> mapBCP47ToICUCalendarKeyword(const String&);
    150163
    151 JSArray* createArrayFromStringVector(JSGlobalObject*, Vector<String, 1>&&);
    152 
    153164} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/IntlObjectInlines.h

    r278035 r281788  
    226226}
    227227
     228template<typename Container>
     229JSArray* createArrayFromStringVector(JSGlobalObject* globalObject, const Container& elements)
     230{
     231    VM& vm = globalObject->vm();
     232    auto scope = DECLARE_THROW_SCOPE(vm);
     233
     234    JSArray* result = JSArray::tryCreate(vm, globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous), elements.size());
     235    if (!result) {
     236        throwOutOfMemoryError(globalObject, scope);
     237        return nullptr;
     238    }
     239    for (unsigned index = 0; index < elements.size(); ++index) {
     240        result->putDirectIndex(globalObject, index, jsString(vm, elements[index]));
     241        RETURN_IF_EXCEPTION(scope, { });
     242    }
     243    return result;
     244}
     245
    228246} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp

    r280760 r281788  
    202202#include "SymbolObject.h"
    203203#include "SymbolPrototype.h"
     204#include "TemporalCalendar.h"
     205#include "TemporalCalendarConstructor.h"
     206#include "TemporalCalendarPrototype.h"
    204207#include "TemporalObject.h"
    205208#include "VMTrapsInlines.h"
     
    12131216
    12141217    if (Options::useTemporal()) {
     1218        m_calendarStructure.initLater(
     1219            [] (const Initializer<Structure>& init) {
     1220                JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner);
     1221                TemporalCalendarPrototype* calendarPrototype = TemporalCalendarPrototype::create(init.vm, globalObject, TemporalCalendarPrototype::createStructure(init.vm, globalObject, globalObject->objectPrototype()));
     1222                init.set(TemporalCalendar::createStructure(init.vm, globalObject, calendarPrototype));
     1223            });
     1224
    12151225        TemporalObject* temporal = TemporalObject::create(vm, TemporalObject::createStructure(vm, this));
    12161226        putDirectWithoutTransition(vm, vm.propertyNames->Temporal, temporal, static_cast<unsigned>(PropertyAttribute::DontEnum));
     
    20912101    thisObject->m_numberFormatStructure.visit(visitor);
    20922102
     2103    thisObject->m_calendarStructure.visit(visitor);
     2104
    20932105    visitor.append(thisObject->m_nullGetterFunction);
    20942106    visitor.append(thisObject->m_nullSetterFunction);
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r281429 r281788  
    325325    LazyClassStructure m_numberFormatStructure;
    326326
     327    LazyProperty<JSGlobalObject, Structure> m_calendarStructure;
     328
    327329    WriteBarrier<NullGetterFunction> m_nullGetterFunction;
    328330    WriteBarrier<NullSetterFunction> m_nullSetterFunction;
     
    871873    JSObject* numberFormatPrototype() { return m_numberFormatStructure.prototype(this); }
    872874
     875    Structure* calendarStructure() { return m_calendarStructure.get(this); }
     876
    873877    JS_EXPORT_PRIVATE void setRemoteDebuggingEnabled(bool);
    874878    JS_EXPORT_PRIVATE bool remoteDebuggingEnabled() const;
  • trunk/Source/JavaScriptCore/runtime/TemporalObject.cpp

    r280506 r281788  
    11/*
    22 *  Copyright (C) 2021 Igalia S.L. All rights reserved.
     3 *  Copyright (C) 2021 Apple Inc. All rights reserved.
    34 *
    45 *  This library is free software; you can redistribute it and/or
     
    2122#include "TemporalObject.h"
    2223
     24#include "FunctionPrototype.h"
    2325#include "JSCJSValueInlines.h"
    2426#include "JSGlobalObject.h"
    2527#include "JSObjectInlines.h"
    2628#include "ObjectPrototype.h"
     29#include "TemporalCalendarConstructor.h"
     30#include "TemporalCalendarPrototype.h"
    2731#include "TemporalNow.h"
    2832
     
    3034
    3135STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(TemporalObject);
     36
     37static JSValue createCalendarConstructor(VM& vm, JSObject* object)
     38{
     39    TemporalObject* temporalObject = jsCast<TemporalObject*>(object);
     40    JSGlobalObject* globalObject = temporalObject->globalObject(vm);
     41    return TemporalCalendarConstructor::create(vm, TemporalCalendarConstructor::createStructure(vm, globalObject, globalObject->functionPrototype()), jsCast<TemporalCalendarPrototype*>(globalObject->calendarStructure()->storedPrototypeObject()));
     42}
    3243
    3344static JSValue createNowObject(VM& vm, JSObject* object)
     
    4657/* Source for TemporalObject.lut.h
    4758@begin temporalObjectTable
     59  Calendar       createCalendarConstructor       DontEnum|PropertyCallback
    4860  Now            createNowObject                 DontEnum|PropertyCallback
    4961@end
  • trunk/Source/JavaScriptCore/runtime/VM.cpp

    r279216 r281788  
    163163#include "StructureInlines.h"
    164164#include "SymbolObject.h"
     165#include "TemporalCalendar.h"
    165166#include "TestRunnerUtils.h"
    166167#include "ThunkGenerators.h"
     
    15851586DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(symbolObjectSpace, cellHeapCellType.get(), SymbolObject)
    15861587DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(templateObjectDescriptorSpace, destructibleCellHeapCellType.get(), JSTemplateObjectDescriptor)
     1588DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(temporalCalendarSpace, cellHeapCellType.get(), TemporalCalendar)
    15871589DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(uint8ArraySpace, cellHeapCellType.get(), JSUint8Array)
    15881590DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(uint8ClampedArraySpace, cellHeapCellType.get(), JSUint8ClampedArray)
  • trunk/Source/JavaScriptCore/runtime/VM.h

    r279976 r281788  
    194194class VirtualRegister;
    195195class VMEntryScope;
     196class TemporalCalendar;
    196197class TopLevelGlobalObjectScope;
    197198class TypeProfiler;
     
    592593    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(symbolObjectSpace)
    593594    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(templateObjectDescriptorSpace)
     595    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(temporalCalendarSpace)
    594596    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(uint8ArraySpace)
    595597    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(uint8ClampedArraySpace)
  • trunk/Source/WTF/ChangeLog

    r281771 r281788  
     12021-08-30  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Implement Temporal.Calendar
     4        https://bugs.webkit.org/show_bug.cgi?id=229651
     5
     6        Reviewed by Ross Kirsling.
     7
     8        Add UChar version of createStaticStringImpl to make immortal thread-safe StringImpl with UChar.
     9
     10        * wtf/text/StringImpl.cpp:
     11        (WTF::StringImpl::createStaticStringImpl):
     12        * wtf/text/StringImpl.h:
     13        (WTF::StringImpl::createStaticStringImpl):
     14
    1152021-08-30  Sihui Liu  <sihui_liu@apple.com>
    216
  • trunk/Source/WTF/wtf/text/StringImpl.cpp

    r281513 r281788  
    285285}
    286286
    287 Ref<StringImpl> StringImpl::createStaticStringImpl(const char* characters, unsigned length)
    288 {
    289     const LChar* lcharCharacters = reinterpret_cast<const LChar*>(characters);
    290     ASSERT(charactersAreAllASCII(lcharCharacters, length));
    291     Ref<StringImpl> result = createInternal(lcharCharacters, length);
    292     result->setHash(StringHasher::computeHashAndMaskTop8Bits(lcharCharacters, length));
     287Ref<StringImpl> StringImpl::createStaticStringImpl(const LChar* characters, unsigned length)
     288{
     289    if (!length)
     290        return *empty();
     291    Ref<StringImpl> result = createInternal(characters, length);
     292    result->hash();
     293    result->m_refCount |= s_refCountFlagIsStaticString;
     294    return result;
     295}
     296
     297Ref<StringImpl> StringImpl::createStaticStringImpl(const UChar* characters, unsigned length)
     298{
     299    if (!length)
     300        return *empty();
     301    Ref<StringImpl> result = create8BitIfPossible(characters, length);
     302    result->hash();
    293303    result->m_refCount |= s_refCountFlagIsStaticString;
    294304    return result;
  • trunk/Source/WTF/wtf/text/StringImpl.h

    r281737 r281788  
    260260    template<typename CharacterType> static RefPtr<StringImpl> tryCreateUninitialized(unsigned length, CharacterType*&);
    261261
    262     WTF_EXPORT_PRIVATE static Ref<StringImpl> createStaticStringImpl(const char*, unsigned length);
     262    static Ref<StringImpl> createStaticStringImpl(const char* characters, unsigned length)
     263    {
     264        ASSERT(charactersAreAllASCII(bitwise_cast<const LChar*>(characters), length));
     265        return createStaticStringImpl(bitwise_cast<const LChar*>(characters), length);
     266    }
     267    WTF_EXPORT_PRIVATE static Ref<StringImpl> createStaticStringImpl(const LChar*, unsigned length);
     268    WTF_EXPORT_PRIVATE static Ref<StringImpl> createStaticStringImpl(const UChar*, unsigned length);
    263269
    264270    // Reallocate the StringImpl. The originalString must be only owned by the Ref,
Note: See TracChangeset for help on using the changeset viewer.