idb-binary-key-detached.any.js (1227B)
1 // META: title= IndexedDB: Detached buffers supplied as binary keys 2 // META: global=window,worker 3 // META: script=resources/support.js 4 5 // Specs: 6 // http://w3c.github.io/IndexedDB/#convert-a-value-to-a-key 7 // https://webidl.spec.whatwg.org/#dfn-get-buffer-source-copy 8 9 "use strict"; 10 11 indexeddb_test( 12 (t, db) => { db.createObjectStore('store'); }, 13 (t, db) => { 14 const tx = db.transaction('store', 'readwrite'); 15 const store = tx.objectStore('store'); 16 17 const array = createDetachedArrayBuffer(); 18 const buffer = array.buffer; 19 assert_throws_dom("DataError", () => { store.put('', buffer); }); 20 assert_throws_dom("DataError", () => { store.put('', [buffer]); }); 21 t.done(); 22 }, 23 'Detached ArrayBuffers must throw DataError when used as a key' 24 ); 25 26 indexeddb_test( 27 (t, db) => { db.createObjectStore('store'); }, 28 (t, db) => { 29 const tx = db.transaction('store', 'readwrite'); 30 const store = tx.objectStore('store'); 31 32 const array = createDetachedArrayBuffer(); 33 assert_throws_dom("DataError", () => { store.put('', array); }); 34 assert_throws_dom("DataError", () => { store.put('', [array]); }); 35 t.done(); 36 }, 37 'Detached TypedArrays must throw DataError when used as a key' 38 );