Commit graph

4126 commits

Author SHA1 Message Date
Timothy Flynn
b4113536ef LibJS: Use substrings-with-superstrings in Intl.NumberFormat's grouping
To add grouping to a number, we take a string such as "123456.123" and
break it into integer and fraction parts. Then we take the integer part
and break it into locale-specific sized groups to inject the locale's
group separator (e.g. a comma in en-US). We currently create new strings
for each of these groups. Instead, we can use the shared superstring
method to avoid all of that string copying.
2023-02-18 20:00:15 +01:00
Jelle Raaijmakers
8f015a18a5 LibJS: Dereference intrinsic accessor before deleting it
The iterator used to find an intrinsic accessor is used after calling
`HashMap.remove()` on it, which works for our current implementation but
will fall apart when you consider that modifications to the hash map
might invalidate all existing iterators that came from it, as many
implementations do.

Since we're aiming to replace our `HashTable` implementation with
something new, let's fix this first :^)
2023-02-17 22:29:51 -07:00
Timothy Flynn
f6503577f6 LibJS: Propagate out-of-memory errors from HostImportModuleDynamically 2023-02-17 09:14:23 -05:00
Timothy Flynn
f98d0acd27 LibJS: Convert Error's constructor and prototype to String 2023-02-17 09:14:23 -05:00
Timothy Flynn
1400a85fae LibJS: Remove unused CodeGenerationError::to_deprecated_string 2023-02-17 09:14:23 -05:00
Timothy Flynn
88814acbd3 LibJS+Everywhere: Convert JS::Error to String
This includes an Error::create overload to create an Error from a UTF-8
StringView. If creating a String from that view fails, the factory will
return an OOM InternalError instead. VM::throw_completion can also make
use of this overload via its perfect forwarding.
2023-02-17 09:14:23 -05:00
Timothy Flynn
153b793638 LibJS: Add a throwable StringBuilder::join method 2023-02-17 09:14:23 -05:00
Timothy Flynn
4d10911f96 LibJS: Pre-allocate the out-of-memory error string on the VM
If we are out of memory, we can't try to allocate a string that could
fail as well. When Error is converted to String, this would result in an
endless OOM-throwing loop. Instead, pre-allocate the string on the VM,
and use it to construct the Error.

Note that as of this commit, the OOM string is still a DeprecatedString.
This is just preporatory for Error's conversion to String.
2023-02-17 09:14:23 -05:00
Timothy Flynn
93ad25fbe5 LibJS: Add to_string definitions to CodeGenerationError and ParserError 2023-02-17 09:14:23 -05:00
Ali Mohammad Pur
b409a40377 LibJS: Actually escape \n|\r|LS|PS when escaping RegExp.source
We were previously encoding them as `\<literal newline>`, which is just
all sorts of wrong :P
2023-02-16 23:32:35 +01:00
Ali Mohammad Pur
bcfbe0fbf7 LibJS: Manually loop over escaped regex pattern instead of ::replace()
This makes it ever-so-slightly faster, but more importantly, it fixes
the bug where a `/\//` regex's `source` property would return `\\/`
("\\\\/") instead of `\/` due to the existing '/' -> '\/' replace()
call.
2023-02-16 21:03:19 +01:00
Ali Mohammad Pur
a8bcb901c0 LibJS: Escape printed strings making them proper string literals
Previously we just printed '"' string-contents '"', which was not a
proper string literal.
2023-02-16 21:03:19 +01:00
Timothy Flynn
ba40ef1f3a LibJS: Remove Value::to_deprecated_string_without_side_effects 2023-02-16 14:32:22 +01:00
Timothy Flynn
24e9cea524 LibJS: Convert remaining usages of Value::TDSWOSE to Value::TSWOSE
Note the couple of cases using MUST are just debugging statements.
2023-02-16 14:32:22 +01:00
Timothy Flynn
c17589a402 LibJS: Change Print's print_type helper to accept a StringView
There's no benefit to accepting a fly string, and this will soon be
needed to be used with String.
2023-02-16 14:32:22 +01:00
Timothy Flynn
bb64b49749 LibJS: Remove unused Reference::to_deprecated_string 2023-02-16 14:32:22 +01:00
Timothy Flynn
36d72a7f4c LibJS: Convert CanonicalNumericIndexString to use NumberToString 2023-02-16 14:32:22 +01:00
Timothy Flynn
9a5a4302d9 LibJS: Convert PropertyDescriptor's formatter to String
And generally propagate OOM.
2023-02-16 14:32:22 +01:00
Timothy Flynn
a73b8292ed LbJS: Convert exception-related usages of Value::TDSWOSE to String
TDSWOSE being to_deprecated_string_without_side_effects.
2023-02-16 14:32:22 +01:00
Timothy Flynn
3ffb6d9b5a LibJS: Define Value::to_string_without_side_effects for String 2023-02-16 14:32:22 +01:00
Timothy Flynn
dc4207323b LibJS: Remove the VM parameter from the NumberToString AO
This will be needed by Value::to_string_without_side_effects, which can
be called in contexts without a VM (e.g. in AK::Format specializations).
So to_string_without_side_effects will need to be callable without a VM,
thus NumberToString must be as well.
2023-02-16 14:32:22 +01:00
Timothy Flynn
7a7a649f5b LibJS: Define BigInt::to_string to complement to_deprecated_string 2023-02-16 14:32:22 +01:00
Timothy Flynn
b245300ba1 LibJS+Everywhere: Deprecate Value::to_string_without_side_effects 2023-02-16 14:32:22 +01:00
Timothy Flynn
7cb956d17b LibJS: Use iterative text segmentation algorithms for Intl.Segmenter
This uses the find-next and find-previous APIs instead of storing all
indices as a vector.
2023-02-16 11:18:53 +01:00
Nico Weber
3c8bfa4662 LibJS: Keep escaping forward slashes
Reverts 5dce916a50.

Now:

    > new RegExp('/').source
    "\/"

This matches spec (and v8).
2023-02-15 16:41:56 +01:00
Timothy Flynn
5cbf054651 LibUnicode: Fix typos causing text segmentation on mid-word punctuation
For example the words "can't" and "32.3" should not have boundaries
detected on the "'" and "." code points, respectively.

The String test cases fixed here are because "b'ar" is now considered
one word.
2023-02-15 12:36:47 +01:00
Timothy Flynn
2d487e4e4c LibUnicode+LibJS: Move text segmentation algorithms to their own files
These algorithms are quite chonky, and more APIs around them are to be
added, so let's move them to their own files for a bit of organization.
2023-02-15 12:36:47 +01:00
Ali Mohammad Pur
5dce916a50 LibJS: Don't escape backslashes in RegExp.source
The spec doesn't require this, and no one else does so.
2023-02-15 10:14:26 +01:00
Tim Schumacher
43f98ac6e1 Everywhere: Remove the AK:: qualifier from Stream usages 2023-02-13 00:50:07 +00:00
Tim Schumacher
874c7bba28 LibCore: Remove Stream.h 2023-02-13 00:50:07 +00:00
Tim Schumacher
d43a7eae54 LibCore: Rename File to DeprecatedFile
As usual, this removes many unused includes and moves used includes
further down the chain.
2023-02-13 00:50:07 +00:00
Linus Groh
a8bf2f8e4c LibJS: Port Symbol to String
This includes the VM's global_symbol_registry HashMap, which can now
store String keys.
2023-02-11 21:47:57 +00:00
Linus Groh
5e72fde954 LibJS: Unify Symbol::description() and raw_description()
Let callers take care of handling the empty optional case (undefined in
the spec).
2023-02-11 21:47:57 +00:00
Linus Groh
fcdabd179a LibJS: Remove unused forwarding getters from SymbolObject 2023-02-11 21:47:57 +00:00
Linus Groh
89700a2101 LibJS: Rename Symbol::to_deprecated_string() to descriptive_string()
This implements the spec's SymbolDescriptiveString AO and should be
named accordingly.
2023-02-11 21:47:57 +00:00
Luke Wilde
588dae8aa6 LibJS/Temporal: Allow annotations after YYYY-MM and MM-DD
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/160e836
2023-02-11 18:42:32 +00:00
Luke Wilde
f09d2ae395 LibJS: Add missing assignment to offset_string in ZDT conversion 2023-02-11 00:57:59 +00:00
Timothy Flynn
3b4879d29b LibJS+Userland: Port the JS Console object and direct callers to String 2023-02-10 17:26:20 +00:00
Timothy Flynn
8f9659a549 LibJS: Surround the VM parameter of TRY_OR_THROW_OOM with parentheses
Depending on how this is invoked, the preprocessor may get confused when
pasting the VM parameter into this expression. For example, it trips up
on the JS REPL in cases such as:

    TRY_OR_THROW_OOM(*g_vm, ...);
2023-02-10 17:26:20 +00:00
Timothy Flynn
519a1cd23d LibJS: Add a fallible ThrowableStringBuilder::appendff 2023-02-10 17:26:20 +00:00
Timothy Flynn
7163e4d456 LibJS: Change ThrowableStringBuilder to privately inherit StringBuilder
Not an issue currently, but while developing, it's easy to miss cases
where an infallible AK::StringBuilder method is still used. By making
this inheritance private, and explicitly pulling in base methods we
can safely use, we get extra help from the compiler to indicate such
mistakes immediately.
2023-02-10 17:26:20 +00:00
Timothy Flynn
604d5f5bca AK+Everywhere: Do not implicitly copy variables in TRY macros
For example, consider cases where we want to propagate errors only in
specific instances:

    auto result = read_data(); // something like ErrorOr<ByteBuffer>
    if (result.is_error() && result.error().code() != EINTR)
        continue;
    auto bytes = TRY(result);

The TRY invocation will currently copy the byte buffer when the
expression (in this case, just a local variable) is stored into
_temporary_result.

This patch binds the expression to a reference to prevent such copies.
In less trival invocations (such as TRY(some_function()), this will
incur only temporary lifetime extensions, i.e. no functional change.
2023-02-10 09:08:52 +00:00
Timothy Flynn
c3abb1396c LibJS+LibWeb: Convert string view PrimitiveString instances to String
First, this adds an overload of PrimitiveString::create for StringView.
This overload will throw an OOM completion if creating a String fails.
This is not only a bit more convenient, but it also ensures at compile
time that all PrimitiveString::create(string_view) invocations will be
handled as String and OOM-aware.

Next, this wraps all invocations to PrimitiveString::create(string_view)
with MUST_OR_THROW_OOM.

A small PrimitiveString::create(DeprecatedFlyString) overload also had
to be added to disambiguate between the StringView and DeprecatedString
overloads.
2023-02-09 17:13:33 +00:00
Timothy Flynn
69a56a8e39 LibJS: Convert short string literal PrimitiveString instances to String 2023-02-09 17:13:33 +00:00
Timothy Flynn
49e8dcf0b2 LibJS+LibWeb: Convert empty PrimitiveString instances to String 2023-02-09 17:13:33 +00:00
MacDue
63b11030f0 Everywhere: Use ReadonlySpan<T> instead of Span<T const> 2023-02-08 19:15:45 +00:00
Timothy Flynn
8670526f2a LibJS+LibLocale: Propagate OOM from CLDR RelativeTime Vector operations 2023-02-08 18:32:37 +00:00
Timothy Flynn
89da8de4ca LibJS+LibLocale: Propagate OOM from CLDR NumberFormat Vector operations 2023-02-08 18:32:37 +00:00
Timothy Flynn
858126d236 LibJS: Propagate OOM from remaining Intl Vector operations 2023-02-08 18:32:37 +00:00
Timothy Flynn
9af525bbb0 LibJS: Propagate OOM from Intl.RelativeTimeFormat Vector operations 2023-02-08 18:32:37 +00:00