1// Copyright 2013 the V8 project authors. All rights reserved. 2// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3// 4// Redistribution and use in source and binary forms, with or without 5// modification, are permitted provided that the following conditions 6// are met: 7// 1. Redistributions of source code must retain the above copyright 8// notice, this list of conditions and the following disclaimer. 9// 2. Redistributions in binary form must reproduce the above copyright 10// notice, this list of conditions and the following disclaimer in the 11// documentation and/or other materials provided with the distribution. 12// 13// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY 14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY 17// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 24description("Test to ensure that we handle caching of prototype chains containing dictionaries."); 25 26var Test = function(){}; 27 28var methodCount = 65; 29 30for (var i = 0; i < methodCount; i++){ 31 Test.prototype['myMethod' + i] = function(){}; 32} 33 34var test1 = new Test(); 35 36for (var k in test1); 37 38Test.prototype.myAdditionalMethod = function(){}; 39var test2 = new Test(); 40var j = k; 41var foundNewPrototypeProperty = false; 42for (var k in test2){ 43 if ("myAdditionalMethod" == k) foundNewPrototypeProperty = true; 44} 45shouldBeTrue('foundNewPrototypeProperty'); 46 47var Test = function(){}; 48for (var i = 0; i < methodCount; i++){ 49 Test.prototype['myMethod' + i] = function(){}; 50} 51var test1 = new Test(); 52 53for (var k in test1); 54 55delete (Test.prototype)[k] 56var test2 = new Test(); 57var j = k; 58var foundRemovedPrototypeProperty = false; 59for (var k in test2){ 60 if (j == k) foundRemovedPrototypeProperty = true; 61} 62shouldBeFalse("foundRemovedPrototypeProperty"); 63 64var Test = function(){}; 65for (var i = 0; i < methodCount; i++){ 66 Test.prototype['myMethod' + i] = function(){}; 67} 68 69function update(test) { 70 test.newProperty = true; 71} 72var test1 = new Test(); 73update(test1); 74 75var test2 = new Test(); 76update(test2); 77 78var test3 = new Test(); 79update(test3); 80var calledNewPrototypeSetter = false; 81Test.prototype.__defineSetter__("newProperty", function(){ calledNewPrototypeSetter = true; }); 82var test4 = new Test(); 83update(test4); 84shouldBeTrue('calledNewPrototypeSetter'); 85 86var test4 = {__proto__:{prop:"on prototype"}}; 87for (var i = 0; i < 200; i++) 88 test4[i]=[i]; 89 90var test5 = {__proto__:{__proto__:{prop:"on prototype's prototype"}}}; 91for (var i = 0; i < 200; i++) 92 test5[i]=[i]; 93 94getTestProperty = function(o) { 95 return o.prop; 96} 97 98getTestProperty(test4); 99getTestProperty(test4); 100shouldBe("getTestProperty(test4)", '"on prototype"'); 101test4.prop = "on self"; 102shouldBe("getTestProperty(test4)", '"on self"'); 103 104getTestProperty = function(o) { 105 return o.prop; 106} 107 108getTestProperty(test5); 109getTestProperty(test5); 110shouldBe("getTestProperty(test5)", '"on prototype\'s prototype"'); 111test5.prop = "on self"; 112shouldBe("getTestProperty(test5)", '"on self"'); 113