示例#1
0
RefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext& context, JSValue key, ExceptionCodeWithMessage& ec)
{
    LOG(IndexedDB, "IDBObjectStore::get");
    ASSERT(currentThread() == m_transaction->database().originThreadID());

    auto exec = context.execState();
    if (!exec) {
        ec.code = IDBDatabaseException::UnknownError;
        ec.message = ASCIILiteral("Failed to execute 'get' on 'IDBObjectStore': Script execution context does not have an execution state.");
        return nullptr;
    }

    if (!m_transaction->isActive()) {
        ec.code = IDBDatabaseException::TransactionInactiveError;
        ec.message = ASCIILiteral("Failed to execute 'get' on 'IDBObjectStore': The transaction is inactive or finished.");
        return nullptr;
    }

    if (m_deleted) {
        ec.code = IDBDatabaseException::InvalidStateError;
        ec.message = ASCIILiteral("Failed to execute 'get' on 'IDBObjectStore': The object store has been deleted.");
        return nullptr;
    }

    Ref<IDBKey> idbKey = scriptValueToIDBKey(*exec, key);
    if (!idbKey->isValid()) {
        ec.code = IDBDatabaseException::DataError;
        ec.message = ASCIILiteral("Failed to execute 'get' on 'IDBObjectStore': The parameter is not a valid key.");
        return nullptr;
    }

    return m_transaction->requestGetRecord(context, *this, idbKey.ptr());
}
示例#2
0
RefPtr<IDBRequest> IDBObjectStore::modernDelete(ScriptExecutionContext& context, JSValue key, ExceptionCodeWithMessage& ec)
{
    auto exec = context.execState();
    if (!exec) {
        ec.code = IDBDatabaseException::UnknownError;
        ec.message = ASCIILiteral("Failed to execute 'delete' on 'IDBObjectStore': Script execution context does not have an execution state.");
        return nullptr;
    }

    Ref<IDBKey> idbKey = scriptValueToIDBKey(*exec, key);
    if (!idbKey->isValid()) {
        ec.code = IDBDatabaseException::DataError;
        ec.message = ASCIILiteral("Failed to execute 'delete' on 'IDBObjectStore': The parameter is not a valid key.");
        return nullptr;
    }

    return doDelete(context, &IDBKeyRange::create(WTFMove(idbKey)).get(), ec);
}
示例#3
0
RefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext& context, JSValue key, ExceptionCodeWithMessage& ec)
{
    LOG(IndexedDB, "IDBObjectStore::count");

    auto exec = context.execState();
    if (!exec) {
        ec.code = IDBDatabaseException::UnknownError;
        ec.message = ASCIILiteral("Failed to execute 'count' on 'IDBObjectStore': Script execution context does not have an execution state.");
        return nullptr;
    }

    Ref<IDBKey> idbKey = scriptValueToIDBKey(*exec, key);
    if (!idbKey->isValid()) {
        ec.code = IDBDatabaseException::DataError;
        ec.message = ASCIILiteral("Failed to execute 'count' on 'IDBObjectStore': The parameter is not a valid key.");
        return nullptr;
    }

    return doCount(context, IDBKeyRangeData(idbKey.ptr()), ec);
}