OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 7217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7228 NULL | 7228 NULL |
7229 }; | 7229 }; |
7230 // clang-format on | 7230 // clang-format on |
7231 | 7231 |
7232 static const ParserFlag fail_flags[] = { | 7232 static const ParserFlag fail_flags[] = { |
7233 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst, | 7233 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst, |
7234 kAllowHarmonyDestructuring}; | 7234 kAllowHarmonyDestructuring}; |
7235 RunParserSyncTest(context_data, fail_data, kError, NULL, 0, fail_flags, | 7235 RunParserSyncTest(context_data, fail_data, kError, NULL, 0, fail_flags, |
7236 arraysize(fail_flags)); | 7236 arraysize(fail_flags)); |
7237 } | 7237 } |
7238 | |
7239 | |
7240 TEST(EscapedKeywords) { | |
adamk
2015/11/03 23:00:57
I think you also want some more non-error cases: y
caitp (gmail)
2015/11/04 04:49:25
I've added sloppy vs strict tests for the future r
| |
7241 // clang-format off | |
7242 const char* sloppy_context_data[][2] = { | |
7243 {"", ""}, | |
7244 {NULL, NULL} | |
7245 }; | |
7246 | |
7247 const char* strict_context_data[][2] = { | |
7248 {"'use strict';", ""}, | |
7249 {NULL, NULL} | |
7250 }; | |
7251 | |
7252 const char* fail_data[] = { | |
7253 "for (var i = 0; i < 100; ++i) { br\\u0065ak; }", | |
caitp (gmail)
2015/11/03 17:19:13
There are probably some good test cases missing, l
| |
7254 "cl\\u0061ss Foo {}", | |
7255 "var x = cl\\u0061ss {}", | |
7256 "\\u0063onst foo = 1;", | |
7257 "while (i < 10) { if (i++ & 1) c\\u006fntinue; this.x++; }", | |
7258 "d\\u0065bugger;", | |
7259 "d\\u0065lete this.a;", | |
7260 "\\u0063o { } while(0)", | |
7261 "if (d\\u006f { true }) {}", | |
7262 "if (false) { this.a = 1; } \\u0065lse { this.b = 1; }", | |
7263 "e\\u0078port var foo;", | |
adamk
2015/11/03 23:00:57
This would already be failing since you're not par
caitp (gmail)
2015/11/04 04:49:25
I've added a helper for testing module parsing, an
| |
7264 "try { } catch (e) {} f\\u0069nally { }", | |
7265 "f\\u006fr (var i = 0; i < 10; ++i);", | |
7266 "f\\u0075nction fn() {}", | |
7267 "var f = f\\u0075nction() {}", | |
7268 "\\u0069f (true) { }", | |
7269 "\\u0069mport blah from './foo.js';", | |
adamk
2015/11/03 23:00:57
same here as above for export
caitp (gmail)
2015/11/04 04:49:25
These would have been errors before, but only beca
| |
7270 "n\\u0065w function f() {}", | |
7271 "(function() { r\\u0065turn; })()", | |
7272 "class C extends function() {} { constructor() { sup\\u0065r() } }", | |
7273 "class C extends function() {} { constructor() { sup\\u0065r.a = 1 } }", | |
7274 "sw\\u0069tch (this.a) {}", | |
7275 "var x = th\\u0069s;", | |
7276 "th\\u0069s.a = 1;", | |
7277 "thr\\u006fw 'boo';", | |
7278 "t\\u0072y { true } catch (e) {}", | |
7279 "var x = typ\\u0065of 'blah'", | |
7280 "v\\u0061r a = true", | |
7281 "var v\\u0061r = true", | |
7282 "(function() { return v\\u006fid 0; })()", | |
7283 "wh\\u0069le (true) { }", | |
7284 "w\\u0069th (this.scope) { }", | |
7285 "(function*() { y\\u0069eld 1; })()", | |
7286 | |
7287 "var \\u0065num = 1;", | |
7288 "var { \\u0065num } = {}", | |
7289 "(\\u0065num = 1);", | |
7290 | |
7291 // Null / Boolean literals | |
7292 "(x === n\\u0075ll);", | |
7293 "var x = n\\u0075ll;", | |
7294 "var n\\u0075ll = 1;", | |
7295 "var { n\\u0075ll } = { 1 };", | |
7296 "n\\u0075ll = 1;", | |
7297 "(x === tr\\u0075e);", | |
7298 "var x = tr\\u0075e;", | |
7299 "var tr\\u0075e = 1;", | |
7300 "var { tr\\u0075e } = {};", | |
7301 "tr\\u0075e = 1;", | |
7302 "(x === f\\u0061lse);", | |
7303 "var x = f\\u0061lse;", | |
7304 "var f\\u0061lse = 1;", | |
7305 "var { f\\u0061lse } = {};", | |
7306 "f\\u0061lse = 1;", | |
7307 | |
7308 // TODO(caitp): consistent error messages for labeled statements and | |
7309 // expressions | |
7310 "switch (this.a) { c\\u0061se 6: break; }", | |
7311 "try { } c\\u0061tch (e) {}", | |
7312 "switch (this.a) { d\\u0065fault: break; }", | |
7313 "class C \\u0065xtends function B() {} {}", | |
7314 "for (var a i\\u006e this) {}", | |
7315 "if ('foo' \\u0069n this) {}", | |
7316 "if (this \\u0069nstanceof Array) {}", | |
7317 "(n\\u0065w function f() {})", | |
7318 "(typ\\u0065of 123)", | |
7319 "(v\\u006fid 0)", | |
7320 "do { ; } wh\\u0069le (true) { }", | |
7321 "(function*() { return (n++, y\\u0069eld 1); })()", | |
7322 "class C { st\\u0061tic bar() {} }", | |
7323 NULL | |
7324 }; | |
7325 // clang-format on | |
7326 | |
7327 static const ParserFlag always_flags[] = { | |
7328 kAllowHarmonySloppy, kAllowHarmonyDestructuring}; | |
7329 RunParserSyncTest(sloppy_context_data, fail_data, kError, NULL, 0, | |
7330 always_flags, arraysize(always_flags)); | |
7331 RunParserSyncTest(strict_context_data, fail_data, kError, NULL, 0, | |
7332 always_flags, arraysize(always_flags)); | |
7333 | |
7334 // clang-format off | |
7335 const char* let_data[] = { | |
7336 "var l\\u0065t = 1;", | |
7337 "l\\u0065t = 1;", | |
7338 "(l\\u0065t === 1);", | |
7339 NULL | |
7340 }; | |
7341 // clang-format on | |
7342 | |
7343 RunParserSyncTest(sloppy_context_data, let_data, kSuccess, NULL, 0, | |
7344 always_flags, arraysize(always_flags)); | |
7345 RunParserSyncTest(strict_context_data, let_data, kError, NULL, 0, | |
7346 always_flags, arraysize(always_flags)); | |
7347 | |
7348 static const ParserFlag sloppy_let_flags[] = { | |
7349 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kAllowHarmonyDestructuring}; | |
7350 RunParserSyncTest(sloppy_context_data, let_data, kError, NULL, 0, | |
7351 sloppy_let_flags, arraysize(sloppy_let_flags)); | |
7352 } | |
OLD | NEW |