Commit Graph

192 Commits

Author SHA1 Message Date
Tim Ledbetter
7e288e80fe LibWeb: Allow FormData entry list to be mutated within a FormDataEvent
Previously, the list was copied when constructing the FormData object,
then the original list was passed to the event, meaning any changes to
the list that happened within the event would not be reflected outside
of it.

(cherry picked from commit ea0e434d1d6b464ab0a56c4b7150950be78ae7d3)
2024-11-25 12:19:33 -05:00
Tim Ledbetter
6bf08818be LibWeb: Don't crash when parsing large floating point number values
Previously, attempting to parse a floating point number with an integer
part larger than `(2 ^ 31) - 1` would cause the browser to crash. We now
avoid this by converting the integer part of the number to a `double`
rather than an `i32`.

(cherry picked from commit 21a32e4b6dc594c2fe8dd3ee11c829c250a103ad)
2024-11-25 12:19:33 -05:00
Alan Kemp
ae8d143338 LibWeb: Pageshow event dispatched by the user agent should be trusted
The spec says that "isTrusted is a convenience that indicates whether
an event is dispatched by the user agent (as opposed to using
dispatchEvent())"

But when dispatching a pageshow event the flag was incorrectly set
to false.

This fixes https://wpt.fyi/results/html/syntax/parsing/the-end.html

(cherry picked from commit d2fbbabd893d84a6b8b68a8bc8034e4d6dc4da4a)
2024-11-25 09:21:14 -05:00
Andreas Kling
48d994839c LibWeb: Don't swallow args when forwarding cross-origin WindowProxy call
Fixes at least one WPT test that was previously timing out:
- html/semantics/document-metadata/the-base-element/base_target_does_not_affect_iframe_src_navigation.html

(cherry picked from commit 0b403d30d765ab8e5db3b7443ebeca7f85c3acf2)
2024-11-25 08:50:54 -05:00
Timothy Flynn
1322fed4c8 LibWeb+WebContent: Do not include DOM HTML in text test expectations
For example, in the following abbreviated test HTML:

    <span>some text</span>
    <script>println("whf")</script>

We would have to craft the expectation file to include the "some text"
segment, usually with some leading whitespace. This is a bit annoying,
and makes it difficult to manually craft expectation files.

So instead of comparing the expectation against the entire DOM inner
text, we now send the inner text of just the <pre> element containing
the test output when we invoke `internals.signalTextTestIsDone`.

(cherry picked from commit bf668696de9a68bbcd6adfeaac809a475da015dc;
amended a bit but not as much as one might think -- see PR for details)
2024-11-24 22:42:15 -05:00
Timothy Flynn
0446c98053 LibWeb: Convert some sync tests to be async
The events tested here are decidedly async. We also can't really write
sync tests of the form "test(async () => {})". Nothing will await the
async callback.

(cherry picked from commit c9cbaeb59d6f699b33bf3924688987b3ca917fee)
2024-11-24 22:42:15 -05:00
Shannon Booth
65f4aae1d8 LibURL+Everywhere: Only percent decode URL paths when actually needed
Web specs do not return through javascript percent decoded URL path
components - but we were doing this in a number of places due to the
default behaviour of URL::serialize_path.

Since percent encoded URL paths may not contain valid UTF-8 - this was
resulting in us crashing in these places.

For example - on an HTMLAnchorElement when retrieving the pathname for
the URL of:

http://ladybird.org/foo%C2%91%91

To fix this make the URL class only return the percent encoded
serialized path, matching the URL spec. When the decoded path is
required instead explicitly call URL::percent_decode.

This fixes a crash running WPT URL tests for the anchor element on:

https://wpt.live/url/a-element.html
(cherry picked from commit cc557323326ba55514ef2a8a6e0efd7f09330f06;
amended heavily to call `URL::percent_decode()` on all results of
`url.serialize_path()` in the rest of serenity -- except in
LibGemini, where it looked incorrect, and in LibHTTP, where
LadybirdBrowser/ladybird#983 will add it.)
2024-11-21 17:47:14 -05:00
Andreas Kling
a65b5cb135 LibWeb: Mark image elements for layout before firing their load event
This removes a long-standing source of flakiness seen for example in
WPT's /referrer-policy/ tests.

(cherry picked from commit 063cd68bf472061ec35cf9b8970aa6e614632c9b)
2024-11-20 22:51:34 -05:00
Luke Wilde
27c1ce5299 LibWeb: Make default document readiness be "complete"
This is required by mini Cloudflare invisible challenges, as it will
only run if the readyState is not "loading". If it is "loading", then
it waits for readystatechange to check that it's not "loading" anymore.

Initial about:blank iframes do not go through the full navigation and
thus don't go through HTMLParser::the_end, which sets the ready state
to something other than "loading". Therefore, the challenge would never
run, as readyState would never change.

Seen on https://discord.com/login

(cherry picked from commit f638f84185938c74a47f5691e8d7c5e1d4dca07c)
2024-11-20 22:51:34 -05:00
Luke Wilde
a7b4b170ed LibWeb: Make MessageEvents from {Window,MessagePort}.postMessage trusted
The MessagePort one in particular is required by Cloudflare Turnstile,
as the method it takes to run JS in a worker is to `eval` the contents
of `MessageEvent.data`. However, it will only do this if
`MessageEvent.isTrusted` is true, `MessageEvent.origin` is the empty
string and `MessageEvent.source` is `null`.

The Window version is a quick fix whilst in the vicinity, as its
MessageEvent should also be trusted.

(cherry picked from commit 079c28d5e68ad983340c02f3d043acfdf2846d18)
2024-11-17 15:18:20 -05:00
Andrew Kaster
1dfd8755bc LibWeb: Add a feature to LibWeb tests to fail on unhandled exceptions
Previously, if there was an unhandled exception in an async test, it
might fail to call done() and timeout. Now we have a default "error"
handler to catch unhandled exceptions and fail the test. A few tests
want to actually test the behavior of window.onerror, so they need an
escape hatch.

(cherry picked from commit 8edaec79dea2f39a31ee97738dfa2e74911efe26)
2024-11-17 13:47:42 -05:00
Andreas Kling
23fd706ea9 LibWeb: Fire navigation event as required in History.pushState()
(cherry picked from commit a1519e67fb7a47755d12ff1e8ce2a7de28087933)
2024-11-17 13:47:42 -05:00
Andreas Kling
3e5f37f983 LibWeb: Allow changing the query of file:// URL via history.pushState()
The spec didn't match how other browsers behave, and we dutifully did
what the spec said. A spec bug has been filed, so let's fix this locally
for now with a FIXME.

(cherry picked from commit e3408c4a7f2fe2ce2435d34e816e9b5b7e58f4af)
2024-11-17 13:47:42 -05:00
sin-ack
23e49f2835 BindingsGenerator: Handle global interfaces without named properties
DedicatedWorkerGlobalScope is an object with a Global extended
attribute, but does not define any named property getters. This needs to
be handled by setting the prototype chain to:

    DedicatedWorkerGlobalScope
    ^ DedicatedWorkerGlobalScopePrototype
    ^ WorkerGlobalScopePrototype

(This is different from something like Window, where there is an
intermediate WindowProperties object for named properties.)

Previously, we treated the GlobalMixin object as if it was a simple
prototype object, accidentally setting DedicatedWorkerGlobalScope's
prototype to WorkerGlobalScopePrototype. This caused the expression

    self instanceof DedicatedWorkerGlobalScope

to return false inside workers.

This makes us pass many more of the "/xhr/idlharness.any.worker" WPT
tests than before, rather than failing early.

(cherry picked from commit d5948709cd499ef0e7bfa3c24e8c03befed115fe)
2024-11-14 17:46:06 -05:00
Arhcout
0845de1018 LibWeb: Don't trigger onchange event when setting <select> value
(cherry picked from commit 5d00211a8605b0fab9f330082699f6f089961052)
2024-11-14 17:46:06 -05:00
Luke Wilde
c1767b1964 LibWeb: Make iframe insertion steps check the shadow including root
The insertion steps for iframes were following an old version of the
spec, where it was checking if the iframe was "in a document tree",
which doesn't cross shadow root boundaries. The spec has since been
updated to check the shadow including root instead.

This is now needed for Cloudflare Turnstile iframe widgets to appear,
as they are now inserted into a shadow root.

(cherry picked from commit 4dd14d812f73377cb1efa5a8e8a114912a90b5af)
2024-11-13 19:32:02 -05:00
Andreas Kling
337b113e68 LibWeb: Use the correct document URL in DOMParser.parseFromString()
We were hard-coding "about:blank" as the document URL for parsed HTML
documents, which was definitely not correct.

This fixes a bunch of WPT tests under /domparsing/ :^)

(cherry picked from commit 55f58eea99c0429dcc39cd0430fafa60eecf5542)
2024-11-13 10:17:34 -05:00
Benjamin Bjerken
a3c986021d LibWeb: Add SVGImageElement load and error events
This resolves all WPT timeouts in html/canvas/element/manual/imagebitmap
We can now run an additional 6 tests and 126 subtests :)

This also adds regression tests for this behavior.

(cherry picked from commit 0c04bd66764dfbe8f6da515d09b076683c61e93c)
2024-11-13 10:17:34 -05:00
Benjamin Bjerken
6268e8f559 LibWeb: Fix CloseWatcher constructor for detached iframes
This fixes the last subtest in /close-watcher/frame-removal.html :)

(cherry picked from commit 63d9ed9d8c4fafd569e042e0698bd5dc844a1b29)
2024-11-13 10:17:34 -05:00
Tim Ledbetter
05e8835555 LibWeb: Follow spec steps to set the selectionDirection attribute value
(cherry picked from commit d0b97873d421d092eb41e3b7a7d8959347b3b436)
2024-11-12 22:26:21 -05:00
Tim Ledbetter
be7110a3a4 LibWeb: Map dimension attributes for table elements
(cherry picked from commit 140dc95e6769a41542f98abef333d5bc32b86e39)
2024-11-12 19:57:55 -05:00
Tim Ledbetter
ea8914aeac LibWeb: Map embedded content element attributes to dimension properties
(cherry picked from commit 728236f4d20b4dbabfe0936b79a2f63ac80f4da3)
2024-11-12 19:57:55 -05:00
Tim Ledbetter
8dee6b9ebd Libweb: Map marquee attributes to dimension properties
(cherry picked from commit baca0e5e5568b1b9b301cefa7d6cc8312b39be28)
2024-11-12 19:57:55 -05:00
Tim Ledbetter
7e456212c7 LibWeb: Map hr width attribute to the width dimension property
(cherry picked from commit 4c3101e021e323b487e8ab10026a14fdf40fa2f0)
2024-11-12 19:57:55 -05:00
Tim Ledbetter
bb798071a0 LibWeb: Treat dates and times with repeated separators as invalid
These would previously be treated as valid by the value sanitization
algorithm.

(cherry picked from commit f9282f65d3a4daf7df2c6033b03c70a56130aa72)
2024-11-12 19:57:55 -05:00
Tim Ledbetter
c7a699ed73 LibWeb: Make input type state change handling specification compliant
This change ensures that the value sanitization algorithm is run and
the text cursor is set to the correct position when the type attribute
of an input is changed.

(cherry picked from commit 1b74104c17726018788034f2ad66201889ce6225)
2024-11-12 10:45:53 -05:00
Tim Ledbetter
a77b65d46a LibWeb: Don't attempt to set selection if control has no selectable text
(cherry picked from commit 2c8fb4957871bca5694fc9e9f8932c9769967bd1)
2024-11-12 10:45:53 -05:00
Totto16
c1b0ac6376 LibWeb: Reject Promise in createImageBitmap for Not Implemented Types
If we don't reject the Promise, it lasts forever,
so rejecting non implemented Promises is essential,
to not timeout in e.g. WPT tests

(cherry picked from commit aab5a9e944f8b1c1a9de321047556bbcaa282a56)
2024-11-11 19:54:09 -05:00
Tim Ledbetter
f9158f4210 LibWeb: Fire iframe load event on document close
This matches the behavior of other browsers.

(cherry picked from commit e1eeb93cc6095a47371d23db0bbf55eb30215cee)
2024-11-11 19:54:09 -05:00
Shannon Booth
9150241db9 LibWeb: Throw a SyntaxError on invalid URL for Location href setter
Aligning with a spec update, fixing 195 tests for:

https://wpt.live/url/failure.html
(cherry picked from commit ea971792b5da5f10cadb4f88f49c9722d88b32f6)
2024-11-11 17:22:42 -05:00
samu698
a37e4092bc LibWeb/HTML: Implement inner text set according to spec
Replaced the ad-hoc implementation with a spec compliant one.
This change fixes 36 WPT tests.

(cherry picked from commit 50f642613de54c73473c216fdc4d7e607e712679)
2024-11-10 21:48:40 -05:00
Timothy Flynn
26551f6700 LibWeb: Always call document.close after document.write
This ensures the HTML parser completes running if it previously stopped
at an insertion point during a call to `document.write`.

(cherry picked from commit 230314238655204b89dd0736da4537b475eb252a)
2024-11-10 17:42:37 -05:00
Tim Ledbetter
fa08ac3631 LibWeb: Fire error event when script has an execution error
We now use the "report an exception" AO when a script has an execution
error. This has mostly replaced the older "report the exception" AO in
various specifications. Using this newer AO ensures that
`window.onerror` is invoked when a script has an execution error.

(cherry picked from commit 579a289d3db849657987c3310e7b1d71d290b566)
2024-11-10 10:46:01 -05:00
Andreas Kling
adad01a830 LibWeb: Always flush character insertions before exiting HTML parser
This fixes an issue where document.write() with only text input would
leave all the character data as unflushed text in the parser.

This fixes many of the WPT tests for document.write().

(cherry picked from commit a0ed12e839f14b3ac80caca0e18a09ca256fd99d)
2024-11-10 10:46:01 -05:00
Tim Ledbetter
961272cf60 LibWeb: Don't crash when determining slot element auto directionality
(cherry picked from commit 0de314507153b6ae17d15f3b03df10a7844ed224)
2024-11-09 16:08:01 -05:00
Jamie Mansfield
ee8de58b98 LibWeb/HTML: Implement DataTransferItem.webkitGetAsEntry()
(cherry picked from commit 2e9aec984cc3c75f10ea3e6f50ea2ed34f4bd2b6)
2024-11-09 16:08:01 -05:00
Khaled Lakehal
71a01c8122 LibWeb: Add setter implementation for location.search
This commit implements the setter for `location.search`, allowing
updates to the query string of the URL.

(cherry picked from commit 514a2a1757b10b9b4ff020237c84f70ba5a79c4b)
2024-11-09 16:08:01 -05:00
Tim Ledbetter
943f47fa97 LibWeb: Implement the setter for location.protocol
(cherry picked from commit 1365289d984c32ca7bc076b7892dd56041ab26e2)
2024-11-09 07:30:40 -05:00
Tim Ledbetter
892c6c0439 LibWeb: Return empty string if object element data URL is invalid
(cherry picked from commit c61262684b51864618de99f8b302567c932455be)
2024-11-09 07:30:40 -05:00
Tim Ledbetter
760fea7ffa LibWeb: Return empty string if image element currentSrc URL is invalid
(cherry picked from commit 4f7a4d9c578429b156f4dab78f4f8b0601be9f39)
2024-11-09 07:30:40 -05:00
Jamie Mansfield
89d7ae75b2 LibWeb/SVG: Implement default_tab_index_value for a element
Another FIXME bites the dust :^)

(cherry picked from commit 9c4e80a3eca8329e5fd9e9fe75eac816b5666069)
2024-11-09 07:30:40 -05:00
Tim Ledbetter
51854c4ffd LibWeb: Resolve HTMLFormElement.action relative to document base URL
Rather than returning a relative URL, an absolutized URL is now
returned relative to the document base URL

(cherry picked from commit 48e5d28ec985aeaee565d06a625a0d664b6975d3)
2024-11-09 07:29:52 -05:00
Tim Ledbetter
ec91831999 LibWeb: Implement HTMLInputElement.formAction
(cherry picked from commit 33c62be7f96eec887d8f65552bbd61439b09a346)
2024-11-09 07:29:52 -05:00
Tim Ledbetter
42d17fb875 LibWeb: Return document URL if formAction attribute is missing or empty
This change also ensures that relative URLs are resolved relative to
the document's base URL.

(cherry picked from commit c25dda767eb43d1620602ccc2c955bc56ef1745b)
2024-11-09 07:29:52 -05:00
Timothy Flynn
7fbe1f8db9 LibWeb: Implement DataTransferItem.prototype.getAsString()
(cherry picked from commit 181ece4d9c64bdd97c19a7c10ed54cdd0e59b43f)
2024-11-08 22:32:11 -05:00
Timothy Flynn
a3b3221607 LibWeb: Implement DataTransferItem.prototype.getAsFile()
This is used on imgur after drag-and-dropping an image onto its page.

(cherry picked from commit b978dba8bdb53f0a1e54b74dde3031242ec268f9)
2024-11-08 22:32:11 -05:00
Jamie Mansfield
38dc317291 LibWeb: Implement HTMLTableCellElement.cellIndex
See:
 - http://wpt.live/html/semantics/tabular-data/attributes-common-to-td-and-th-elements/cellIndex.html
(cherry picked from commit fa5800ebc52a51ad66ddbf5a97ffb9fbb5424b70)
2024-11-08 21:51:25 -05:00
Jamie Mansfield
d81af2f5f5 LibWeb: Set script force async to false when async changes
(cherry picked from commit bedb626c29913f4e355dfd50c29194e15ed71561)
2024-11-08 21:51:25 -05:00
Jamie Mansfield
ceebaac9ef LibWeb: Script force async flag should default to true
See:
 - http://wpt.live/html/semantics/scripting-1/the-script-element/async_001.htm
(cherry picked from commit 77c41a82bec370ae7c8998aa939bd1117a29b31a)
2024-11-08 21:51:25 -05:00
Maciej
1e3bb7dbe1 LibWeb: Make innerHTML for XML nodes actually return inner HTML
The spec says to just call the XML serialization algorithm, but it
returns the "outer serialization", and we need the "inner" one. Let's
just concatenate serializations of children; then the result produced is
similar to one from Blink or Gecko.

(cherry picked from commit 9eb568eacbcb36e6c1ffd6e61ebf8242a4422119)
2024-11-08 21:51:25 -05:00