Commit Graph

32 Commits

Author SHA1 Message Date
Andreas Kling
c084269e5f LibJS: Make PrimitiveString::utf8_string() infallible
Work towards #20449.
2023-08-09 17:09:16 +02:00
Andreas Kling
1a27c525d5 LibJS: Make PrimitiveString::create() infallible
Work towards #20449.
2023-08-09 17:09:16 +02:00
Linus Groh
b84f8fb55b LibJS: Make intrinsics getters return NonnullGCPtr
Some of these are allocated upon initialization of the intrinsics, and
some lazily, but in neither case the getters actually return a nullptr.

This saves us a whole bunch of pointer dereferences (as NonnullGCPtr has
an `operator T&()`), and also has the interesting side effect of forcing
us to explicitly use the FunctionObject& overload of call(), as passing
a NonnullGCPtr is ambigous - it could implicitly be turned into a Value
_or_ a FunctionObject& (so we have to dereference manually).
2023-04-13 14:29:42 +02:00
Andreas Kling
64bda6de2a LibWeb: Use equals_ignoring_ascii_case() in infra helper 2023-03-10 13:15:44 +01:00
Luke Wilde
d036862f2b LibWeb: Refactor XHR (almost) exactly to the spec
This makes XHR now rely on Fetch, which allows it to correct send
Origin and Referer headers, CORS-preflight and filtering and many other
goodies.

The main thing that's missing is Streams, which means we can't properly
produce progress events or switch to the Loading ready state.

This also doesn't implement the Document responseType just yet.
2023-03-07 11:51:12 +00:00
Luke Wilde
9acc542059 LibWeb: Propagate Realm instead of VM more through Fetch
This makes Fetch rely less on using main_thread_vm().current_realm(),
which relies on the dummy execution context if no JavaScript is
currently running.
2023-03-07 11:51:12 +00:00
Matthew Olsson
bab883bf8e LibJS+LibWeb: Add a bunch of missing includes 2023-03-06 13:05:43 +00:00
Linus Groh
7800276c0f LibWeb/Infra: Port serialize_javascript_value_to_json_string() to String 2023-03-04 23:27:08 +00:00
Linus Groh
93ed1b59c8 LibWeb/Infra: Port strip_and_collapse_whitespace() to new String 2023-03-04 23:27:08 +00:00
Linus Groh
f65cbeef5c LibWeb/Infra: Rename to_ascii_{{lower,upper}_case => {lower,upper}case} 2023-03-04 22:42:42 +00:00
Kenneth Myhra
31a9bd2bfd LibWeb: Add to_ascii_upper_case() from the Infra spec
https://infra.spec.whatwg.org/#ascii-uppercase
2023-02-26 00:27:22 +01:00
Kenneth Myhra
2c1e15bd3b LibWeb: Add to_ascii_lower_case() from the Infra spec
https://infra.spec.whatwg.org/#ascii-lowercase
2023-02-26 00:27:22 +01:00
Sam Atkins
2db168acc1 LibTextCodec+Everywhere: Port Decoders to new Strings 2023-02-19 17:15:47 +01:00
Sam Atkins
a419039bb2 LibWeb: Implement ASCII case-insensitive matching
While DeprecatedString and StringView use ASCII case-insensitivity when
matching, String uses the Unicode rules, so in order to match the spec,
we need to *not* use `String::equals_ignoring_case()`.

This function needs to be used everywhere that the spec refers to
an "ASCII case-insensitive match".
2023-02-15 12:48:26 -05:00
Kenneth Myhra
b74d5a423d LibWeb: Add convert string into scalar value from Infra spec 2023-02-12 00:18:09 +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
Arda Cinar
4d335f3819 LibWeb: Remove all whitespace from input in decode_forgiving_base64
Instead of only stripping it from the ends, since that's actually what
the spec says.
2023-01-10 17:54:01 +00:00
Arda Cinar
283187afc5 AK+LibWeb: Move decode forgiving base64 under Web::Infra namespace
Since the forgiving base64 is part of the web infra standard
2023-01-10 17:54:01 +00:00
Timothy Flynn
115baa7e32 LibJS+Everywhere: Make PrimitiveString and Utf16String fallible
This makes construction of Utf16String fallible in OOM conditions. The
immediate impact is that PrimitiveString must then be fallible as well,
as it may either transcode UTF-8 to UTF-16, or create a UTF-16 string
from ropes.

There are a couple of places where it is very non-trivial to propagate
the error further. A FIXME has been added to those locations.
2023-01-08 12:13:15 +01:00
Timothy Flynn
1edb96376b AK+Everywhere: Make UTF-8 and UTF-32 to UTF-16 converters fallible
These could fail to allocate the underlying storage needed to store the
UTF-16 data. Propagate these errors.
2023-01-08 12:13:15 +01:00
Timothy Flynn
d8044c5358 LibJS+LibWeb: Move the macro to convert ENOMEM to an exception to LibJS
Move the macro to LibJS and change it to return a throw completion
instead of a WebIDL exception. This will let us use this macro within
LibJS to handle OOM conditions.
2023-01-08 12:13:15 +01:00
Linus Groh
525f22d018 LibJS: Replace standalone js_string() with PrimitiveString::create()
Note that js_rope_string() has been folded into this, the old name was
misleading - it would not always create a rope string, only if both
sides are not empty strings. Use a three-argument create() overload
instead.
2022-12-07 16:43:06 +00:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
networkException
ee27d8cdfd LibWeb: Add is_code_unit_prefix() function 2022-10-24 23:06:56 +01:00
Linus Groh
d2e9faf2da LibWeb: Run 'UTF-8 decode' in parse_json_bytes_to_javascript_value() 2022-10-04 20:05:09 +01:00
Linus Groh
7760c00714 LibWeb: Move strip_and_collapse_whitespace() to Infra/
...and make it spec compliant by considering all ASCII whitespace,
greatly simplifying it in the process :^)
2022-10-02 21:32:49 +02:00
Linus Groh
b9220a18d1 LibWeb: Replace incorrect uses of String::trim_whitespace() 2022-10-02 21:32:49 +02:00
Linus Groh
87ac38c78b LibWeb: Add is_ascii_whitespace() function
This matches the Infra spec's definition of 'ASCII whitespace', and we
can at last stop using AK::is_ascii_space(), which has a different idea
about what 'whitespace' means.
2022-10-02 21:32:49 +02:00
Andrew Kaster
56b381aac0 LibWeb: Cleanup unecessary uses and includes of HTML::Window
The big global refactor left some stragglers behind for atomicity.

Clean up the rest, and remove a ton of includes of LibWeb/HTML/Window.h
2022-10-01 21:05:32 +01:00
Linus Groh
00fa71725b LibWeb: Implement JS value <-> JSON parsing/serialization AOs 2022-09-27 14:56:17 +01:00
Linus Groh
1748362e05 LibWeb: Add 'byte-{lower,upper}case' operations from the Infra spec
Usually operations that mirror AOs from the Infra spec are simply part
of the underlying data structures in AK directly, but these don't seem
generally useful enough to add them as ByteBuffer methods.
2022-07-14 00:42:26 +01:00