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 1363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1374 kAllowLazy, | 1374 kAllowLazy, |
1375 kAllowNatives, | 1375 kAllowNatives, |
1376 kAllowHarmonyModules, | 1376 kAllowHarmonyModules, |
1377 kAllowHarmonyArrowFunctions, | 1377 kAllowHarmonyArrowFunctions, |
1378 kAllowHarmonyClasses, | 1378 kAllowHarmonyClasses, |
1379 kAllowHarmonyObjectLiterals, | 1379 kAllowHarmonyObjectLiterals, |
1380 kAllowHarmonyRestParameters, | 1380 kAllowHarmonyRestParameters, |
1381 kAllowHarmonySloppy, | 1381 kAllowHarmonySloppy, |
1382 kAllowHarmonyUnicode, | 1382 kAllowHarmonyUnicode, |
1383 kAllowHarmonyComputedPropertyNames, | 1383 kAllowHarmonyComputedPropertyNames, |
1384 kAllowStrongMode, | 1384 kAllowHarmonySpreadCalls, |
1385 kAllowHarmonySpreadCalls | 1385 kAllowHarmonyDestructuring, |
1386 kAllowStrongMode | |
1386 }; | 1387 }; |
1387 | 1388 |
1388 | 1389 |
1389 enum ParserSyncTestResult { | 1390 enum ParserSyncTestResult { |
1390 kSuccessOrError, | 1391 kSuccessOrError, |
1391 kSuccess, | 1392 kSuccess, |
1392 kError | 1393 kError |
1393 }; | 1394 }; |
1394 | 1395 |
1395 template <typename Traits> | 1396 template <typename Traits> |
1396 void SetParserFlags(i::ParserBase<Traits>* parser, | 1397 void SetParserFlags(i::ParserBase<Traits>* parser, |
1397 i::EnumSet<ParserFlag> flags) { | 1398 i::EnumSet<ParserFlag> flags) { |
1398 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1399 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
1399 parser->set_allow_natives(flags.Contains(kAllowNatives)); | 1400 parser->set_allow_natives(flags.Contains(kAllowNatives)); |
1400 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules)); | 1401 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules)); |
1401 parser->set_allow_harmony_object_literals( | 1402 parser->set_allow_harmony_object_literals( |
1402 flags.Contains(kAllowHarmonyObjectLiterals)); | 1403 flags.Contains(kAllowHarmonyObjectLiterals)); |
1403 parser->set_allow_harmony_arrow_functions( | 1404 parser->set_allow_harmony_arrow_functions( |
1404 flags.Contains(kAllowHarmonyArrowFunctions)); | 1405 flags.Contains(kAllowHarmonyArrowFunctions)); |
1405 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses)); | 1406 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses)); |
1406 parser->set_allow_harmony_rest_params( | 1407 parser->set_allow_harmony_rest_params( |
1407 flags.Contains(kAllowHarmonyRestParameters)); | 1408 flags.Contains(kAllowHarmonyRestParameters)); |
1408 parser->set_allow_harmony_spreadcalls( | 1409 parser->set_allow_harmony_spreadcalls( |
1409 flags.Contains(kAllowHarmonySpreadCalls)); | 1410 flags.Contains(kAllowHarmonySpreadCalls)); |
1410 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); | 1411 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); |
1411 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); | 1412 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); |
1412 parser->set_allow_harmony_computed_property_names( | 1413 parser->set_allow_harmony_computed_property_names( |
1413 flags.Contains(kAllowHarmonyComputedPropertyNames)); | 1414 flags.Contains(kAllowHarmonyComputedPropertyNames)); |
1415 parser->set_allow_harmony_destructuring( | |
1416 flags.Contains(kAllowHarmonyDestructuring)); | |
1414 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); | 1417 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); |
1415 } | 1418 } |
1416 | 1419 |
1417 | 1420 |
1418 void TestParserSyncWithFlags(i::Handle<i::String> source, | 1421 void TestParserSyncWithFlags(i::Handle<i::String> source, |
1419 i::EnumSet<ParserFlag> flags, | 1422 i::EnumSet<ParserFlag> flags, |
1420 ParserSyncTestResult result) { | 1423 ParserSyncTestResult result) { |
1421 i::Isolate* isolate = CcTest::i_isolate(); | 1424 i::Isolate* isolate = CcTest::i_isolate(); |
1422 i::Factory* factory = isolate->factory(); | 1425 i::Factory* factory = isolate->factory(); |
1423 | 1426 |
(...skipping 4913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6337 v8::Script::Compile(v8_str(script3)); | 6340 v8::Script::Compile(v8_str(script3)); |
6338 CHECK(try_catch2.HasCaught()); | 6341 CHECK(try_catch2.HasCaught()); |
6339 v8::String::Utf8Value exception(try_catch2.Exception()); | 6342 v8::String::Utf8Value exception(try_catch2.Exception()); |
6340 CHECK_EQ(0, | 6343 CHECK_EQ(0, |
6341 strcmp( | 6344 strcmp( |
6342 "ReferenceError: In strong mode, using an undeclared global " | 6345 "ReferenceError: In strong mode, using an undeclared global " |
6343 "variable 'not_there3' is not allowed", | 6346 "variable 'not_there3' is not allowed", |
6344 *exception)); | 6347 *exception)); |
6345 } | 6348 } |
6346 } | 6349 } |
6350 | |
6351 | |
6352 TEST(DestructuringPositiveTests) { | |
6353 i::FLAG_harmony_destructuring = true; | |
6354 | |
6355 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, | |
6356 {"var ", " = {};"}, | |
6357 {"'use strict'; const ", " = {};"}, | |
6358 {NULL, NULL}}; | |
6359 | |
6360 const char* data[] = {"a", "{ x : y }", "[a]", "[a,b,c]", "{ x : x, y : y }", | |
rossberg
2015/04/27 17:20:24
Add [], {}, and {x}, and a couple of nested cases
arv (Not doing code reviews)
2015/04/27 17:56:55
Nit: Don't let `git cl format` bully you. These th
arv (Not doing code reviews)
2015/04/27 17:56:55
How about?
- nested patterns
- array elision
- re
Dmitry Lomov (no reviews)
2015/04/28 10:15:49
No! All hail 'git cl format'! Our Blessed Format-L
Dmitry Lomov (no reviews)
2015/04/28 10:15:49
Done.
Dmitry Lomov (no reviews)
2015/04/28 10:15:49
Added everything I support yet. Rest, initializers
| |
6361 NULL}; | |
6362 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring}; | |
6363 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | |
6364 arraysize(always_flags)); | |
6365 } | |
6366 | |
6367 | |
6368 TEST(DestructuringNegativeTests) { | |
6369 i::FLAG_harmony_destructuring = true; | |
6370 | |
6371 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, | |
6372 {"var ", " = {};"}, | |
6373 {"'use strict'; const ", " = {};"}, | |
6374 {NULL, NULL}}; | |
6375 | |
6376 const char* data[] = { | |
6377 "a++", "++a", "delete a", "void a", "typeof a", "--a", "+a", "-a", "~a", | |
6378 "!a", "{ x : y++ }", "[a++]", "(x => y)", "a[i]", "a()", "a.b", "new a", | |
arv (Not doing code reviews)
2015/04/27 17:56:55
also "() => x"
Dmitry Lomov (no reviews)
2015/04/28 10:15:49
Done.
| |
6379 "a + a", "a - a", "a * a", "a / a", "a == a", "a != a", "a > a", "a < a", | |
6380 "a <<< a", "a >>> a", "function a() {}", "a`bcd`", "x => x", "this", | |
6381 "null", "true", "false", "1", "'abc'", "class {}", NULL}; | |
arv (Not doing code reviews)
2015/04/27 17:56:55
How about some keywords, eval/arguments and strict
Dmitry Lomov (no reviews)
2015/04/28 10:15:49
Done.
| |
6382 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring}; | |
6383 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | |
6384 arraysize(always_flags)); | |
6385 } | |
OLD | NEW |