commit-queue@webkit.org | 77e4cc2 | 2015-07-30 03:33:32 +0000 | [diff] [blame] | 1 | /* |
commit-queue@webkit.org | cc0ef6d | 2018-05-07 22:44:28 +0000 | [diff] [blame] | 2 | * Copyright (C) 2015 Andy VanWagoner (andy@vanwagoner.family) |
commit-queue@webkit.org | 77e4cc2 | 2015-07-30 03:33:32 +0000 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
ryanhaddad@apple.com | 22104f5 | 2016-09-28 17:08:17 +0000 | [diff] [blame] | 26 | #pragma once |
commit-queue@webkit.org | 77e4cc2 | 2015-07-30 03:33:32 +0000 | [diff] [blame] | 27 | |
ysuzuki@apple.com | 827d8d8 | 2019-12-03 01:47:31 +0000 | [diff] [blame] | 28 | #include "JSObject.h" |
commit-queue@webkit.org | b07fa91 | 2015-12-23 21:50:47 +0000 | [diff] [blame] | 29 | #include <unicode/udat.h> |
commit-queue@webkit.org | c8f5856 | 2017-04-21 17:58:32 +0000 | [diff] [blame] | 30 | |
commit-queue@webkit.org | 77e4cc2 | 2015-07-30 03:33:32 +0000 | [diff] [blame] | 31 | namespace JSC { |
| 32 | |
commit-queue@webkit.org | 77e4cc2 | 2015-07-30 03:33:32 +0000 | [diff] [blame] | 33 | class JSBoundFunction; |
| 34 | |
ysuzuki@apple.com | 827d8d8 | 2019-12-03 01:47:31 +0000 | [diff] [blame] | 35 | class IntlDateTimeFormat final : public JSNonFinalObject { |
commit-queue@webkit.org | 77e4cc2 | 2015-07-30 03:33:32 +0000 | [diff] [blame] | 36 | public: |
ysuzuki@apple.com | 827d8d8 | 2019-12-03 01:47:31 +0000 | [diff] [blame] | 37 | using Base = JSNonFinalObject; |
| 38 | |
| 39 | static constexpr bool needsDestruction = true; |
| 40 | |
| 41 | static void destroy(JSCell* cell) |
| 42 | { |
| 43 | static_cast<IntlDateTimeFormat*>(cell)->IntlDateTimeFormat::~IntlDateTimeFormat(); |
| 44 | } |
| 45 | |
| 46 | template<typename CellType, SubspaceAccess mode> |
| 47 | static IsoSubspace* subspaceFor(VM& vm) |
| 48 | { |
| 49 | return vm.intlDateTimeFormatSpace<mode>(); |
| 50 | } |
commit-queue@webkit.org | 77e4cc2 | 2015-07-30 03:33:32 +0000 | [diff] [blame] | 51 | |
utatane.tea@gmail.com | f77bece | 2016-05-15 21:11:27 +0000 | [diff] [blame] | 52 | static IntlDateTimeFormat* create(VM&, Structure*); |
commit-queue@webkit.org | 77e4cc2 | 2015-07-30 03:33:32 +0000 | [diff] [blame] | 53 | static Structure* createStructure(VM&, JSGlobalObject*, JSValue); |
| 54 | |
| 55 | DECLARE_INFO; |
| 56 | |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 57 | void initializeDateTimeFormat(JSGlobalObject*, JSValue locales, JSValue options); |
ross.kirsling@sony.com | 22951d3 | 2020-05-05 18:21:32 +0000 | [diff] [blame] | 58 | JSValue format(JSGlobalObject*, double value) const; |
| 59 | JSValue formatToParts(JSGlobalObject*, double value) const; |
| 60 | JSObject* resolvedOptions(JSGlobalObject*) const; |
commit-queue@webkit.org | 5db3dc4 | 2015-12-23 10:48:26 +0000 | [diff] [blame] | 61 | |
commit-queue@webkit.org | 77e4cc2 | 2015-07-30 03:33:32 +0000 | [diff] [blame] | 62 | JSBoundFunction* boundFormat() const { return m_boundFormat.get(); } |
| 63 | void setBoundFormat(VM&, JSBoundFunction*); |
| 64 | |
ross.kirsling@sony.com | 02ea60d | 2020-04-21 06:11:07 +0000 | [diff] [blame] | 65 | private: |
commit-queue@webkit.org | 77e4cc2 | 2015-07-30 03:33:32 +0000 | [diff] [blame] | 66 | IntlDateTimeFormat(VM&, Structure*); |
| 67 | void finishCreation(VM&); |
commit-queue@webkit.org | 77e4cc2 | 2015-07-30 03:33:32 +0000 | [diff] [blame] | 68 | static void visitChildren(JSCell*, SlotVisitor&); |
| 69 | |
ross.kirsling@sony.com | 774a736 | 2020-04-30 03:00:35 +0000 | [diff] [blame] | 70 | static Vector<String> localeData(const String&, size_t); |
| 71 | |
rmorisset@apple.com | 8bf8268 | 2019-03-11 17:54:59 +0000 | [diff] [blame] | 72 | enum class Weekday : uint8_t { None, Narrow, Short, Long }; |
| 73 | enum class Era : uint8_t { None, Narrow, Short, Long }; |
| 74 | enum class Year : uint8_t { None, TwoDigit, Numeric }; |
| 75 | enum class Month : uint8_t { None, TwoDigit, Numeric, Narrow, Short, Long }; |
| 76 | enum class Day : uint8_t { None, TwoDigit, Numeric }; |
| 77 | enum class Hour : uint8_t { None, TwoDigit, Numeric }; |
| 78 | enum class Minute : uint8_t { None, TwoDigit, Numeric }; |
| 79 | enum class Second : uint8_t { None, TwoDigit, Numeric }; |
| 80 | enum class TimeZoneName : uint8_t { None, Short, Long }; |
commit-queue@webkit.org | 5db3dc4 | 2015-12-23 10:48:26 +0000 | [diff] [blame] | 81 | |
sukolsak@gmail.com | ee0d79a | 2016-02-22 01:55:41 +0000 | [diff] [blame] | 82 | struct UDateFormatDeleter { |
| 83 | void operator()(UDateFormat*) const; |
| 84 | }; |
| 85 | |
| 86 | void setFormatsFromPattern(const StringView&); |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 87 | static ASCIILiteral weekdayString(Weekday); |
| 88 | static ASCIILiteral eraString(Era); |
| 89 | static ASCIILiteral yearString(Year); |
| 90 | static ASCIILiteral monthString(Month); |
| 91 | static ASCIILiteral dayString(Day); |
| 92 | static ASCIILiteral hourString(Hour); |
| 93 | static ASCIILiteral minuteString(Minute); |
| 94 | static ASCIILiteral secondString(Second); |
| 95 | static ASCIILiteral timeZoneNameString(TimeZoneName); |
commit-queue@webkit.org | 5db3dc4 | 2015-12-23 10:48:26 +0000 | [diff] [blame] | 96 | |
commit-queue@webkit.org | 77e4cc2 | 2015-07-30 03:33:32 +0000 | [diff] [blame] | 97 | WriteBarrier<JSBoundFunction> m_boundFormat; |
sukolsak@gmail.com | ee0d79a | 2016-02-22 01:55:41 +0000 | [diff] [blame] | 98 | std::unique_ptr<UDateFormat, UDateFormatDeleter> m_dateFormat; |
commit-queue@webkit.org | 5db3dc4 | 2015-12-23 10:48:26 +0000 | [diff] [blame] | 99 | |
sukolsak@gmail.com | ee0d79a | 2016-02-22 01:55:41 +0000 | [diff] [blame] | 100 | String m_locale; |
| 101 | String m_calendar; |
| 102 | String m_numberingSystem; |
| 103 | String m_timeZone; |
commit-queue@webkit.org | a779d0e | 2018-08-01 21:19:27 +0000 | [diff] [blame] | 104 | String m_hourCycle; |
commit-queue@webkit.org | 5db3dc4 | 2015-12-23 10:48:26 +0000 | [diff] [blame] | 105 | Weekday m_weekday { Weekday::None }; |
| 106 | Era m_era { Era::None }; |
| 107 | Year m_year { Year::None }; |
| 108 | Month m_month { Month::None }; |
| 109 | Day m_day { Day::None }; |
| 110 | Hour m_hour { Hour::None }; |
| 111 | Minute m_minute { Minute::None }; |
| 112 | Second m_second { Second::None }; |
| 113 | TimeZoneName m_timeZoneName { TimeZoneName::None }; |
commit-queue@webkit.org | 77e4cc2 | 2015-07-30 03:33:32 +0000 | [diff] [blame] | 114 | }; |
commit-queue@webkit.org | 77e4cc2 | 2015-07-30 03:33:32 +0000 | [diff] [blame] | 115 | |
| 116 | } // namespace JSC |