-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend FixedVector to allow initialization from a failable generator
https://bugs.webkit.org/show_bug.cgi?id=274491 Reviewed by Darin Adler. Adds support to FixedVector (or any TrailingArray subtype) being constructed using a failable generator. A failable generator is an invocable type that takes an size_t index and returns a std::optional<T>. If one of the indices fails, the whole construction fails. This is going to be used to support variadic JS functions like: `undefined append((Node or DOMString or TrustedScript)... nodes);` from ParentNode.idl, once interfaces in IDL unions use Ref rather than RefPtr. The implementation function will end up being: `ExceptionOr<void> append(FixedVector<Ref<Node>, String, Ref<TrustedScript>>&&)` To call that, the bindings used to create a FixedVector of the appropriate size, and then insert the items in as they get converted. That doesn't work if the items are non-POD types due to TrailingArray's constructor calling: `VectorTypeOperations<T>::initializeIfNonPOD(begin(), end())` * Source/WTF/wtf/EmbeddedFixedVector.h: * Source/WTF/wtf/FixedVector.h: (WTF::FixedVector::createWithSizeFromGenerator): (WTF::FixedVector::FixedVector): * Source/WTF/wtf/TrailingArray.h: (WTF::TrailingArray::TrailingArray): - Pipe support to the failable constructor. On failure, the size is set to 0 and no storage is allocated. * Tools/TestWebKitAPI/Tests/WTF/FixedVector.cpp: (TestWebKitAPI::TEST(WTF_FixedVector, FailableGeneratorConstructor)): - Adds tests using the new constructor. Canonical link: https://commits.webkit.org/279089@main
- Loading branch information
Showing
4 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters