Home | History | Annotate | Download | only in regress
      1 // Copyright 2012 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 // Test that global eval calls of strict code (independent from whether being
     29 // direct or indirect) have their own lexical and variable environment.
     30 
     31 "use strict";
     32 var evil = eval;
     33 
     34 // Test global direct strict eval in strict script.
     35 // Expects new environment.
     36 var no_touch = 0;
     37 eval('"use strict"; var no_touch = 1;');
     38 assertSame(0, no_touch);
     39 
     40 // Test global indirect strict eval in strict script.
     41 // Expects new environment.
     42 var no_touch = 0;
     43 evil('"use strict"; var no_touch = 2;');
     44 assertSame(0, no_touch);
     45 
     46 // Test global direct non-strict eval in strict script.
     47 // Expects new environment.
     48 var no_touch = 0;
     49 eval('var no_touch = 3;');
     50 assertSame(0, no_touch);
     51 
     52 // Test global indirect non-strict eval in strict script.
     53 // Expects global environment.
     54 var no_touch = 0;
     55 evil('var no_touch = 4;');
     56 assertSame(4, no_touch);
     57 
     58 // Test non-global direct strict eval in strict script.
     59 // Expects new environment.
     60 var no_touch = 0;
     61 (function() {
     62   var no_touch = 0;
     63   eval('"use strict"; var no_touch = 5;');
     64   assertSame(0, no_touch);
     65 })()
     66 assertSame(0, no_touch);
     67 
     68 // Test non-global indirect strict eval in strict script.
     69 // Expects new environment.
     70 var no_touch = 0;
     71 (function() {
     72   var no_touch = 0;
     73   evil('"use strict"; var no_touch = 6;');
     74   assertSame(0, no_touch);
     75 })()
     76 assertSame(0, no_touch);
     77 
     78 // Test non-global direct non-strict eval in strict script.
     79 // Expects new environment.
     80 var no_touch = 0;
     81 (function() {
     82   var no_touch = 0;
     83   eval('var no_touch = 7;');
     84   assertSame(0, no_touch);
     85 })()
     86 assertSame(0, no_touch);
     87 
     88 // Test non-global indirect non-strict eval in strict script.
     89 // Expects global environment.
     90 var no_touch = 0;
     91 (function() {
     92   var no_touch = 0;
     93   evil('var no_touch = 8;');
     94   assertSame(0, no_touch);
     95 })()
     96 assertSame(8, no_touch);
     97 
     98 // Test non-global direct strict eval in strict script.
     99 // Expects new environment.
    100 var no_touch = 0;
    101 (function() {
    102   "use strict";
    103   var no_touch = 0;
    104   eval('"use strict"; var no_touch = 9;');
    105   assertSame(0, no_touch);
    106 })()
    107 assertSame(0, no_touch);
    108 
    109 // Test non-global indirect strict eval in strict script.
    110 // Expects new environment.
    111 var no_touch = 0;
    112 (function() {
    113   "use strict";
    114   var no_touch = 0;
    115   evil('"use strict"; var no_touch = 10;');
    116   assertSame(0, no_touch);
    117 })()
    118 assertSame(0, no_touch);
    119 
    120 // Test non-global direct non-strict eval in strict script.
    121 // Expects new environment.
    122 var no_touch = 0;
    123 (function() {
    124   "use strict";
    125   var no_touch = 0;
    126   eval('var no_touch = 11;');
    127   assertSame(0, no_touch);
    128 })()
    129 assertSame(0, no_touch);
    130 
    131 // Test non-global indirect non-strict eval in strict script.
    132 // Expects global environment.
    133 var no_touch = 0;
    134 (function() {
    135   "use strict";
    136   var no_touch = 0;
    137   evil('var no_touch = 12;');
    138   assertSame(0, no_touch);
    139 })()
    140 assertSame(12, no_touch);
    141