Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 6cfd3789faf5b0f12819dbe85a3163b4e099e307
      
https://github.com/WebKit/WebKit/commit/6cfd3789faf5b0f12819dbe85a3163b4e099e307
  Author: Sam Weinig <wei...@apple.com>
  Date:   2024-05-21 (Tue, 21 May 2024)

  Changed paths:
    M Source/WTF/wtf/EmbeddedFixedVector.h
    M Source/WTF/wtf/FixedVector.h
    M Source/WTF/wtf/TrailingArray.h
    M Tools/TestWebKitAPI/Tests/WTF/FixedVector.cpp

  Log Message:
  -----------
  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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to