void IDBCursor::continuePrimaryKey(ScriptState* scriptState, const ScriptValue& keyValue, const ScriptValue& primaryKeyValue, ExceptionState& exceptionState) { IDB_TRACE("IDBCursor::continuePrimaryKey"); IDBKey* key = scriptValueToIDBKey(scriptState->isolate(), keyValue); IDBKey* primaryKey = scriptValueToIDBKey(scriptState->isolate(), primaryKeyValue); if (!key->isValid() || !primaryKey->isValid()) { exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); return; } continueFunction(key, primaryKey, exceptionState); }
void IDBCursor::continuePrimaryKey(ExecutionContext* context, const ScriptValue& keyValue, const ScriptValue& primaryKeyValue, ExceptionState& exceptionState) { IDB_TRACE("IDBCursor::continuePrimaryKey"); RefPtrWillBeRawPtr<IDBKey> key = scriptValueToIDBKey(toIsolate(context), keyValue); RefPtrWillBeRawPtr<IDBKey> primaryKey = scriptValueToIDBKey(toIsolate(context), primaryKeyValue); if (!key->isValid() || !primaryKey->isValid()) { exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); return; } continueFunction(key.release(), primaryKey.release(), exceptionState); }
PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackend::PutMode putMode, PassRefPtr<IDBAny> source, JSC::ExecState* state, Deprecated::ScriptValue& value, const Deprecated::ScriptValue& keyValue, ExceptionCode& ec) { ScriptExecutionContext* context = scriptExecutionContextFromExecState(state); DOMRequestState requestState(context); RefPtr<IDBKey> key = scriptValueToIDBKey(&requestState, keyValue); return put(putMode, source, state, value, key.release(), ec); }
RefPtr<IDBRequest> IDBObjectStore::put(ExecState& execState, JSValue value, JSValue key, ExceptionCodeWithMessage& ec) { RefPtr<IDBKey> idbKey; if (!key.isUndefined()) idbKey = scriptValueToIDBKey(execState, key); return putOrAdd(execState, value, idbKey, IndexedDB::ObjectStoreOverwriteMode::Overwrite, InlineKeyCheck::Perform, ec); }
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()); }
RefPtr<WebCore::IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, const Deprecated::ScriptValue& key, ExceptionCodeWithMessage& ec) { LOG(IndexedDB, "IDBObjectStore::get"); if (!context) { ec.code = IDBDatabaseException::InvalidStateError; 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; return nullptr; } DOMRequestState requestState(context); RefPtr<IDBKey> idbKey = scriptValueToIDBKey(&requestState, key); if (!idbKey || idbKey->type() == KeyType::Invalid) { ec.code = IDBDatabaseException::DataError; ec.message = ASCIILiteral("Failed to execute 'get' on 'IDBObjectStore': The parameter is not a valid key."); return nullptr; } Ref<IDBRequest> request = m_transaction->requestGetRecord(*context, *this, idbKey.get()); return WTF::move(request); }
RefPtr<WebCore::IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, const Deprecated::ScriptValue& key, ExceptionCode& ec) { LOG(IndexedDB, "IDBObjectStore::get"); if (!context) { ec = INVALID_STATE_ERR; return nullptr; } if (!m_transaction->isActive()) { ec = static_cast<ExceptionCode>(IDBExceptionCode::TransactionInactiveError); return nullptr; } if (m_deleted) { ec = INVALID_STATE_ERR; return nullptr; } DOMRequestState requestState(context); RefPtr<IDBKey> idbKey = scriptValueToIDBKey(&requestState, key); if (!idbKey || idbKey->type() == KeyType::Invalid) { ec = static_cast<ExceptionCode>(IDBExceptionCode::DataError); return nullptr; } Ref<IDBRequest> request = m_transaction->requestGetRecord(*context, *this, idbKey.get()); return WTF::move(request); }
PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackendInterface::PutMode putMode, PassRefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, const ScriptValue& keyValue, ExceptionCode& ec) { ScriptExecutionContext* context = scriptExecutionContextFromScriptState(state); DOMRequestState requestState(context); RefPtr<IDBKey> key = keyValue.isUndefined() ? 0 : scriptValueToIDBKey(&requestState, keyValue); return put(putMode, source, state, value, key.release(), ec); }
short IDBFactory::cmp(ScriptExecutionContext* context, const Deprecated::ScriptValue& firstValue, const Deprecated::ScriptValue& secondValue, ExceptionCode& ec) { DOMRequestState requestState(context); RefPtr<IDBKey> first = scriptValueToIDBKey(&requestState, firstValue); RefPtr<IDBKey> second = scriptValueToIDBKey(&requestState, secondValue); ASSERT(first); ASSERT(second); if (!first->isValid() || !second->isValid()) { ec = IDBDatabaseException::DataError; return 0; } return static_cast<short>(first->compare(second.get())); }
short IDBFactory::cmp(ScriptExecutionContext* context, const Deprecated::ScriptValue& firstValue, const Deprecated::ScriptValue& secondValue, ExceptionCodeWithMessage& ec) { DOMRequestState requestState(context); RefPtr<IDBKey> first = scriptValueToIDBKey(&requestState, firstValue); RefPtr<IDBKey> second = scriptValueToIDBKey(&requestState, secondValue); ASSERT(first); ASSERT(second); if (!first->isValid() || !second->isValid()) { ec.code = IDBDatabaseException::DataError; ec.message = ASCIILiteral("Failed to execute 'cmp' on 'IDBFactory': The parameter is not a valid key."); return 0; } return static_cast<short>(first->compare(second.get())); }
IDBKeyRange* IDBKeyRange::lowerBound(ExecutionContext* context, const ScriptValue& boundValue, bool open, ExceptionState& exceptionState) { IDBKey* bound = scriptValueToIDBKey(toIsolate(context), boundValue); if (!bound || !bound->isValid()) { exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); return 0; } return IDBKeyRange::create(bound, 0, open ? LowerBoundOpen : LowerBoundClosed, UpperBoundOpen); }
ExceptionOr<Ref<IDBRequest>> IDBIndex::getKey(ExecState& execState, JSValue key) { LOG(IndexedDB, "IDBIndex::getKey"); auto idbKey = scriptValueToIDBKey(execState, key); if (!idbKey->isValid()) return Exception { IDBDatabaseException::DataError, ASCIILiteral("Failed to execute 'getKey' on 'IDBIndex': The parameter is not a valid key.") }; return doGetKey(execState, IDBKeyRangeData(idbKey.ptr())); }
IDBKeyRange* IDBKeyRange::only(ExecutionContext* context, const ScriptValue& keyValue, ExceptionState& exceptionState) { IDBKey* key = scriptValueToIDBKey(toIsolate(context), keyValue); if (!key || !key->isValid()) { exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); return 0; } return IDBKeyRange::create(key, key, LowerBoundClosed, UpperBoundClosed); }
void IDBCursor::continueFunction(ScriptState* scriptState, const ScriptValue& keyValue, ExceptionState& exceptionState) { IDB_TRACE("IDBCursor::continue"); IDBKey* key = keyValue.isUndefined() || keyValue.isNull() ? nullptr : scriptValueToIDBKey(scriptState->isolate(), keyValue); if (key && !key->isValid()) { exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); return; } continueFunction(key, 0, exceptionState); }
IDBKeyRange* IDBKeyRange::bound(ExecutionContext* context, const ScriptValue& lowerValue, const ScriptValue& upperValue, bool lowerOpen, bool upperOpen, ExceptionState& exceptionState) { IDBKey* lower = scriptValueToIDBKey(toIsolate(context), lowerValue); IDBKey* upper = scriptValueToIDBKey(toIsolate(context), upperValue); if (!lower || !lower->isValid() || !upper || !upper->isValid()) { exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); return 0; } if (upper->isLessThan(lower)) { exceptionState.throwDOMException(DataError, "The lower key is greater than the upper key."); return 0; } if (upper->isEqual(lower) && (lowerOpen || upperOpen)) { exceptionState.throwDOMException(DataError, "The lower key and upper key are equal and one of the bounds is open."); return 0; } return IDBKeyRange::create(lower, upper, lowerOpen ? LowerBoundOpen : LowerBoundClosed, upperOpen ? UpperBoundOpen : UpperBoundClosed); }
PassRefPtr<IDBKeyRange> IDBKeyRange::upperBound(ScriptExecutionContext* context, const ScriptValue& boundValue, bool open, ExceptionState& es) { DOMRequestState requestState(context); RefPtr<IDBKey> bound = scriptValueToIDBKey(&requestState, boundValue); if (!bound || !bound->isValid()) { es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); return 0; } return IDBKeyRange::create(0, bound, LowerBoundOpen, open ? UpperBoundOpen : UpperBoundClosed); }
PassRefPtr<IDBKeyRange> IDBKeyRange::only(ScriptExecutionContext* context, const ScriptValue& keyValue, ExceptionState& es) { DOMRequestState requestState(context); RefPtr<IDBKey> key = scriptValueToIDBKey(&requestState, keyValue); if (!key || !key->isValid()) { es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); return 0; } return IDBKeyRange::create(key, key, LowerBoundClosed, UpperBoundClosed); }
RefPtr<IDBRequest> IDBObjectStore::deleteFunction(ExecState& execState, JSValue key, ExceptionCodeWithMessage& ec) { Ref<IDBKey> idbKey = scriptValueToIDBKey(execState, 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(execState, &IDBKeyRange::create(WTFMove(idbKey)).get(), ec); }
RefPtr<WebCore::IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* context, const Deprecated::ScriptValue& key, ExceptionCode& ec) { DOMRequestState requestState(context); RefPtr<IDBKey> idbKey = scriptValueToIDBKey(&requestState, key); if (!idbKey || idbKey->type() == KeyType::Invalid) { ec = static_cast<ExceptionCode>(IDBExceptionCode::DataError); return nullptr; } return deleteFunction(context, &IDBKeyRange::create(idbKey.get()).get(), ec); }
void IDBCursor::continueFunction(ScriptExecutionContext* context, const Deprecated::ScriptValue& keyValue, ExceptionCode& ec) { if (!context) { ec = IDBDatabaseException::InvalidStateError; return; } DOMRequestState requestState(context); RefPtr<IDBKey> key = scriptValueToIDBKey(&requestState, keyValue); continueFunction(key.get(), ec); }
PassRefPtr<IDBKeyRange> IDBKeyRange::bound(ScriptExecutionContext* context, const ScriptValue& lowerValue, const ScriptValue& upperValue, bool lowerOpen, bool upperOpen, ExceptionState& es) { DOMRequestState requestState(context); RefPtr<IDBKey> lower = scriptValueToIDBKey(&requestState, lowerValue); RefPtr<IDBKey> upper = scriptValueToIDBKey(&requestState, upperValue); if (!lower || !lower->isValid() || !upper || !upper->isValid()) { es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); return 0; } if (upper->isLessThan(lower.get())) { es.throwDOMException(DataError, "The lower key is greater than the upper key."); return 0; } if (upper->isEqual(lower.get()) && (lowerOpen || upperOpen)) { es.throwDOMException(DataError, "The lower key and upper key are equal and one of the bounds is open."); return 0; } return IDBKeyRange::create(lower, upper, lowerOpen ? LowerBoundOpen : LowerBoundClosed, upperOpen ? UpperBoundOpen : UpperBoundClosed); }
RefPtr<WebCore::IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* context, JSC::JSValue key, ExceptionCodeWithMessage& ec) { DOMRequestState requestState(context); RefPtr<IDBKey> idbKey = scriptValueToIDBKey(&requestState, key); if (!idbKey || idbKey->type() == KeyType::Invalid) { ec.code = IDBDatabaseException::DataError; ec.message = ASCIILiteral("Failed to execute 'delete' on 'IDBObjectStore': The parameter is not a valid key."); return nullptr; } return deleteFunction(context, &IDBKeyRange::create(idbKey.get()).get(), ec); }
RefPtr<IDBRequest> IDBObjectStore::count(ExecState& execState, JSValue key, ExceptionCodeWithMessage& ec) { LOG(IndexedDB, "IDBObjectStore::count"); Ref<IDBKey> idbKey = scriptValueToIDBKey(execState, 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(execState, IDBKeyRangeData(idbKey.ptr()), ec); }
RefPtr<IDBRequest> IDBIndex::getKey(ScriptExecutionContext& context, const Deprecated::ScriptValue& key, ExceptionCodeWithMessage& ec) { LOG(IndexedDB, "IDBIndex::getKey"); DOMRequestState requestState(&context); RefPtr<IDBKey> idbKey = scriptValueToIDBKey(&requestState, key); if (!idbKey || idbKey->type() == KeyType::Invalid) { ec.code = IDBDatabaseException::DataError; ec.message = ASCIILiteral("Failed to execute 'getKey' on 'IDBIndex': The parameter is not a valid key."); return nullptr; } return doGetKey(context, IDBKeyRangeData(idbKey.get()), ec); }
IDBKeyRange* IDBKeyRange::fromScriptValue(ExecutionContext* context, const ScriptValue& value, ExceptionState& exceptionState) { if (value.isUndefined() || value.isNull()) return 0; IDBKeyRange* range = scriptValueToIDBKeyRange(toIsolate(context), value); if (range) return range; IDBKey* key = scriptValueToIDBKey(toIsolate(context), value); if (!key || !key->isValid()) { exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); return 0; } return new IDBKeyRange(key, key, LowerBoundClosed, UpperBoundClosed); }
PassRefPtr<IDBKeyRange> IDBKeyRange::fromScriptValue(ExecutionContext* context, const ScriptValue& value, ExceptionState& es) { DOMRequestState requestState(context); if (value.isUndefined() || value.isNull()) return 0; RefPtr<IDBKeyRange> range = scriptValueToIDBKeyRange(&requestState, value); if (range) return range.release(); RefPtr<IDBKey> key = scriptValueToIDBKey(&requestState, value); if (!key || !key->isValid()) { es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); return 0; } return adoptRef(new IDBKeyRange(key, key, LowerBoundClosed, UpperBoundClosed)); }
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); }
RefPtr<WebCore::IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, const Deprecated::ScriptValue& key, ExceptionCode& ec) { LOG(IndexedDB, "IDBObjectStore::count"); if (!context) { ec = INVALID_STATE_ERR; return nullptr; } DOMRequestState requestState(context); RefPtr<IDBKey> idbKey = scriptValueToIDBKey(&requestState, key); if (!idbKey || idbKey->type() == KeyType::Invalid) { ec = static_cast<ExceptionCode>(IDBExceptionCode::DataError); return nullptr; } return doCount(*context, IDBKeyRangeData(idbKey.get()), ec); }
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); }
RefPtr<WebCore::IDBRequest> IDBObjectStore::put(JSC::ExecState& execState, JSC::JSValue value, JSC::JSValue key, ExceptionCode& ec) { auto idbKey = scriptValueToIDBKey(execState, key); return putOrAdd(execState, value, idbKey, IndexedDB::ObjectStoreOverwriteMode::Overwrite, ec); }