Commit Graph

605 Commits

Author SHA1 Message Date
Andreas Kling
4c887bf6c3 LibWeb: Remove Document::interpreter()
Nobody needs this anymore, so we can finally remove it. :^)
2022-09-06 00:27:09 +02:00
Andreas Kling
2d72abc3d4 LibWeb+WebContent: Store Realm instead of Interpreter in ConsoleClient 2022-09-06 00:27:09 +02:00
Andreas Kling
905eb8cb4d LibWeb: Make MutationObserver GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
43ec0f734f LibWeb: Make MutationRecord GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
48e0066371 LibWeb: Make NodeList GC-allocated 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
bb547ce1c4 LibWeb: Make AbstractRange and subclasses GC-allocated 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
a4ddb0ef87 LibWeb: Make TreeWalker GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
bd629c45b5 LibWeb: Make NodeIterator 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
Andreas Kling
967a3e5a45 LibWeb: Make DOMImplementation GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
0176d42f49 LibWeb: Make DOMTokenList GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
a56b3f9862 LibWeb: Make NamedNodeMap GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
72bacba97b LibWeb: Make CSSStyleDeclaration GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
5d6cb9cbdb LibWeb: Make CSSRuleList GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
5366924f11 LibWeb: Make StyleSheetList GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
5d60212076 LibWeb: Make StyleSheet and CSSStyleSheet GC-allocated 2022-09-06 00:27:09 +02:00
Linus Groh
61bd9fef7d LibJS+LibWeb: Remove last uses of GlobalObject::associated_realm() 2022-08-27 11:29:10 +01:00
MacDue
8d2c2f7c52 LibWeb: Determine the origin when navigating across documents 2022-08-26 00:21:10 +02:00
martinfalisse
e4c5799026 LibWeb: Add GridFormattingContext 2022-08-25 13:47:48 +02:00
Linus Groh
61e18c681b LibWeb: Restore realm retrieval from 'this' in activate_event_handler()
Removing the FIXME'd code in b99cc7d was a bit too eager, and relying on
the main thread VM's current realm only works when JS is being executed.

Restore a simplified version of the old code to determine the realm this
time instead of the global object, following the assumptions already
made in get_current_value_of_event_handler() regarding what kind of
event target 'this' can be.
2022-08-23 17:44:39 +01:00
Linus Groh
b465f46e00 LibJS: Remove GlobalObject parameter from native functions 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
a022e548b8 LibJS: Replace GlobalObject with VM in Value AOs [Part 4/19]
This is where the fun begins. :^)
2022-08-23 13:58:30 +01:00
Linus Groh
e992a9f469 LibJS+LibWeb: Replace GlobalObject with Realm in Heap::allocate<T>()
This is a continuation of the previous three commits.

Now that create() receives the allocating realm, we can simply forward
that to allocate(), which accounts for the majority of these changes.
Additionally, we can get rid of the realm_from_global_object() in one
place, with one more remaining in VM::throw_completion().
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
Linus Groh
c8f1651761 LibJS+LibWeb: Restore type safety of Realm::set_global_object()
The changes from 8a03b17 to allow any JS::Value aren't a good fit, as
shown by the excessive amount of verify_cast needed :^)
2022-08-06 12:02:48 +02:00
Andreas Kling
2a7924f96c LibWeb: Bring browsing context creation closer to spec
This patch implements the "create a new browsing context" function from
the HTML spec and replaces our existing logic with it.

The big difference is that browsing contexts now initially navigate to
"about:blank" instead of starting out in a strange "empty" state.
This makes it possible for websites to create a new iframe and start
scripting inside it right away, without having to load an URL into it.
2022-08-05 12:46:42 +02:00
Andreas Kling
73f77969a6 LibWeb: Add API for setting a document's referrer 2022-08-05 12:46:42 +02:00
Andreas Kling
6e71e400e6 LibWeb: Store document origin as a HTML::Origin object
This will allow us to remember an arbitrary origin instead of deriving
it from the document's URL.
2022-08-05 12:46:42 +02:00
Andreas Kling
b6bd793ede LibWeb: Clear the "is initial about:blank" flag in Document.write() 2022-08-05 12:46:41 +02:00
Andreas Kling
c46a8194b4 LibWeb: Use Document::m_type to check for XML documents
...instead of doing a string compare on the DOCTYPE node.
2022-08-05 12:46:41 +02:00
Andreas Kling
602f927982 LibWeb: Start implementing "create and initialize a Document" from HTML
The way we've been creating DOM::Document has been pretty far from what
the spec tells us to do, and this is a first big step towards getting us
closer to spec.

The new Document::create_and_initialize() is called by FrameLoader after
loading a "text/html" resource.

We create the JS Realm and the Window object when creating the Document
(previously, we'd do it on first access to Document::interpreter().)

The realm execution context is owned by the Environment Settings Object.
2022-08-05 12:46:40 +02:00
Andreas Kling
b838f2029b LibWeb: Move DOM::Document factory functions out of line 2022-08-05 12:42:46 +02:00
Andreas Kling
29a4266367 LibWeb: Add the "is initial about:blank" flag to DOM::Document 2022-08-05 12:42:46 +02:00
MacDue
d4b2eb22e1 LibWeb: Resolve circular IDL imports
These circular imports led to the generator silently failing to
generate the required methods/properties.
2022-07-30 13:20:47 +02:00
Sam Atkins
200e111af0 LibWeb: Extract the InnerHTML IDL mixin 2022-07-29 17:15:49 +01:00
Sam Atkins
d4c40e3aad LibWeb: Extract the ParentNode IDL mixin 2022-07-29 17:15:49 +01:00
Sam Atkins
79fdc08de9 LibWeb: Correct typo in Document.idl
Makes me wonder how things were working when Document was never
including GlobalEventHandlers.
2022-07-29 17:15:49 +01:00
Sam Atkins
d6a5ddd3c0 LibWeb: Extract the ChildNode IDL mixin 2022-07-29 17:15:49 +01:00
Andreas Kling
2ad98fdf80 LibWeb: Add fast_is<HTMLElement>()
This avoids slow RTTI lookups in selector matching.
2022-07-27 17:29:48 +02:00
Andreas Kling
9f32da1dbc LibWeb: Add fast_is<HTMLBaseElement>()
This avoids slow RTTI lookups in Document::base_url().
2022-07-27 17:29:48 +02:00
Andreas Kling
71a707480c LibWeb: Move "has-definite-width/height" flags to UsedValues
This state is less static than we originally assumed, and there are
special formatting context-specific rules that say certain sizes are
definite in special circumstances.

To be able to support this, we move the has-definite-size flags from
the layout node to the UsedValues struct instead.
2022-07-26 01:53:41 +02:00
Andreas Kling
16c173de43 LibWeb: Destroy ICB formatting context before committing used values
Absolutely positioned boxes are handled by the BFC destructor, so we
need to make sure the ICB BFC is destroyed if we want these boxes
to get laid out.
2022-07-26 00:04:21 +02:00
Andreas Kling
ed8930fff5 LibWeb: Add accessors for UsedValues::computed_{width,height}
This is preparation for doing some more work when assigning to these
values.
2022-07-19 15:40:41 +02: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
Luke Wilde
aa9f7cc597 LibWeb: Fix queuing mutation records for node removal
Step 19 of node removal was missing, which allows the mutations of the
descendants of the removed node to still be observed by the parent.

Step 20 of node removal queued the mutation record for the removed
node instead of it's parent. Since queuing takes place after the node
is removed from the tree, the mutation record would be lost as the only
inclusive ancestor of the node at this point is only the node itself.
2022-07-17 18:21:09 +01:00
Andreas Kling
9b46091f38 LibWeb: Rename LayoutState::NodeState => LayoutState::UsedValues
This object contains all the CSS "used values" as seen during the layout
process, so calling it "used values" seems appropriate. :^)
2022-07-17 14:11:37 +02:00
Andreas Kling
52862c72d0 LibWeb: Rename FormattingState to LayoutState
This seems a bit more descriptive (and also a bit shorter).
2022-07-17 14:11:36 +02:00