Skip to content

Commit

Permalink
IndexedDB: objectStore() should fail after transaction is aborted
Browse files Browse the repository at this point in the history
Noticed via code inspection: The IDBTransaction::objectStore() and
IDBObjectStore::index() methods return IDBObjectStore and IDBIndex
objects when the transaction is alive, but are specified to throw when
"finished". Blink splits this to two different states: |kFinishing|
when abort() is called or a commit is triggered, and |kFinished| when
the backend has ack'd. The implementation of index() was including the
|kFinishing| state in its check, but the implementation of
objectStore() was not.

Align the checks to include both states, which matches the behavior in
Firefox, and add web-platform-test coverage.

R=pwnall@chromium.org

Review-Url: https://codereview.chromium.org/2820593002
Cr-Commit-Position: refs/heads/master@{#464569}
  • Loading branch information
inexorabletash authored and chromium-wpt-export-bot committed Apr 13, 2017
1 parent 690108a commit 9d1ec68
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
26 changes: 26 additions & 0 deletions IndexedDB/idbobjectstore-index-finished.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!doctype html>
<meta charset=utf-8>
<title>IndexedDB: IDBObjectStore index() when transaction is finished</title>
<link rel="help" href="https://w3c.github.io/IndexedDB/#dom-idbobjectstore-index">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>

indexeddb_test(
(t, db) => {
const store = db.createObjectStore('store');
store.createIndex('index', 'key_path');
},
(t, db) => {
const tx = db.transaction('store');
const store = tx.objectStore('store');
tx.abort();
assert_throws('InvalidStateError', () => store.index('index'),
'index() should throw if transaction is finished');
t.done();
},
'IDBObjectStore index() behavior when transaction is finished'
);

</script>
24 changes: 24 additions & 0 deletions IndexedDB/idbtransaction-objectStore-finished.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!doctype html>
<meta charset=utf-8>
<title>IndexedDB: IDBTransaction objectStore() when transaction is finished</title>
<link rel="help" href="https://w3c.github.io/IndexedDB/#dom-idbtransaction-objectstore">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>

indexeddb_test(
(t, db) => {
db.createObjectStore('store');
},
(t, db) => {
const tx = db.transaction('store');
tx.abort();
assert_throws('InvalidStateError', () => tx.objectStore('store'),
'objectStore() should throw if transaction is finished');
t.done();
},
'IDBTransaction objectStore() behavior when transaction is finished'
);

</script>

0 comments on commit 9d1ec68

Please sign in to comment.