Commit graph

68626 commits

Author SHA1 Message Date
stelar7
aa4e303b9f LibWeb/IDB: Make some debug messages more descriptive 2025-04-10 19:12:30 -06:00
stelar7
fc06d088c3 LibWeb/IDB: Implement IDBTransaction::objectStore 2025-04-10 19:12:30 -06:00
stelar7
8fcb54dada LibWeb/IDB: Abort requests in the transactions request list 2025-04-10 19:12:30 -06:00
stelar7
a61315a68e LibWeb/IDB: Use correct wait condition when upgrading database 2025-04-10 19:12:30 -06:00
stelar7
de640ffef4 LibWeb/IDB: Implement auto-commit for IDBTransaction 2025-04-10 19:12:30 -06:00
stelar7
da56c1b1eb LibWeb/IDB: Implement IDBTransaction::commit 2025-04-10 19:12:30 -06:00
stelar7
b6b00acbd1 LibWeb/IDB: Implement abort and wait steps for closing a connection 2025-04-10 19:12:30 -06:00
stelar7
fc93ec135e LibWeb/IDB: Keep track of the connection used to start a transaction 2025-04-10 19:12:30 -06:00
stelar7
d1dabb9039 LibWeb/IDB: Make close_a_database_connection take a GC::Ref 2025-04-10 19:12:30 -06:00
stelar7
7c3de67b16 LibWeb/IDB: Dont set the forced flag when aborting connection 2025-04-10 19:12:30 -06:00
stasoid
32ddeb82d6 LibURL+LibWeb: Remove leading slash when converting url to path
...on Windows
2025-04-10 19:04:21 -06:00
stasoid
5ff32fb090 WebContent: Replace static_assert IPC fixmes with comments
Fixes compilation errors on Windows
2025-04-10 19:03:00 -06:00
stasoid
beb11f0447 RequestServer: Compile on Windows 2025-04-10 19:03:00 -06:00
stasoid
17fcbce324 LibCore: Make single-shot timer objects manually reset on Windows
This fixes a really nasty EventLoop bug which I debugged for 2 weeks.

The spin_until([&]{return completed_tasks == total_tasks;}) in
TraversableNavigable::check_if_unloading_is_canceled spins forever.

Cause of the bug:

check_if_unloading_is_canceled is called deferred

check_if_unloading_is_canceled creates a task:

        queue_global_task(..., [&] {
            ...
            completed_tasks++;
        }));

This task is never executed.

queue_global_task calls TaskQueue::add

void TaskQueue::add(task)
{
    m_tasks.append(task);
    m_event_loop->schedule();
}

void HTML::EventLoop::schedule()
{
    if (!m_system_event_loop_timer)
        m_system_event_loop_timer = Timer::create_single_shot(
            0, // delay
            [&] { process(); });

    if (!m_system_event_loop_timer->is_active())
        m_system_event_loop_timer->restart();
}

EventLoop::process executes one task from task queue and calls
schedule again if there are more tasks.

So task processing relies on one single-shot zero-delay timer,
m_system_event_loop_timer.

Timers and other notification events are handled by Core::EventLoop
and Core::ThreadEventQueue, these are different from HTML::EventLoop
and HTML::TaskQueue mentioned above.

check_if_unloading_is_canceled is called using deferred_invoke
mechanism, different from m_system_event_loop_timer,
see Navigable::navigate and Core::EventLoop::deferred_invoke.

The core of the problem is that Core::EventLoop::pump is called again
(from spin_until) after timer fired but before its handler is executed.

In ThreadEventQueue::process events are moved into local variable before
executing. The first of those events is check_if_unloading_is_canceled.
One of the rest events is Web::HTML::EventLoop::process sheduled in
EventLoop::schedule using m_system_event_loop_timer.
When check_if_unloading_is_canceled calls queue_global_task its
m_system_event_loop_timer is still active because Timer::timer_event
was not yet called, so the timer is not restarted.
But Timer::timer_event (and hence EventLoop::process) will never execute
because check_if_unloading_is_canceled calls spin_until after
queue_global_task, and EventLoop::process is no longer in
event_queue.m_private->queued_events.

By making a single-shot timer manually-reset we are allowing it to fire
several times. So when spin_until is executed m_system_event_loop_timer
is fired again. Not an ideal solution, but this is the best I could
come up with. This commit makes the behavior match EventLoopImplUnix,
in which single-shot timer can also fire several times.

Adding event_queue.process(); at the start of pump like in EvtLoopImplQt
doesn't fix the problem.

Note: Timer::start calls EventReceiver::start_timer, which calls
EventLoop::register_timer with should_reload always set to true
(single-shot vs periodic are handled in Timer::timer_event instead),
so I use static_cast<Timer&>(object).is_single_shot() instead of
!should_reload.
2025-04-10 19:02:03 -06:00
stasoid
2bfed2e417 LibCore: Check for all events in EventLoopImplementationWindows::pump
This fixes the problem when none of the timers or notifiers get
executed if wake() is called frequently.

Note that calling WaitForMultipleObjects repeatedly until it fails
will not work because rapidly firing timer can get all the attention.
That's why I check every event individually with WaitForSingleObject.

This behavior matches EventLoopImplementationUnix.
2025-04-10 19:02:03 -06:00
stasoid
5ea4d26458 LibCore: Don't wait in WaitForMultipleObjects if thread event queue
has pending events in EventLoopImplementationWindows

This matches the behavior of the Linux version:
https://github.com/LadybirdBrowser/ladybird/blob/911cd4aefd0c/Libraries/LibCore/EventLoopImplementationUnix.cpp#L371
2025-04-10 19:02:03 -06:00
stasoid
33457f389d LibCore: Check for null ThreadData in unregister_notifier
and unregister_timer in EventLoopManagerWindows

Destructors for thread local objects are called before destructors of
global not thread local objects.

This is a partial stack of the problem, thread_data is already
destroyed at this point:

>WebContent.exe!Core::ThreadData::the
 WebContent.exe!Core::EventLoopManagerWindows::unregister_notifier
 WebContent.exe!Core::EventLoop::unregister_notifier
 WebContent.exe!Core::Notifier::set_enabled
 WebContent.exe!Core::LocalSocket::~LocalSocket
 WebContent.exe!Requests::RequestClient::~RequestClient
 WebContent.exe!Web::`dynamic atexit destructor for 's_resource_loader'
2025-04-10 19:02:03 -06:00
Aliaksandr Kalenik
b53694b4c0 LibIPC+LibWeb: Delete LargeMessageWrapper workaround in IPC connection
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Bring back 2d625f5c23
2025-04-10 23:40:02 +02:00
Aliaksandr Kalenik
681333d329 LibIPC: Protect underlying socket of TransportSocket with RWLock
This is necessary to prevent the socket from being closed while it is
being used for reading or writing.
2025-04-10 23:40:02 +02:00
Aliaksandr Kalenik
14dc7686c3 LibIPC: Change TransportSocket to write large messages in small chunks
Bring back d6080d1fdc with a missing check
whether underlying socket is closed, before accessing `fd()` that is
optional and empty in case of closed socket.
2025-04-10 23:40:02 +02:00
Tim Ledbetter
1ee56d34e7 Revert "LibIPC+LibWeb: Delete LargeMessageWrapper workaround in IPC…
…connection"

This reverts commit 2d625f5c23.
2025-04-10 16:24:38 +01:00
Tim Ledbetter
3fcdbef327 Revert "LibIPC: Change TransportSocket to write large messages in…"
…small chunks.

This reverts commit d6080d1fdc.
2025-04-10 16:24:38 +01:00
Jess
23cdd78f1a LibTest: Ensure other time statistic doesn't underflow
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
2025-04-10 11:17:06 +02:00
Sam Atkins
9dbeecb73d LibWeb: Correct some spec typos
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Corresponds to 285a58bf30
2025-04-10 04:01:37 +02:00
Andreas Kling
4a5863bcdb LibJS: Remove unnecessary FunctionObject::name() virtual
This allows us to remove the BoundFunction::m_name field, which we
were initializing with a formatted FlyString on every function binding,
despite never using it for anything.
2025-04-10 04:01:00 +02:00
Andreas Kling
6bd2cf3195 LibWeb: Make Document::m_shadow_roots an IntrusiveList
This makes unregistering a ShadowRoot O(1) instead of O(n) and erases
a 2.2% item entirely from the Speedometer 2.1 profile.
2025-04-10 04:01:00 +02:00
Aliaksandr Kalenik
2d625f5c23 LibIPC+LibWeb: Delete LargeMessageWrapper workaround in IPC connection
It's no longer needed because TransportSocket is now capable of properly
sending large messages.
2025-04-10 01:30:08 +02:00
Aliaksandr Kalenik
d6080d1fdc LibIPC: Change TransportSocket to write large messages in small chunks
With this change TransportSocket becomes capable of sending large
messages without relying on workarounds, such as sending the message as
a shared memory file descriptor when it can't fully fit into the socket
buffer.

It's implemented by combining all enqueued messages into two buffers:
one for bytes and another for fds, and repeatedly attempts to write them
in smaller chunks, waiting for the socket to become writable again if
the receiver needs time to consume the data.

Another significant improvement brought by this change is that we no
longer drop messages queued for sending if the socket doesn't become
writable after a 100ms timeout. Instead, we return the message to the
send buffer and continue waiting for the socket to become writable.
2025-04-10 01:30:08 +02:00
Andreas Kling
fc111537bb LibJS: Move Value::to_i32() and to_u32() back out-of-line
While good on arm64, this appears to have angered the x86_64 benchmark
runner, so let's just put them back out-of-line.
2025-04-10 00:33:54 +02:00
Andreas Kling
8c8023465b LibJS: Make use of arm64 FJCVTZS instruction if available
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
FJCVTZS (Floating-point Javascript Convert to Signed fixed-point,
rounding toward Zero) does exactly what we need for ToInt32 in the
JavaScript specification.

This isn't world-changing, but it does give a ~2% boost on compute-
heavy benchmarks like JetStream, so we should obviously use it.
2025-04-09 22:06:49 +02:00
Andreas Kling
938b1e91fe LibJS: Inline the fast path of Value::to_i32() and simplify to_u32()
The fast path of to_i32() can be neatly inlined everywhere, and we still
have to_i32_slow_case() for non-trivial conversions.

For to_u32(), it really can just be implemented as a static cast to i32!
2025-04-09 22:06:49 +02:00
stelar7
f1fba24538 LibWeb/IDB: Add ObjectStore to IDBDatabases store set 2025-04-09 11:48:49 -06:00
stelar7
1fc2d6f1af LibWeb/IDB: Comment out infinite loop while waiting for next PR
Since the steps needed to avoid this loop is quite long,
adding this as a fixme for the future will make this PR easier to review
2025-04-09 11:48:49 -06:00
stelar7
6ec914c7f7 LibWeb/IDB: Add some debug output 2025-04-09 11:48:49 -06:00
stelar7
4084a127de LibWeb/IDB: Change reference to a GC::Ref in abort_a_transaction 2025-04-09 11:48:49 -06:00
stelar7
5298ecfc94 LibWeb/IDB: Implement IDBTransaction attributes
This also uncovered a bug, where the transactions type was never set :^)
2025-04-09 11:48:49 -06:00
stelar7
718c805e95 LibWeb/IDB: Implement IDBObjectStore::deleteIndex 2025-04-09 11:48:49 -06:00
stelar7
fce936e05a LibWeb/IDB: Implement IDBObjectStore::index 2025-04-09 11:48:49 -06:00
stelar7
fba7ad6969 LibWeb/IDB: Implement IDBObjectStore::indexNames 2025-04-09 11:48:49 -06:00
stelar7
3367352991 LibWeb/IDB: Implement IDBObjectStore::createIndex 2025-04-09 11:48:49 -06:00
stelar7
a235dd4300 LibWeb/IDB: Fillout IDBIndex attributes 2025-04-09 11:48:49 -06:00
stelar7
9321ad04c0 LibWeb/IDB: Add internal Index object 2025-04-09 11:48:49 -06:00
Sam Atkins
8beade51e0 LibWeb/CSS: Make it clear that StyleSheet::media() is never null 2025-04-09 18:45:57 +01:00
Sam Atkins
848a250b29 LibWeb/CSS: Mark CSSImportRule.media as nullable
See the linked spec issue for more details. The MediaList can be null
internally, and this was upsetting GCC as it meant our bindings code
was dereferencing a null pointer.
2025-04-09 18:45:57 +01:00
Sam Atkins
0f42d5ec3e LibWeb/CSS: Don't resolve @import URLs until they are used
The regression in the "conditional-CSSGroupingRule" test is we now fail
the "inserting an `@import`" subtests differently and the subtests
aren't independent. Specifically, we don't yet implement the checks in
`CSSRuleList::insert_a_css_rule()` that reject certain rules from being
inserted. Previously we didn't insert the `@import` rule because we
failed to parse its relative URL. Now we parse it correctly, we end up
inserting it.
2025-04-09 18:45:57 +01:00
Sam Atkins
ca0890ce16 LibWeb/CSS: Only try to fetch @imports with a parent style sheet
When `CSSRuleList::remove_a_css_rule()` is called, the removed rule has
its parent style sheet set to null. We shouldn't try to fetch an import
in this case.
2025-04-09 18:45:57 +01:00
Sam Atkins
1d9902e22c Tests: Import some @import tests 2025-04-09 18:45:57 +01:00
Sam Atkins
c679643391 LibWeb/CSS: Extract CSSStyleSheet's ParsingParams code into a method
This repeated code is a bit unwieldy.
2025-04-09 18:45:57 +01:00
Sam Atkins
1abc628cd8 LibWeb/CSS: Allow CSSImportRule's document to be null on construction
It's possible to parse an `@import` rule that isn't attached to a
document. We only actually need it to have one when fetching the linked
style sheet, and that should only happen when the CSSImportRule is
attached to a document. So, we can just accept a null pointer when
constructing it.

We relied on that Document to get the Realm, so pass that in as a
separate parameter.
2025-04-09 18:45:57 +01:00
Sam Atkins
a8ab4d64c4 LibWeb/DOM: Use document's URL as location for inline stylesheets
This is ad-hoc, and the spec doesn't seem to tell us what to actually do
here. Without this, following the spec steps for loading relative
`@import` URLs from a `<style>` tag always fails, because that uses the
parent style sheet's location as the base URL.
2025-04-09 18:45:57 +01:00