The recursive tail call optimisation is wrong on closures
[WebKit-https.git] / PerformanceTests / IndexedDB / index-multientry.html
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../resources/runner.js"></script>
5 <script>
6
7 var iterationCount = 20;
8 var numberDeleted = 0;
9
10 // Delete all databases for the test ahead of time.
11 var databaseNamePrefix = "index-multientry-DB-";
12 for (var i = 0; i < iterationCount + 1; ++i) {
13     req = indexedDB.deleteDatabase(databaseNamePrefix + i);
14     req.onsuccess = function() {
15         if (++numberDeleted == iterationCount)
16             startIteration();
17     }
18 }
19
20 var testGenerator = null;
21 var db = null;
22 var transaction = null;
23 var currentIteration = 0;
24
25 PerfTestRunner.prepareToMeasureValuesAsync({
26     customIterationCount: iterationCount,
27     unit: 'ms',
28     done: function () {
29         transaction = null;
30         db = null;
31         testGenerator = null;
32         PerfTestRunner.gc();
33         ++currentIteration;
34     }
35 });
36
37 function startIteration()
38 {
39     testGenerator = runIteration();
40     nextStep();
41 }
42
43 function nextStep()
44 {
45     testGenerator.next();
46 }
47
48 var object = { test: 'yo', indexKeys: [] };
49 for (var i = 0; i < 5000; i++)
50     object.indexKeys.push('index_no_' + i);
51
52 function *runIteration()
53 {
54     var startTime = PerfTestRunner.now();
55
56     var openRequest = indexedDB.open(databaseNamePrefix + currentIteration);
57     openRequest.onupgradeneeded = function(event) {
58         db = event.target.result;
59         db.createObjectStore('store').createIndex('index', 'indexKeys', { multiEntry: true });
60     }
61     openRequest.onsuccess = nextStep;
62
63     yield;
64
65     transaction = db.transaction('store', 'readwrite');
66     transaction.objectStore('store').put(object, 1);
67     transaction.oncomplete = nextStep;
68
69     yield;
70
71     var index = db.transaction('store').objectStore('store').index('index');
72
73     var completedGets = 0;
74     for (var i = 0; i < 1000; i++)
75     {
76         index.get('index_no_' + i).onsuccess = function (event) {
77             if (event.target.result.test != "yo")
78                 alert("Expected 'yo', got '" + event.target.result.test + "'");
79
80             if (++completedGets == 1000)
81                 nextStep();
82         };
83     }
84
85     yield;
86
87     if (!PerfTestRunner.measureValueAsync(PerfTestRunner.now() - startTime))
88         return;
89
90     setTimeout(startIteration, 0);
91 }
92 </script>
93 </body>
94 </html>