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