Commit graph

131 commits

Author SHA1 Message Date
Idan Horowitz
ace36681ff LibJS+LibIMAP: Use the new Optional<U>(Optional<T>) constructor
These look much nicer than these repeated ternaries :^)
2022-01-23 18:53:42 +02:00
Linus Groh
0e3def1d0b LibJS: Don't parse/re-format offset in parse_temporal_time_zone_string()
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/6abe146
2022-01-23 00:22:10 +00:00
Linus Groh
6d744eb4a7 LibJS: Use consistent name for offset strings
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/17f8cdb
2022-01-23 00:22:10 +00:00
Linus Groh
b9093dd0ab LibJS: Don't validate time zone name when parsing Instant string
This is normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/2a81fbc
2022-01-13 10:08:34 +01:00
Linus Groh
392f5bfebd LibJS: Fix fraction substring range in parse_temporal_time_zone_string()
Two issues:

- The intended range was 9 characters starting from index 1. Since the
  second argument to String::substring() is the length, 10 is
  potentially reading further than the string's length (when only
  providing one fraction digit), causing an assertion failure crash.
- The spec's intention to skip the decimal separator by starting at
  index 1 is incorrect, no decimal separator is present in the result of
  parsing TimeZoneUTCOffsetFractionalPart. I filed a spec fix for this,
  see: https://github.com/tc39/proposal-temporal/pull/1999
2022-01-12 21:24:12 +01:00
Linus Groh
027e4bd439 LibJS: Fix calculation overflow in parse_temporal_time_zone_string()
As all variables and numeric literals in the expression have an integral
data type, it would evaluate to an int and could easily overflow as
we're multiplying seconds with 10^9.

Introduce a floating point literal into the expression to make it result
in a double.
2022-01-12 21:24:12 +01:00
Linus Groh
323e1e17cf LibJS: Fix sign data type in parse_temporal_time_zone_string()
A sign that's either the value 1 or -1 should obviously not have an
unsigned data type :^)

This would cause it to become 255 for the negative offset case, which
would then completely screw up the offset_nanoseconds calculation as it
serves as a multiplier.
2022-01-12 21:24:12 +01:00
Linus Groh
09a11fa6ea LibJS: Implement proper Iterator records
Instead of using plain objects as Iterator records, causes confusion
about the object itself actually being its [[Iterator]] slot, and
requires non-standard type conversion shenanigans fpr the [[NextValue]]
and [[Done]] internal slots,  implement a proper Iterator record struct
and use it throughout.

Also annotate the remaining Iterator AOs with spec comments while we're
here.
2022-01-09 22:02:43 +01:00
Linus Groh
3301b0b33d LibJS: Remove duplicate assignment step from parse_iso_date_time()
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/eb68de2
2022-01-08 00:31:28 +01:00
Linus Groh
d42336312c LibJS: Include time zone name in TemporalInvalidTimeZoneName error 2022-01-06 21:49:50 +01:00
Linus Groh
29e96eceeb LibJS: Convert PropertyKey::from_value() to ThrowCompletionOr
Lots of MUST() - perhaps we'll eventually come up with a better API for
the common case where it can't fail.
2022-01-04 23:37:26 +00:00
Linus Groh
3ab1c52e2b LibJS: Require 'T' prefix for ambiguous time-only strings
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/514ede3
2021-12-24 00:07:52 +01:00
Linus Groh
9271005357 LibJS: Fix typo in spec comment 2021-12-19 09:35:02 +00:00
Linus Groh
f7fe7f8c77 LibJS: Capture TimeFraction parse result instead of Fraction
Not much of a difference as TimeFraction just parses Fraction, but let's
do it correctly. Small mistake I did in 4b7f716.

Thanks to YouTube user gla3dr for noticing this :^)
2021-12-19 09:29:46 +00:00
Linus Groh
4b7f716f21 LibJS: Fix ambiguity in FractionalPart grammar
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/0f11bd6
2021-12-18 22:32:39 +00:00
Linus Groh
006bea5d31 LibJS: Remove outdated comment in prepare_partial_temporal_fields()
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/bf066ea
2021-12-18 22:32:39 +00:00
Linus Groh
7270bbb255 LibJS: Remove outdated comment from parse_temporal_duration_string()
This is a normative change in the Temporal spec.

See:

- https://github.com/tc39/proposal-temporal/commit/e7182d3
- https://github.com/tc39/proposal-temporal/commit/6dae066
2021-12-18 22:32:39 +00:00
Luke Wilde
4f3c283f24 LibJS: Move calendar validation out of parse_temporal_calendar_string
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/7207a1c
2021-12-08 19:11:50 +00:00
Luke Wilde
80dcddacea LibJS: Simplify return in parse_temporal_date_time_string
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/1f7e486
2021-12-08 19:11:50 +00:00
Luke Wilde
6244969ae2 LibJS: Remove duplicated spec step in parse_iso_date_time
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/516bf24
2021-12-08 19:11:50 +00:00
Timothy Flynn
1039159a6c LibJS: Change LargerOfTwoTemporalUnits AO to return a StringView 2021-11-30 00:01:07 +00:00
Linus Groh
f7ba81ac52 LibJS: Implement parsing of TemporalDurationString 2021-11-28 10:32:28 +00:00
Linus Groh
1e41a8668d LibJS: Add sign(Crypto::SignedBigInteger const&) overload 2021-11-24 17:53:00 +00:00
Linus Groh
78724fdd33 LibJS: Don't accept UTC designators in strings for plain Temporal types
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/cd2dc7d
2021-11-24 08:56:03 +00:00
Linus Groh
836ce8ee5d LibJS: Fix parse ErrorType used in parse_temporal_date_string()
TemporalInvalidDateString, not TemporalInvalidDateTimeString.
2021-11-24 08:38:50 +00:00
Linus Groh
55dbd19a16 LibJS: Update to_largest_temporal_unit() to allow undefined fallback
This is required for Temporal.Duration.prototype.round(). Subsequently,
this now returns ThrowCompletionOr<Optional<String>>, which brings the
signature in line with that of to_smallest_temporal_unit().
Much nicer! :^)
2021-11-23 21:03:05 +00:00
Linus Groh
783222f87a LibJS: Implement parsing of TemporalInstantString 2021-11-20 23:10:09 +00:00
Linus Groh
79a18b058f LibJS: Implement parsing of TemporalCalendarString 2021-11-20 23:10:09 +00:00
Linus Groh
1583c7257c LibJS: Implement parsing of TemporalRelativeToString 2021-11-20 23:10:09 +00:00
Linus Groh
98b876ad3f LibJS: Implement parsing of TemporalZonedDateTimeString 2021-11-20 23:10:09 +00:00
Linus Groh
3b1de431cc LibJS: Implement parsing of TemporalYearMonthString 2021-11-20 23:10:09 +00:00
Linus Groh
3ddab2f4fe LibJS: Implement parsing of TemporalMonthDayString 2021-11-20 23:10:09 +00:00
Linus Groh
453c78215c LibJS: Implement parsing of TemporalTimeString 2021-11-20 23:10:09 +00:00
Linus Groh
b42b7d5f16 LibJS: Implement parsing of TemporalDateTimeString 2021-11-20 23:10:09 +00:00
Linus Groh
02e7de2cba LibJS: Implement parsing of TemporalDateString 2021-11-20 23:10:09 +00:00
Linus Groh
9628452550 LibJS: Fix fallback of hour, minute, second in parse_iso_date_time()
It's not the `to_uint<u8>()` call that would fail, if we have a value
for these productions they will always be valid numbers. We do need to
provide a fallback for when that's not the case and any of them is
undefined, i.e. an empty Optional.
2021-11-20 23:10:09 +00:00
Linus Groh
de23f0b68c LibJS: Start fleshing out an ISO 8601 parser for Temporal
This is the start of a parser for the ISO 8601 grammar used in the
Temporal spec:
https://tc39.es/proposal-temporal/#sec-temporal-iso8601grammar

We will, on purpose, not use a generic ISO 8601 parser from AK or
similar for two reasons:

- Many AOs make specific assumptions about which productions exist and
  access them directly, even when they're part of a larger production.
- The spec says "The grammar deviates from the standard given in ISO
  8601 in the following ways:" and then lists 17 of such deviations.
  Making that work with a general purpose parser is not worth it.

The public API is not being used anywhere yet, but will be in the next
couple of commits. Likewise, the Production enum will be populated with
all the productions accessed directly (e.g. TemporalDateString).

Many thanks to Ali for showing me how to improve my initial approach
full of macros with a nice RAII helper - it's much nicer :^)

Co-Authored-By: Ali Mohammad Pur <mpfard@serenityos.org>
2021-11-20 23:10:09 +00:00
Linus Groh
8d6d39e07c LibJS: Treat relativeTo parameters as PlainDate or ZonedDateTime
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/c822e14
2021-11-19 19:59:13 +00:00
Linus Groh
ec1e1f4f12 LibJS: Disallow Temporal.Duration input values to be non-integers
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/8c85450
2021-11-17 22:20:59 +00:00
Luke Wilde
ac65fb40d9 LibJS: Implement Temporal.PlainDate.prototype.since 2021-11-16 01:06:07 +00:00
Linus Groh
dbe70e7c55 LibJS: Implement Temporal.Duration.prototype.total() 2021-11-13 18:50:54 +00:00
Linus Groh
0d9defdad8 LibJS: Rename MatchBehavior members back to their old names
I changed this in 6ef1a27 to "match the spec", but the spec calls it
`match exactly` and `match minutes` - so what we had before was correct
and the change made no sense whatsoever.
2021-11-13 00:25:40 +00:00
Luke Wilde
29072f4b09 LibJS: Implement the required AOs for Temporal.Duration.compare 2021-11-11 21:06:54 +00:00
Linus Groh
fdffdc43fa LibJS: Implement the rest of to_temporal_month_day()
Always throws at the moment, because parse_temporal_month_day_string()
is basically a stub, and parse_iso_date_time() isn't functional either.

The spec issue has been resolved though, so I figured we might as well
get one small step further :^)
2021-11-10 22:28:27 +00:00
Luke Wilde
dc72d416b2 LibJS: Implement the required AOs for ZonedDateTime stringifiers 2021-11-10 12:56:56 +00:00
Linus Groh
c3c9ac93d0 LibJS: Implement Temporal.PlainDate.prototype.with()
With one caveat: in the PreparePartialTemporalFields AO I made a change
to fix a spec issue that would require the input object to always have a
month or monthCode property.
This is tracked in https://github.com/tc39/proposal-temporal/issues/1910
and may get accepted as-is, in which case we simply need to remove the
NOTE comment.
2021-11-08 22:19:45 +00:00
Linus Groh
46d7c34028 LibJS: Use StringView literals in prepare_temporal_fields() 2021-11-08 19:12:47 +00:00
Linus Groh
b2548393d2 LibJS: Implement Temporal.Duration.prototype.toString()
I hereby claim "implemented largest AO in LibJS ever" (450 lines). :^)
2021-11-07 15:31:28 +01:00
Luke Wilde
2b89d2a360 LibJS: Implement ToTemporalZonedDateTime and the required AOs 2021-11-07 15:35:16 +02:00
Linus Groh
0dae7c9420 LibJS: Replace a couple of TODO()'s in Temporal with InternalError
This helps us to distinguish between crashes because of incomplete code
paths and crashes because of genuine bugs more easily when running
test262.
2021-11-04 23:59:40 +01:00