summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webstorage/storage_indexing.html
blob: 7bce1051437ec8c79cb5cc4716b872b76dda8adb (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
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>WebStorage Test: Storage - indexed getter</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
["localStorage", "sessionStorage"].forEach(function(name) {
    test(function() {
        var storage = window[name];
        storage.clear();
        storage["name"] = "user1";
        storage["age"] = "42";

        test(function() {
            assert_equals(storage[-1], undefined);
            assert_equals(storage[0], undefined);
            assert_equals(storage[1], undefined);
            assert_equals(storage[2], undefined);
        }, "Getting number properties on " + name);

        test(function() {
            assert_equals(storage["-1"], undefined);
            assert_equals(storage["0"], undefined);
            assert_equals(storage["1"], undefined);
            assert_equals(storage["2"], undefined);
        }, "Getting number-valued string properties on " + name);

        test(function() {
            storage.setItem(1, "number");
            assert_equals(storage[1], "number");
            assert_equals(storage["1"], "number");
        }, "Getting existing number-valued properties on " + name);
    }, "Indexed getter on " + name);
});
</script>