Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: third_party/WebKit/LayoutTests/storage/indexeddb/resources/promise-idb.js

Issue 2449563002: [IndexedDB] Add Observer Tests (Closed)
Patch Set: Fixed errors in other tests, and marked observer tests as long Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Quick and dirty promise wrapper of IDB.
2
3 var pdb = {
4 _transformRequestToPromise: function(thisobj, func, argArray) {
5 return new Promise(function(resolve, reject) {
6 var request = func.apply(thisobj, argArray);
7 request.onsuccess = function() {
8 resolve(request.result);
9 };
10 request.onerror = reject;
11 })
12 },
13
14 transact: function(db, objectStores, style) {
15 return Promise.resolve(db.transaction(objectStores, style));
16 },
17
18 openCursor: function(txn, indexOrObjectStore, keyrange, callback) {
19 return new Promise(function(resolve, reject) {
20 var request = indexOrObjectStore.openCursor(keyrange);
21 request.onerror = reject;
22 request.onsuccess = function() {
23 var cursor = request.result;
24 var cont = false;
25 var control = {
26 continue: function() {cont = true;}
27 };
28 if (cursor) {
29 callback(control, cursor.value);
30 if (cont) {
31 cursor.continue();
32 } else {
33 resolve(txn);
34 }
35 } else {
36 resolve(txn);
37 }
38 };
39 });
40 },
41
42 get: function(indexOrObjectStore, key) {
43 return this._transformRequestToPromise(indexOrObjectStore, indexOrObjectStor e.get, [key]);
44 },
45
46 count: function(indexOrObjectStore, key) {
47 return this._transformRequestToPromise(indexOrObjectStore, indexOrObjectStor e.count, [key]);
48 },
49
50 put: function(objectStore, key, value) {
51 return this._transformRequestToPromise(objectStore, objectStore.put, [key, v alue]);
52 },
53
54 add: function(objectStore, key, value) {
55 return this._transformRequestToPromise(objectStore, objectStore.add, [key, v alue]);
56 },
57
58 delete: function(objectStore, key) {
59 return this._transformRequestToPromise(objectStore, objectStore.delete, [key ]);
60 },
61
62 clear: function(objectStore) {
63 return this._transformRequestToPromise(objectStore, objectStore.clear, []);
64 },
65
66 getKey: function(index, key) {
67 return this._transformRequestToPromise(index, index.getKey, [key]);
68 },
69
70 waitForTransaction: function(txn) {
71 return new Promise(function(resolve, reject) {
72 txn.oncomplete = resolve;
73 txn.onerror = reject;
74 txn.onabort = reject;
75 });
76 }
77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698