summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webstorage/defineProperty.window.js
blob: d8ab163df68332af6236c25335bb41e5c04fe33c (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
["localStorage", "sessionStorage"].forEach(function(name) {
    [9, "x"].forEach(function(key) {
        test(function() {
            var desc = {
                value: "value",
            };

            var storage = window[name];
            storage.clear();

            assert_equals(storage[key], undefined);
            assert_equals(storage.getItem(key), null);
            assert_equals(Object.defineProperty(storage, key, desc), storage);
            assert_equals(storage[key], "value");
            assert_equals(storage.getItem(key), "value");
        }, "Defining data property for key " + key + " on " + name);

        test(function() {
            var desc1 = {
                value: "value",
            };
            var desc2 = {
                value: "new value",
            };

            var storage = window[name];
            storage.clear();

            assert_equals(storage[key], undefined);
            assert_equals(storage.getItem(key), null);
            assert_equals(Object.defineProperty(storage, key, desc1), storage);
            assert_equals(storage[key], "value");
            assert_equals(storage.getItem(key), "value");

            assert_equals(Object.defineProperty(storage, key, desc2), storage);
            assert_equals(storage[key], "new value");
            assert_equals(storage.getItem(key), "new value");
        }, "Defining data property for key " + key + " on " + name + " twice");

        test(function() {
            var desc = {
                value: {
                    toString: function() { return "value"; }
                },
            };

            var storage = window[name];
            storage.clear();

            assert_equals(storage[key], undefined);
            assert_equals(storage.getItem(key), null);
            assert_equals(Object.defineProperty(storage, key, desc), storage);
            assert_equals(storage[key], "value");
            assert_equals(storage.getItem(key), "value");
        }, "Defining data property with toString for key " + key + " on " + name);
    });
});