Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 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 | try { |
| 46 | eval(code1); |
| 47 | assertUnreachable("did not throw exception"); |
| 48 | } catch (e) { |
| 49 | assertInstanceof(e, SyntaxError); |
| 50 | } |
| 51 | |
| 52 | function strict2() { |
| 53 | try { |
| 54 | eval(code2); |
| 55 | assertUnreachable("did not throw exception"); |
| 56 | } catch (e) { |
| 57 | assertInstanceof(e, SyntaxError); |
| 58 | } |
| 59 | |
| 60 | function strict3() { |
| 61 | try { |
| 62 | eval(code3); |
| 63 | assertUnreachable("did not throw exception"); |
| 64 | } catch (e) { |
| 65 | assertInstanceof(e, SyntaxError); |
| 66 | } |
| 67 | |
| 68 | function strict4() { |
| 69 | try { |
| 70 | eval(code4); |
| 71 | assertUnreachable("did not throw exception"); |
| 72 | } catch (e) { |
| 73 | assertInstanceof(e, SyntaxError); |
| 74 | } |
| 75 | } |
| 76 | strict4(); |
| 77 | } |
| 78 | strict3(); |
| 79 | } |
| 80 | strict2(); |
| 81 | } |
| 82 | strict1(); |