idbobjectstore-add-put-exception-order.any.js (2419B)
1 // META: global=window,worker 2 // META: title=IndexedDB: IDBObjectStore add()/put() Exception Ordering 3 // META: script=resources/support.js 4 5 // Spec: https://w3c.github.io/IndexedDB/#dom-idbobjectstore-put 6 // Spec: https://w3c.github.io/IndexedDB/#dom-idbobjectstore-add 7 8 'use strict'; 9 10 ['put', 'add'].forEach(method => { 11 indexeddb_test( 12 (t, db) => { 13 const store = db.createObjectStore('s'); 14 const store2 = db.createObjectStore('s2'); 15 16 db.deleteObjectStore('s2'); 17 18 setTimeout( 19 t.step_func(() => { 20 assert_throws_dom( 21 'InvalidStateError', 22 () => { 23 store2[method]('key', 'value'); 24 }, 25 '"has been deleted" check (InvalidStateError) should precede ' + 26 '"not active" check (TransactionInactiveError)'); 27 t.done(); 28 }), 29 0); 30 }, 31 (t, db) => {}, 32 `IDBObjectStore.${method} exception order: ` + 33 'InvalidStateError vs. TransactionInactiveError'); 34 35 indexeddb_test( 36 (t, db) => { 37 const store = db.createObjectStore('s'); 38 }, 39 (t, db) => { 40 const tx = db.transaction('s', 'readonly'); 41 const store = tx.objectStore('s'); 42 43 setTimeout( 44 t.step_func(() => { 45 assert_throws_dom( 46 'TransactionInactiveError', 47 () => { 48 store[method]('key', 'value'); 49 }, 50 '"not active" check (TransactionInactiveError) should precede ' + 51 '"read only" check (ReadOnlyError)'); 52 t.done(); 53 }), 54 0); 55 }, 56 57 `IDBObjectStore.${method} exception order: ` + 58 'TransactionInactiveError vs. ReadOnlyError'); 59 60 indexeddb_test( 61 (t, db) => { 62 const store = db.createObjectStore('s'); 63 }, 64 (t, db) => { 65 const tx = db.transaction('s', 'readonly'); 66 const store = tx.objectStore('s'); 67 68 assert_throws_dom( 69 'ReadOnlyError', 70 () => { 71 store[method]({}, 'value'); 72 }, 73 '"read only" check (ReadOnlyError) should precede ' + 74 'key/data check (DataError)'); 75 76 t.done(); 77 }, 78 79 `IDBObjectStore.${method} exception order: ` + 80 'ReadOnlyError vs. DataError'); 81 });