IDBError MemoryObjectStore::addRecord(MemoryBackingStoreTransaction& transaction, const IDBKeyData& keyData, const IDBValue& value) { LOG(IndexedDB, "MemoryObjectStore::addRecord"); ASSERT(m_writeTransaction); ASSERT_UNUSED(transaction, m_writeTransaction == &transaction); ASSERT(!m_keyValueStore || !m_keyValueStore->contains(keyData)); ASSERT(!m_orderedKeys || m_orderedKeys->find(keyData) == m_orderedKeys->end()); if (!m_keyValueStore) { ASSERT(!m_orderedKeys); m_keyValueStore = std::make_unique<KeyValueMap>(); m_orderedKeys = std::make_unique<std::set<IDBKeyData>>(); } auto mapResult = m_keyValueStore->set(keyData, value.data()); ASSERT(mapResult.isNewEntry); auto listResult = m_orderedKeys->insert(keyData); ASSERT(listResult.second); // If there was an error indexing this addition, then revert it. auto error = updateIndexesForPutRecord(keyData, value.data()); if (!error.isNull()) { m_keyValueStore->remove(mapResult.iterator); m_orderedKeys->erase(listResult.first); } else updateCursorsForPutRecord(listResult.first); return error; }
static JSValue deserializeIDBValueToJSValue(ExecState& state, JSC::JSGlobalObject& globalObject, const IDBValue& value) { // FIXME: I think it's peculiar to use undefined to mean "null data" and null to mean "empty data". // But I am not changing this at the moment because at least some callers are specifically checking isUndefined. if (!value.data().data()) return jsUndefined(); auto& data = *value.data().data(); if (data.isEmpty()) return jsNull(); auto serializedValue = SerializedScriptValue::createFromWireBytes(Vector<uint8_t>(data)); state.vm().apiLock().lock(); Vector<RefPtr<MessagePort>> messagePorts; JSValue result = serializedValue->deserialize(state, &globalObject, messagePorts, value.blobURLs(), value.sessionID(), value.blobFilePaths(), SerializationErrorMode::NonThrowing); state.vm().apiLock().unlock(); return result; }