Esempio n. 1
0
RefPtr<AtomicStringImpl> JSRopeString::resolveRopeToExistingAtomicString(ExecState* exec) const
{
    if (length() > maxLengthForOnStackResolve) {
        resolveRope(exec);
        if (RefPtr<AtomicStringImpl> existingAtomicString = AtomicStringImpl::lookUp(m_value.impl())) {
            m_value = *existingAtomicString;
            setIs8Bit(m_value.impl()->is8Bit());
            clearFibers();
            return existingAtomicString;
        }
        return nullptr;
    }
    
    if (is8Bit()) {
        LChar buffer[maxLengthForOnStackResolve];
        resolveRopeInternal8(buffer);
        if (RefPtr<AtomicStringImpl> existingAtomicString = AtomicStringImpl::lookUp(buffer, length())) {
            m_value = *existingAtomicString;
            setIs8Bit(m_value.impl()->is8Bit());
            clearFibers();
            return existingAtomicString;
        }
    } else {
        UChar buffer[maxLengthForOnStackResolve];
        resolveRopeInternal16(buffer);
        if (RefPtr<AtomicStringImpl> existingAtomicString = AtomicStringImpl::lookUp(buffer, length())) {
            m_value = *existingAtomicString;
            setIs8Bit(m_value.impl()->is8Bit());
            clearFibers();
            return existingAtomicString;
        }
    }

    return nullptr;
}
Esempio n. 2
0
void JSRopeString::resolveRope(ExecState* exec) const
{
    ASSERT(isRope());

    if (is8Bit()) {
        LChar* buffer;
        if (RefPtr<StringImpl> newImpl = StringImpl::tryCreateUninitialized(m_length, buffer)) {
            Heap::heap(this)->reportExtraMemoryCost(newImpl->cost());
            m_value = newImpl.release();
        } else {
            outOfMemory(exec);
            return;
        }
        resolveRopeInternal8(buffer);
        clearFibers();
        ASSERT(!isRope());
        return;
    }

    UChar* buffer;
    if (RefPtr<StringImpl> newImpl = StringImpl::tryCreateUninitialized(m_length, buffer)) {
        Heap::heap(this)->reportExtraMemoryCost(newImpl->cost());
        m_value = newImpl.release();
    } else {
        outOfMemory(exec);
        return;
    }

    resolveRopeInternal16(buffer);
    clearFibers();
    ASSERT(!isRope());
}
Esempio n. 3
0
void JSRopeString::resolveRopeToAtomicString(ExecState* exec) const
{
    if (length() > maxLengthForOnStackResolve) {
        resolveRope(exec);
        m_value = AtomicString(m_value);
        setIs8Bit(m_value.impl()->is8Bit());
        return;
    }

    if (is8Bit()) {
        LChar buffer[maxLengthForOnStackResolve];
        resolveRopeInternal8(buffer);
        m_value = AtomicString(buffer, length());
        setIs8Bit(m_value.impl()->is8Bit());
    } else {
        UChar buffer[maxLengthForOnStackResolve];
        resolveRopeInternal16(buffer);
        m_value = AtomicString(buffer, length());
        setIs8Bit(m_value.impl()->is8Bit());
    }

    clearFibers();

    // If we resolved a string that didn't previously exist, notify the heap that we've grown.
    if (m_value.impl()->hasOneRef())
        Heap::heap(this)->reportExtraMemoryAllocated(m_value.impl()->cost());
}
Esempio n. 4
0
void JSRopeString::outOfMemory(ExecState* exec) const
{
    clearFibers();
    ASSERT(isRope());
    ASSERT(m_value.isNull());
    if (exec)
        throwOutOfMemoryError(exec);
}
Esempio n. 5
0
void JSRopeString::outOfMemory(ExecState* exec) const
{
    VM& vm = exec->vm();
    auto scope = DECLARE_THROW_SCOPE(vm);

    clearFibers();
    ASSERT(isRope());
    ASSERT(m_value.isNull());
    if (exec)
        throwOutOfMemoryError(exec, scope);
}
Esempio n. 6
0
void JSRopeString::resolveRope(ExecState* exec) const
{
    ASSERT(isRope());
    
    if (isSubstring()) {
        ASSERT(!substringBase()->isRope());
        m_value = substringBase()->m_value.substringSharingImpl(substringOffset(), length());
        substringBase().clear();
        return;
    }
    
    if (is8Bit()) {
        LChar* buffer;
        if (auto newImpl = StringImpl::tryCreateUninitialized(length(), buffer)) {
            Heap::heap(this)->reportExtraMemoryAllocated(newImpl->cost());
            m_value = WTFMove(newImpl);
        } else {
            outOfMemory(exec);
            return;
        }
        resolveRopeInternal8NoSubstring(buffer);
        clearFibers();
        ASSERT(!isRope());
        return;
    }

    UChar* buffer;
    if (auto newImpl = StringImpl::tryCreateUninitialized(length(), buffer)) {
        Heap::heap(this)->reportExtraMemoryAllocated(newImpl->cost());
        m_value = WTFMove(newImpl);
    } else {
        outOfMemory(exec);
        return;
    }

    resolveRopeInternal16NoSubstring(buffer);
    clearFibers();
    ASSERT(!isRope());
}