19258b6bc66e09368ada54001f619d53b4fc976d5ager@chromium.org// Copyright 2008 the V8 project authors. All rights reserved. 29a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// Redistribution and use in source and binary forms, with or without 39a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// modification, are permitted provided that the following conditions are 49a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// met: 59a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// 69a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// * Redistributions of source code must retain the above copyright 79a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// notice, this list of conditions and the following disclaimer. 89a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// * Redistributions in binary form must reproduce the above 99a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// copyright notice, this list of conditions and the following 109a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// disclaimer in the documentation and/or other materials provided 119a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// with the distribution. 129a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// * Neither the name of Google Inc. nor the names of its 139a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// contributors may be used to endorse or promote products derived 149a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// from this software without specific prior written permission. 159a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// 169a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 179a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 189a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 199a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 209a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 219a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 229a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 239a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 249a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 259a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 269a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 279a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 289a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// Test that the inline caches correctly detect that constant 299a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// functions on value prototypes change. 309a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 319a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comfunction testString() { 329a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com function f(s, expected) { 339a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com var result = s.toString(); 349a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com assertEquals(expected, result); 359a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com }; 369a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 379a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com for (var i = 0; i < 10; i++) { 389a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com var s = String.fromCharCode(i); 399a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com f(s, s); 409a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com } 419a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 429a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com String.prototype.toString = function() { return "ostehaps"; }; 439a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 449a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com for (var i = 0; i < 10; i++) { 459a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com var s = String.fromCharCode(i); 469a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com f(s, "ostehaps"); 479a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com } 489a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com} 499a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 509a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comtestString(); 519a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 529a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 539a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comfunction testNumber() { 549a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com Number.prototype.toString = function() { return 0; }; 559a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 569a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com function f(n, expected) { 579a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com var result = n.toString(); 589a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com assertEquals(expected, result); 599a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com }; 609a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 619a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com for (var i = 0; i < 10; i++) { 629a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com f(i, 0); 639a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com } 649a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 659a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com Number.prototype.toString = function() { return 42; }; 669a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 679a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com for (var i = 0; i < 10; i++) { 689a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com f(i, 42); 699a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com } 709a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com} 719a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 729a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comtestNumber(); 739a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 749a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 759a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comfunction testBoolean() { 769a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com Boolean.prototype.toString = function() { return 0; }; 779a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 789a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com function f(b, expected) { 799a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com var result = b.toString(); 809a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com assertEquals(expected, result); 819a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com }; 829a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 839a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com for (var i = 0; i < 10; i++) { 849a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com f((i % 2 == 0), 0); 859a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com } 869a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 879a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com Boolean.prototype.toString = function() { return 42; }; 889a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 899a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com for (var i = 0; i < 10; i++) { 909a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com f((i % 2 == 0), 42); 919a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com } 929a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com} 939a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 949a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comtestBoolean(); 95