OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 var y = "\0"; | 159 var y = "\0"; |
160 })(); | 160 })(); |
161 | 161 |
162 // Octal before "use strict" | 162 // Octal before "use strict" |
163 assertThrows('\ | 163 assertThrows('\ |
164 function strict() {\ | 164 function strict() {\ |
165 "octal\\032directive";\ | 165 "octal\\032directive";\ |
166 "use strict";\ | 166 "use strict";\ |
167 }', SyntaxError); | 167 }', SyntaxError); |
168 | 168 |
169 // Duplicate data properties. | |
170 CheckStrictMode("var x = { dupe : 1, nondupe: 3, dupe : 2 };", SyntaxError); | |
171 CheckStrictMode("var x = { '1234' : 1, '2345' : 2, '1234' : 3 };", SyntaxError); | |
172 CheckStrictMode("var x = { '1234' : 1, '2345' : 2, 1234 : 3 };", SyntaxError); | |
173 CheckStrictMode("var x = { 3.14 : 1, 2.71 : 2, 3.14 : 3 };", SyntaxError); | |
174 CheckStrictMode("var x = { 3.14 : 1, '3.14' : 2 };", SyntaxError); | |
175 CheckStrictMode("var x = { \ | |
176 123: 1, \ | |
177 123.00000000000000000000000000000000000000000000000000000000000000000001: 2 \ | |
178 }", SyntaxError); | |
179 | |
180 // Non-conflicting data properties. | 169 // Non-conflicting data properties. |
181 (function StrictModeNonDuplicate() { | 170 (function StrictModeNonDuplicate() { |
182 "use strict"; | 171 "use strict"; |
183 var x = { 123 : 1, "0123" : 2 }; | 172 var x = { 123 : 1, "0123" : 2 }; |
184 var x = { | 173 var x = { |
185 123: 1, | 174 123: 1, |
186 '123.00000000000000000000000000000000000000000000000000000000000000000001': | 175 '123.00000000000000000000000000000000000000000000000000000000000000000001': |
187 2 | 176 2 |
188 }; | 177 }; |
189 })(); | 178 })(); |
190 | 179 |
191 // Two getters (non-strict) | 180 // Duplicate properties are no longer errors in ES6. |
192 assertThrows("var x = { get foo() { }, get foo() { } };", SyntaxError); | 181 (function Duplicates() { |
193 assertThrows("var x = { get foo(){}, get 'foo'(){}};", SyntaxError); | 182 "use strict"; |
194 assertThrows("var x = { get 12(){}, get '12'(){}};", SyntaxError); | |
195 | 183 |
196 // Two setters (non-strict) | 184 ({ dupe : 1, nondupe: 3, dupe : 2 }); |
197 assertThrows("var x = { set foo(v) { }, set foo(v) { } };", SyntaxError); | 185 ({ '1234' : 1, '2345' : 2, '1234' : 3 }); |
198 assertThrows("var x = { set foo(v) { }, set 'foo'(v) { } };", SyntaxError); | 186 ({ '1234' : 1, '2345' : 2, 1234 : 3 }); |
199 assertThrows("var x = { set 13(v) { }, set '13'(v) { } };", SyntaxError); | 187 ({ 3.14 : 1, 2.71 : 2, 3.14 : 3 }); |
| 188 ({ 3.14 : 1, '3.14' : 2 }); |
| 189 ({ |
| 190 123: 1, |
| 191 123.00000000000000000000000000000000000000000000000000000000000000000001: 2 |
| 192 }); |
200 | 193 |
201 // Setter and data (non-strict) | 194 // Two getters |
202 assertThrows("var x = { foo: 'data', set foo(v) { } };", SyntaxError); | 195 ({ get foo() { }, get foo() { } }); |
203 assertThrows("var x = { set foo(v) { }, foo: 'data' };", SyntaxError); | 196 ({ get foo(){}, get 'foo'(){}}); |
204 assertThrows("var x = { foo: 'data', set 'foo'(v) { } };", SyntaxError); | 197 ({ get 12(){}, get '12'(){}}); |
205 assertThrows("var x = { set foo(v) { }, 'foo': 'data' };", SyntaxError); | |
206 assertThrows("var x = { 'foo': 'data', set foo(v) { } };", SyntaxError); | |
207 assertThrows("var x = { set 'foo'(v) { }, foo: 'data' };", SyntaxError); | |
208 assertThrows("var x = { 'foo': 'data', set 'foo'(v) { } };", SyntaxError); | |
209 assertThrows("var x = { set 'foo'(v) { }, 'foo': 'data' };", SyntaxError); | |
210 assertThrows("var x = { 12: 1, set '12'(v){}};", SyntaxError); | |
211 assertThrows("var x = { 12: 1, set 12(v){}};", SyntaxError); | |
212 assertThrows("var x = { '12': 1, set '12'(v){}};", SyntaxError); | |
213 assertThrows("var x = { '12': 1, set 12(v){}};", SyntaxError); | |
214 | 198 |
215 // Getter and data (non-strict) | 199 // Two setters |
216 assertThrows("var x = { foo: 'data', get foo() { } };", SyntaxError); | 200 ({ set foo(v) { }, set foo(v) { } }); |
217 assertThrows("var x = { get foo() { }, foo: 'data' };", SyntaxError); | 201 ({ set foo(v) { }, set 'foo'(v) { } }); |
218 assertThrows("var x = { 'foo': 'data', get foo() { } };", SyntaxError); | 202 ({ set 13(v) { }, set '13'(v) { } }); |
219 assertThrows("var x = { get 'foo'() { }, 'foo': 'data' };", SyntaxError); | 203 |
220 assertThrows("var x = { '12': 1, get '12'(){}};", SyntaxError); | 204 // Setter and data |
221 assertThrows("var x = { '12': 1, get 12(){}};", SyntaxError); | 205 ({ foo: 'data', set foo(v) { } }); |
| 206 ({ set foo(v) { }, foo: 'data' }); |
| 207 ({ foo: 'data', set 'foo'(v) { } }); |
| 208 ({ set foo(v) { }, 'foo': 'data' }); |
| 209 ({ 'foo': 'data', set foo(v) { } }); |
| 210 ({ set 'foo'(v) { }, foo: 'data' }); |
| 211 ({ 'foo': 'data', set 'foo'(v) { } }); |
| 212 ({ set 'foo'(v) { }, 'foo': 'data' }); |
| 213 ({ 12: 1, set '12'(v){}}); |
| 214 ({ 12: 1, set 12(v){}}); |
| 215 ({ '12': 1, set '12'(v){}}); |
| 216 ({ '12': 1, set 12(v){}}); |
| 217 |
| 218 // Getter and data |
| 219 ({ foo: 'data', get foo() { } }); |
| 220 ({ get foo() { }, foo: 'data' }); |
| 221 ({ 'foo': 'data', get foo() { } }); |
| 222 ({ get 'foo'() { }, 'foo': 'data' }); |
| 223 ({ '12': 1, get '12'(){}}); |
| 224 ({ '12': 1, get 12(){}}); |
| 225 })(); |
222 | 226 |
223 // Assignment to eval or arguments | 227 // Assignment to eval or arguments |
224 CheckStrictMode("function strict() { eval = undefined; }", SyntaxError); | 228 CheckStrictMode("function strict() { eval = undefined; }", SyntaxError); |
225 CheckStrictMode("function strict() { arguments = undefined; }", SyntaxError); | 229 CheckStrictMode("function strict() { arguments = undefined; }", SyntaxError); |
226 CheckStrictMode("function strict() { print(eval = undefined); }", SyntaxError); | 230 CheckStrictMode("function strict() { print(eval = undefined); }", SyntaxError); |
227 CheckStrictMode("function strict() { print(arguments = undefined); }", | 231 CheckStrictMode("function strict() { print(arguments = undefined); }", |
228 SyntaxError); | 232 SyntaxError); |
229 CheckStrictMode("function strict() { var x = eval = undefined; }", SyntaxError); | 233 CheckStrictMode("function strict() { var x = eval = undefined; }", SyntaxError); |
230 CheckStrictMode("function strict() { var x = arguments = undefined; }", | 234 CheckStrictMode("function strict() { var x = arguments = undefined; }", |
231 SyntaxError); | 235 SyntaxError); |
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 assertSame(null, test(i)); | 1212 assertSame(null, test(i)); |
1209 } | 1213 } |
1210 })(); | 1214 })(); |
1211 | 1215 |
1212 | 1216 |
1213 (function TestStrictModeEval() { | 1217 (function TestStrictModeEval() { |
1214 "use strict"; | 1218 "use strict"; |
1215 eval("var eval_local = 10;"); | 1219 eval("var eval_local = 10;"); |
1216 assertThrows(function() { return eval_local; }, ReferenceError); | 1220 assertThrows(function() { return eval_local; }, ReferenceError); |
1217 })(); | 1221 })(); |
OLD | NEW |