OLD | NEW |
1 if (this.importScripts) { | 1 if (this.importScripts) { |
2 importScripts('promise-idb.js'); | 2 importScripts('promise-idb.js'); |
3 } | 3 } |
4 | 4 |
5 window=this; | 5 window=this; |
6 var isWorker = window.document === undefined; | 6 var isWorker = window.document === undefined; |
7 | 7 |
8 function indexeddb_observers_actions(db1_name, db2_name, error_callback) { | 8 function indexeddb_observers_actions(db1_name, db2_name, error_callback) { |
9 var perform_db1_actions_part1 = function() { | 9 var perform_db1_actions_part1 = function() { |
10 var open_request = indexedDB.open(db1_name); | 10 var open_request = indexedDB.open(db1_name); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 [pdb.put(os1, 'e', 'c'), | 64 [pdb.put(os1, 'e', 'c'), |
65 pdb.put(os2, 'f', 'z'), | 65 pdb.put(os2, 'f', 'z'), |
66 pdb.waitForTransaction(txn)]); | 66 pdb.waitForTransaction(txn)]); |
67 }).catch(error_callback); | 67 }).catch(error_callback); |
68 } | 68 } |
69 } | 69 } |
70 perform_db1_actions_part1(); | 70 perform_db1_actions_part1(); |
71 perform_db2_actions_part1(); | 71 perform_db2_actions_part1(); |
72 } | 72 } |
73 | 73 |
| 74 function increment_key_actions(db_name, num_iters, key) { |
| 75 var open_request = indexedDB.open(db_name); |
| 76 open_request.onsuccess = function() { |
| 77 var db = open_request.result; |
| 78 |
| 79 var increment_number = function(old_value, num_left) { |
| 80 if (num_left == 0) return; |
| 81 var txn = db.transaction(['store'], 'readwrite'); |
| 82 var os = txn.objectStore('store'); |
| 83 var new_value = old_value + 1; |
| 84 os.put(new_value, key); |
| 85 txn.oncomplete = function() { |
| 86 increment_number(new_value, num_left - 1); |
| 87 }; |
| 88 }; |
| 89 increment_number(0, num_iters); |
| 90 }; |
| 91 }; |
| 92 |
74 if (isWorker && location.hash != "") { | 93 if (isWorker && location.hash != "") { |
75 var hash = location.hash.split("#")[1]; | 94 var hash = location.hash.split("#")[1]; |
76 var names = JSON.parse(decodeURIComponent(hash)); | 95 var names = JSON.parse(decodeURIComponent(hash)); |
77 | 96 |
78 var errorCallback = function(event) { | 97 var errorCallback = function(event) { |
79 console.log('Error in actions: ' + event.target.error.message); | 98 console.log('Error in actions: ' + event.target.error.message); |
80 } | 99 } |
81 | 100 if (names.incrementing_actions) { |
82 indexeddb_observers_actions(names.db1_name, names.db2_name, errorCallback); | 101 increment_key_actions(names.db_name, names.num_iters, names.key); |
| 102 } else { |
| 103 indexeddb_observers_actions(names.db1_name, names.db2_name, errorCallback); |
| 104 } |
83 } | 105 } |
OLD | NEW |