Commit graph

3793 commits

Author SHA1 Message Date
Andreas Kling
c333042e63 LibWeb: Add opt-in tracing of update_layout() calls with reason 2025-03-08 03:37:38 +01:00
R-Goc
fe26c3145d AK: Add stacktrace support using the standard lib
This commit adds support for using the standard library implementation
of <stacktrace> if libbacktrace is not found. This can also be
explicitly enabled through ENABLE_STD_STACKTRACE for platforms that have
libbacktrace available.

Co-Authored-By: Andrew Kaster <andrew@ladybird.org>
2025-03-05 10:25:12 -07:00
Timothy Flynn
1adcaf7181 AK: Fix the JsonArray constructor for accepting an iterable type
There were a couple of issues here. First, the IterableContainerOf
concept was testing if dereferencing an iterator of ContainerType<T>
returns a value of type T. However, it should return a T&.

Second, the constructor was trying to move values out of a constant
reference to the container. We now accept both lvalue and rvalue
containers.
2025-03-04 15:33:39 -05:00
R-Goc
94de31ff3b AK: Remove fast_u32_xxx apis from Memory.h
This commit removes the fast_u32_fill and fast_u32_copy functions,
as they were only used in one place, and are not optimal.
2025-03-03 15:58:27 +01:00
Jess
88c4f71114 AK/Checked: Dont verify overflow bit in lvalue operations
Before, adding an overflow'n `Checked<T>` to another `Checked<T>` would
cause a verification faliure when instead it should propogate m_overflow
and allow the user to handle the overflow.
2025-02-25 11:20:13 +00:00
Shannon Booth
a808cd1631 AK: Add a 'weeks_in_year' helper
A week variant of the pre-existing 'days_in_year'.
2025-02-22 19:09:41 +00:00
Shannon Booth
ad8a0e4940 AK: Introduce UnixDateTime::from_iso8601_week
This is intended to be used by the <input> element 'week' type state
and convert that to milliseconds from the Unix epoch (ignoring leap
seconds).

I am certain there is a much better way of writing this that does
not need a loop, but I am less convinced about writing that without
running into some edge case I didn't consider.
2025-02-22 19:09:41 +00:00
Shannon Booth
08331f5d62 AK: Move some time conversion constants into global scope
These can be useful outside of the scope of the function these are
used.
2025-02-22 19:09:41 +00:00
Timothy Flynn
fe2dff4944 AK+Everywhere: Convert JSON value serialization to String
This removes the use of StringBuilder::OutputType (which was ByteString,
and only used by the JSON classes). And it removes the StringBuilder
template parameter from the serialization methods; this was only ever
used with StringBuilder, so a template is pretty overkill here.
2025-02-20 19:27:51 -05:00
Timothy Flynn
2c03de60da AK+Everywhere: Remove now-unecessary use of ByteString with JSON types
This removes JsonObject::get_byte_string and JsonObject::to_byte_string.
2025-02-20 19:27:51 -05:00
Timothy Flynn
bc54c0cdfb AK+Everywhere: Store JSON strings as String 2025-02-20 19:27:51 -05:00
Timothy Flynn
e591636419 AK+Everywhere: Store JSON object keys as String 2025-02-20 19:27:51 -05:00
Timothy Flynn
70eb0ba1cd AK+Everywhere: Remove the char const* JSON value constructor 2025-02-20 19:27:51 -05:00
Timothy Flynn
ee70f1327a AK: Remove unused JSON string APIs 2025-02-20 19:27:51 -05:00
Timothy Flynn
a8bc0aed4a AK: De-duplicate the definition of the JSON value variant 2025-02-20 19:27:51 -05:00
Timothy Flynn
58bc44ba2a LibDevTools: Introduce a Firefox DevTools server library
To aid with debugging web page issues in Ladybird without needing to
implement a fully fledged inspector, we can implement the Firefox
DevTools protocol and use their DevTools. The protocol is described
here:

https://firefox-source-docs.mozilla.org/devtools/backend/protocol.html

This commit contains just enough to connect to Ladybird from a DevTools
client.
2025-02-19 08:45:51 -05:00
Timothy Flynn
0fc1d4cd69 AK: Provide a few mutable JSON object/array accessors
We have mutable accessors on the JsonValue class already. This will be
needed for interaction with Firefox's DevTools, where we will want to
mutate the serialized DOM tree we receive from WebContent.
2025-02-19 08:45:51 -05:00
stasoid
dcfc552d25 AK: Don't crash on empty extension in LexicalPath::has_extension
... on Windows
2025-02-17 14:57:00 +01:00
Sam Atkins
8b52a354fa AK: Add String factories for Roman numerals and bijective bases
These are copied and modified from ByteString, with the addition of a
Case parameter so that we can construct them in lowercase instead of
having to them make a copy.
2025-02-11 10:39:27 +01:00
Aliaksandr Kalenik
f926604cc3 AK: Define hash() and equals() for WeakPtr 2025-02-11 10:22:23 +01:00
Undefine
0c882c441e LibCompress: Remove unused Lzma compression and decompression 2025-02-10 16:22:32 +00:00
Tim Ledbetter
26ea5335c7 AK: Add FlyString::is_one_of_ignoring_ascii_case() 2025-02-08 07:30:27 -05:00
stasoid
4180fe5b58 AK: Add default value for ByteString::find_any_of::direction 2025-02-06 15:15:16 -07:00
stasoid
b77016cc34 LibCore: Consistently treat file descriptors as handles on Windows
Also:
 * implement dup and is_socket
 * implement and call init_crt_and_wsa
2025-02-05 19:27:47 -07:00
stasoid
870cce9d11 AK: Add Error::from_windows_error(void)
Also slightly improve Error::from_windows_error(int)
2025-02-05 19:27:47 -07:00
Sam Atkins
b16b24c615 AK: Add Utf8View::contains_any_of()
Useful when you need to check for more than one code point, some of
which are multiple bytes. (In which case StringView::contains() will
return wrong results.)
2025-02-04 08:49:25 +00:00
Tim Ledbetter
fb56da4144 AK: Allow as to perform dynamic cast where necessary
This aligns the behavior of `as` with `is` and `as_if`.
2025-01-31 14:29:48 +01:00
Tim Ledbetter
1f87a09503 AK: Allow as_if to perform dynamic cast when necessary
This means that if `is<OutputType>(x)` is true, that
`as_if<OutputType>(x)` should always succeed.
2025-01-31 14:29:48 +01:00
Andreas Kling
cfe3dbe99f AK: Avoid unnecessary copies when in JsonValue-from-array/object ctors
Knocks 1.1 seconds of loading time off of https://wpt.fyi/
2025-01-24 17:54:34 +01:00
Timothy Flynn
85b424464a AK+Everywhere: Rename verify_cast to as
Follow-up to fc20e61e72.
2025-01-21 11:34:06 -05:00
Timothy Flynn
fc20e61e72 AK: Introduce an as_if<OutputType>() cast
We currently have a fair amount of code of the form:

    if (is<Child>(parent)) {
        auto& child = static_cast<Child&>(parent);

        if (child.foo()) {
        }
    }

This new cast allows us to instead write code of the form:

    if (auto* child = as_if<Child>(parent); child && child->foo()) {
    }

N.B. The name "as_if" was chosen because we are considering renaming
verify_cast to "as".

Co-authored-by: Tim Ledbetter <tim.ledbetter@ladybird.org>
2025-01-21 14:58:32 +01:00
Timothy Flynn
c2741ea85e AK: Remove default parameter from StringBuilder's constructor
This separates the StringBuilder constructor into 2 constructors. This
essentially allows forming code of the following pattern:

    StringBuilder foo() { return {}; }

Otherwise, we would get the following compiler error:

    chosen constructor is explicit in copy-initialization

Due to the explicitness of the StringBuilder constructor.

This is required for an upcoming update to ICU 76, where we use our
StringBuilder in templated ICU code.
2025-01-18 17:56:40 -05:00
Ali Mohammad Pur
5876417357 AK: Add a const iterator for COWVector 2025-01-17 10:13:51 +01:00
stasoid
3e81d7ea2e AK: Show executable name in rich debug format on Windows 2025-01-13 20:05:05 -07:00
Sam Atkins
c86ad5c505 AK: Make ScopeGuard and ArmedScopeGuard [[nodiscard]]
Brought to you by a significant amount of pain and suffering, which this
would have prevented.
2025-01-09 18:36:34 +00:00
Ivan Zuzak
36190e3baf AK: Optimize performance in GenericShorthands via forwarding references
Functions in AK/GenericShorthands used pass-by-value which results in
copying values when calling those functions. This could be expensive
for complex types. To optimize performance, we switch the functions to
use forwarding references.
2025-01-09 09:03:50 +01:00
stasoid
9884cd0628 AK: Stub out AK::demangle on Windows 2025-01-05 15:02:32 +00:00
Aliaksandr Kalenik
ae9257bf3b AK: Define operator== for BitmapView 2025-01-04 20:32:35 +01:00
Lucas CHOLLET
d6abd44522 AK: Merge implementations of operator== for Optional
Instead of having a overload of the operator in each specialization of
Optional, use a free function as a common implementation.
2025-01-03 17:11:22 +01:00
stasoid
49bdda1475 AK: Simplify usage of windows.h and winsock2.h
Use <AK/Windows.h> instead of windows.h/winsock2.h
to avoid timeval-related errors.

Note: winsock2.h includes windows.h
2025-01-02 10:17:51 -07:00
Timothy Flynn
27478ec7d4 Everywhere: Run clang-format
The following command was used to clang-format these files:

    clang-format-19 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.mm" -o -name "*.h")
2024-12-28 05:39:32 -08:00
Pavel Shliak
2be45c1ccf AK: Remove redundant condition from Quick Sort
if (size <= 1)
       return;
This means that size is at the very minimum 2,
and pivot_point at the very minimum equals 1 as size / 2;
The condition if (pivot_point) can never be false.
2024-12-22 12:33:41 +01:00
stasoid
0a90143420 AK: Fix BumpAllocator.h compilation errors on Windows 2024-12-14 16:12:12 +01:00
Ali Mohammad Pur
44798f44ef AK: Add Vector::get(index) convenience function
This is similar to HashMap::get(key), which returns an Optional, empty
if the index is out of bounds for the vector.
2024-12-13 10:00:16 +01:00
Pavel Shliak
ff7cca38bd AK: Remove clang-specific templates 2024-12-12 15:12:27 -07:00
Pavel Shliak
6f81b80114 Everywhere: Include HashMap only where it's actually used 2024-12-09 12:31:16 +01:00
Pavel Shliak
97d99aa8d6 AK: Verify that HashMap is not empty in take_first
This makes the behavior uniform with:
- HashTable
- SinglyLinkedList
- Vector
2024-12-09 12:31:16 +01:00
R-Goc
f380b4b95b AK: Port BumpAllocator.h to Windows
Done by forward declaring the required functions and defining the needed
constants. The defines shouldn't collide as they are from memoryapi.h.
This is done to avoid including windows.h.
2024-12-08 17:36:37 -07:00
Totto16
14e808e574 AK: Add Flatten Variant helper
This will be used in future commits.
It has to be present for types, that are generated by the IDL since the
IDL flattens variants of variants.
2024-12-06 13:10:27 +00:00
Pavel Shliak
c16c20b836 AK: Fix InsertionSort to respect specified bounds
Previously, it ignored 'start', sorting from the array's
beginning. This caused unintended changes and slower
performance. Fix ensures sorting stays within 'start'
and 'end' indices only.
2024-12-06 06:44:27 +00:00