Diff
Modified: trunk/Source/WebCore/ChangeLog (286452 => 286453)
--- trunk/Source/WebCore/ChangeLog 2021-12-02 22:21:46 UTC (rev 286452)
+++ trunk/Source/WebCore/ChangeLog 2021-12-02 22:22:49 UTC (rev 286453)
@@ -1,3 +1,23 @@
+2021-12-02 Chris Dumez <cdu...@apple.com>
+
+ MessageChannel::port1() / port2() should return references instead of pointers
+ https://bugs.webkit.org/show_bug.cgi?id=233772
+
+ Reviewed by Alex Christensen.
+
+ This was extracted from Alex Christensen's large patch at Bug 230382.
+
+ * Modules/webaudio/AudioWorkletNode.cpp:
+ (WebCore::AudioWorkletNode::create):
+ * bindings/js/JSMessageChannelCustom.cpp:
+ (WebCore::JSMessageChannel::visitAdditionalChildren):
+ * dom/MessageChannel.cpp:
+ (WebCore::generateMessagePorts):
+ (WebCore::MessageChannel::MessageChannel):
+ * dom/MessageChannel.h:
+ (WebCore::MessageChannel::port1 const):
+ (WebCore::MessageChannel::port2 const):
+
2021-12-02 Devin Rousso <drou...@apple.com>
[Payment Request] Validate payment method data on construction
Modified: trunk/Source/WebCore/Modules/webaudio/AudioWorkletNode.cpp (286452 => 286453)
--- trunk/Source/WebCore/Modules/webaudio/AudioWorkletNode.cpp 2021-12-02 22:21:46 UTC (rev 286452)
+++ trunk/Source/WebCore/Modules/webaudio/AudioWorkletNode.cpp 2021-12-02 22:22:49 UTC (rev 286453)
@@ -82,8 +82,8 @@
return Exception { InvalidStateError, "Audio context's frame is detached"_s };
auto messageChannel = MessageChannel::create(*context.scriptExecutionContext());
- auto nodeMessagePort = messageChannel->port1();
- auto processorMessagePort = messageChannel->port2();
+ auto& nodeMessagePort = messageChannel->port1();
+ auto& processorMessagePort = messageChannel->port2();
RefPtr<SerializedScriptValue> serializedOptions;
{
@@ -95,7 +95,7 @@
}
auto parameterData = WTFMove(options.parameterData);
- auto node = adoptRef(*new AudioWorkletNode(context, name, WTFMove(options), *nodeMessagePort));
+ auto node = adoptRef(*new AudioWorkletNode(context, name, WTFMove(options), nodeMessagePort));
node->suspendIfNeeded();
auto result = node->handleAudioNodeOptions(options, { 2, ChannelCountMode::Max, ChannelInterpretation::Speakers });
@@ -109,7 +109,7 @@
if (node->numberOfOutputs() > 0)
context.sourceNodeWillBeginPlayback(node);
- context.audioWorklet().createProcessor(name, processorMessagePort->disentangle(), serializedOptions.releaseNonNull(), node);
+ context.audioWorklet().createProcessor(name, processorMessagePort.disentangle(), serializedOptions.releaseNonNull(), node);
{
// The node should be manually added to the automatic pull node list, even without a connect() call.
Modified: trunk/Source/WebCore/bindings/js/JSMessageChannelCustom.cpp (286452 => 286453)
--- trunk/Source/WebCore/bindings/js/JSMessageChannelCustom.cpp 2021-12-02 22:21:46 UTC (rev 286452)
+++ trunk/Source/WebCore/bindings/js/JSMessageChannelCustom.cpp 2021-12-02 22:22:49 UTC (rev 286453)
@@ -36,11 +36,8 @@
template<typename Visitor>
void JSMessageChannel::visitAdditionalChildren(Visitor& visitor)
{
- if (MessagePort* port = wrapped().port1())
- visitor.addOpaqueRoot(port);
-
- if (MessagePort* port = wrapped().port2())
- visitor.addOpaqueRoot(port);
+ visitor.addOpaqueRoot(&wrapped().port1());
+ visitor.addOpaqueRoot(&wrapped().port2());
}
DEFINE_VISIT_ADDITIONAL_CHILDREN(JSMessageChannel);
Modified: trunk/Source/WebCore/dom/MessageChannel.cpp (286452 => 286453)
--- trunk/Source/WebCore/dom/MessageChannel.cpp 2021-12-02 22:21:46 UTC (rev 286452)
+++ trunk/Source/WebCore/dom/MessageChannel.cpp 2021-12-02 22:22:49 UTC (rev 286453)
@@ -33,6 +33,14 @@
namespace WebCore {
+static std::pair<Ref<MessagePort>, Ref<MessagePort>> generateMessagePorts(ScriptExecutionContext& context)
+{
+ MessagePortIdentifier id1 = { Process::identifier(), ObjectIdentifier<MessagePortIdentifier::PortIdentifierType>::generate() };
+ MessagePortIdentifier id2 = { Process::identifier(), ObjectIdentifier<MessagePortIdentifier::PortIdentifierType>::generate() };
+
+ return { MessagePort::create(context, id1, id2), MessagePort::create(context, id2, id1) };
+}
+
Ref<MessageChannel> MessageChannel::create(ScriptExecutionContext& context)
{
return adoptRef(*new MessageChannel(context));
@@ -39,20 +47,15 @@
}
MessageChannel::MessageChannel(ScriptExecutionContext& context)
+ : m_ports(generateMessagePorts(context))
{
- MessagePortIdentifier id1 = { Process::identifier(), ObjectIdentifier<MessagePortIdentifier::PortIdentifierType>::generate() };
- MessagePortIdentifier id2 = { Process::identifier(), ObjectIdentifier<MessagePortIdentifier::PortIdentifierType>::generate() };
-
- m_port1 = MessagePort::create(context, id1, id2);
- m_port2 = MessagePort::create(context, id2, id1);
-
if (!context.activeDOMObjectsAreStopped()) {
- ASSERT(!m_port1->closed());
- ASSERT(!m_port2->closed());
- MessagePortChannelProvider::fromContext(context).createNewMessagePortChannel(id1, id2);
+ ASSERT(!port1().closed());
+ ASSERT(!port2().closed());
+ MessagePortChannelProvider::fromContext(context).createNewMessagePortChannel(port1().identifier(), port2().identifier());
} else {
- ASSERT(m_port1->closed());
- ASSERT(m_port2->closed());
+ ASSERT(port1().closed());
+ ASSERT(port2().closed());
}
}
Modified: trunk/Source/WebCore/dom/MessageChannel.h (286452 => 286453)
--- trunk/Source/WebCore/dom/MessageChannel.h 2021-12-02 22:21:46 UTC (rev 286452)
+++ trunk/Source/WebCore/dom/MessageChannel.h 2021-12-02 22:22:49 UTC (rev 286453)
@@ -39,14 +39,13 @@
static Ref<MessageChannel> create(ScriptExecutionContext&);
~MessageChannel();
- MessagePort* port1() const { return m_port1.get(); }
- MessagePort* port2() const { return m_port2.get(); }
+ MessagePort& port1() const { return m_ports.first.get(); }
+ MessagePort& port2() const { return m_ports.second.get(); }
private:
explicit MessageChannel(ScriptExecutionContext&);
- RefPtr<MessagePort> m_port1;
- RefPtr<MessagePort> m_port2;
+ std::pair<Ref<MessagePort>, Ref<MessagePort>> m_ports;
};
} // namespace WebCore