1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:17:45 +00:00

LibJS+LibWeb: Apply the Rule of Zero to {Nonnull,}GCPtr<T>

The compiler-generated copy constructor and copy assignment operator
already do the right thing (which is to simply copy the underlying
pointer).

The [Itanium C++ ABI][1] treats any class with non-trivial copy/move
constructors and destructors as non-trivial for the purposes of calls --
even if they are functionally identical to the compiler-generated ones.
If a class is non-trivial, it cannot be passed or returned in registers,
only via an invisible reference, which is worse for codegen. This commit
makes `{Nonnull,}GCPtr` trivial.

As the compiler can be sure that capturing a `GCPtr` by value has no
side effects, a few `-Wunused-lambda-capture` warnings had to be
addressed in LibWeb.

GCC seems to have a bug that prevents `ExceptionOr<Variant<GCPtr<T>>>`
from being implicitly constructed from `GCPtr<T>` after this change. A
non-invasive workaround is to explicitly construct the inner Variant
type.

[1]: https://itanium-cxx-abi.github.io/cxx-abi/abi.html#non-trivial
This commit is contained in:
Daniel Bertalan 2023-07-26 19:02:37 +02:00 committed by Tim Flynn
parent 82495083c3
commit 9feb1ce39f
4 changed files with 8 additions and 26 deletions

View file

@ -97,13 +97,13 @@ WebIDL::ExceptionOr<ReadableStreamReader> ReadableStream::get_reader(ReadableStr
{
// 1. If options["mode"] does not exist, return ? AcquireReadableStreamDefaultReader(this).
if (!options.mode.has_value())
return TRY(acquire_readable_stream_default_reader(*this));
return ReadableStreamReader { TRY(acquire_readable_stream_default_reader(*this)) };
// 2. Assert: options["mode"] is "byob".
VERIFY(*options.mode == Bindings::ReadableStreamReaderMode::Byob);
// 3. Return ? AcquireReadableStreamBYOBReader(this).
return TRY(acquire_readable_stream_byob_reader(*this));
return ReadableStreamReader { TRY(acquire_readable_stream_byob_reader(*this)) };
}
JS::ThrowCompletionOr<void> ReadableStream::initialize(JS::Realm& realm)