1
0
Fork 0
firefox/testing/web-platform/tests/IndexedDB/idb-binary-key-detached.htm
Daniel Baumann 5e9a113729
Adding upstream version 140.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
2025-06-25 09:37:52 +02:00

52 lines
1.7 KiB
HTML

<!doctype html>
<meta charset=utf-8>
<title>IndexedDB: Detached buffers supplied as binary keys</title>
<meta name="help" href="http://w3c.github.io/IndexedDB/#convert-a-value-to-a-key">
<meta name="help" href="https://webidl.spec.whatwg.org/#dfn-get-buffer-source-copy">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/support.js"></script>
<script>
function createDetachedArrayBuffer() {
const array = new Uint8Array([1,2,3,4]);
const buffer = array.buffer;
assert_equals(array.byteLength, 4);
// Detach the ArrayBuffer by transferring it to a worker.
const worker = new Worker(URL.createObjectURL(new Blob([])));
worker.postMessage('', [buffer]);
assert_equals(array.byteLength, 0);
return array;
}
indexeddb_test(
(t, db) => { db.createObjectStore('store'); },
(t, db) => {
const tx = db.transaction('store', 'readwrite');
const store = tx.objectStore('store');
const array = createDetachedArrayBuffer();
const buffer = array.buffer;
assert_throws_dom("DataError", () => { store.put('', buffer); });
assert_throws_dom("DataError", () => { store.put('', [buffer]); });
t.done();
},
'Detached ArrayBuffers must throw DataError when used as a key'
);
indexeddb_test(
(t, db) => { db.createObjectStore('store'); },
(t, db) => {
const tx = db.transaction('store', 'readwrite');
const store = tx.objectStore('store');
const array = createDetachedArrayBuffer();
assert_throws_dom("DataError", () => { store.put('', array); });
assert_throws_dom("DataError", () => { store.put('', [array]); });
t.done();
},
'Detached TypedArrays must throw DataError when used as a key'
);
</script>