Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a concrete result type for JSValue -> Implementation conversions #29085

Conversation

weinig
Copy link
Contributor

@weinig weinig commented May 24, 2024

9a160ff

Introduce a concrete result type for JSValue -> Implementation conversions
https://bugs.webkit.org/show_bug.cgi?id=274682

Reviewed by Ryosuke Niwa.

Introduces "ConversionResult" a template type that serves as the return value
for all the JSValue -> Implementation conversion functions. It acts much like
ExceptionOr, is even implemented similarly on top of Expected, but instead of
storing either a result or the exception information, it stores the result or
a token indicating an exception exists on the JS stack.

The goal of this type is to allow conversions to non-default initializable
types, crucially, dictionaries and unions with Ref members. This introductory
change does not utilize that, but rather has deferred that to a follow up.

This change is mostly comprised of:

- Updating the code generator to handle the new return type.
- Updating JSDOM* converters to return the new type.
- Update non-generated uses of the convert<...> family of functions to handle
  the new result type.

* Source/WTF/wtf/TrailingArray.h:
(WTF::TrailingArray::TrailingArray):
    - Ensure the destructors don't run on the uninitialized elements when
      initializing trailing array's from a generator.

* Source/WebCore/Headers.cmake:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
    - Add new files

* Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:
    - Update code generation to handle new conversion result type.

* Source/WebCore/bindings/IDLTypes.h:
    - Add new trait types ConversionResultType and NullableConversionResultType
      to allow customization of the storage in ConversionResult for that type.

    - Also adds a new IDLOptional type that the generator uses to streamline
      optional arguments and optional dictionary members.

* Source/WebCore/bindings/js/JSDOMConvertResult.h: Added.
    - New result type.

* Source/WebCore/bindings/js/JSCallbackData.h:
    - Callback functions and interfaces now generate a JSDOMCallbackConverterTraits
      instance to allow generic mapping from the JS callback type to the implementation
      callback type.

* Source/WebCore/bindings/js/JSDOMConvertAny.h:
* Source/WebCore/bindings/js/JSDOMConvertBase.h:
* Source/WebCore/bindings/js/JSDOMConvertBoolean.h:
* Source/WebCore/bindings/js/JSDOMConvertBufferSource.h:
* Source/WebCore/bindings/js/JSDOMConvertCallbacks.h:
* Source/WebCore/bindings/js/JSDOMConvertDate.h:
* Source/WebCore/bindings/js/JSDOMConvertDictionary.h:
* Source/WebCore/bindings/js/JSDOMConvertEnumeration.h:
* Source/WebCore/bindings/js/JSDOMConvertEventListener.h:
* Source/WebCore/bindings/js/JSDOMConvertInterface.h:
* Source/WebCore/bindings/js/JSDOMConvertJSON.h:
* Source/WebCore/bindings/js/JSDOMConvertNull.h:
* Source/WebCore/bindings/js/JSDOMConvertNullable.h:
* Source/WebCore/bindings/js/JSDOMConvertNumbers.cpp:
* Source/WebCore/bindings/js/JSDOMConvertNumbers.h:
* Source/WebCore/bindings/js/JSDOMConvertObject.h:
* Source/WebCore/bindings/js/JSDOMConvertOptional.h:
* Source/WebCore/bindings/js/JSDOMConvertPromise.h:
* Source/WebCore/bindings/js/JSDOMConvertRecord.h:
* Source/WebCore/bindings/js/JSDOMConvertScheduledAction.h:
* Source/WebCore/bindings/js/JSDOMConvertSequences.h:
* Source/WebCore/bindings/js/JSDOMConvertSerializedScriptValue.h:
* Source/WebCore/bindings/js/JSDOMConvertXPathNSResolver.h:
* Source/WebCore/bindings/js/JSDOMConvertStrings.cpp:
* Source/WebCore/bindings/js/JSDOMConvertStrings.h:
    - Update to return new ConversionResult type.

    - Where there was a lot of unnecessary repetition, such as typed arrays,
      strings and numbers, intermediary converters were added to help reduce
      the overhead.

* Source/WebCore/bindings/js/JSDOMConvertUnion.h:
    - In addition to updating to the new result type, some simplification was
      done using constexpr to replace "Conditional*" meta-functions.

* Source/WebCore/bindings/js/JSDOMConvertVariadic.h:
    - Updated to use the recently introduced FixedVector::createWithSizeFromGenerator,
      which allows creation with non-default constructible arguments that can fail.

* Source/WebCore/Modules/applepay-ams-ui/ApplePayAMSUIPaymentHandler.cpp:
* Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
* Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp:
* Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.cpp:
* Source/WebCore/Modules/mediastream/RTCRtpScriptTransformer.cpp:
* Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp:
* Source/WebCore/Modules/permissions/Permissions.cpp:
* Source/WebCore/Modules/streams/TransformStream.cpp:
* Source/WebCore/Modules/webaudio/AudioWorkletGlobalScope.cpp:
* Source/WebCore/Modules/webtransport/DatagramSink.cpp:
* Source/WebCore/animation/KeyframeEffect.cpp:
* Source/WebCore/bindings/js/InternalReadableStream.cpp:
* Source/WebCore/bindings/js/JSCustomElementRegistryCustom.cpp:
* Source/WebCore/bindings/js/JSDOMWindowCustom.cpp:
* Source/WebCore/bindings/js/JSDocumentCustom.cpp:
* Source/WebCore/bindings/js/JSElementCustom.cpp:
* Source/WebCore/bindings/js/JSElementInternalsCustom.cpp:
* Source/WebCore/bindings/js/JSEventListener.cpp:
* Source/WebCore/bindings/js/JSExtendableMessageEventCustom.cpp:
* Source/WebCore/bindings/js/JSNodeIteratorCustom.cpp:
* Source/WebCore/bindings/js/JSRTCRtpSFrameTransformCustom.cpp:
* Source/WebCore/bindings/js/JSTreeWalkerCustom.cpp:
* Source/WebCore/bindings/js/JSWebAnimationCustom.cpp:
* Source/WebCore/crypto/SubtleCrypto.cpp:
* Source/WebCore/css/CSSStyleSheetObservableArray.cpp:
* Source/WebCore/html/HTMLCanvasElement.cpp:
* Source/WebCore/html/OffscreenCanvas.cpp:
* Source/WebCore/inspector/InspectorCanvas.cpp:
* Source/WebCore/inspector/InspectorCanvasCallTracer.h:
* Source/WebCore/worklets/PaintWorkletGlobalScope.cpp:
* Source/WebKit/WebProcess/Network/WebTransportSendStreamSink.cpp:
    - Update account for new result types.

Canonical link: https://commits.webkit.org/279321@main

c2de37b

Misc iOS, tvOS & watchOS macOS Linux Windows
❌ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 wincairo
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug 🧪 wpe-wk2 ✅ 🧪 wincairo-tests
✅ 🧪 webkitperl 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-cairo
✅ 🛠 🧪 jsc 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 🧪 jsc-arm64 ✅ 🛠 tv 🧪 mac-AS-debug-wk2 🧪 gtk-wk2
✅ 🛠 tv-sim ✅ 🧪 mac-wk2-stress 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🛠 watch ✅ 🛠 jsc-armv7
✅ 🛠 watch-sim ❌ 🧪 jsc-armv7-tests

@weinig weinig self-assigned this May 24, 2024
@weinig weinig requested a review from aprotyas as a code owner May 24, 2024 21:11
@weinig weinig added the Bindings For bugs related to the DOM bindings label May 24, 2024
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 24, 2024
@weinig weinig removed the merging-blocked Applied to prevent a change from being merged label May 24, 2024
@weinig weinig force-pushed the eng/Introduce-a-concrete-result-type-for-JSValue---Implementation-conversions branch from 4294501 to 3d7ddba Compare May 24, 2024 22:38
@weinig weinig force-pushed the eng/Introduce-a-concrete-result-type-for-JSValue---Implementation-conversions branch from 3d7ddba to 91ca944 Compare May 24, 2024 22:40
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 25, 2024
@weinig weinig removed the merging-blocked Applied to prevent a change from being merged label May 25, 2024
@weinig weinig force-pushed the eng/Introduce-a-concrete-result-type-for-JSValue---Implementation-conversions branch from 91ca944 to bf3b064 Compare May 25, 2024 03:25
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 25, 2024
@weinig weinig removed the merging-blocked Applied to prevent a change from being merged label May 25, 2024
@weinig weinig force-pushed the eng/Introduce-a-concrete-result-type-for-JSValue---Implementation-conversions branch from bf3b064 to b15a379 Compare May 25, 2024 18:16
@weinig weinig force-pushed the eng/Introduce-a-concrete-result-type-for-JSValue---Implementation-conversions branch from b15a379 to 720aa32 Compare May 25, 2024 18:21
@weinig weinig force-pushed the eng/Introduce-a-concrete-result-type-for-JSValue---Implementation-conversions branch from 720aa32 to c2de37b Compare May 25, 2024 18:40
@weinig weinig added the merge-queue Applied to send a pull request to merge-queue label May 25, 2024
…sions

https://bugs.webkit.org/show_bug.cgi?id=274682

Reviewed by Ryosuke Niwa.

Introduces "ConversionResult" a template type that serves as the return value
for all the JSValue -> Implementation conversion functions. It acts much like
ExceptionOr, is even implemented similarly on top of Expected, but instead of
storing either a result or the exception information, it stores the result or
a token indicating an exception exists on the JS stack.

The goal of this type is to allow conversions to non-default initializable
types, crucially, dictionaries and unions with Ref members. This introductory
change does not utilize that, but rather has deferred that to a follow up.

This change is mostly comprised of:

- Updating the code generator to handle the new return type.
- Updating JSDOM* converters to return the new type.
- Update non-generated uses of the convert<...> family of functions to handle
  the new result type.

* Source/WTF/wtf/TrailingArray.h:
(WTF::TrailingArray::TrailingArray):
    - Ensure the destructors don't run on the uninitialized elements when
      initializing trailing array's from a generator.

* Source/WebCore/Headers.cmake:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
    - Add new files

* Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:
    - Update code generation to handle new conversion result type.

* Source/WebCore/bindings/IDLTypes.h:
    - Add new trait types ConversionResultType and NullableConversionResultType
      to allow customization of the storage in ConversionResult for that type.

    - Also adds a new IDLOptional type that the generator uses to streamline
      optional arguments and optional dictionary members.

* Source/WebCore/bindings/js/JSDOMConvertResult.h: Added.
    - New result type.

* Source/WebCore/bindings/js/JSCallbackData.h:
    - Callback functions and interfaces now generate a JSDOMCallbackConverterTraits
      instance to allow generic mapping from the JS callback type to the implementation
      callback type.

* Source/WebCore/bindings/js/JSDOMConvertAny.h:
* Source/WebCore/bindings/js/JSDOMConvertBase.h:
* Source/WebCore/bindings/js/JSDOMConvertBoolean.h:
* Source/WebCore/bindings/js/JSDOMConvertBufferSource.h:
* Source/WebCore/bindings/js/JSDOMConvertCallbacks.h:
* Source/WebCore/bindings/js/JSDOMConvertDate.h:
* Source/WebCore/bindings/js/JSDOMConvertDictionary.h:
* Source/WebCore/bindings/js/JSDOMConvertEnumeration.h:
* Source/WebCore/bindings/js/JSDOMConvertEventListener.h:
* Source/WebCore/bindings/js/JSDOMConvertInterface.h:
* Source/WebCore/bindings/js/JSDOMConvertJSON.h:
* Source/WebCore/bindings/js/JSDOMConvertNull.h:
* Source/WebCore/bindings/js/JSDOMConvertNullable.h:
* Source/WebCore/bindings/js/JSDOMConvertNumbers.cpp:
* Source/WebCore/bindings/js/JSDOMConvertNumbers.h:
* Source/WebCore/bindings/js/JSDOMConvertObject.h:
* Source/WebCore/bindings/js/JSDOMConvertOptional.h:
* Source/WebCore/bindings/js/JSDOMConvertPromise.h:
* Source/WebCore/bindings/js/JSDOMConvertRecord.h:
* Source/WebCore/bindings/js/JSDOMConvertScheduledAction.h:
* Source/WebCore/bindings/js/JSDOMConvertSequences.h:
* Source/WebCore/bindings/js/JSDOMConvertSerializedScriptValue.h:
* Source/WebCore/bindings/js/JSDOMConvertXPathNSResolver.h:
* Source/WebCore/bindings/js/JSDOMConvertStrings.cpp:
* Source/WebCore/bindings/js/JSDOMConvertStrings.h:
    - Update to return new ConversionResult type.

    - Where there was a lot of unnecessary repetition, such as typed arrays,
      strings and numbers, intermediary converters were added to help reduce
      the overhead.

* Source/WebCore/bindings/js/JSDOMConvertUnion.h:
    - In addition to updating to the new result type, some simplification was
      done using constexpr to replace "Conditional*" meta-functions.

* Source/WebCore/bindings/js/JSDOMConvertVariadic.h:
    - Updated to use the recently introduced FixedVector::createWithSizeFromGenerator,
      which allows creation with non-default constructible arguments that can fail.

* Source/WebCore/Modules/applepay-ams-ui/ApplePayAMSUIPaymentHandler.cpp:
* Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
* Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp:
* Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.cpp:
* Source/WebCore/Modules/mediastream/RTCRtpScriptTransformer.cpp:
* Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp:
* Source/WebCore/Modules/permissions/Permissions.cpp:
* Source/WebCore/Modules/streams/TransformStream.cpp:
* Source/WebCore/Modules/webaudio/AudioWorkletGlobalScope.cpp:
* Source/WebCore/Modules/webtransport/DatagramSink.cpp:
* Source/WebCore/animation/KeyframeEffect.cpp:
* Source/WebCore/bindings/js/InternalReadableStream.cpp:
* Source/WebCore/bindings/js/JSCustomElementRegistryCustom.cpp:
* Source/WebCore/bindings/js/JSDOMWindowCustom.cpp:
* Source/WebCore/bindings/js/JSDocumentCustom.cpp:
* Source/WebCore/bindings/js/JSElementCustom.cpp:
* Source/WebCore/bindings/js/JSElementInternalsCustom.cpp:
* Source/WebCore/bindings/js/JSEventListener.cpp:
* Source/WebCore/bindings/js/JSExtendableMessageEventCustom.cpp:
* Source/WebCore/bindings/js/JSNodeIteratorCustom.cpp:
* Source/WebCore/bindings/js/JSRTCRtpSFrameTransformCustom.cpp:
* Source/WebCore/bindings/js/JSTreeWalkerCustom.cpp:
* Source/WebCore/bindings/js/JSWebAnimationCustom.cpp:
* Source/WebCore/crypto/SubtleCrypto.cpp:
* Source/WebCore/css/CSSStyleSheetObservableArray.cpp:
* Source/WebCore/html/HTMLCanvasElement.cpp:
* Source/WebCore/html/OffscreenCanvas.cpp:
* Source/WebCore/inspector/InspectorCanvas.cpp:
* Source/WebCore/inspector/InspectorCanvasCallTracer.h:
* Source/WebCore/worklets/PaintWorkletGlobalScope.cpp:
* Source/WebKit/WebProcess/Network/WebTransportSendStreamSink.cpp:
    - Update account for new result types.

Canonical link: https://commits.webkit.org/279321@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Introduce-a-concrete-result-type-for-JSValue---Implementation-conversions branch from c2de37b to 9a160ff Compare May 25, 2024 19:45
@webkit-commit-queue
Copy link
Collaborator

Committed 279321@main (9a160ff): https://commits.webkit.org/279321@main

Reviewed commits have been landed. Closing PR #29085 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 9a160ff into WebKit:main May 25, 2024
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bindings For bugs related to the DOM bindings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants