chromium/third_party/blink/web_tests/fast/js/pic/cached-getter-dictionary-and-proto.html

<p>
This page tests cached access to properties of dictionary objects and objects
with changing prototypes. If the test passes, you'll see a series of PASS messages
below.
</p>

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

<script>
(function() {
    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(a, aDescription, b)
    {
        if (a === b) {
            log("PASS: " + aDescription + " should be " + b + " and is.\n");
        } else {
            log("FAIL: " + aDescription + " should be " + b + " but instead is " + a + ".\n");
        }
    }
    
    (function() {
        function getX(o)
        {
            return o.x;
        }
        
        var o = {
            x: 0,
            y: 0
        };

        getX(o);
        getX(o);
        
        for (var i = 0; i < 128; ++i)
            o["p" + i] = 1;
        
        shouldBe(getX(o), "getX(o)", 0);
    })();

    (function() {
        function getProtoX(o)
        {
            return o.protoX;
        }

        var o = {
            __proto__ : {
                protoX: 0,
                protoY: 0
            },
        };

        getProtoX(o);
        getProtoX(o);
        
        o.__proto__ = {
            protoY: 1,
            protoX: 2
        };

        shouldBe(getProtoX(o), "getProtoX(o)", 2);
    })();

    (function() {
        function getProtoX(o)
        {
            return o.protoX;
        }

        var o = {
            __proto__ : {
                protoX: 0,
                protoY: 0
            },
        };

        getProtoX(o);
        getProtoX(o);
        
        delete o.__proto__.protoX;

        shouldBe(getProtoX(o), "getProtoX(o)", undefined);
    })();
})();
</script>