idbcursor-advance-exception-order.any.js (2907B)
1 // META: global=window,worker 2 // META: title=IndexedDB: IDBCursor advance() Exception Ordering 3 // META: script=resources/support.js 4 5 // Spec: https://w3c.github.io/IndexedDB/#dom-idbcursor-advance 6 7 'use strict'; 8 9 indexeddb_test( 10 (t, db) => { 11 const store = db.createObjectStore('s'); 12 store.put('value', 'key'); 13 }, 14 (t, db) => { 15 const tx = db.transaction('s', 'readonly'); 16 const store = tx.objectStore('s'); 17 18 const r = store.openKeyCursor(); 19 r.onsuccess = t.step_func(() => { 20 r.onsuccess = null; 21 22 const cursor = r.result; 23 24 setTimeout( 25 t.step_func(() => { 26 assert_throws_js( 27 TypeError, 28 () => { 29 cursor.advance(0); 30 }, 31 '"zero" check (TypeError) should precede ' + 32 '"not active" check (TransactionInactiveError)'); 33 t.done(); 34 }), 35 0); 36 }); 37 }, 38 'IDBCursor.advance exception order: TypeError vs. TransactionInactiveError'); 39 40 indexeddb_test( 41 (t, db) => { 42 const store = db.createObjectStore('s'); 43 44 const s = db.createObjectStore('s2'); 45 s.put('value', 'key'); 46 47 const r = s.openKeyCursor(); 48 r.onsuccess = t.step_func(() => { 49 r.onsuccess = null; 50 51 const cursor = r.result; 52 db.deleteObjectStore('s2'); 53 54 setTimeout( 55 t.step_func(() => { 56 assert_throws_dom( 57 'TransactionInactiveError', 58 () => { 59 cursor.advance(1); 60 }, 61 '"not active" check (TransactionInactiveError) ' + 62 'should precede "deleted" check (InvalidStateError)'); 63 t.done(); 64 }), 65 0); 66 }); 67 }, 68 (t, db) => {}, 69 'IDBCursor.advance exception order: ' + 70 'TransactionInactiveError vs. InvalidStateError #1'); 71 72 indexeddb_test( 73 (t, db) => { 74 const store = db.createObjectStore('s'); 75 store.put('value', 'key'); 76 }, 77 (t, db) => { 78 const tx = db.transaction('s', 'readonly'); 79 const store = tx.objectStore('s'); 80 81 const r = store.openKeyCursor(); 82 r.onsuccess = t.step_func(() => { 83 r.onsuccess = null; 84 85 const cursor = r.result; 86 cursor.advance(1); 87 88 setTimeout( 89 t.step_func(() => { 90 assert_throws_dom( 91 'TransactionInactiveError', 92 () => { 93 cursor.advance(1); 94 }, 95 '"not active" check (TransactionInactiveError) ' + 96 'should precede "got value" check (InvalidStateError)'); 97 t.done(); 98 }), 99 0); 100 }); 101 }, 102 'IDBCursor.advance exception order: ' + 103 'TransactionInactiveError vs. InvalidStateError #2');