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

Unable to postMessage a WebAssembly module to a worklet #6596

Merged

Conversation

cdumez
Copy link
Contributor

@cdumez cdumez commented Nov 17, 2022

a9d61c9

Unable to postMessage a WebAssembly module to a worklet
https://bugs.webkit.org/show_bug.cgi?id=220038
rdar://72596556

Reviewed by Darin Adler.

We were previously unable to send WASM modules (and WASM memory) via message
ports, even if the destination was in the same process (e.g. another window on
the same page or a dedicated worker).

There were two reasons for this:
- MessagePort::postMessage() was using the default SerializationContext, which
  doesn't allow encoding on WASM types. I updated the serialization context to
  address that.
- Such WASM types are not serializable over IPC and despite the changes in
  255948@main, messages would often still go over IPC, even when the
  destination is in the same process. To address this, I now mark MessagePorts
  as out-of-process when they get sent over IPC, instead of doing it when they
  get disentangled (which can happen when sending the port to an in-process
  dedicated worker)

* LayoutTests/fast/storage/serialized-script-value.html:
* LayoutTests/http/wpt/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-postmessage-wasm-module.https-expected.txt: Added.
* LayoutTests/http/wpt/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-postmessage-wasm-module.https.html: Added.
* LayoutTests/http/wpt/webaudio/the-audio-api/the-audioworklet-interface/processors/wasm-module-processor.js: Added.
(WASMModuleProcessor):
(WASMModuleProcessor.prototype.testModule):
(WASMModuleProcessor.prototype.handleMessage):
(WASMModuleProcessor.prototype.handleMessageError):
(WASMModuleProcessor.prototype.process):
* LayoutTests/imported/w3c/web-platform-tests/wasm/serialization/module/window-messagechannel-success-expected.txt:
* Source/WebCore/bindings/js/JSDOMGlobalObject.cpp:
(WebCore::JSDOMGlobalObject::defaultAgentClusterID):
(WebCore::JSDOMGlobalObject::agentClusterID const):
* Source/WebCore/bindings/js/JSDOMGlobalObject.h:
* Source/WebCore/bindings/js/SerializedScriptValue.cpp:
(WebCore::agentClusterIDFromGlobalObject):
(WebCore::CloneSerializer::dumpIfTerminal):
(WebCore::CloneDeserializer::readTerminal):
* Source/WebCore/dom/MessagePort.cpp:
(WebCore::MessagePort::postMessage):
* Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp:
(WebKit::WebSWClientConnection::postMessageToServiceWorker):
* Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp:
(WebKit::WebSWContextManagerConnection::postMessageToServiceWorkerClient):
* Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.cpp:
(WebKit::WebMessagePortChannelProvider::entangleLocalPortInThisProcessToRemote):
(WebKit::WebMessagePortChannelProvider::messagePortDisentangled):
(WebKit::WebMessagePortChannelProvider::messagePortSentToRemote):
(WebKit::WebMessagePortChannelProvider::postMessageToRemote):
* Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.h:

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

284a06e

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

@cdumez cdumez self-assigned this Nov 17, 2022
@cdumez cdumez added the Web Audio Bugs against the Web Audio API label Nov 17, 2022
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Nov 17, 2022
@cdumez cdumez removed the merging-blocked Applied to prevent a change from being merged label Nov 18, 2022
@cdumez cdumez force-pushed the 220038_postMessage_wasm_mobule branch from dd09a69 to affd86c Compare November 18, 2022 00:11
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Nov 18, 2022
@cdumez cdumez removed the merging-blocked Applied to prevent a change from being merged label Nov 18, 2022
@cdumez cdumez force-pushed the 220038_postMessage_wasm_mobule branch from affd86c to 3f77422 Compare November 18, 2022 04:15
TIMEOUT WebAssembly.Module cannot cross agent clusters, BroadcastChannel edition Test timed out

Harness Error (FAIL), message = Unhandled rejection: The object can not be cloned.
Harness Error (TIMEOUT), message = null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failure tests cases are still failing. This is because they rely on the messageerror event which we don't support. When deserialization fails, we fire a regular message event but with data being null.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you plan on adding messageerror?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need to add it. I have a work-in-progress patch for it but haven't gotten around to finish it yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have verified that with the messageerror event implemented, this test and the one below start passing.
My patch to support the messageerror event is almost ready.

@cdumez cdumez marked this pull request as ready for review November 18, 2022 15:26
@cdumez cdumez requested a review from rniwa as a code owner November 18, 2022 15:26
TIMEOUT WebAssembly.Module cannot cross agent clusters, BroadcastChannel edition Test timed out

Harness Error (FAIL), message = Unhandled rejection: The object can not be cloned.
Harness Error (TIMEOUT), message = null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you plan on adding messageerror?

@@ -31,6 +31,7 @@
#include <JavaScriptCore/JSGlobalObject.h>
#include <JavaScriptCore/JSObjectInlines.h>
#include <JavaScriptCore/WeakGCMap.h>
#include <wtf/text/WTFString.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A forward declaration usually suffices to just use something as a return type.

@cdumez cdumez force-pushed the 220038_postMessage_wasm_mobule branch from 3f77422 to 284a06e Compare November 18, 2022 16:16
@cdumez cdumez added the merge-queue Applied to send a pull request to merge-queue label Nov 18, 2022
https://bugs.webkit.org/show_bug.cgi?id=220038
rdar://72596556

Reviewed by Darin Adler.

We were previously unable to send WASM modules (and WASM memory) via message
ports, even if the destination was in the same process (e.g. another window on
the same page or a dedicated worker).

There were two reasons for this:
- MessagePort::postMessage() was using the default SerializationContext, which
  doesn't allow encoding on WASM types. I updated the serialization context to
  address that.
- Such WASM types are not serializable over IPC and despite the changes in
  255948@main, messages would often still go over IPC, even when the
  destination is in the same process. To address this, I now mark MessagePorts
  as out-of-process when they get sent over IPC, instead of doing it when they
  get disentangled (which can happen when sending the port to an in-process
  dedicated worker)

* LayoutTests/fast/storage/serialized-script-value.html:
* LayoutTests/http/wpt/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-postmessage-wasm-module.https-expected.txt: Added.
* LayoutTests/http/wpt/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-postmessage-wasm-module.https.html: Added.
* LayoutTests/http/wpt/webaudio/the-audio-api/the-audioworklet-interface/processors/wasm-module-processor.js: Added.
(WASMModuleProcessor):
(WASMModuleProcessor.prototype.testModule):
(WASMModuleProcessor.prototype.handleMessage):
(WASMModuleProcessor.prototype.handleMessageError):
(WASMModuleProcessor.prototype.process):
* LayoutTests/imported/w3c/web-platform-tests/wasm/serialization/module/window-messagechannel-success-expected.txt:
* Source/WebCore/bindings/js/JSDOMGlobalObject.cpp:
(WebCore::JSDOMGlobalObject::defaultAgentClusterID):
(WebCore::JSDOMGlobalObject::agentClusterID const):
* Source/WebCore/bindings/js/JSDOMGlobalObject.h:
* Source/WebCore/bindings/js/SerializedScriptValue.cpp:
(WebCore::agentClusterIDFromGlobalObject):
(WebCore::CloneSerializer::dumpIfTerminal):
(WebCore::CloneDeserializer::readTerminal):
* Source/WebCore/dom/MessagePort.cpp:
(WebCore::MessagePort::postMessage):
* Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp:
(WebKit::WebSWClientConnection::postMessageToServiceWorker):
* Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp:
(WebKit::WebSWContextManagerConnection::postMessageToServiceWorkerClient):
* Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.cpp:
(WebKit::WebMessagePortChannelProvider::entangleLocalPortInThisProcessToRemote):
(WebKit::WebMessagePortChannelProvider::messagePortDisentangled):
(WebKit::WebMessagePortChannelProvider::messagePortSentToRemote):
(WebKit::WebMessagePortChannelProvider::postMessageToRemote):
* Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.h:

Canonical link: https://commits.webkit.org/256853@main
@webkit-commit-queue
Copy link
Collaborator

Committed 256853@main (a9d61c9): https://commits.webkit.org/256853@main

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

@webkit-early-warning-system webkit-early-warning-system merged commit a9d61c9 into WebKit:main Nov 18, 2022
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Web Audio Bugs against the Web Audio API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants