bool ArrayBuffer::transfer(ArrayBufferContents& result)
{
    Ref<ArrayBuffer> protect(*this);

    if (!m_contents.m_data) {
        result.m_data = 0;
        return false;
    }

    bool isNeuterable = !m_pinCount;

    if (isNeuterable)
        m_contents.transfer(result);
    else {
        m_contents.copyTo(result);
        if (!result.m_data)
            return false;
    }

    for (size_t i = numberOfIncomingReferences(); i--;) {
        JSArrayBufferView* view = jsDynamicCast<JSArrayBufferView*>(incomingReferenceAt(i));
        if (view)
            view->neuter();
    }
    return true;
}
Esempio n. 2
0
void ArrayBuffer::notifyIncommingReferencesOfTransfer(VM& vm)
{
    for (size_t i = numberOfIncomingReferences(); i--;) {
        JSCell* cell = incomingReferenceAt(i);
        if (JSArrayBufferView* view = jsDynamicCast<JSArrayBufferView*>(vm, cell))
            view->neuter();
        else if (ArrayBufferNeuteringWatchpoint* watchpoint = jsDynamicCast<ArrayBufferNeuteringWatchpoint*>(vm, cell))
            watchpoint->fireAll();
    }
}