Home | History | Annotate | Download | only in regress
      1 // Copyright 2013 the V8 project authors. All rights reserved.
      2 // Redistribution and use in source and binary forms, with or without
      3 // modification, are permitted provided that the following conditions are
      4 // met:
      5 //
      6 //     * Redistributions of source code must retain the above copyright
      7 //       notice, this list of conditions and the following disclaimer.
      8 //     * Redistributions in binary form must reproduce the above
      9 //       copyright notice, this list of conditions and the following
     10 //       disclaimer in the documentation and/or other materials provided
     11 //       with the distribution.
     12 //     * Neither the name of Google Inc. nor the names of its
     13 //       contributors may be used to endorse or promote products derived
     14 //       from this software without specific prior written permission.
     15 //
     16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 
     28 var CheckStringReceiver = function() {
     29   "use strict";
     30   // Receivers of strict functions are not coerced.
     31   assertEquals("string", typeof this);
     32 };
     33 
     34 var CheckNumberReceiver = function() {
     35   "use strict";
     36   // Receivers of strict functions are not coerced.
     37   assertEquals("number", typeof this);
     38 };
     39 
     40 var CheckUndefinedReceiver = function() {
     41   "use strict";
     42   // Receivers of strict functions are not coerced.
     43   assertEquals("undefined", String(this));
     44 };
     45 
     46 var CheckNullReceiver = function() {
     47   "use strict";
     48   // Receivers of strict functions are not coerced.
     49   assertEquals("null", String(this));
     50 };
     51 
     52 var CheckCoersion = function() {
     53   // Receivers of non-strict functions are coerced to objects.
     54   assertEquals("object", typeof this);
     55 };
     56 
     57 
     58 function strict_mode() {
     59   "use strict";
     60   CheckStringReceiver.call("foo");
     61   CheckNumberReceiver.call(42);
     62   CheckUndefinedReceiver.call(undefined);
     63   CheckNullReceiver.call(null);
     64   [1].forEach(CheckStringReceiver, "foo");
     65   [2].every(CheckStringReceiver, "foo");
     66   [3].filter(CheckStringReceiver, "foo");
     67   [4].some(CheckNumberReceiver, 42);
     68   [5].map(CheckNumberReceiver, 42);
     69 
     70   CheckCoersion.call("foo");
     71   CheckCoersion.call(42);
     72   CheckCoersion.call(undefined);
     73   CheckCoersion.call(null);
     74   [1].forEach(CheckCoersion, "foo");
     75   [2].every(CheckCoersion, "foo");
     76   [3].filter(CheckCoersion, "foo");
     77   [4].some(CheckCoersion, 42);
     78   [5].map(CheckCoersion, 42);
     79 };
     80 strict_mode();
     81 
     82 function sloppy_mode() {
     83   CheckStringReceiver.call("foo");
     84   CheckNumberReceiver.call(42);
     85   CheckUndefinedReceiver.call(undefined);
     86   CheckNullReceiver.call(null);
     87   [1].forEach(CheckStringReceiver, "foo");
     88   [2].every(CheckStringReceiver, "foo");
     89   [3].filter(CheckStringReceiver, "foo");
     90   [4].some(CheckNumberReceiver, 42);
     91   [5].map(CheckNumberReceiver, 42);
     92 
     93   CheckCoersion.call("foo");
     94   CheckCoersion.call(42);
     95   CheckCoersion.call(undefined);
     96   CheckCoersion.call(null);
     97   [1].forEach(CheckCoersion, "foo");
     98   [2].every(CheckCoersion, "foo");
     99   [3].filter(CheckCoersion, "foo");
    100   [4].some(CheckCoersion, 42);
    101   [5].map(CheckCoersion, 42);
    102 };
    103 sloppy_mode();
    104