15a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org// Copyright 2008 the V8 project authors. All rights reserved.
25a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org// Redistribution and use in source and binary forms, with or without
35a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org// modification, are permitted provided that the following conditions are
45a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org// met:
55a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org//
65a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org//     * Redistributions of source code must retain the above copyright
75a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org//       notice, this list of conditions and the following disclaimer.
85a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org//     * Redistributions in binary form must reproduce the above
95a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org//       copyright notice, this list of conditions and the following
105a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org//       disclaimer in the documentation and/or other materials provided
115a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org//       with the distribution.
125a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org//     * Neither the name of Google Inc. nor the names of its
135a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org//       contributors may be used to endorse or promote products derived
145a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org//       from this software without specific prior written permission.
155a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org//
165a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
175a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
185a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
195a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
205a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
215a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
225a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
235a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
245a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
255a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
265a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
275a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org
285a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.orgassertEquals("[object global]", this.toString());
29d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.orgassertEquals("[object Undefined]", toString());
305a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org
315a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.orgassertEquals("[object global]", eval("this.toString()"));
32d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.orgassertEquals("[object Undefined]", eval("toString()"));
335a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org
345a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.orgassertEquals("[object global]", eval("var f; this.toString()"));
35d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.orgassertEquals("[object Undefined]", eval("var f; toString()"));
365a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org
375a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org
385a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.orgfunction F(f) {
395a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org  assertEquals("[object global]", this.toString());
40d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org  assertEquals("[object Undefined]", toString());
415a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org
425a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org  assertEquals("[object global]", eval("this.toString()"));
43d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org  assertEquals("[object Undefined]", eval("toString()"));
445a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org
455a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org  assertEquals("[object global]", eval("var f; this.toString()"));
46d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org  assertEquals("[object Undefined]", eval("var f; toString()"));
475a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org
48d2be901879306d8ff27e78e37783028d581d46fcricow@chromium.org  assertEquals("[object Undefined]", eval("f()"));
495a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org
505a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org  // Receiver should be the arguments object here.
51c4c927273ae2b690c4a015b4640a2a469c9a1a69ager@chromium.org  assertEquals("[object Arguments]", eval("arguments[0]()"));
529fe21c6d4c657d15af27c8751257d3e2bf113e45kasperl@chromium.org  with (arguments) {
53c4c927273ae2b690c4a015b4640a2a469c9a1a69ager@chromium.org    assertEquals("[object Arguments]", toString());
549fe21c6d4c657d15af27c8751257d3e2bf113e45kasperl@chromium.org  }
555a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org}
565a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.org
575a8ca6c70c6fc9716f18f6223c98d1fef5752cf6kasperl@chromium.orgF(Object.prototype.toString);
58