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

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

Issue 1168643005: [es6] parse destructuring assignment (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix arrow function parsing Created 5 years, 6 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
« src/preparser.h ('K') | « src/preparser.h ('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 6519 matching lines...) Expand 10 before | Expand all | Expand 10 after
6530 "[yield]", 6530 "[yield]",
6531 "{ x : yield }", 6531 "{ x : yield }",
6532 NULL}; 6532 NULL};
6533 // clang-format on 6533 // clang-format on
6534 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 6534 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6535 arraysize(always_flags)); 6535 arraysize(always_flags));
6536 } 6536 }
6537 } 6537 }
6538 6538
6539 6539
6540 TEST(DestructuringAssignmentPositiveTests) {
6541 i::FLAG_harmony_destructuring = true;
6542 i::FLAG_harmony_computed_property_names = true;
6543
6544 const char* context_data[][2] = {{"'use strict'; let x, y, z; (", " = {});"},
6545 {"var x, y, z; (", " = {});"},
arv (Not doing code reviews) 2015/06/04 20:08:04 Do you want to do for-in and for-of too?
caitp (gmail) 2015/06/05 18:37:14 Done.
6546 {NULL, NULL}};
6547
6548 // clang-format off
6549 const char* data[] = {
6550 "x",
6551 "{ x : y }",
6552 "{ x : y = 1 }",
6553 "{ x }",
6554 "{ x, y, z }",
6555 "{ x = 1, y: z, z: y }",
6556 "{x = 42, y = 15}",
6557 "[x]",
6558 "[x = 1]",
6559 "[x,y,z]",
6560 "[x, y = 42, z]",
6561 "{ x : x, y : y }",
6562 "{ x : x = 1, y : y }",
6563 "{ x : x, y : y = 42 }",
6564 "[]",
6565 "{}",
6566 "[{x:x, y:y}, [,x,z,]]",
6567 "[{x:x = 1, y:y = 2}, [z = 3, z = 4, z = 5]]",
6568 "[x,,y]",
6569 "{42 : x}",
6570 "{42 : x = 42}",
6571 "{42e-2 : x}",
6572 "{42e-2 : x = 42}",
6573 "{'hi' : x}",
6574 "{'hi' : x = 42}",
6575 "{var: x}",
6576 "{var: x = 42}",
6577 "{[x] : z}",
6578 "{[1+1] : z}",
6579 "{[foo()] : z}",
6580 "[...x]",
6581 "[x,y,...z]",
6582 "[x,,...z]",
6583 NULL};
arv (Not doing code reviews) 2015/06/04 20:08:04 Needs more LHS expressions. this.x super.x o['x']
caitp (gmail) 2015/06/05 18:37:14 I've added a bunch of these
6584 // clang-format on
6585 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals,
6586 kAllowHarmonyComputedPropertyNames,
6587 kAllowHarmonyDestructuring};
6588 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
6589 arraysize(always_flags));
6590 }
6591
6592
6593 TEST(DestructuringAssignmentNegativeTests) {
6594 i::FLAG_harmony_destructuring = true;
6595 i::FLAG_harmony_computed_property_names = true;
6596
6597 const char* context_data[][2] = {{"'use strict'; let x, y, z; (", " = {});"},
6598 {"var x, y, z; (", " = {});"},
6599 {NULL, NULL}};
6600
6601 // clang-format off
6602 const char* data[] = {
6603 "{ x : ++y }",
6604 "{ x : y * 2 }",
6605 "{ ...x }",
6606 "{ get x() {} }",
6607 "{ set x() {} }",
6608 "{ x: y() }",
6609 "{ this }",
6610 "{ x: this }",
6611 "{ x: this = 1 }",
6612 "{ super }",
6613 "{ x: super }",
6614 "{ x: super = 1 }",
6615 "{ new.target }",
6616 "{ x: new.target }",
arv (Not doing code reviews) 2015/06/04 20:08:04 I think this is valid syntax inside a function but
caitp (gmail) 2015/06/04 20:54:15 IsValidSimpleAssignmentTarget returns false for `n
6617 "{ x: new.target = 1 }",
6618 "[x--]",
6619 "[--x = 1]",
6620 "[x()]",
6621 "[this]",
6622 "[this = 1]",
6623 "[new.target]",
6624 "[new.target = 1]",
6625 "[super]",
6626 "[super = 1]",
6627 "[function f() {}]",
6628 "[50]",
6629 "{ x: 50 }",
6630 "['str']",
6631 "{ x: 'str' }",
6632 NULL};
6633 // clang-format on
6634 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals,
6635 kAllowHarmonyComputedPropertyNames,
6636 kAllowHarmonyDestructuring};
6637 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6638 arraysize(always_flags));
6639 }
6640
6641
6540 TEST(DestructuringDisallowPatternsInForVarIn) { 6642 TEST(DestructuringDisallowPatternsInForVarIn) {
6541 i::FLAG_harmony_destructuring = true; 6643 i::FLAG_harmony_destructuring = true;
6542 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring}; 6644 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
6543 const char* context_data[][2] = { 6645 const char* context_data[][2] = {
6544 {"", ""}, {"function f() {", "}"}, {NULL, NULL}}; 6646 {"", ""}, {"function f() {", "}"}, {NULL, NULL}};
6545 // clang-format off 6647 // clang-format off
6546 const char* error_data[] = { 6648 const char* error_data[] = {
6547 "for (var {x} = {} in null);", 6649 "for (var {x} = {} in null);",
6548 "for (var {x} = {} of null);", 6650 "for (var {x} = {} of null);",
6549 "for (let x = {} in null);", 6651 "for (let x = {} in null);",
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
6601 "[a, ...]", 6703 "[a, ...]",
6602 "[..., ]", 6704 "[..., ]",
6603 "[..., ...]", 6705 "[..., ...]",
6604 "[ (...a)]", 6706 "[ (...a)]",
6605 NULL}; 6707 NULL};
6606 // clang-format on 6708 // clang-format on
6607 static const ParserFlag always_flags[] = {kAllowHarmonySpreadArrays}; 6709 static const ParserFlag always_flags[] = {kAllowHarmonySpreadArrays};
6608 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 6710 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6609 arraysize(always_flags)); 6711 arraysize(always_flags));
6610 } 6712 }
OLDNEW
« src/preparser.h ('K') | « src/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698