mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
LibJS: Move ISO-related structures to their own file
Currently, AbstractOperations.h needs to include Time.h for the Time structure. Soon, Time.h will need to include AbstractOperations.h for structures defined there. To avoid a circular include, let's put the ISO types into their own file, so that AO.h does not need to include any JS type header.
This commit is contained in:
parent
46998e922a
commit
021a5f4ded
Notes:
github-actions[bot]
2024-11-23 13:47:25 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/021a5f4deda Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2513 Reviewed-by: https://github.com/shannonbooth ✅
8 changed files with 79 additions and 58 deletions
|
@ -18,6 +18,7 @@
|
|||
#include <LibJS/Runtime/Temporal/PlainDate.h>
|
||||
#include <LibJS/Runtime/Temporal/PlainDateTime.h>
|
||||
#include <LibJS/Runtime/Temporal/PlainMonthDay.h>
|
||||
#include <LibJS/Runtime/Temporal/PlainTime.h>
|
||||
#include <LibJS/Runtime/Temporal/PlainYearMonth.h>
|
||||
#include <LibJS/Runtime/Temporal/TimeZone.h>
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include <LibJS/Forward.h>
|
||||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/Temporal/ISO8601.h>
|
||||
#include <LibJS/Runtime/Temporal/PlainTime.h>
|
||||
#include <LibJS/Runtime/Temporal/ISORecords.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibJS/Runtime/ValueInlines.h>
|
||||
#include <math.h>
|
||||
|
@ -134,25 +134,6 @@ struct RelativeTo {
|
|||
GC::Ptr<JS::Object> zoned_relative_to; // [[ZonedRelativeTo]]
|
||||
};
|
||||
|
||||
// 13.31 ISO String Time Zone Parse Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-string-time-zone-parse-records
|
||||
struct ParsedISOTimeZone {
|
||||
bool z_designator { false };
|
||||
Optional<String> offset_string;
|
||||
Optional<String> time_zone_annotation;
|
||||
};
|
||||
|
||||
// 13.32 ISO Date-Time Parse Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-time-parse-records
|
||||
struct ParsedISODateTime {
|
||||
struct StartOfDay { };
|
||||
|
||||
Optional<i32> year { 0 };
|
||||
u8 month { 0 };
|
||||
u8 day { 0 };
|
||||
Variant<StartOfDay, Time> time;
|
||||
ParsedISOTimeZone time_zone;
|
||||
Optional<String> calendar;
|
||||
};
|
||||
|
||||
struct DifferenceSettings {
|
||||
Unit smallest_unit;
|
||||
Unit largest_unit;
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
|
||||
#include <AK/Optional.h>
|
||||
#include <LibCrypto/BigFraction/BigFraction.h>
|
||||
#include <LibCrypto/BigInt/SignedBigInteger.h>
|
||||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
||||
#include <LibJS/Runtime/Temporal/ISORecords.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
|
||||
namespace JS::Temporal {
|
||||
|
@ -89,10 +89,6 @@ struct PartialDuration {
|
|||
Optional<double> nanoseconds;
|
||||
};
|
||||
|
||||
// A time duration is an integer in the inclusive interval from -maxTimeDuration to maxTimeDuration, where
|
||||
// maxTimeDuration = 2**53 × 10**9 - 1 = 9,007,199,254,740,991,999,999,999. It represents the portion of a
|
||||
// Temporal.Duration object that deals with time units, but as a combined value of total nanoseconds.
|
||||
using TimeDuration = Crypto::SignedBigInteger;
|
||||
extern TimeDuration const MAX_TIME_DURATION;
|
||||
|
||||
// 7.5.3 Internal Duration Records, https://tc39.es/proposal-temporal/#sec-temporal-internal-duration-records
|
||||
|
|
72
Libraries/LibJS/Runtime/Temporal/ISORecords.h
Normal file
72
Libraries/LibJS/Runtime/Temporal/ISORecords.h
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Tim Flynn <trflynn89@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Types.h>
|
||||
#include <AK/Variant.h>
|
||||
#include <LibCrypto/BigInt/SignedBigInteger.h>
|
||||
|
||||
namespace JS::Temporal {
|
||||
|
||||
// 3.5.1 ISO Date Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-records
|
||||
struct ISODate {
|
||||
i32 year { 0 };
|
||||
u8 month { 0 };
|
||||
u8 day { 0 };
|
||||
};
|
||||
|
||||
// 4.5.1 Time Records, https://tc39.es/proposal-temporal/#sec-temporal-time-records
|
||||
struct Time {
|
||||
double days { 0 };
|
||||
u8 hour { 0 };
|
||||
u8 minute { 0 };
|
||||
u8 second { 0 };
|
||||
u16 millisecond { 0 };
|
||||
u16 microsecond { 0 };
|
||||
u16 nanosecond { 0 };
|
||||
};
|
||||
|
||||
// 5.5.1 ISO Date-Time Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-time-records
|
||||
struct ISODateTime {
|
||||
ISODate iso_date;
|
||||
Time time;
|
||||
};
|
||||
|
||||
// 7.5.3 Internal Duration Records, https://tc39.es/proposal-temporal/#sec-temporal-internal-duration-records
|
||||
// A time duration is an integer in the inclusive interval from -maxTimeDuration to maxTimeDuration, where
|
||||
// maxTimeDuration = 2**53 × 10**9 - 1 = 9,007,199,254,740,991,999,999,999. It represents the portion of a
|
||||
// Temporal.Duration object that deals with time units, but as a combined value of total nanoseconds.
|
||||
using TimeDuration = Crypto::SignedBigInteger;
|
||||
|
||||
// 9.5.1 ISO Year-Month Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-year-month-records
|
||||
struct ISOYearMonth {
|
||||
i32 year { 0 };
|
||||
u8 month { 0 };
|
||||
};
|
||||
|
||||
// 13.31 ISO String Time Zone Parse Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-string-time-zone-parse-records
|
||||
struct ParsedISOTimeZone {
|
||||
bool z_designator { false };
|
||||
Optional<String> offset_string;
|
||||
Optional<String> time_zone_annotation;
|
||||
};
|
||||
|
||||
// 13.32 ISO Date-Time Parse Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-time-parse-records
|
||||
struct ParsedISODateTime {
|
||||
struct StartOfDay { };
|
||||
|
||||
Optional<i32> year { 0 };
|
||||
u8 month { 0 };
|
||||
u8 day { 0 };
|
||||
Variant<StartOfDay, Time> time;
|
||||
ParsedISOTimeZone time_zone;
|
||||
Optional<String> calendar;
|
||||
};
|
||||
|
||||
}
|
|
@ -13,16 +13,10 @@
|
|||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
||||
#include <LibJS/Runtime/Temporal/ISORecords.h>
|
||||
|
||||
namespace JS::Temporal {
|
||||
|
||||
// 3.5.1 ISO Date Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-records
|
||||
struct ISODate {
|
||||
i32 year { 0 };
|
||||
u8 month { 0 };
|
||||
u8 day { 0 };
|
||||
};
|
||||
|
||||
class PlainDate final : public Object {
|
||||
JS_OBJECT(PlainDate, Object);
|
||||
GC_DECLARE_ALLOCATOR(PlainDate);
|
||||
|
|
|
@ -8,17 +8,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Runtime/Temporal/PlainDate.h>
|
||||
#include <LibJS/Runtime/Temporal/PlainTime.h>
|
||||
#include <LibJS/Runtime/Temporal/ISORecords.h>
|
||||
|
||||
namespace JS::Temporal {
|
||||
|
||||
// 5.5.1 ISO Date-Time Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-time-records
|
||||
struct ISODateTime {
|
||||
ISODate iso_date;
|
||||
Time time;
|
||||
};
|
||||
|
||||
ISODateTime combine_iso_date_and_time_record(ISODate, Time);
|
||||
bool iso_date_time_within_limits(ISODateTime);
|
||||
ISODateTime balance_iso_date_time(double year, double month, double day, double hour, double minute, double second, double millisecond, double microsecond, double nanosecond);
|
||||
|
|
|
@ -8,21 +8,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Types.h>
|
||||
#include <LibJS/Runtime/Temporal/ISORecords.h>
|
||||
|
||||
namespace JS::Temporal {
|
||||
|
||||
// 4.5.1 Time Records, https://tc39.es/proposal-temporal/#sec-temporal-time-records
|
||||
struct Time {
|
||||
double days { 0 };
|
||||
u8 hour { 0 };
|
||||
u8 minute { 0 };
|
||||
u8 second { 0 };
|
||||
u16 millisecond { 0 };
|
||||
u16 microsecond { 0 };
|
||||
u16 nanosecond { 0 };
|
||||
};
|
||||
|
||||
Time create_time_record(double hour, double minute, double second, double millisecond, double microsecond, double nanosecond, double delta_days = 0);
|
||||
Time midnight_time_record();
|
||||
Time noon_time_record();
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
||||
#include <LibJS/Runtime/Temporal/ISORecords.h>
|
||||
#include <LibJS/Runtime/Temporal/PlainDate.h>
|
||||
|
||||
namespace JS::Temporal {
|
||||
|
@ -32,12 +33,6 @@ private:
|
|||
String m_calendar; // [[Calendar]]
|
||||
};
|
||||
|
||||
// 9.5.1 ISO Year-Month Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-year-month-records
|
||||
struct ISOYearMonth {
|
||||
i32 year { 0 };
|
||||
u8 month { 0 };
|
||||
};
|
||||
|
||||
ThrowCompletionOr<GC::Ref<PlainYearMonth>> to_temporal_year_month(VM&, Value item, Value options = js_undefined());
|
||||
bool iso_year_month_within_limits(ISODate);
|
||||
ISOYearMonth balance_iso_year_month(double year, double month);
|
||||
|
|
Loading…
Add table
Reference in a new issue