The recursive tail call optimisation is wrong on closures
[WebKit-https.git] / PerformanceTests / IndexedDB / objectstore-cursor.html
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../resources/runner.js"></script>
5 <script>
6
7 var iterationCount = 10;
8 var numberDeleted = 0;
9 // Delete all databases for the test ahead of time.
10 var databaseName = "objectstore-cursor-DB";
11 indexedDB.deleteDatabase(databaseName).onsuccess = function() {
12     startIteration();
13 }
14
15 var testGenerator = null;
16 var db = null;
17 var currentIteration = 0;
18
19 PerfTestRunner.prepareToMeasureValuesAsync({
20     customIterationCount: iterationCount,
21     unit: 'ms',
22     done: function () {
23         db = null;
24         testGenerator = null;
25         PerfTestRunner.gc();
26         ++currentIteration;
27     }
28 });
29
30 function startIteration()
31 {
32     testGenerator = runIteration();
33     nextStep();
34 }
35
36 function nextStep()
37 {
38     testGenerator.next();
39 }
40
41 function *runIteration()
42 {
43     var openRequest = indexedDB.open(databaseName);
44     openRequest.onupgradeneeded = function(event) {
45         db = event.target.result;
46         var objectStore = db.createObjectStore('store');
47         for (var i = 0; i < 25000; ++i) {
48             var suffix = ("0000000" + i).slice(-7);
49             objectStore.put("bar_value_" + suffix, "foo_key_" + suffix);
50         }
51     }
52     openRequest.onsuccess = nextStep;
53
54     yield;
55
56     var startTime = PerfTestRunner.now();
57     var cursorRequest = db.transaction('store').objectStore('store').openCursor();
58     var cursorIteration = 0;
59     cursorRequest.onsuccess = function(event) {
60         var cursor = event.target.result;
61         if (cursor) {
62             var suffix = ("0000000" + cursorIteration).slice(-7);
63             if (cursor.key != "foo_key_" + suffix)
64                 alert("Incorrect value retrieved: " + cursor.key);
65             if (cursor.value != "bar_value_" + suffix)
66                 alert("Incorrect value retrieved: " + cursor.key);
67             ++cursorIteration;
68             cursor.continue();
69         } else
70             nextStep();
71     };
72
73     yield;
74
75     if (!PerfTestRunner.measureValueAsync(PerfTestRunner.now() - startTime))
76         return;
77
78     setTimeout(startIteration, 0);
79 }
80 </script>
81 </body>
82 </html>