fire-error-event-exception.any.js (5610B)
1 // META: global=window,worker 2 // META: title=Fire error event - Exception thrown 3 // META: script=resources/support.js 4 5 // Spec: "https://w3c.github.io/IndexedDB/#fire-error-event" 6 7 'use strict'; 8 9 setup({allow_uncaught_exception: true}); 10 11 function fire_error_event_test(func, description) { 12 indexeddb_test( 13 (t, db) => { 14 db.createObjectStore('s'); 15 }, 16 (t, db) => { 17 const tx = db.transaction('s', 'readwrite'); 18 tx.oncomplete = t.unreached_func('transaction should abort'); 19 const store = tx.objectStore('s'); 20 store.put(0, 0); 21 const request = store.add(0, 0); 22 request.onsuccess = t.unreached_func('request should fail'); 23 func(t, db, tx, request); 24 tx.addEventListener('abort', t.step_func_done(() => { 25 assert_equals(tx.error.name, 'AbortError'); 26 })); 27 }, 28 description); 29 } 30 31 // Listeners on the request. 32 33 fire_error_event_test((t, db, tx, request) => { 34 request.onerror = () => { 35 throw Error(); 36 }; 37 }, 'Exception in error event handler on request'); 38 39 fire_error_event_test((t, db, tx, request) => { 40 request.onerror = e => { 41 e.preventDefault(); 42 throw Error(); 43 }; 44 }, 'Exception in error event handler on request, with preventDefault'); 45 46 fire_error_event_test((t, db, tx, request) => { 47 request.addEventListener('error', () => { 48 throw Error(); 49 }); 50 }, 'Exception in error event listener on request'); 51 52 fire_error_event_test((t, db, tx, request) => { 53 request.addEventListener('error', { 54 get handleEvent() { 55 throw new Error(); 56 }, 57 }); 58 }, 'Exception in error event listener ("handleEvent" lookup) on request'); 59 60 fire_error_event_test((t, db, tx, request) => { 61 request.addEventListener('error', {}); 62 }, 'Exception in error event listener (non-callable "handleEvent") on request'); 63 64 fire_error_event_test((t, db, tx, request) => { 65 request.addEventListener( 66 'error', 67 () => { 68 // no-op 69 }); 70 request.addEventListener('error', () => { 71 throw Error(); 72 }); 73 }, 'Exception in second error event listener on request'); 74 75 fire_error_event_test( 76 (t, db, tx, request) => { 77 let second_listener_called = false; 78 request.addEventListener('error', () => { 79 throw Error(); 80 }); 81 request.addEventListener('error', t.step_func(() => { 82 second_listener_called = true; 83 assert_true( 84 is_transaction_active(tx, 's'), 85 'Transaction should be active until dispatch completes'); 86 })); 87 tx.addEventListener('abort', t.step_func(() => { 88 assert_true(second_listener_called); 89 })); 90 }, 91 'Exception in first error event listener on request, ' + 92 'transaction active in second'); 93 94 // Listeners on the transaction. 95 96 fire_error_event_test((t, db, tx, request) => { 97 tx.onerror = () => { 98 throw Error(); 99 }; 100 }, 'Exception in error event handler on transaction'); 101 102 fire_error_event_test((t, db, tx, request) => { 103 tx.onerror = e => { 104 e.preventDefault(); 105 throw Error(); 106 }; 107 }, 'Exception in error event handler on transaction, with preventDefault'); 108 109 fire_error_event_test((t, db, tx, request) => { 110 tx.addEventListener('error', () => { 111 throw Error(); 112 }); 113 }, 'Exception in error event listener on transaction'); 114 115 fire_error_event_test((t, db, tx, request) => { 116 tx.addEventListener( 117 'error', 118 () => { 119 // no-op 120 }); 121 tx.addEventListener('error', () => { 122 throw Error(); 123 }); 124 }, 'Exception in second error event listener on transaction'); 125 126 fire_error_event_test( 127 (t, db, tx, request) => { 128 let second_listener_called = false; 129 tx.addEventListener('error', () => { 130 throw Error(); 131 }); 132 tx.addEventListener('error', t.step_func(() => { 133 second_listener_called = true; 134 assert_true( 135 is_transaction_active(tx, 's'), 136 'Transaction should be active until dispatch completes'); 137 })); 138 tx.addEventListener('abort', t.step_func(() => { 139 assert_true(second_listener_called); 140 })); 141 }, 142 'Exception in first error event listener on transaction, ' + 143 'transaction active in second'); 144 145 // Listeners on the connection. 146 147 fire_error_event_test((t, db, tx, request) => { 148 db.onerror = () => { 149 throw Error(); 150 }; 151 }, 'Exception in error event handler on connection'); 152 153 fire_error_event_test((t, db, tx, request) => { 154 db.onerror = e => { 155 e.preventDefault() 156 throw Error(); 157 }; 158 }, 'Exception in error event handler on connection, with preventDefault'); 159 160 fire_error_event_test((t, db, tx, request) => { 161 db.addEventListener('error', () => { 162 throw Error(); 163 }); 164 }, 'Exception in error event listener on connection'); 165 166 fire_error_event_test((t, db, tx, request) => { 167 db.addEventListener( 168 'error', 169 () => { 170 // no-op 171 }); 172 db.addEventListener('error', () => { 173 throw Error(); 174 }); 175 }, 'Exception in second error event listener on connection'); 176 177 fire_error_event_test( 178 (t, db, tx, request) => { 179 let second_listener_called = false; 180 db.addEventListener('error', () => { 181 throw Error(); 182 }); 183 db.addEventListener('error', t.step_func(() => { 184 second_listener_called = true; 185 assert_true( 186 is_transaction_active(tx, 's'), 187 'Transaction should be active until dispatch completes'); 188 })); 189 tx.addEventListener('abort', t.step_func(() => { 190 assert_true(second_listener_called); 191 })); 192 }, 193 'Exception in first error event listener on connection, ' + 194 'transaction active in second');