Commit graph

138 commits

Author SHA1 Message Date
Andreas Kling
647ac1bdba LibWeb: Make Blob and File GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
ffad902c07 LibWeb: Use cached_web_prototype() as much as possible
Unlike ensure_web_prototype<T>(), the cached version doesn't require the
prototype type to be fully formed, so we can use it without including
the FooPrototype.h header. It's also a bit less verbose. :^)
2022-09-06 00:27:09 +02:00
Andreas Kling
8f4ea4e308 LibWeb: Don't use a JS::Handle for XHR response object 2022-09-06 00:27:09 +02:00
Andreas Kling
6f433c8656 LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated
This is a monster patch that turns all EventTargets into GC-allocated
PlatformObjects. Their C++ wrapper classes are removed, and the LibJS
garbage collector is now responsible for their lifetimes.

There's a fair amount of hacks and band-aids in this patch, and we'll
have a lot of cleanup to do after this.
2022-09-06 00:27:09 +02:00
Andreas Kling
7c3db526b0 LibWeb: Make DOM::Event and all its subclasses GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
8cda70c892 LibWeb: Move event listeners, handlers and callbacks to the GC heap
This patch moves the following things to being GC-allocated:
- Bindings::CallbackType
- HTML::EventHandler
- DOM::IDLEventListener
- DOM::DOMEventListener
- DOM::NodeFilter

Note that we only use PlatformObject for things that might be exposed
to web content. Anything that is only used internally inherits directly
from JS::Cell instead, making them a bit more lightweight.
2022-09-06 00:27:09 +02:00
Linus Groh
50428ea8d2 LibJS: Move intrinsics to the realm
Intrinsics, i.e. mostly constructor and prototype objects, but also
things like empty and new object shape now live on a new heap-allocated
JS::Intrinsics object, thus completing the long journey of taking all
the magic away from the global object.
This represents the Realm's [[Intrinsics]] slot in the spec and matches
its existing [[GlobalObject]] / [[GlobalEnv]] slots in terms of
architecture.

In the majority of cases it should now be possibly to fully allocate a
regular object without the global object existing, and in fact that's
what we do now - the realm is allocated before the global object, and
the intrinsics between both :^)
2022-08-27 11:29:10 +01:00
Linus Groh
b345a0acca LibJS+LibWeb: Reduce use of GlobalObject as an intermediary
- Prefer VM::current_realm() over GlobalObject::associated_realm()
- Prefer VM::heap() over GlobalObject::heap()
- Prefer Cell::vm() over Cell::global_object()
- Prefer Wrapper::vm() over Wrapper::global_object()
- Inline Realm::global_object() calls used to access intrinsics as they
  will later perform a direct lookup without going through the global
  object
2022-08-23 13:58:30 +01:00
Linus Groh
40a70461a0 LibWeb: Replace GlobalObject with Realm in wrapper functions
Similar to create() in LibJS, wrap() et al. are on a low enough level to
warrant passing a Realm directly instead of relying on the current realm
from the VM, as a wrapper may need to be allocated while no JS is being
executed.
2022-08-23 13:58:30 +01:00
Linus Groh
25849f8a6d LibJS: Replace GlobalObject with VM in common AOs [Part 18/19] 2022-08-23 13:58:30 +01:00
Linus Groh
b99cc7d050 LibJS+LibWeb: Replace GlobalObject with Realm in create() functions
This is a continuation of the previous two commits.

As allocating a JS cell already primarily involves a realm instead of a
global object, and we'll need to pass one to the allocate() function
itself eventually (it's bridged via the global object right now), the
create() functions need to receive a realm as well.
The plan is for this to be the highest-level function that actually
receives a realm and passes it around, AOs on an even higher level will
use the "current realm" concept via VM::current_realm() as that's what
the spec assumes; passing around realms (or global objects, for that
matter) on higher AO levels is pointless and unlike for allocating
individual objects, which may happen outside of regular JS execution, we
don't need control over the specific realm that is being used there.
2022-08-23 13:58:30 +01:00
Kenneth Myhra
622a4f29a7 LibWeb: Add public get accessor function for Blob's internal ByteBuffer
Blob::bytes() returns the ReadonlyBytes representation of our internal
ByteBuffer.

This change requires us to ByteBuffer::copy() Blob's ReadonlyBytes to a
ByteBuffer in XHR::send() and corresponding error handling of the copy
operation.

This removes the need for Blob to declare XMLHttpRequest as a friend
class.
2022-07-26 20:54:30 +01:00
Kenneth Myhra
9a1c27a163 LibWeb: Implement BufferSource support for XHR::send() 2022-07-22 23:08:28 +01:00
Kenneth Myhra
5830ff5be9 LibWeb: Let XHR::extract_body() return ErrorOr
This is a minor refactor of XHR::extract_body() letting it return
ErrorOr<...> instead of just Fetch::Infrastructure::BodyWithType.

This also updates the one place extract_body() is used.
2022-07-22 23:08:28 +01:00
Linus Groh
042dfc7284 LibWeb: Move extract_mime_type() from XMLHttpRequest to HeaderList
Except some minor tweaks, this is a direct copy of Luke's initial
implementation in XMLHttpRequest, now replacing the former.
2022-07-20 18:03:21 +01:00
Linus Groh
2726fc9c73 LibWeb: Move Fetch infra into the Web::Fetch::Infrastructure namespace
The Fetch spec unfortunately will cause a name clash between the Request
concept and the Request JS object - both cannot live in the Web::Fetch
namespace, and WrapperGenerator generally assumes `Web::<Name>` for
things living in the `<Name>/` subdirectory, so let's instead move infra
code into its own namespace - it already sits in a (sub-)subdirectory
anyway.
2022-07-19 00:27:35 +01:00
Kenneth Myhra
0a511e29d1 LibWeb: Add support for Blob to XHR::send() 2022-07-18 14:57:58 +01:00
Kenneth Myhra
9b3da5a142 LibWeb: Move extract_body() towards spec compliance 2022-07-18 14:57:58 +01:00
Kenneth Myhra
bc4ccadcac LibWeb: XHR::extra_body() rewrite to use Variant::visit() 2022-07-18 14:57:58 +01:00
Kenneth Myhra
48b59aaeb1 LibWeb: Mark body argument of extract_body() as const reference 2022-07-18 14:57:58 +01:00
Kenneth Myhra
42e76d8de9 LibWeb: Rename safely_extract_body() to extract_body()
We have not yet implemented safely_extract_body so renaming this to
extract_body() and adding a spec link.
2022-07-18 14:57:58 +01:00
Linus Groh
6619483169 LibWeb: Update incorrect Fetch namespaces
Oops, this namespace rename wasn't committed yet.
2022-07-18 08:14:04 +01:00
Linus Groh
c501453425 LibWeb: Use Fetch's HeaderList::get_decode_and_split() in XMLHttpRequest 2022-07-18 08:10:54 +01:00
Linus Groh
bc68539e26 LibWeb: Add & use TRY_OR_RETURN_OOM macro
This is a convenient way to return a DOM exception for operations that
return ErrorOr and only have an OOM failure path.
2022-07-17 21:08:10 +01:00
Kenneth Myhra
5806eeec08 LibWeb: Add support for XHR response type Blob 2022-07-17 00:23:19 +01:00
Linus Groh
db5c455238 LibWeb: Use newly added 'Status' Fetch infrastructure in XMLHttpRequest 2022-07-14 00:42:26 +01:00
Linus Groh
aa852fd9f2 LibWeb: Use newly added 'Headers' Fetch infrastructure in XMLHttpRequest 2022-07-14 00:42:26 +01:00
Linus Groh
d232f3fc41 LibWeb: Use newly added 'Methods' Fetch infrastructure in XMLHttpRequest 2022-07-14 00:42:26 +01:00
Linus Groh
f42f0cceaa LibWeb: Make Fetch::collect_an_http_quoted_string()'s 2nd param optional 2022-07-14 00:42:26 +01:00
Linus Groh
fad69fcacd LibWeb: Move Fetch::collect_an_http_quoted_string() into HTTP.{cpp,h}
The Fetch spec is too big to have a generic AbstractOperations.{cpp,h}
file, so let's keep AOs in their section-specific files.
2022-07-14 00:42:26 +01:00
Linus Groh
e3798886ed LibWeb: Add & use 'HTTP whitespace' from '2.2. HTTP' in the Fetch spec
We had two independent definitions of this already, both referring to
the Fetch spec.
2022-07-14 00:42:26 +01:00
Linus Groh
df3e25f1bb LibWeb: Add & use 'HTTP tab or space' from '2.2. HTTP' in the Fetch spec 2022-07-14 00:42:26 +01:00
Linus Groh
22a627fc1a LibWeb: Move Origin into the HTML namespace
Origin is defined in the HTML Standard, and therefore belongs into the
HTML directory and namespace in LibWeb.
https://html.spec.whatwg.org/multipage/origin.html#origin
2022-07-14 00:42:26 +01:00
Ankur Sundara
400ef9913e LibWeb: Fix regexes for XHR
Regexes for is_method and is_header_name did not escape the "-"
and unintentionally allowed for "," to be part of a
method/header name, not following the spec.
This commit escapes the "-" character to follow the spec.
2022-07-13 22:52:10 +02:00
sin-ack
3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
Kenneth Myhra
247951e09c LibWeb: Add URLSearchParams as part of union type for XHR::send()
This patch adds support for URLSearchParams to XHR::send() and
introduces the union type XMLHttpRequestBodyInit.

XHR::send() now has support for String and URLSearchParams.
2022-07-08 12:37:01 +02:00
Kenneth Myhra
445c3050d4 LibWeb: Wire up XHR::ontimeout event 2022-07-03 13:26:32 +02:00
Kenneth Myhra
c805987329 LibWeb: Add timeout functionality to ResourceLoader
Add timeout functionality to ResourceLoader and use it from
XMLHttpRequest.
2022-06-21 10:29:14 +01:00
Kenneth Myhra
8b42c05648 LibWeb: Add XMLHttpRequest::timeout setter and getter 2022-06-21 10:29:14 +01:00
Luke Wilde
1f820f8840 LibWeb: Add support for the <base> element changing the base URL
Used by Google seemingly almost all around account sign in and
management. The modern sign in page has this near the beginning:
```html
<base href="https://accounts.google.com">
```
All of the XHRs performed by sign in are relative URLs to this
base URL. Previously we ignored this and did it relative to the
current URL, causing the XHRs to 404 and sign in to fall apart.

I presume they do this because you can access the sign in page
from multiple endpoints, such as `/ServiceLogin` and
`/o/oauth2/auth/identifier`
2022-06-19 16:35:43 +01:00
Kenneth Myhra
a5514fece9 LibWeb: Move XHR::open() towards more spec compliance
Following FIXMEs have been addressed:
- 1. Let settingsObject be this’s relevant settings object.
- 2. If settingsObject has a responsible document and it is not fully
     active, then throw an "InvalidStateError" DOMException.
- 6. Let parsedURL be the result of parsing url with settingsObject's
     API base URL and settingsObject’s API URL character encoding.
- 8. If the async argument is omitted, set async to true, and set
     username and password to null.
2022-04-23 18:05:55 +02:00
Kenneth Myhra
01194053b7 LibWeb: XHR set_request_header() validate header name and value 2022-04-23 18:05:55 +02:00
Kenneth Myhra
1ca1a73d67 LibWeb: Trim leading and trailing HTTP whitespace bytes
The XMLHttpRequest specification specifices that header values should be
normalized by trimming leading and trailing HTTP whitespace bytes.
2022-04-23 18:05:55 +02:00
Kenneth Myhra
fccea8888e LibWeb: Use a more restrictive regex for method token production
This changes the regular expression for is_method() to a more
restrictive pattern.
2022-04-23 18:05:55 +02:00
Kenneth Myhra
053bcd4859 LibWeb: Combine headers in XMLHttpRequest::set_request_header
This patch adds support for combining header values, in addtion it adds
spec comments for readability.
2022-04-23 18:05:55 +02:00
Kenneth Myhra
69f05a66fc LibWeb: Add XMLHttpRequest::open() overload
This adds the XMLHttpRequest::open(String, String, bool, String, String)
overload.

The following FIXMEs has been implemented:
- If method is not a method, then throw a "SyntaxError" DOMException.
- If the username argument is not null, set the username given parsedURL
  and username.
- If the password argument is not null, set the password given parsedURL
  and password.
- Set this’s synchronous flag if async is false; otherwise unset this’s
  synchronous flag.

Spec comments has also been updated.
2022-04-05 22:33:44 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Hendiadyoin1
6a95df2526 LibTextCodec: Don't allocate Strings on encoding normalisation
This ripples down to LibWeb's HTML and XHR decoders, which therefore
become less allocation heavy.
2022-03-21 10:48:17 +01:00
Lenny Maiorani
c37820b898 Libraries: Use default constructors/destructors in LibWeb
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-17 17:23:49 +00:00
Linus Groh
1422bd45eb LibWeb: Move Window from DOM directory & namespace to HTML
The Window object is part of the HTML spec. :^)
https://html.spec.whatwg.org/multipage/window-object.html
2022-03-08 00:30:30 +01:00