idb-explicit-commit-throw.any.js (1561B)
1 // META: script=resources/support-promises.js 2 'use strict'; 3 4 setup({allow_uncaught_exception:true}); 5 6 promise_test(async testCase => { 7 // Register an event listener that will prevent the intentionally thrown 8 // error from bubbling up to the window and failing the testharness. This 9 // is necessary because currently allow_uncaught_exception does not behave 10 // as expected for promise_test. 11 // 12 // Git issue: https://github.com/web-platform-tests/wpt/issues/14041 13 self.addEventListener('error', (event) => { event.preventDefault(); }); 14 15 const db = await createDatabase(testCase, async db => { 16 await createBooksStore(testCase, db); 17 }); 18 19 const txn = db.transaction(['books'], 'readwrite'); 20 const objectStore = txn.objectStore('books'); 21 const putRequest = objectStore.put({isbn:'one', title:'title'}); 22 txn.commit(); 23 putRequest.onsuccess = () => { 24 throw new Error('This error thrown after an explicit commit should not ' + 25 'prevent the transaction from committing.'); 26 } 27 await promiseForTransaction(testCase, txn); 28 29 // Ensure that despite the uncaught error after the put request, the explicit 30 // commit still causes the request to be committed. 31 const txn2 = db.transaction(['books'], 'readwrite'); 32 const objectStore2 = txn2.objectStore('books'); 33 const getRequest = objectStore2.get('one'); 34 await promiseForTransaction(testCase, txn2); 35 36 assert_equals(getRequest.result.title, 'title'); 37 }, 'Any errors in callbacks that run after an explicit commit will not stop ' 38 + 'the commit from being processed.');