Commit graph

2274 commits

Author SHA1 Message Date
Linus Groh
ad294ff2ee LibJS: Simplify TemporalRelativeToString
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/d3b2e90
2021-11-24 18:18:05 +00:00
Linus Groh
de69f5dbf4 LibJS: Implement Temporal.ZonedDateTime.prototype.since() 2021-11-24 17:53:00 +00:00
Linus Groh
7a2eeae8c6 LibJS: Implement Temporal.ZonedDateTime.prototype.until() 2021-11-24 17:53:00 +00:00
Luke Wilde
7dc846d51c LibJS: Implement balance_duration_relative() 2021-11-24 17:53:00 +00:00
Luke Wilde
9559cea8e5 LibJS: Implement add_duration() 2021-11-24 17:53:00 +00:00
Luke Wilde
1f84deaf63 LibJS: Implement default_temporal_largest_unit() 2021-11-24 17:53:00 +00:00
Luke Wilde
16301a603c LibJS: Implement difference_zoned_date_time() 2021-11-24 17:53:00 +00:00
Linus Groh
1e41a8668d LibJS: Add sign(Crypto::SignedBigInteger const&) overload 2021-11-24 17:53:00 +00:00
Linus Groh
a20b189eab LibJS: Fix incorrectly formatted section comments
A couple of missing URLs, spaces, and a stray comma.
2021-11-24 17:37:27 +00:00
Timothy Flynn
251f692440 LibJS: Re-implement SetNumberFormatDigitOptions AO
This is an editorial change in the Intl spec.

See: https://github.com/tc39/ecma402/commit/d89c84f
2021-11-24 14:17:15 +00:00
Timothy Flynn
a2f629f38a LibJS: Update spec comments in GetOption and DefaultNumberOption AOs
This is an editorial change in the Intl spec.

See: https://github.com/tc39/ecma402/commit/913ca6d
2021-11-24 14:17:15 +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
davidot
0982a73d1d LibJS: Parse async generator functions 2021-11-21 21:46:39 +00:00
davidot
5d0f666f22 LibJS: Don't set a prototype property on async functions
This is now as defined in the spec. However since we execute async
functions in bytecode by transforming it to a generator function it must
have a prototype for the GeneratorObject. We check whether it is an
async function and in that case use the hardcoded generator object
prototype. This also ensures that user code cannot override this
property thus preventing exposing internal implementation details.
2021-11-21 21:46:39 +00:00
davidot
de46a2cff1 LibJS: Parse async arrow functions 2021-11-21 21:46:39 +00:00
Linus Groh
0619c34703 LibJS: Implement Temporal.PlainDateTime.prototype.since() 2021-11-21 20:04:19 +00:00
Linus Groh
803eddbb62 LibJS: Implement Temporal.PlainDateTime.prototype.until() 2021-11-21 20:04:19 +00:00
Linus Groh
aed444253c LibJS: Implement Temporal.PlainTime.prototype.since() 2021-11-21 20:04:19 +00:00
Linus Groh
2ac1774fd3 LibJS: Implement Temporal.PlainTime.prototype.until() 2021-11-21 20:04:19 +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
3f1af7c05f LibJS: Update parse_temporal_time_zone() to match the spec again 2021-11-20 23:10:09 +00:00
Linus Groh
27304017e3 LibJS: Don't assume calendar was parsed in to_temporal_zoned_date_time()
The first step of to_temporal_calendar_with_iso_default() is checking
whether the given value is undefined, so we should actually pass that
instead of unconditionally dereferencing the Optional<String>.
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
2ecb47c985 LibJS: Update spec comments in format_time_zone_offset_string()
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/60c753a
2021-11-19 19:29:18 +00:00
Linus Groh
d0c29c9735 LibJS: Allow string as parameter in Temporal's round() / total()
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/1f0c586
2021-11-19 11:06:53 +00:00
Linus Groh
eaa3329573 LibJS: Fix incorrect use of "modulo" in get_iso_parts_from_epoch()
This would return incorrect results for negative inputs. It still does
to some extent, remainder() in step 2 might need to be replaced with
modulo (I opened an issue in tc39/proposal-temporal about that).
2021-11-17 22:31:28 +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
davidot
22e679d844 LibJS + js: Rethrow exception on the vm after bytecode interpreter run
When the bytecode interpreter was converted to ThrowCompletionOr<Value>
it then also cleared the vm.exception() making it seem like no exception
was thrown.
Also removed the TRY_OR_DISCARD as that would skip the error handling
parts.
2021-11-17 13:12:05 +00:00
Luke Wilde
3666d2132b LibJS: Remove fallback value for get_offset_nanoseconds_for
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/664f02d

Note that the tests are not comprehensive.
2021-11-17 11:30:13 +00:00
Linus Groh
f1784c9c87 LibJS/Tests: Fix failing Array.prototype.toLocaleString() test 2021-11-17 10:00:20 +00:00
Timothy Flynn
39ab1a8999 LibJS: Implement ECMA-402 Array.prototype.toLocaleString
Turns out the only difference between our existing implementation and
the ECMA-402 implementation is we weren't passing the locales and
options list to each element.toLocaleString invocation.

This also adds spec comments to the definition.
2021-11-17 09:01:32 +00:00
Timothy Flynn
c19c3205ff LibJS: Implement ECMA-402 Number.prototype.toLocaleString 2021-11-17 09:01:32 +00:00
Andreas Kling
216e21a1fa AK: Convert AK::Format formatting helpers to returning ErrorOr<void>
This isn't a complete conversion to ErrorOr<void>, but a good chunk.
The end goal here is to propagate buffer allocation failures to the
caller, and allow the use of TRY() with formatting functions.
2021-11-17 00:21:13 +01:00
Andreas Kling
587f9af960 AK: Make JSON parser return ErrorOr<JsonValue> (instead of Optional)
Also add slightly richer parse errors now that we can include a string
literal with returned errors.

This will allow us to use TRY() when working with JSON data.
2021-11-17 00:21:10 +01:00
Timothy Flynn
a1d5849e67 LibJS: Implement unit number formatting 2021-11-16 23:14:09 +00:00
Timothy Flynn
04b8b87c17 LibJS+LibUnicode: Support multiple identifiers within format pattern
This wasn't the case for compact patterns, but unit patterns can contain
multiple (up to 2, really) identifiers that must each be recognized by
LibJS.

Each generated NumberFormat object now stores an array of identifiers
parsed. The format pattern itself is encoded with the index into this
array for that identifier, e.g. the compact format string "0K" will
become "{number}{compactIdentifier:0}".
2021-11-16 23:14:09 +00:00
Timothy Flynn
3b68370212 LibJS+LibUnicode: Rename the generated compact_identifier to identifier
This field is currently used to store the StringView into the compact
name/symbol in the format string. Units will need to store a similar
field, so rename the field to be more generic, and extract the parser
for it.
2021-11-16 23:14:09 +00:00
Timothy Flynn
6d34a0b4e8 LibJS+LibUnicode: Rename method to select a NumberFormat plurality
Instead of currency pattern lookups within select_currency_unit_pattern,
rename the method to select_pattern_with_plurality and accept any list
of patterns. This method will be needed for units.
2021-11-16 23:14:09 +00:00