Esempio n. 1
0
void ScriptRunner::executeScripts()
{
    RefPtrWillBeRawPtr<Document> protect(m_document.get());

    WillBeHeapDeque<RawPtrWillBeMember<ScriptLoader>> scriptLoaders;
    scriptLoaders.swap(m_scriptsToExecuteSoon);

    WillBeHeapHashSet<RawPtrWillBeMember<ScriptLoader>> inorderSet;
    while (!m_scriptsToExecuteInOrder.isEmpty() && m_scriptsToExecuteInOrder.first()->isReady()) {
        ScriptLoader* script = m_scriptsToExecuteInOrder.takeFirst();
        inorderSet.add(script);
        scriptLoaders.append(script);
    }

    while (!scriptLoaders.isEmpty()) {
        scriptLoaders.takeFirst()->execute();
        m_document->decrementLoadEventDelayCount();

        if (yieldForHighPriorityWork())
            break;
    }

    // If we have to yield, we must re-enqueue any scriptLoaders back onto the front of
    // m_scriptsToExecuteInOrder or m_scriptsToExecuteSoon depending on where the script
    // came from.
    // NOTE a yield followed by a notifyScriptReady(... ASYNC_EXECUTION) will result in that script executing
    // before any pre-existing ScriptsToExecuteInOrder.
    while (!scriptLoaders.isEmpty()) {
        ScriptLoader* script = scriptLoaders.takeLast();
        if (inorderSet.contains(script))
            m_scriptsToExecuteInOrder.prepend(script);
        else
            m_scriptsToExecuteSoon.prepend(script);
    }
}
Esempio n. 2
0
void WebSocket::EventQueue::dispatchQueuedEvents()
{
    if (m_state != Active)
        return;

    RefPtrWillBeRawPtr<EventQueue> protect(this);

    WillBeHeapDeque<RefPtrWillBeMember<Event> > events;
    events.swap(m_events);
    while (!events.isEmpty()) {
        if (m_state == Stopped || m_state == Suspended)
            break;
        ASSERT(m_state == Active);
        ASSERT(m_target->executionContext());
        m_target->dispatchEvent(events.takeFirst());
        // |this| can be stopped here.
    }
    if (m_state == Suspended) {
        while (!m_events.isEmpty())
            events.append(m_events.takeFirst());
        events.swap(m_events);
    }
}