Rather than adding a bunch of `get_*_from_mime_type` functions, add just
one to get the Core::MimeType instance. We will need multiple fields at
once in Browser.
While StringView does have a null state, we have been moving away from
this in our other String classes. To represent a StringView not being
given at all on the commandline, use an Optional.
Core::System already had some wrappers for *env() functions, which I've
copied over. But 1) the set of functions there was incomplete, and 2)
the environment feels like an object in its own right, so let's treat it
as one. :^)
Also add `Core::Environment::has(StringView)` for situations where we
just care if a variable is defined.
Previously, `true` was passed into the ElapsedTimer constructor if a
precise timer was required. We now use an enum to more explicitly
specify whether we would like a precise or a coarse timer.
This introduces a new TimeoutSet class for use in
EventLoopImplementationUnix. It is responsible for finding a timer that
expires the soonest and for firing expired timers. TimeoutSet expects
timeouts to be subclasses of EventLoopTimeout, of which EventLoopTimer
is now a subclass, obviously.
TimeoutSet stores timeouts in a binary heap, so
EventLoopImplementationUnix should handle large amounts of timers a lot
better now.
TimeoutSet also supports scheduling of timeouts whose fire time is
relative to the start of the next event loop iteration (i. e. ones
that directly bound polling time). This functionality will reveal its
full potential later with the implementation of asynchronous sockets but
it is currently used to implement zero-timeout timers that are an analog
of Core::deferred_invoke with slightly different semantics.
There is already a parser for the time offset but it requires a positive
or negative sign. There are some weird formats on the web that do not
have the sign, so let's support that. I chose to implement this as a new
option instead of editing the old one to avoid any unknown breaking
changes.
.pam is a "portrable arbitrarymap" as documented at
https://netpbm.sourceforge.net/doc/pam.html
It's very similar to .pbm, .pgm, and .ppm, so this uses the
PortableImageMapLoader framework. The header is slightly different,
so this has a custom header parsing function.
Also, .pam only exixts in binary form, so the ascii form support
becomes optional.
This method (unlike can_read_line) ensures that the delimiter is present
in the buffer, and doesn't return true after eof when the delimiter is
absent.
Add a boolean to ProcessSpawnOptions, `search_for_executable_in_path`,
which when true, calls into posix_spawnp() instead of posix_spawn().
This defaults to false to maintain the existing behavior.
The `path` field is renamed to `executable` because having two fields
refer to "path" and mean different things seemed unnecessarily
confusing.
This will be useful in the upcoming listdir utility (in the next commit)
to get the file type which is obtained in the get_dir_entries syscall,
so it's not changed later by the fstatat syscall.
This will ensure that we get the raw file type value as it's represented
by directory entries from the get_dir_entries syscall.
If no EventLoop is present in the stack (like when you forget to create
one), a message is nicer than letting the developer go through the
stacktrace to figure out what went wrong.
This overload is currently unused. When used, it doesn't compile due to
mismatched return types in the handler provided to the function and the
type of `on_resolution`.
In a bunch of cases, this actually ends up simplifying the code as
to_number will handle something such as:
```
Optional<I> opt;
if constexpr (IsSigned<I>)
opt = view.to_int<I>();
else
opt = view.to_uint<I>();
```
For us.
The main goal here however is to have a single generic number conversion
API between all of the String classes.
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).
This commit is auto-generated:
$ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
Meta Ports Ladybird Tests Kernel)
$ perl -pie 's/\bDeprecatedString\b/ByteString/g;
s/deprecated_string/byte_string/g' $xs
$ clang-format --style=file -i \
$(git diff --name-only | grep \.cpp\|\.h)
$ gn format $(git ls-files '*.gn' '*.gni')
The construct `adopt_ref(*new Obj(TRY(get_resource())))` is another
manifestation of a classic anti-pattern. In old C++, you would leak the
object's memory if the argument threw an exception, or if a member
initializer threw an exception. In our case, we leak if the MappedFile
returns an Error. This is pretty concerning, and we should avoid this
pattern at all costs, and try to use the "safer" helpers whenever
possible.
The st_mode field in struct stat is a bitfield of more than just the
file type, this commit masks off the non-filetype bits to ensure no
unrelated bits are checked.
Let's replace this bool with an `enum class` in order to enhance
readability. This is done by repurposing `MappedFile`'s `OpenMode` into
a shared `enum` simply called `Mode`.
For example, LibJS will need to parse date strings of the form:
Wed Dec 31 1969 19:00:00 GMT-0500 (Eastern Standard Time)
This string contains both the time zone offset (-05:00) and a display
name for the time zone (Eastern Standard Time). Because we will already
handle time zone adjustments when we handle the offsets, we will want to
just skip the time zone name. This patch will let us use a format string
of the form "GMT%z (%+)" to do so.