chromium/third_party/blink/web_tests/fast/js/pic/undictionary.html

<p>
This page tests for a caching error when transitioning prototypes away from being dictionaries.
If the test passes, you'll see a series of PASS messages below.
</p>

<pre id="console"></pre>

<script>
if (window.testRunner)
    testRunner.dumpAsText();

function log(s)
{
    if (this.document)
        document.getElementById("console").appendChild(document.createTextNode(s + "\n"));
    else
        print(s + "\n");
}

function shouldBe(aDescription, a, b)
{
    if (a === b) {
        log("PASS: " + aDescription + " should be " + b + " and is.");
    } else {
        log("FAIL: " + aDescription + " should be " + b + " but instead is " + a + ".");
    }
}

// Prototype tests
(function () {
    function getB(o)
    {
        return o.b;
    }

    var o = {
        __proto__ : {
            a: "a",
            b: "b"
        }
    };

    delete o.__proto__.a;
    o.__proto__.c = "c"; // if o.__proto__ un-dictionaries itself, .c will overwrite the deleted .b slot.
    for (var i = 0; i < 3; ++i)
        shouldBe("getB(o)", getB(o), "b");
        
    var o2 = {
        __proto__ : {
            a2: "a2",
            b: "b"
        }
    };

    delete o2.__proto__.a2;
    o2.__proto__.c2 = "c2"; // if o2.__proto__ un-dictionaries itself, .c2 will overwrite the deleted .b slot.
    for (var i = 0; i < 3; ++i)
        shouldBe("getB(o2)", getB(o2), "b");
})();

// Prototype chain tests
(function () {
    function getB(o)
    {
        return o.b;
    }

    var o = {
        __proto__ : {
            __proto__ : {
                a: "a",
                b: "b"
            }
        }
    };

    delete o.__proto__.__proto__.a;
    o.__proto__.__proto__.c = "c"; // if o.__proto__.__proto__ un-dictionaries itself, .c will overwrite the deleted .b slot.
    for (var i = 0; i < 3; ++i)
        shouldBe("getB(o)", getB(o), "b");

    var o2 = {
        __proto__ : {
            __proto__ : {
                a2: "a",
                b: "b"
            }
        }
    };

    delete o2.__proto__.__proto__.a2;
    o2.__proto__.__proto__.c = "c"; // if o2.__proto__.__proto__ un-dictionaries itself, .c will overwrite the deleted .b slot.
    for (var i = 0; i < 3; ++i)
        shouldBe("getB(o2)", getB(o2), "b");
})();
</script>