1 // Copyright 2011 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 "use strict"; 29 30 var code1 = "function f(eval) {}"; 31 var code2 = "function f(a, a) {}"; 32 var code3 = "var x = '\\020;'"; 33 var code4 = "function arguments() {}"; 34 35 // Verify the code compiles just fine in non-strict mode 36 // (using aliased eval to force non-strict mode) 37 var eval_alias = eval; 38 39 eval_alias(code1); 40 eval_alias(code2); 41 eval_alias(code3); 42 eval_alias(code4); 43 44 function strict1() { 45 var exception = false; 46 try { 47 eval(code1); 48 } catch (e) { 49 exception = true; 50 assertInstanceof(e, SyntaxError); 51 } 52 assertTrue(exception); 53 54 function strict2() { 55 var exception = false; 56 try { 57 eval(code2); 58 } catch (e) { 59 exception = true; 60 assertInstanceof(e, SyntaxError); 61 } 62 assertTrue(exception); 63 64 function strict3() { 65 var exception = false; 66 try { 67 eval(code3); 68 } catch (e) { 69 exception = true; 70 assertInstanceof(e, SyntaxError); 71 } 72 assertTrue(exception); 73 74 function strict4() { 75 var exception = false; 76 try { 77 eval(code4); 78 } catch (e) { 79 exception = true; 80 assertInstanceof(e, SyntaxError); 81 } 82 assertTrue(exception); 83 } 84 strict4(); 85 } 86 strict3(); 87 } 88 strict2(); 89 } 90 strict1(); 91