OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 loopCount = 0; | 5 loopCount = 0; |
6 function endlessLoop() | 6 function endlessLoop() |
7 { | 7 { |
8 var request = objectStore.get(0); | 8 var request = objectStore.get(0); |
9 request.onsuccess = endlessLoop; | 9 request.onsuccess = endlessLoop; |
10 request.onerror = unexpectedErrorCallback; | 10 request.onerror = unexpectedErrorCallback; |
11 | 11 |
12 loopCount += 1; | 12 loopCount += 1; |
13 if (loopCount == 7) { | 13 if (loopCount == 7) { |
14 // If we've already looped 7 times, it's pretty safe to assume | 14 // If we've already looped 7 times, it's pretty safe to assume |
15 // we'll continue looping for some time... | 15 // we'll continue looping for some time... |
16 debug("Looping infinitely within a transaction."); | 16 debug("Looping infinitely within a transaction."); |
17 done(); | 17 done(); |
18 } | 18 } |
19 } | 19 } |
20 | 20 |
21 function newTransactionComplete() | 21 function newTransactionComplete() |
22 { | 22 { |
23 debug('The transaction completed.'); | 23 debug('The transaction completed.'); |
24 | 24 |
25 var finalTransaction = db.transaction([], IDBTransaction.READ_ONLY); | 25 var finalTransaction = db.transaction(['employees'], |
| 26 IDBTransaction.READ_ONLY); |
26 finalTransaction.oncomplete = unexpectedCompleteCallback; | 27 finalTransaction.oncomplete = unexpectedCompleteCallback; |
27 finalTransaction.onabort = unexpectedErrorCallback; | 28 finalTransaction.onabort = unexpectedErrorCallback; |
28 | 29 |
29 objectStore = finalTransaction.objectStore('employees'); | 30 objectStore = finalTransaction.objectStore('employees'); |
30 endlessLoop(); | 31 endlessLoop(); |
31 endlessLoop(); // Make sure at least one is in flight at any time. | 32 endlessLoop(); // Make sure at least one is in flight at any time. |
32 } | 33 } |
33 | 34 |
34 function onSetVersionComplete() | 35 function onSetVersionComplete() |
35 { | 36 { |
36 debug('Creating new transaction.'); | 37 debug('Creating new transaction.'); |
37 var newTransaction = db.transaction([], IDBTransaction.READ_WRITE); | 38 var newTransaction = db.transaction(['employees'], IDBTransaction.READ_WRITE); |
38 newTransaction.oncomplete = newTransactionComplete; | 39 newTransaction.oncomplete = newTransactionComplete; |
39 newTransaction.onabort = unexpectedAbortCallback; | 40 newTransaction.onabort = unexpectedAbortCallback; |
40 | 41 |
41 var request = newTransaction.objectStore('employees').put( | 42 var request = newTransaction.objectStore('employees').put( |
42 {id: 0, name: 'John Doe', desk: 'LON-BEL-123'}); | 43 {id: 0, name: 'John Doe', desk: 'LON-BEL-123'}); |
43 request.onerror = unexpectedErrorCallback; | 44 request.onerror = unexpectedErrorCallback; |
44 } | 45 } |
45 | 46 |
46 function onSetVersion() | 47 function onSetVersion() |
47 { | 48 { |
(...skipping 22 matching lines...) Expand all Loading... |
70 IDBCursor = webkitIDBCursor; | 71 IDBCursor = webkitIDBCursor; |
71 IDBKeyRange = webkitIDBKeyRange; | 72 IDBKeyRange = webkitIDBKeyRange; |
72 IDBTransaction = webkitIDBTransaction; | 73 IDBTransaction = webkitIDBTransaction; |
73 } | 74 } |
74 | 75 |
75 debug('Connecting to indexedDB.'); | 76 debug('Connecting to indexedDB.'); |
76 var request = indexedDB.open('name'); | 77 var request = indexedDB.open('name'); |
77 request.onsuccess = setVersion; | 78 request.onsuccess = setVersion; |
78 request.onerror = unexpectedErrorCallback; | 79 request.onerror = unexpectedErrorCallback; |
79 } | 80 } |
OLD | NEW |