blob: 391daaa37c6fdb996faa8878492c2eea4ed2abc3 [file] [log] [blame]
Steve Block1e0659c2011-05-24 12:43:12 +01001// 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
30var code1 = "function f(eval) {}";
31var code2 = "function f(a, a) {}";
32var code3 = "var x = '\\020;'";
33var code4 = "function arguments() {}";
34
35// Verify the code compiles just fine in non-strict mode
36// (using aliased eval to force non-strict mode)
37var eval_alias = eval;
38
39eval_alias(code1);
40eval_alias(code2);
41eval_alias(code3);
42eval_alias(code4);
43
44function strict1() {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000045 var exception = false;
Steve Block1e0659c2011-05-24 12:43:12 +010046 try {
47 eval(code1);
Steve Block1e0659c2011-05-24 12:43:12 +010048 } catch (e) {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000049 exception = true;
Steve Block1e0659c2011-05-24 12:43:12 +010050 assertInstanceof(e, SyntaxError);
51 }
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000052 assertTrue(exception);
Steve Block1e0659c2011-05-24 12:43:12 +010053
54 function strict2() {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000055 var exception = false;
Steve Block1e0659c2011-05-24 12:43:12 +010056 try {
57 eval(code2);
Steve Block1e0659c2011-05-24 12:43:12 +010058 } catch (e) {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000059 exception = true;
Steve Block1e0659c2011-05-24 12:43:12 +010060 assertInstanceof(e, SyntaxError);
61 }
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000062 assertTrue(exception);
Steve Block1e0659c2011-05-24 12:43:12 +010063
64 function strict3() {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000065 var exception = false;
Steve Block1e0659c2011-05-24 12:43:12 +010066 try {
67 eval(code3);
Steve Block1e0659c2011-05-24 12:43:12 +010068 } catch (e) {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000069 exception = true;
Steve Block1e0659c2011-05-24 12:43:12 +010070 assertInstanceof(e, SyntaxError);
71 }
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000072 assertTrue(exception);
Steve Block1e0659c2011-05-24 12:43:12 +010073
74 function strict4() {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000075 var exception = false;
Steve Block1e0659c2011-05-24 12:43:12 +010076 try {
77 eval(code4);
Steve Block1e0659c2011-05-24 12:43:12 +010078 } catch (e) {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000079 exception = true;
Steve Block1e0659c2011-05-24 12:43:12 +010080 assertInstanceof(e, SyntaxError);
81 }
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000082 assertTrue(exception);
Steve Block1e0659c2011-05-24 12:43:12 +010083 }
84 strict4();
85 }
86 strict3();
87 }
88 strict2();
89}
90strict1();