Commit graph

3698 commits

Author SHA1 Message Date
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
Pavel Shliak
b521badbef AK: Remove QuickSelect 2024-12-05 16:53:28 +01:00
Pavel Shliak
ede0dbafc6 AK: Remove Statistics.h
This also removes MedianCut and GIFWriter
2024-12-05 16:53:28 +01:00
Jonne Ransijn
6d1fa64f5f AK: Allow NonnullRawPtr to be used in constant expressions 2024-12-04 16:45:58 +00:00
Jonne Ransijn
e2b69fe7e2 AK: Restrict template parameter of JsonArray constructor
This constructor doesn't need to accept iterable containers of anything
other than `JsonValue`s.
2024-12-04 16:45:58 +00:00
Jonne Ransijn
a4f23c512c AK: Add IterableContainerOf concept
This concept not only checks that the given type is iterable, but it
also checks that the iterated value is of the expected type.
2024-12-04 16:45:58 +00:00
Jonne Ransijn
e8b2d35410 AK: Add IsTemplateBaseOf<Base, Derived> concept
This concept checks if any specialization of `Base<...>` is a base class
of `Derived`.
2024-12-04 16:45:58 +00:00
Jonne Ransijn
b7e22f0916 AK: Disallow creating NonnullRawPtrs from r-value references
This would always result in a use-after-free.
2024-12-04 16:45:58 +00:00
Jonne Ransijn
bea602f5ed AK: Use Noncopyable.h in NonnullRawPtr 2024-12-04 16:45:58 +00:00
Jonne Ransijn
501a7dbaa3 AK: Use Noncopyable.h in Badge 2024-12-04 16:45:58 +00:00
Jonne Ransijn
cca84aa28d AK: Fix ASSERT_NOT_REACHED macro when NDEBUG is not defined
This is supposed to be a function-like macro just like
`VERIFY_NOT_REACHED()` and when `NDEBUG` is defined.
2024-12-04 16:45:58 +00:00
Jonne Ransijn
d5fbf7323a AK+LibJS: Allow {TRY,MUST}{,_OR_THROW_OOM} on list-initializers
List initializers may contain commas without surrounding parenthesis,
causing them to be passed as multiple macro arguments.
2024-12-04 16:45:58 +00:00
Jonne Ransijn
f617127772 AK: Allow calling ASSERT and VERIFY on list-initializers
List initializers may contain commas without surrounding parenthesis,
causing them to be passed as multiple macro arguments.
2024-12-04 16:45:58 +00:00
Jonne Ransijn
0de15264ab AK: Remove clang-tidy warnings for ASSERT(a || b) lines
Lines like these were getting a warning to simplify the expanded
boolean expression from `!(a || b)` to `(a && b)`, but since the
`!(...)` is part of the macro, that is never going to happen.
2024-12-04 16:45:58 +00:00
Jonne Ransijn
211dc5659c LibWeb: Fix stack-use-after-scope
The refactor in the previous commit was storing a reference to a stack
allocated `Infrastructure::Request::BodyType` which was then immediately
freed. To fix this, we can store the `Infrastructure::Request::BodyType`
in a variable beforehand, so it becomes safe to reference.
2024-12-04 01:58:22 +01:00
Jonne Ransijn
d7596a0a61 AK: Don't implicitly convert Optional<T&> to Optional<T>
C++ will jovially select the implicit conversion operator, even if it's
complete bogus, such as for unknown-size types or non-destructible
types. Therefore, all such conversions (which incur a copy) must
(unfortunately) be explicit so that non-copyable types continue to work.

NOTE: We make an exception for trivially copyable types, since they
are, well, trivially copyable.

Co-authored-by: kleines Filmröllchen <filmroellchen@serenityos.org>
2024-12-04 01:58:22 +01:00
kleines Filmröllchen
8468fb9ae5 AK: Use StringView as its own peek type
StringView is already a reference type, and copying it is cheap, so we
should use it as its own peek type.
2024-12-04 01:58:22 +01:00
Jonne Ransijn
55383998b1 AK: Use Noncopyable.h in Optional<T&>
This makes them trivially copyable/movable, silencing

> "parameter is copied for each invocation"

warnings on `Optional<T&>`, which are unnecessairy,
since `Optional<T&>` is just a trivially copyable pointer.

This creates a slight change in behaviour when moving out of an
`Optional<T&>`, since the moved-from optional no longer gets cleared.

Moved-from values should be considered to be in an undefined state,
and if clearing a moved-from `Optional<T&>` is desired, you should be
using `Optional<T&>::release_value()` instead.
2024-12-04 01:58:22 +01:00
Jonne Ransijn
e38b206957 AK: Print a more useful error message when a MUST(...) fails
```
VERIFICATION FAILED: !_temporary_result.is_error()
```

is not really a helpful error message.

When we are including `AK/Format.h`, which is most of the time,
we can easily print a much more useful error message:

```
UNEXPECTED ERROR: Cannot allocate memory (errno=12)
```
2024-12-02 20:07:38 +01:00
stasoid
ac590fe30d AK: Don't include winsock2.h in Time.h
This is architecturally preferable, see https://github.com/LadybirdBrowser/ladybird/blob/master/Documentation/Porting.md#windows
and https://discord.com/channels/1247070541085671459/1306918361732616212/1310437609679487006
(note: winsock2.h includes windows.h)
2024-11-29 10:55:52 +01:00
Andrew Kaster
fc3ebd7efd AK: Add workaround for older Xcode versions in Swift.h 2024-11-26 11:00:48 +01:00
Jonne Ransijn
75b482bbb9 AK: Fix "assignment from temporary" check of Optional::operator=
There was an existing check to ensure that `U` was an lvalue reference,
but when this check fails, overload resolution will just move right on
to the copy asignment operator, which will cause the temporary to be
assigned anyway.

Disallowing `Optional<T&>`s to be created from temporaries entirely
would be undesired, since existing code has valid reasons for creating
`Optional<T&>`s from temporaries, such as for function call arguments.

This fix explicitly deletes the `Optional::operator=(U&&)` operator,
so overload resolution stops.
2024-11-24 23:04:34 -07:00
Ali Mohammad Pur
3bcd91b109 LibDNS: Hide some debug logs behind DNS_DEBUG 2024-11-20 21:37:58 +01:00
Ali Mohammad Pur
b93d8ef875 AK: Disable implicit conversion from char* -> ipv4 -> ipv6
This is a footgun with some massive bullets.
2024-11-20 21:37:58 +01:00
Pavel Shliak
8a07131229 LibGfx: Clean up #include directives
We actually include what we use where we use it.
This change aims to improve the speed of incremental builds.
2024-11-20 21:13:23 +01:00
stasoid
a423493dd8 AK: Add LexicalPath::is_root() 2024-11-19 22:07:01 -07:00
stasoid
ddd15e96b6 AK: Define pid_t on Windows 2024-11-19 14:40:03 -07:00
stasoid
69f5f40617 AK: Add static bool LexicalPath::is_absolute_path(StringView path); 2024-11-19 14:35:52 -07:00
Andrew Kaster
32cf4d1e29 AK: Add missing swift/bridging empty defines for non-Swift compilers 2024-11-19 14:32:11 -07:00
Andrew Kaster
458167935c AK: Add an extension to construct an AK.String from a Swift.String 2024-11-19 14:32:11 -07:00
Andrew Kaster
a95f761cb4 AK: Include missing StdLibExtras from NeverDestroyed 2024-11-19 14:32:11 -07:00
Timothy Flynn
be09893fa7 AK+LibJS: Don't use Temporal for console.time() and console.timeLog()
We don't need nanosecond precision here anyways, as we only display
millisecond resolution.

This uses our simple duration formatter from AK, which is updated to
accept a Duration here. This method did not have any users after the
move from Serenity.
2024-11-18 17:46:41 -05:00
Sam Atkins
3f10a5701d AK: Add Utf8View::for_each_split_view() method
Returns one Utf8View at a time, using a callback function to identify
code points to split on.
2024-11-15 23:18:29 +01:00
Sam Atkins
ec5101a1d3 AK: Ensure empty StringViews all compare as equal
Before this change, a StringView with a character-data pointer would
never compare as equal to one with a null pointer, even if they were
both length 0. This could happen for example if one is
default-initialized, and the other is created as a substring.
2024-11-15 23:18:29 +01:00
Andrew Kaster
e0adbf3ebb AK: Add a Swift helper for StringView::ends_with 2024-11-15 10:51:45 -07:00
Jonne Ransijn
d842d04be4 AK: Remove DeprecatedStringCodePointIterator
The functionality in this class is no longer used, we can just use
`Utf8View` instead.
2024-11-14 23:06:42 +01:00
rmg-x
c1ec2ddb63 AK: Add 16-bit float type 2024-11-10 14:48:20 -07:00
Andreas Kling
11458f0d91 AK: Use getrlimit() to find the correct main thread stack size on macOS
This is what JavaScriptCore does as well.
2024-11-10 19:12:59 +01:00
stasoid
31bf40b659 AK: Make LexicalPath::relative_path() fallible 2024-11-09 12:42:27 -07:00
stasoid
f026d495cd AK: Port LexicalPath to Windows
Supported:
* Normal absolute and relative paths: C:\Windows\Fonts, AK\LexicalPath.h
* Forward slashes and multiple separators: C:/Windows///\\\notepad.exe

Not supported:
* Paths starting with two backslashes: \\?\C:\Windows, \\server\share
* Unusual relative paths like C:, C:a\b, \, \a\b

More on Windows path formats: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats
2024-11-09 12:42:27 -07:00
stasoid
9ebed7d8d5 AK: Add StringBuilder::append_repeated(StringView, size_t)
By analogy with append_repeated(char, size_t)
2024-11-09 12:42:27 -07:00
Jonne Ransijn
1d8e62926f AK: Remove clang-tidy warnings for VERIFY(a || b) lines
Lines like these were getting a warning to simplify the expanded
boolean expression from `!(a || b)` to `(a && b)`, but since the
`!(...)` is part of the macro, that is never going to happen.
2024-11-09 17:55:03 +01:00
Timothy Flynn
0447d05d52 Meta: Support fully static distribution release builds
This adds the vcpkg triplets and CMake preset to perform release
builds for distribution. These builds are fully static, and currently
intended to be used for the `js` ESVU release.

In the future, linking everything statically into the final binary is
probably not what we will do for released Ladybird builds. Instead, we
may have a "libladybird.so", which is then linked into the binary. But
this should be fine for `js` for now.
2024-11-08 11:29:18 -07:00
Andrew Kaster
dfd928a8f8 CMake: Install simdutf runtime components as required
Using install(IMPORTED_RUNTIME_ARTIFACTS), we can re-export the
shared library and frameworks we imported from outside the build
tree into our install treer. This is required for simdutf as it
is a dependency of the AK library, and we need liblagom-ak.so to
be loadable when doing fuzzer and cross-compile builds for the
Lagom tools.
2024-11-06 10:38:57 -07:00
Jonne Ransijn
e50b9f5478 AK: Add NonnullRawPtr<T> abstraction
It is a non-null `T*` with reference semantics.
Or a `T&` whose address can be copied and re-assigned.
Or a `NonnullRefPtr` whose memory is not managed.

It can be useful when you want to store a reference in a
data structure that needs to be copyable or assignable.
2024-11-06 09:43:15 +00:00
Gingeh
57ba720fb1 AK: Avoid returning null StringViews instead of empty views
This was error-prone and most users were just checking the length anyway
2024-11-05 14:01:45 +00:00