diff --git a/dom/indexedDB/IDBObjectStore.cpp b/dom/indexedDB/IDBObjectStore.cpp index 0aa9d06649..e0e3db0ed0 100644 --- a/dom/indexedDB/IDBObjectStore.cpp +++ b/dom/indexedDB/IDBObjectStore.cpp @@ -68,7 +68,9 @@ struct IDBObjectStore::StructuredCloneWriteInfo uint64_t mOffsetToKeyProp; explicit StructuredCloneWriteInfo(IDBDatabase* aDatabase) - : mCloneBuffer(JS::StructuredCloneScope::DifferentProcessForIndexedDB, nullptr, + // DifferentProcessForIndexedDB is a read-only compatibility mode. New + // records must use the durable, cross-process serialization format. + : mCloneBuffer(JS::StructuredCloneScope::DifferentProcess, nullptr, nullptr) , mDatabase(aDatabase) , mOffsetToKeyProp(0) diff --git a/dom/indexedDB/test/unit/test_cache_record_roundtrip.js b/dom/indexedDB/test/unit/test_cache_record_roundtrip.js new file mode 100644 index 0000000000..7fa7c283d7 --- /dev/null +++ b/dom/indexedDB/test/unit/test_cache_record_roundtrip.js @@ -0,0 +1,49 @@ +/** + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +var testGenerator = testSteps(); + +function* testSteps() { + const name = "cache-record-roundtrip"; + let request = indexedDB.open(name, 1); + request.onerror = errorHandler; + request.onupgradeneeded = event => { + event.target.result.createObjectStore("cache", {keyPath: "key"}); + }; + request.onsuccess = grabEventAndContinueHandler; + let event = yield undefined; + let db = event.target.result; + let transaction = db.transaction("cache", "readwrite"); + transaction.onabort = errorHandler; + transaction.oncomplete = grabEventAndContinueHandler; + let store = transaction.objectStore("cache"); + store.put({key: "text", value: "compiled filter data"}); + store.put({key: "bytes", value: new Uint8Array([0, 1, 127, 255])}); + store.put({key: "empty", value: new ArrayBuffer(0)}); + yield undefined; + db.close(); + + // Reopen after committing: test the serialized database records, rather than + // just observing successful writes or values still held by the caller. + request = indexedDB.open(name, 1); + request.onerror = errorHandler; + request.onsuccess = grabEventAndContinueHandler; + event = yield undefined; + db = event.target.result; + request = db.transaction("cache").objectStore("cache").getAll(); + request.onerror = errorHandler; + request.onsuccess = grabEventAndContinueHandler; + event = yield undefined; + let records = event.target.result; + is(records.length, 3, "All committed records are readable"); + is(records[0].key, "bytes", "Records retain their keys"); + ok(records[0].value instanceof Uint8Array, "Typed array type survives storage"); + is(Array.from(records[0].value).join(), "0,1,127,255", "Bytes survive storage"); + is(records[1].value.byteLength, 0, "Empty buffers survive storage"); + is(records[2].value, "compiled filter data", "Strings survive storage"); + db.close(); + finishTest(); + yield undefined; +} diff --git a/dom/indexedDB/test/unit/xpcshell-shared.ini b/dom/indexedDB/test/unit/xpcshell-shared.ini index 05359097bd..8a4db0f4f9 100644 --- a/dom/indexedDB/test/unit/xpcshell-shared.ini +++ b/dom/indexedDB/test/unit/xpcshell-shared.ini @@ -10,6 +10,7 @@ [test_autoIncrement.js] [test_autoIncrement_indexes.js] [test_blocked_order.js] +[test_cache_record_roundtrip.js] [test_clear.js] [test_complex_keyPaths.js] [test_count.js]