Commit graph

38 commits

Author SHA1 Message Date
Timothy Flynn
16151aa7d5 LibJS+LibUnicode: Implement the Intl.DateTimeFormat constructor 2021-11-29 22:48:46 +00:00
Timothy Flynn
bb11437792 LibJS: Change Intl's GetOption AO to accept a Span rather than a Vector
Allocating a Vector for each of these invocations is a bit silly when
the values are basically all compile-time arrays. This AO is used even
more heavily by Intl.DateTimeFormat, so change it to accept a Span to
reduce its cost.

This also adds an overload to accept a fixed-size C-array so callers do
not have to be prefixed with AK::Array, i.e. this:

    get_option(..., AK::Array { "a"sv, "b"sv }, ...);

Reduces to:

    get_option(..., { "a"sv, "b"sv }, ...);

(Which is how all call sites were already written to construct a Vector
in place).
2021-11-29 22:48:46 +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
Andreas Kling
8b1108e485 Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Andreas Kling
398c181c79 LibJS: Rename PropertyName to PropertyKey
Let's use the same name as the spec. :^)
2021-10-24 17:18:07 +02:00
Linus Groh
0881f8160f LibJS: Use implicit ThrowCompletionOr<T> constructor where possible
Luckily this is not very widespread yet as most of it would happen in
the various JS functions instead of AOs.
2021-10-21 09:02:23 +01:00
Idan Horowitz
aad12b050b LibJS: Convert to_length() to ThrowCompletionOr 2021-10-18 08:01:38 +03:00
Idan Horowitz
20d990563c LibJS: Convert to_number() to ThrowCompletionOr 2021-10-18 08:01:38 +03:00
Linus Groh
52976bfac6 LibJS: Convert to_object() to ThrowCompletionOr 2021-10-13 09:55:10 +01:00
Linus Groh
96ab116f0d LibJS: Convert to_primitive_string() to ThrowCompletionOr 2021-10-13 09:55:10 +01:00
Linus Groh
4d8912a92b LibJS: Convert to_string() to ThrowCompletionOr
Also update get_function_name() to use ThrowCompletionOr, but this is
not a standard AO and should be refactored out of existence eventually.
2021-10-13 09:55:10 +01:00
Linus Groh
f38a5957bf LibJS: Convert has_property() to ThrowCompletionOr 2021-10-03 20:14:03 +01:00
Linus Groh
b7e5f08e56 LibJS: Convert Object::get() to ThrowCompletionOr
To no one's surprise, this patch is pretty big - this is possibly the
most used AO of all of them. Definitely worth it though.
2021-10-03 20:14:03 +01:00
Idan Horowitz
407cf04884 LibJS: Convert get_number_option() to ThrowCompletionOr 2021-09-18 22:21:15 +03:00
Idan Horowitz
6d3de03549 LibJS: Convert default_number_option() to ThrowCompletionOr 2021-09-18 22:21:15 +03:00
Idan Horowitz
b9c7a629f8 LibJS: Convert coerce_options_to_object() to ThrowCompletionOr 2021-09-18 22:21:15 +03:00
Idan Horowitz
d0e5fc4576 LibJS: Convert supported_locales() to ThrowCompletionOr 2021-09-18 22:21:15 +03:00
Idan Horowitz
de9785b71b LibJS: Convert Intl::get_option() to ThrowCompletionOr 2021-09-18 22:21:15 +03:00
Idan Horowitz
3758e65293 LibJS: Convert canonicalize_locale_list() to ThrowCompletionOr 2021-09-18 22:21:15 +03:00
Timothy Flynn
7f700bd84e LibJS: Make GetNumberOption's "options" object a const reference 2021-09-12 12:57:17 +01:00
Timothy Flynn
4411e16798 LibJS: Change GetOption AO to accept the options as a concrete Object
This was being verified at runtime anyways, so let the compiler ensure
it. This also matches the GetOption AO in Temporal now.
2021-09-12 12:57:17 +01:00
Timothy Flynn
094c390fb1 LibJS: Move CanonicalCodeForDisplayNames to Intl.DisplayNames
Intl.DisplayNames was the first Intl object implemented, and at that
point all AOs were just put into the main Intl AO header. But AOs that
belong to specific objects belong in that object's header. So this moves
CanonicalCodeForDisplayNames to the Intl.DisplayNames header.
2021-09-12 12:57:17 +01:00
Timothy Flynn
e42ba7f748 LibJS: Implement the Intl.NumberFormat constructor 2021-09-11 11:05:50 +01:00
Timothy Flynn
a1954262f8 LibJS: Handle Unicode locale extensions in the ResolveLocale operation
Currently, all callers of ResolveLocale invoke the operation with an
empty [[RelevantExtensionKeys]] slot, so the block of the method that
deals with those keys was unimplemented. This implements that block now
to prepare for Intl.NumberFormat which has a [[RelevantExtensionKeys]].

Note that the find_key_in_value() method is a simple VERIFY_NOT_REACHED
in just this commit until the Intl.NumberFormat's keys are handled in
its implementation.
2021-09-11 11:05:50 +01:00
Timothy Flynn
cdba40f7ea LibJS: Implement Intl.ListFormat.prototype.format 2021-09-06 23:49:56 +01:00
Timothy Flynn
207319ecf1 LibJS: Implement ECMA-402 String.prototype.toLocale{Lower,Upper}Case 2021-09-06 15:24:27 +01:00
Timothy Flynn
14086c69e7 LibJS: Only remove Unicode locale extensions during the LookupMatcher AO
This was one of the first AOs used for Intl, and I misinterpreted the
spec. Rather than removing all extensions, we must only remove Unicode
locale extensions.

Also use LocaleID::to_string() here instead of the heavier canonical
string method, because the locale is already canonical.
2021-09-06 15:24:27 +01:00
Linus Groh
0094259d72 LibJS: Implement Intl.DisplayNames.supportedLocalesOf() 2021-09-04 19:08:18 +01:00
Timothy Flynn
27fc3cfe75 LibJS: Handle existing Intl.Locale objects in CanonicalizeLocaleList 2021-09-02 17:56:42 +01:00
Timothy Flynn
17639a42ae LibJS: Implement the Intl.Locale constructor 2021-09-02 17:56:42 +01:00
Timothy Flynn
940c023e09 LibJS: Compare Unicode locale variants using case-insensitive matching
In the IsStructurallyValidLanguageTag AO, we of course cannot assume the
variants are canonicalized to lower-case yet, because canonicalization
hasn't happened yet.
2021-09-02 17:56:42 +01:00
Timothy Flynn
fdedb3ab33 LibJS: Remove duplicated error message from ErrorTypes.h
ErrorType::IntlInvalidCode has almost exactly the same message as
ErrorType::OptionIsNotValidValue. Remove it, as all uses of the former
are semantically interchangeable with the latter.
2021-09-02 17:56:42 +01:00
Timothy Flynn
d13142f015 LibJS+LibUnicode: Store parsed Unicode locale data as full strings
Originally, it was convenient to store the parsed Unicode locale data as
views into the original string being parsed. But to implement locale
aliases will require mutating the data that was parsed. To prepare for
that, store the parsed data as proper strings.
2021-09-01 14:14:47 +01:00
Timothy Flynn
6f5fb87d3b LibJS: Handle Unicode locale extensions in LookupMatcher AO 2021-09-01 14:14:47 +01:00
Timothy Flynn
a2f0eeff7a LibJS: Canonicalize Unicode locale extension attributes and keywords 2021-08-30 19:42:40 +01:00
Timothy Flynn
94e66f500c LibJS: Reject structurally invalid Unicode locale extensions 2021-08-30 19:42:40 +01:00
Timothy Flynn
17bb652775 LibJS: Implement Intl.DisplayNames.prototype.of
Note that only option type=region is really implemented. Other types
will resort to the fallback option. This prototype method will be able
to implement other type options once LibUnicode supports more.
2021-08-26 22:04:09 +01:00
Timothy Flynn
e8dd2eea74 LibJS: Implement the Intl.DisplayNames constructor
There is notably FIXME notations in this commit regarding Unicode locale
extensions. We are not parsing extensions (or private use extensions) at
all yet.
2021-08-26 22:04:09 +01:00