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 |
169 // Non-conflicting data properties. | 180 // Non-conflicting data properties. |
170 (function StrictModeNonDuplicate() { | 181 (function StrictModeNonDuplicate() { |
171 "use strict"; | 182 "use strict"; |
172 var x = { 123 : 1, "0123" : 2 }; | 183 var x = { 123 : 1, "0123" : 2 }; |
173 var x = { | 184 var x = { |
174 123: 1, | 185 123: 1, |
175 '123.00000000000000000000000000000000000000000000000000000000000000000001': | 186 '123.00000000000000000000000000000000000000000000000000000000000000000001': |
176 2 | 187 2 |
177 }; | 188 }; |
178 })(); | 189 })(); |
179 | 190 |
180 // Duplicate properties are no longer errors in ES6. | 191 // Two getters (non-strict) |
181 (function Duplicates() { | 192 assertThrows("var x = { get foo() { }, get foo() { } };", SyntaxError); |
182 "use strict"; | 193 assertThrows("var x = { get foo(){}, get 'foo'(){}};", SyntaxError); |
| 194 assertThrows("var x = { get 12(){}, get '12'(){}};", SyntaxError); |
183 | 195 |
184 ({ dupe : 1, nondupe: 3, dupe : 2 }); | 196 // Two setters (non-strict) |
185 ({ '1234' : 1, '2345' : 2, '1234' : 3 }); | 197 assertThrows("var x = { set foo(v) { }, set foo(v) { } };", SyntaxError); |
186 ({ '1234' : 1, '2345' : 2, 1234 : 3 }); | 198 assertThrows("var x = { set foo(v) { }, set 'foo'(v) { } };", SyntaxError); |
187 ({ 3.14 : 1, 2.71 : 2, 3.14 : 3 }); | 199 assertThrows("var x = { set 13(v) { }, set '13'(v) { } };", SyntaxError); |
188 ({ 3.14 : 1, '3.14' : 2 }); | |
189 ({ | |
190 123: 1, | |
191 123.00000000000000000000000000000000000000000000000000000000000000000001: 2 | |
192 }); | |
193 | 200 |
194 // Two getters | 201 // Setter and data (non-strict) |
195 ({ get foo() { }, get foo() { } }); | 202 assertThrows("var x = { foo: 'data', set foo(v) { } };", SyntaxError); |
196 ({ get foo(){}, get 'foo'(){}}); | 203 assertThrows("var x = { set foo(v) { }, foo: 'data' };", SyntaxError); |
197 ({ get 12(){}, get '12'(){}}); | 204 assertThrows("var x = { foo: 'data', set 'foo'(v) { } };", SyntaxError); |
| 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); |
198 | 214 |
199 // Two setters | 215 // Getter and data (non-strict) |
200 ({ set foo(v) { }, set foo(v) { } }); | 216 assertThrows("var x = { foo: 'data', get foo() { } };", SyntaxError); |
201 ({ set foo(v) { }, set 'foo'(v) { } }); | 217 assertThrows("var x = { get foo() { }, foo: 'data' };", SyntaxError); |
202 ({ set 13(v) { }, set '13'(v) { } }); | 218 assertThrows("var x = { 'foo': 'data', get foo() { } };", SyntaxError); |
203 | 219 assertThrows("var x = { get 'foo'() { }, 'foo': 'data' };", SyntaxError); |
204 // Setter and data | 220 assertThrows("var x = { '12': 1, get '12'(){}};", SyntaxError); |
205 ({ foo: 'data', set foo(v) { } }); | 221 assertThrows("var x = { '12': 1, get 12(){}};", SyntaxError); |
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 })(); | |
226 | 222 |
227 // Assignment to eval or arguments | 223 // Assignment to eval or arguments |
228 CheckStrictMode("function strict() { eval = undefined; }", SyntaxError); | 224 CheckStrictMode("function strict() { eval = undefined; }", SyntaxError); |
229 CheckStrictMode("function strict() { arguments = undefined; }", SyntaxError); | 225 CheckStrictMode("function strict() { arguments = undefined; }", SyntaxError); |
230 CheckStrictMode("function strict() { print(eval = undefined); }", SyntaxError); | 226 CheckStrictMode("function strict() { print(eval = undefined); }", SyntaxError); |
231 CheckStrictMode("function strict() { print(arguments = undefined); }", | 227 CheckStrictMode("function strict() { print(arguments = undefined); }", |
232 SyntaxError); | 228 SyntaxError); |
233 CheckStrictMode("function strict() { var x = eval = undefined; }", SyntaxError); | 229 CheckStrictMode("function strict() { var x = eval = undefined; }", SyntaxError); |
234 CheckStrictMode("function strict() { var x = arguments = undefined; }", | 230 CheckStrictMode("function strict() { var x = arguments = undefined; }", |
235 SyntaxError); | 231 SyntaxError); |
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 assertSame(null, test(i)); | 1208 assertSame(null, test(i)); |
1213 } | 1209 } |
1214 })(); | 1210 })(); |
1215 | 1211 |
1216 | 1212 |
1217 (function TestStrictModeEval() { | 1213 (function TestStrictModeEval() { |
1218 "use strict"; | 1214 "use strict"; |
1219 eval("var eval_local = 10;"); | 1215 eval("var eval_local = 10;"); |
1220 assertThrows(function() { return eval_local; }, ReferenceError); | 1216 assertThrows(function() { return eval_local; }, ReferenceError); |
1221 })(); | 1217 })(); |
OLD | NEW |