Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: test/cctest/test-parsing.cc

Issue 1107053002: Parsing binding patterns. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Minor fix to formatter flags Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/preparser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 // clang-format off
6361 const char* data[] = {
6362 "a",
6363 "{ x : y }",
6364 "[a]",
6365 "[a,b,c]",
6366 "{ x : x, y : y }",
6367 "[]",
6368 "{}",
6369 "[{x:x, y:y}, [a,b,c]]",
arv (Not doing code reviews) 2015/04/28 13:42:14 moar "{var: x}", "{42: x}", "{+2: x}", "{-2: x}",
Dmitry Lomov (no reviews) 2015/04/28 16:01:36 Done. {+2: x} and {-2: x} are not valid AFAIU.
arv (Not doing code reviews) 2015/04/28 16:07:22 You are right... but 42e-2 is... not needed though
6370 "[a,,b]",
6371 NULL};
6372 // clang-format on
6373 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
6374 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
6375 arraysize(always_flags));
6376 }
6377
6378
6379 TEST(DestructuringNegativeTests) {
6380 i::FLAG_harmony_destructuring = true;
6381 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
6382
6383 { // All modes.
6384 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6385 {"var ", " = {};"},
6386 {"'use strict'; const ", " = {};"},
6387 {NULL, NULL}};
6388
6389 // clang-format off
6390 const char* data[] = {
6391 "a++",
6392 "++a",
6393 "delete a",
6394 "void a",
6395 "typeof a",
6396 "--a",
6397 "+a",
6398 "-a",
6399 "~a",
6400 "!a",
6401 "{ x : y++ }",
6402 "[a++]",
6403 "(x => y)",
6404 "a[i]", "a()",
6405 "a.b",
6406 "new a",
6407 "a + a",
6408 "a - a",
6409 "a * a",
6410 "a / a",
6411 "a == a",
6412 "a != a",
6413 "a > a",
6414 "a < a",
6415 "a <<< a",
6416 "a >>> a",
6417 "function a() {}",
6418 "a`bcd`",
6419 "x => x",
6420 "this",
6421 "null",
6422 "true",
6423 "false",
arv (Not doing code reviews) 2015/04/28 13:42:14 moar // keywords "var", // nested "[var]", "{x
Dmitry Lomov (no reviews) 2015/04/28 16:01:36 Done.
6424 "1",
6425 "'abc'",
6426 "class {}",
6427 "() => x",
6428 NULL};
6429 // clang-format on
6430 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6431 arraysize(always_flags));
6432 }
6433
6434 { // Strict mode.
6435 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6436 {"'use strict'; const ", " = {};"},
6437 {NULL, NULL}};
6438
6439 // clang-format off
6440 const char* data[] = {
6441 "[eval]",
6442 "{ a : arguments }",
6443 "[public]",
6444 "{ x : private }",
6445 NULL};
6446 // clang-format on
6447 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6448 arraysize(always_flags));
6449 }
6450
6451 { // 'yield' in generators.
6452 const char* context_data[][2] = {
6453 {"function*() { var ", " = {};"},
6454 {"function*() { 'use strict'; let ", " = {};"},
6455 {"function*() { 'use strict'; const ", " = {};"},
6456 {NULL, NULL}};
6457
6458 // clang-format off
6459 const char* data[] = {
6460 "yield",
6461 "[yield]",
6462 "{ x : yield }",
6463 NULL};
6464 // clang-format on
6465 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6466 arraysize(always_flags));
6467 }
6468 }
OLDNEW
« no previous file with comments | « src/preparser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698