void IDBTransaction::objectStoreDeleted(const String& name) { ASSERT(m_state != Finished); ASSERT(isVersionChange()); IDBObjectStoreMap::iterator it = m_objectStoreMap.find(name); if (it != m_objectStoreMap.end()) { IDBObjectStore* objectStore = it->value; m_objectStoreMap.remove(name); objectStore->markDeleted(); m_objectStoreCleanupMap.set(objectStore, objectStore->metadata()); m_deletedObjectStores.add(objectStore); } }
IDBObjectStore* IDBTransaction::objectStore(const String& name, ExceptionState& exceptionState) { if (isFinished()) { exceptionState.throwDOMException( InvalidStateError, IDBDatabase::transactionFinishedErrorMessage); return nullptr; } IDBObjectStoreMap::iterator it = m_objectStoreMap.find(name); if (it != m_objectStoreMap.end()) return it->value; if (!isVersionChange() && !m_scope.contains(name)) { exceptionState.throwDOMException( NotFoundError, IDBDatabase::noSuchObjectStoreErrorMessage); return nullptr; } int64_t objectStoreId = m_database->findObjectStoreId(name); if (objectStoreId == IDBObjectStoreMetadata::InvalidId) { DCHECK(isVersionChange()); exceptionState.throwDOMException( NotFoundError, IDBDatabase::noSuchObjectStoreErrorMessage); return nullptr; } DCHECK(m_database->metadata().objectStores.contains(objectStoreId)); RefPtr<IDBObjectStoreMetadata> objectStoreMetadata = m_database->metadata().objectStores.get(objectStoreId); DCHECK(objectStoreMetadata.get()); IDBObjectStore* objectStore = IDBObjectStore::create(std::move(objectStoreMetadata), this); DCHECK(!m_objectStoreMap.contains(name)); m_objectStoreMap.set(name, objectStore); if (isVersionChange()) { DCHECK(!objectStore->isNewlyCreated()) << "Object store IDs are not assigned sequentially"; RefPtr<IDBObjectStoreMetadata> backupMetadata = objectStore->metadata().createCopy(); m_oldStoreMetadata.set(objectStore, std::move(backupMetadata)); } return objectStore; }
IDBRequest* IDBCursor::update(ScriptState* scriptState, ScriptValue& value, ExceptionState& exceptionState) { IDB_TRACE("IDBCursor::update"); if (!m_gotValue) { exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValueErrorMessage); return 0; } if (isKeyCursor()) { exceptionState.throwDOMException(InvalidStateError, IDBDatabase::isKeyCursorErrorMessage); return 0; } if (isDeleted()) { exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceDeletedErrorMessage); return 0; } if (m_transaction->isFinished() || m_transaction->isFinishing()) { exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage); return 0; } if (!m_transaction->isActive()) { exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionInactiveErrorMessage); return 0; } if (m_transaction->isReadOnly()) { exceptionState.throwDOMException(ReadOnlyError, "The record may not be updated inside a read-only transaction."); return 0; } IDBObjectStore* objectStore = effectiveObjectStore(); const IDBKeyPath& keyPath = objectStore->metadata().keyPath; const bool usesInLineKeys = !keyPath.isNull(); if (usesInLineKeys) { IDBKey* keyPathKey = createIDBKeyFromScriptValueAndKeyPath(scriptState->isolate(), value, keyPath); if (!keyPathKey || !keyPathKey->isEqual(m_primaryKey.get())) { exceptionState.throwDOMException(DataError, "The effective object store of this cursor uses in-line keys and evaluating the key path of the value parameter results in a different value than the cursor's effective key."); return 0; } } return objectStore->put(scriptState, blink::WebIDBPutModeCursorUpdate, IDBAny::create(this), value, m_primaryKey, exceptionState); }
ScriptValue IDBCursor::value(ScriptState* scriptState) { ASSERT(isCursorWithValue()); IDBObjectStore* objectStore = effectiveObjectStore(); const IDBObjectStoreMetadata& metadata = objectStore->metadata(); IDBAny* value; if (metadata.autoIncrement && !metadata.keyPath.isNull()) { value = IDBAny::create(m_value, m_blobs->getInfo(), m_primaryKey, metadata.keyPath); #if ENABLE(ASSERT) assertPrimaryKeyValidOrInjectable(scriptState, m_value, m_blobs->getInfo(), m_primaryKey, metadata.keyPath); #endif } else { value = IDBAny::create(m_value, m_blobs->getInfo()); } m_valueDirty = false; ScriptValue scriptValue = idbAnyToScriptValue(scriptState, value); return scriptValue; }
ScriptValue IDBCursor::value(ScriptState* scriptState) { ASSERT(isCursorWithValue()); IDBObjectStore* objectStore = effectiveObjectStore(); const IDBObjectStoreMetadata& metadata = objectStore->metadata(); IDBAny* value; if (!m_value) { value = IDBAny::createUndefined(); } else if (metadata.autoIncrement && !metadata.keyPath.isNull()) { RefPtr<IDBValue> idbValue = IDBValue::create(m_value.get(), m_primaryKey, metadata.keyPath); #if ENABLE(ASSERT) assertPrimaryKeyValidOrInjectable(scriptState, idbValue.get()); #endif value = IDBAny::create(idbValue.release()); } else { value = IDBAny::create(m_value); } m_valueDirty = false; ScriptValue scriptValue = ScriptValue::from(scriptState, value); return scriptValue; }