Commit Graph

53 Commits

Author SHA1 Message Date
Shannon Booth
dadc610e4a LibWeb: Pass a FlyString to getElementsByTagNameNS 2024-05-12 07:28:09 +01:00
Tim Ledbetter
398bf10b92 LibWeb: Use TraversalDecision for multi level Node traversal methods
This adds the `SkipChildrenAndContinue` option, where traversal
continues but child nodes are not included.
2024-05-07 16:45:28 -06:00
Matthew Olsson
31341b280a LibWeb: Add calls to JS_{DECLARE,DEFINE}_ALLOCATOR() 2024-04-09 09:13:06 +02:00
Shannon Booth
22f6abe5d6 LibWeb: Remove DeprecatedString impls of get_elements_by_tag_name{_ns}
No IDL file pulls in these requiring DeprecatedString support, so we
are now able to remove these functions! :^)

Also leave a FIXME while we are at it, as ideally this function would
take an Optional<FlyString> - but the IDL generator does not currently
support this.
2023-11-06 11:37:08 +01:00
Andreas Kling
3ff81dcb65 LibWeb: Make Web::Namespace::Foo strings be FlyString
This required dealing with a *lot* of fallout, but it's all basically
just switching from DeprecatedFlyString to either FlyString or
Optional<FlyString> in a hundred places to accommodate the change.
2023-11-04 21:28:30 +01:00
Ali Mohammad Pur
0937d88869 LibWeb: Remove more DeprecatedString null state remnants 2023-10-14 09:12:41 -04:00
Shannon Booth
57d7637b59 LibWeb: Remove DeprecatedString support from {Child,Parent}Node
No interface pulls this in that requires DeprecatedString support.
2023-10-06 08:25:40 +02:00
Shannon Booth
4321606bba LibWeb: Port Element interface from DeprecatedString
This is the last IDL interface which was using DeprecatedString! :^)
2023-10-06 08:25:40 +02:00
Shannon Booth
9303e9e76f LibWeb: Port Element::local_name and TagNames from Deprecated String
Which pretty much needs to be done together due to the amount of places
where they are compared together.

This also involves porting over StackOfOpenElements over to FlyString
from DeprecatedFly string to prevent a gazillion calls to
`.to_deprecated_fly_string` calls in HTMLParser.
2023-10-03 14:47:53 +01:00
Shannon Booth
9d88e14f20 LibWeb: Add String variants of get_element_by_{} in ParentNode
These are required for porting over Document from DeprecatedString to
String. We unfortunately can't port this completely over yet as
ParentNode is included by the Element IDL interface, which has not yet
been ported over from DeprecatedString.
2023-09-16 11:17:19 +02:00
Shannon Booth
bfc0773285 LibWeb: Add String versions for some functions in ParentNode
These functions are required in the porting of the DocumentFragment
interface from DeprecatedString to String. Unfortunately since
ParentNode is used by Document, we can't fully remove the deprecated
versions of these functions yet.
2023-09-11 12:07:36 +01:00
Shannon Booth
41928c2902 LibWeb: Port DOMException interface from DeprecatedString to String 2023-09-06 11:44:45 -04:00
Andreas Kling
76580bb9ba LibWeb: Cache lowercased tag name for getElementsByTagName() iteration
Instead of calling to_lowercase() on two strings for every step while
iterating over the HTMLCollection returned by getElementsByTagName(),
we now cache the lowercased tag name beforehand and reuse it.

2.4x speed-up on WebKit/PerformanceTests/DOM/DOMDivWalk.html
2023-08-23 08:06:25 +02:00
Andreas Kling
72c9f56c66 LibJS: Make Heap::allocate<T>() infallible
Stop worrying about tiny OOMs. Work towards #20449.

While going through these, I also changed the function signature in many
places where returning ThrowCompletionOr<T> is no longer necessary.
2023-08-13 15:38:42 +02:00
Sam Atkins
1858f06881 LibWeb: Add namespaces to Universal and TagName selectors 2023-08-08 20:49:45 +01:00
Andreas Kling
df1bb0ff49 LibWeb: Make HTMLCollection faster when it only cares about children
Some of the live HTMLCollection only ever contain children of their root
node. When we know that's the case, we can avoid doing a full subtree
traversal of all descendants and only visit children.

This cuts the ECMA262 spec loading time by over 10 seconds. :^)
2023-05-23 14:38:45 +02:00
Simon Wanner
9e00ef0849 LibWeb: Pass scope in ParentNode::query_selector_all 2023-03-21 10:45:19 +01:00
Simon Wanner
4e6fb65ea3 LibWeb: Pass scope in ParentNode::query_selector 2023-03-21 10:45:19 +01:00
Kenneth Myhra
ff875d353b LibWeb: Make factory method of DOM::HTMLCollection fallible 2023-02-18 00:52:47 +01:00
Timothy Flynn
f3db548a3d AK+Everywhere: Rename FlyString to DeprecatedFlyString
DeprecatedFlyString relies heavily on DeprecatedString's StringImpl, so
let's rename it to A) match the name of DeprecatedString, B) write a new
FlyString class that is tied to String.
2023-01-09 23:00:24 +00: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
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
Andrew Kaster
8de7e49a56 LibWeb: Remove unecessary dependence on Window from DOM and WebIDL
These classes only needed Window to get at its realm. Pass a realm
directly to construct DOM and WebIDL classes.

This change importantly removes the guarantee that a Document will
always have a non-null Window object. Only Documents created by a
BrowsingContext will have a non-null Window object. Documents created by
for example, DocumentFragment, will not have a Window (soon).

This incremental commit leaves some workarounds in place to keep other
parts of the code building.
2022-10-01 21:05:32 +01:00
Linus Groh
bbaa05fcf9 LibWeb: Move DOMException from DOM/ to WebIDL/ 2022-09-25 19:13:31 +01:00
Linus Groh
ad04d7ac9b LibWeb: Move ExceptionOr from DOM/ to WebIDL/
This is a concept fully defined in the Web IDL spec and doesn't belong
in the DOM directory/namespace - not even DOMException, despite the name
:^)
2022-09-25 19:13:31 +01:00
Andreas Kling
dc6e625680 LibWeb: Make ParentNode.children vend the same HTMLCollection every time
Instead of creating a new HTMLCollection every time you access
.children, we now follow the spec and vend the same object.

This was annoyingly difficult before, and trivial now that the DOM is
garbage-collected. :^)
2022-09-18 00:42:33 +02:00
Andreas Kling
6b3293a74b LibWeb: Support getElementsByTagName() properly in non-HTML documents 2022-09-18 00:39:42 +02:00
Andreas Kling
bd0648a492 LibWeb: Simplify getElementsByTagName{,NS}() filters
Everything below the collection root is a descendant of the collection
root, so there's no need to check is_descendant_of() :^)
2022-09-18 00:37:24 +02:00
Andreas Kling
497ead37bc LibWeb: Make DOMException GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
2bba97964b LibWeb: Make HTMLCollection and subclasses 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
Sam Atkins
c449cabae3 LibWeb: Move CSS Parser into new Web::CSS::Parser namespace
The goal here is to move the parser-internal classes into this namespace
so they can have more convenient names without causing collisions. The
Parser itself won't collide, and would be more convenient to just
remain `CSS::Parser`, but having a namespace and a class with the same
name makes C++ unhappy.
2022-04-12 23:03:46 +02:00
Linus Groh
a68d31debd LibWeb: Convert ParentNode to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Luke Wilde
d1bc9358c1 LibWeb: Implement ParentNode.replaceChildren 2022-01-31 15:25:36 +01:00
Luke Wilde
34dfdc3f37 LibWeb: Implement ParentNode.append 2022-01-31 15:25:36 +01:00
Luke Wilde
d5c96c3ccf LibWeb: Implement ParentNode.prepend
`convert_nodes_to_single_node` is inside its own file so ChildNode can
include and use it without having to include other headers such as
DOM/Node.h. This is to prevent circular includes.
2022-01-31 15:25:36 +01:00
Luke Wilde
5ac57db5e9 LibWeb: Don't match the node querySelector(All) was called on
In querySelector(All)'s use of "Match a Selector Against a Tree", it
passes in the node the function was called on as the "optional scoping
root", which causes it and the nodes which aren't descendants of it 
to be excluded from the list of possible nodes to match against.
For us, this is the equivalent of using the non-inclusive variant of
`for_each_in_subtree_of_type`.

This was tripping up the node re-ordering logic of d3 and would cause
it to try and reinsert nodes into their parent, causing an exception
to be thrown.

Note that this should be shadow-including, but we don't currently have
shadow-including tree traversal as per https://dom.spec.whatwg.org/#concept-shadow-including-tree-order

https://drafts.csswg.org/selectors-4/#match-a-selector-against-a-tree
https://dom.spec.whatwg.org/#scope-match-a-selectors-string
2022-01-20 22:18:07 +00:00
Luke Wilde
2f7fb1fe63 LibWeb: Convert ParentNode.querySelectorAll to NodeList 2021-10-03 00:18:52 +02:00
Luke Wilde
d47e431d54 LibWeb: Add getElementsByTagNameNS and add support for * in non-NS
This also moves getElementsByTagName to ParentNode to remove the code
duplication between Document and Element. This additionally fixes a bug
where getElementsByTagName did not check if the element was a
descendant, meaning it would also include the context element if the
condition matched.
2021-09-22 20:33:06 +02:00
Luke Wilde
e4d97add3d LibWeb: Implement ParentNode.children
Required by Web Platform Tests for the innerHTML/outerHTML tests.
2021-09-14 02:09:18 +02:00
Linus Groh
8cd4a889fe LibWeb: Stop dumping selectors in ParentNode::query_selector{,_all}()
This isn't particularly useful (anymore), especially without any context
about _why_ this output suddenly appears in the debug console.
2021-09-13 21:16:33 +01:00
Andreas Kling
0398089275 LibWeb: Throw SyntaxError on bogus querySelector{,All} input selector 2021-09-11 22:54:26 +02:00
Sam Atkins
3bd14941c7 LibWeb: Switch to new CSS Parser :^)
Change all the places that were including the deprecated parser, to
include the new one instead, and then delete the old parser code.

`ParentNode::query_selector[_all]()` now treat their input as a
comma-separated list of selectors, instead of just one, and return
elements that match any of the selectors in that list. This is according
to these specs:

- querySelector/querySelectorAll:
https://dom.spec.whatwg.org/#ref-for-dom-parentnode-queryselector%E2%91%A0
- selector matching algorithm:
https://www.w3.org/TR/selectors-4/#match-against-tree
2021-08-02 19:01:25 +04:30
Alexander
459aa44f6b LibWeb: Avoid UAF in query_selector{,_all}()
This fixes a bug that caused the selector to be dumped.
It would relase the RefPtr into a dump function, and then use it.
2021-07-17 01:48:04 +04:30
Sam Atkins
776b1f4548 LibWeb: Make CSS::Selector reference counted
The end goal is to make the PseudoClass::not_selector be a Selector
instead of a String that is repeatedly re-parsed. But since Selector
contains a Vector of ComplexSelectors, which each have a Vector of
SimpleSelectors, it's probably a good idea to not be passing them
around by value anyway. :^)
2021-07-14 13:31:00 +02:00
Sam Atkins
004ae453d1 LibWeb: Add context to new CSS parser, and deprecate the old one
The new one is the same as the old one, just in the new Parser's
source files. This isn't the most elegant solution but it seemed
like the best option. And it's all temporary, after all.
2021-07-11 23:19:56 +02:00
Luke
31364da590 LibWeb+HackStudio: Use lukew@serenityos.org for my copyright headers 2021-04-22 23:15:33 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Luke
83d2c3f2f5 LibWeb: Move element_child_count to ParentNode and add its IDL attribute
I initially had it in Node just because, but then saw it was part of
ParentNode in the spec.
2021-04-11 18:32:42 +02:00