bool MessagePort::tryGetMessage( RefPtr<SerializedScriptValue>& message, std::unique_ptr<MessagePortChannelArray>& channels) { if (!m_entangledChannel) return false; return tryGetMessageFrom(*m_entangledChannel, message, channels); }
void MessagePort::dispatchMessages() { // Messages for contexts that are not fully active get dispatched too, but JSAbstractEventListener::handleEvent() doesn't call handlers for these. // The HTML5 spec specifies that any messages sent to a document that is not fully active should be dropped, so this behavior is OK. if (!started()) return; RefPtr<SerializedScriptValue> message; OwnPtr<MessagePortChannelArray> channels; while (m_entangledChannel && tryGetMessageFrom(*m_entangledChannel, message, channels)) { // close() in Worker onmessage handler should prevent next message from dispatching. if (executionContext()->isWorkerGlobalScope() && toWorkerGlobalScope(executionContext())->isClosing()) return; OwnPtr<MessagePortArray> ports = MessagePort::entanglePorts(*executionContext(), channels.release()); RefPtrWillBeRawPtr<Event> evt = MessageEvent::create(ports.release(), message.release()); dispatchEvent(evt.release(), ASSERT_NO_EXCEPTION); } }