Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 16afa35bbfd9183c87f5d94dae94c49034e1ce4e
https://github.com/WebKit/WebKit/commit/16afa35bbfd9183c87f5d94dae94c49034e1ce4e
Author: Sam Weinig <[email protected]>
Date: 2025-10-05 (Sun, 05 Oct 2025)
Changed paths:
M Source/WebCore/bindings/js/JSDOMConvertBase.h
M Source/WebCore/bindings/js/JSDOMConvertUnion.h
M Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
M Source/WebCore/bindings/scripts/IDLAttributes.json
M Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
M Source/WebCore/bindings/scripts/test/TestObj.idl
M Source/WebCore/html/canvas/CanvasFillStrokeStyles.idl
M Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
M Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h
Log Message:
-----------
[Bindings] Optimize union IDL attribute setters by avoiding conversion to
variant
https://bugs.webkit.org/show_bug.cgi?id=297124
Reviewed by Chris Dumez.
Adds ability for implementations of union IDL attributes to optimize setting
by exposing function overloads for each member of the union. Implementations
that will not benefit from this can continue to expose a single setter function
that takes the Variant value.
For now, this functionality must also be opted into by using the an extended
attribute `OptimizedUnionSetterUsingOverloads`. This is needed due to existing
overloads of attribute setters that have different behaviors depending on
whether a Variant is the parameter or not. For example, HTMLScriptElement
has two overloads for setText:
WEBCORE_EXPORT void setText(String&&);
ExceptionOr<void> setText(Variant<RefPtr<TrustedScript>, String>&&);
but only the one taking a Variant passes the string through
`trustedTypeCompliantString`.
To begin with, only the `strokeStyle` and `fillStyle` attributes on
the `CanvasFillStrokeStyles` mixin have the extended attribute added.
This is implemented by adding a new kind of JS->Implementation convert
function that takes a "return value functor" and adopting it in
JSDOMConvertUnion.
In this new type of convert, instead of returning the converted value, the
converted value is passed to a provided "return value functor", and the
function instead returns result of calling that functor. This allows us
to pass in a generic lambda as the "return value functor" allowing for
distinct behaviors for each call. In the case of the union, instead of
converting all the way to the variant result, the "return value functor"
is called with the concrete result types.
The original `convert` function can be maintained by calling the new one
with a lambda that just converts to and returns the variant.
* Source/WebCore/bindings/js/JSDOMConvertBase.h:
(WebCore::convert):
- Adds a new overload for the "return value functor" version.
- Adds missing overload taking a string.
- Utilize the `ExceptionThrowerFunctor` concept to disambiguate
between different functors.
* Source/WebCore/bindings/js/JSDOMConvertUnion.h:
- Adopt new "return value functor" style convert function, and
use it to implement the old version.
* Source/WebCore/bindings/scripts/IDLAttributes.json:
* Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:
- Special case non-nullable unions attribute setters to call
the new "return value functor" style convert function. This
can be expanded to nullable unions in the future, but requires
re-thinking the representation.
* Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp:
* Source/WebCore/bindings/scripts/test/TestObj.idl:
- Add new tests and results for when the extended attribute is set.
* Source/WebCore/html/canvas/CanvasFillStrokeStyles.idl:
* Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp:
* Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h:
- Adopt optimized setting for CanvasRenderingContext2D's `strokeStyle` and
`fillStyle` attributes.
Canonical link: https://commits.webkit.org/301035@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes