1d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// Copyright 2011 the V8 project authors. All rights reserved. 2d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// Redistribution and use in source and binary forms, with or without 3d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// modification, are permitted provided that the following conditions are 4d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// met: 5d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// 6d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// * Redistributions of source code must retain the above copyright 7d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// notice, this list of conditions and the following disclaimer. 8d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// * Redistributions in binary form must reproduce the above 9d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// copyright notice, this list of conditions and the following 10d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// disclaimer in the documentation and/or other materials provided 11d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// with the distribution. 12d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// * Neither the name of Google Inc. nor the names of its 13d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// contributors may be used to endorse or promote products derived 14d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// from this software without specific prior written permission. 15d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// 16d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org 28d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// Test that the apply with arguments optimization passes values 29d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// unchanged to strict-mode functions and builtins. 30d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org 31d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org// Flags: --allow-natives-syntax 32d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org 33d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.orgfunction strict() { "use strict"; return this; } 34d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org 35d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.orgfunction test_strict() { 36d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org assertEquals(void 0, strict.apply(undefined, arguments)); 37d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org assertEquals(42, strict.apply(42, arguments)); 38d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org assertEquals("asdf", strict.apply("asdf", arguments)); 39d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org} 40d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org 41d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.orgfor (var i = 0; i < 10; i++) test_strict(); 42d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org%OptimizeFunctionOnNextCall(test_strict); 43d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.orgtest_strict(); 44d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org 45d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.orgfunction test_builtin(receiver) { 46d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org Object.prototype.valueOf.apply(receiver, arguments); 47d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org} 48d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org 49d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.orgfor (var i = 0; i < 10; i++) test_builtin(this); 50d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org%OptimizeFunctionOnNextCall(test_builtin); 51d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.orgtest_builtin(this); 52d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org 53d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.orgvar exception = false; 54d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.orgtry { 55d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org test_builtin(undefined); 56d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org} catch(e) { 57d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org exception = true; 58d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org} 59d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.orgassertTrue(exception); 60