13fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// Copyright 2011 the V8 project authors. All rights reserved. 23fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// Redistribution and use in source and binary forms, with or without 33fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// modification, are permitted provided that the following conditions are 43fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// met: 53fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// 63fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// * Redistributions of source code must retain the above copyright 73fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// notice, this list of conditions and the following disclaimer. 83fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// * Redistributions in binary form must reproduce the above 93fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// copyright notice, this list of conditions and the following 103fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// disclaimer in the documentation and/or other materials provided 113fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// with the distribution. 123fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// * Neither the name of Google Inc. nor the names of its 133fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// contributors may be used to endorse or promote products derived 143fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// from this software without specific prior written permission. 153fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// 163fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 173fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 183fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 193fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 203fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 213fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 223fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 233fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 243fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 253fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 263fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 273fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch 283fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// See: http://code.google.com/p/v8/issues/detail?id=1365 293fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch 303fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// Check that builtin methods are passed undefined as the receiver 313fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// when called as functions through variables. 323fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch 333fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// Flags: --allow-natives-syntax 343fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch 353fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// Global variable. 363fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdochvar valueOf = Object.prototype.valueOf; 373fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdochvar hasOwnProperty = Object.prototype.hasOwnProperty; 383fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch 393fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdochfunction callGlobalValueOf() { valueOf(); } 403fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdochfunction callGlobalHasOwnProperty() { valueOf(); } 413fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch 423fb3ca8c7ca439d408449a395897395c0faae8d1Ben MurdochassertEquals(Object.prototype, Object.prototype.valueOf()); 433fb3ca8c7ca439d408449a395897395c0faae8d1Ben MurdochassertThrows(callGlobalValueOf); 443fb3ca8c7ca439d408449a395897395c0faae8d1Ben MurdochassertThrows(callGlobalHasOwnProperty); 453fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch 463fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch%OptimizeFunctionOnNextCall(Object.prototype.valueOf); 473fb3ca8c7ca439d408449a395897395c0faae8d1Ben MurdochObject.prototype.valueOf(); 483fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch 493fb3ca8c7ca439d408449a395897395c0faae8d1Ben MurdochassertEquals(Object.prototype, Object.prototype.valueOf()); 503fb3ca8c7ca439d408449a395897395c0faae8d1Ben MurdochassertThrows(callGlobalValueOf); 513fb3ca8c7ca439d408449a395897395c0faae8d1Ben MurdochassertThrows(callGlobalHasOwnProperty); 523fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch 533fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdochfunction CheckExceptionCallLocal() { 543fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch var valueOf = Object.prototype.valueOf; 553fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch var hasOwnProperty = Object.prototype.hasOwnProperty; 563fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch var exception = false; 573fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch try { valueOf(); } catch(e) { exception = true; } 583fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch assertTrue(exception); 593fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch exception = false; 603fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch try { hasOwnProperty(); } catch(e) { exception = true; } 613fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch assertTrue(exception); 623fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch} 633fb3ca8c7ca439d408449a395897395c0faae8d1Ben MurdochCheckExceptionCallLocal(); 643fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch 653fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdochfunction CheckExceptionCallParameter(f) { 663fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch var exception = false; 673fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch try { f(); } catch(e) { exception = true; } 683fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch assertTrue(exception); 693fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch} 703fb3ca8c7ca439d408449a395897395c0faae8d1Ben MurdochCheckExceptionCallParameter(Object.prototype.valueOf); 713fb3ca8c7ca439d408449a395897395c0faae8d1Ben MurdochCheckExceptionCallParameter(Object.prototype.hasOwnProperty); 723fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch 733fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdochfunction CheckPotentiallyShadowedByEval() { 743fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch var exception = false; 753fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch try { 763fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch eval("hasOwnProperty('x')"); 773fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch } catch(e) { 783fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch exception = true; 793fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch } 803fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch assertTrue(exception); 813fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch} 823fb3ca8c7ca439d408449a395897395c0faae8d1Ben MurdochCheckPotentiallyShadowedByEval(); 83