summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/IndexedDB/idbworker.js
blob: 359f6fb69119b5c6605047f0e0c38ef6fe847009 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var db

self.addEventListener('message', MessageHandler, false)

function MessageHandler(e)
{
    var open_rq, idb = self.indexedDB || self.msIndexedDB || self.webkitIndexedDB || self.mozIndexedDB

    if (!idb)
    {
        self.postMessage(false)
        return
    }
    else
        self.postMessage(true)

    open_rq = idb.open("webworker101", 1)

    open_rq.onupgradeneeded = function(e) {
        db = e.target.result
        db.createObjectStore("store")
          .add("test", 1)
    }
    open_rq.onsuccess = function(e) {
        db = e.target.result
        db.onerror = function() { self.postMessage("db.error") }
        db.transaction("store").objectStore("store").get(1).onsuccess = function(e) {
            self.postMessage(e.target.result)
            db.close()
        }
    }
    open_rq.onerror = function() { self.postMessage("open.error") }
    open_rq.onblocked = function() { self.postMessage("open.blocked") }
}