File: IndexedDBStructuredCloneBackwardCompatibilityRead.html

package info (click to toggle)
webkit2gtk 2.18.6-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 159,080 kB
  • sloc: cpp: 1,636,147; ansic: 45,350; python: 14,988; perl: 13,794; ruby: 9,803; xml: 9,342; asm: 5,312; yacc: 2,167; lex: 1,007; sh: 773; makefile: 61
file content (99 lines) | stat: -rw-r--r-- 2,788 bytes parent folder | download | duplicates (2)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<script>
    function log(msg)
    {
//        alert(msg);
        window.webkit.messageHandlers.testHandler.postMessage(msg);
    }

    function shouldBeType(_a, _type)
    {
        var exception;
        var _av;
        try {
            _av = eval(_a);
        } catch (e) {
            exception = e;
        }

        var _typev = eval(_type);
        if (_av instanceof _typev) {
            return true;
        } else {
            return false;
        }
    }

    // Values that are used to infer the type of a given primitive type.
    var testValues = [
        undefined,
        null,
        5, // Int
        0,
        1,
        false,
        true,
        5.5, // Double
        "Hello,World!",
        ""
    ];

    // Values that are used to infer the type of a given Boolean/String type.
    var testTypeValues = [
        { item: new Boolean(true), type: "Boolean", value: true },
        { item: new Boolean(false), type: "Boolean", value: false },
        { item: new String(), type: "String", value: "" }
    ];

    var openRequest = indexedDB.open("backward_compatibility");
    openRequest.onerror = function(event) {
        log("Error: " + event.target.error.name);
    }
    openRequest.onsuccess = function(event) {
        db = event.target.result;
        readType();
    }

    var result = true;
    function readType()
    {
        var objectStore = db.transaction("type").objectStore("type");
        objectStore.openCursor().onsuccess = function(event) {
            cursor = event.target.result;
            if (cursor) {
                result = result && shouldBeType("cursor.value", cursor.key);
                cursor.continue();
            } else
                readValue();
        };
    }

    function readValue()
    {
        var objectStore = db.transaction("value").objectStore("value");
        objectStore.openCursor().onsuccess = function(event) {
            cursor = event.target.result;
            if (cursor) {
                result = result && (cursor.value === testValues[cursor.key - 1]);
                cursor.continue();
            } else
                readTypeValue();
        };
    }

    function readTypeValue()
    {
        var objectStore = db.transaction("typeValue").objectStore("typeValue");
        objectStore.openCursor().onsuccess = function(event) {
            cursor = event.target.result;
            if (cursor) {
                result = result && shouldBeType("cursor.value", testTypeValues[cursor.key - 1].type) && (cursor.value == testTypeValues[cursor.key - 1].value);
                cursor.continue();
            } else {
                if (result)
                    log("Pass");
                else
                    log("Fail");
            }
        };
    }
</script>