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

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: Nits ForIn/Of tests 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
« no previous file with comments | « 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 6526 matching lines...) Expand 10 before | Expand all | Expand 10 after
6537 "[yield]", 6537 "[yield]",
6538 "{ x : yield }", 6538 "{ x : yield }",
6539 NULL}; 6539 NULL};
6540 // clang-format on 6540 // clang-format on
6541 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 6541 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6542 arraysize(always_flags)); 6542 arraysize(always_flags));
6543 } 6543 }
6544 } 6544 }
6545 6545
6546 6546
6547 TEST(DestructuringAssignmentPositiveTests) {
6548 i::FLAG_harmony_destructuring = true;
6549 i::FLAG_harmony_computed_property_names = true;
6550
6551 const char* context_data[][2] = {
6552 {"'use strict'; let x, y, z; (", " = {});"},
6553 {"var x, y, z; (", " = {});"},
6554 {"'use strict'; let x, y, z; for (x in ", " = {});"},
6555 {"'use strict'; let x, y, z; for (x of ", " = {});"},
6556 {"var x, y, z; for (x in ", " = {});"},
arv (Not doing code reviews) 2015/06/05 18:45:26 This was not what I had in mind. Here is an exampl
caitp (gmail) 2015/06/05 19:00:20 They're both valid, but we may be reporting an err
6557 {"var x, y, z; for (x of ", " = {});"},
6558 {NULL, NULL}};
6559
6560 // clang-format off
6561 const char* data[] = {
6562 "x",
6563 "{ x : y }",
6564 "{ x : y = 1 }",
6565 "{ x }",
6566 "{ x, y, z }",
6567 "{ x = 1, y: z, z: y }",
6568 "{x = 42, y = 15}",
6569 "[x]",
6570 "[x = 1]",
6571 "[x,y,z]",
6572 "[x, y = 42, z]",
6573 "{ x : x, y : y }",
6574 "{ x : x = 1, y : y }",
6575 "{ x : x, y : y = 42 }",
6576 "[]",
6577 "{}",
6578 "[{x:x, y:y}, [,x,z,]]",
6579 "[{x:x = 1, y:y = 2}, [z = 3, z = 4, z = 5]]",
6580 "[x,,y]",
6581 "[(x),,(y)]",
6582 "[(x)]",
6583 "{42 : x}",
6584 "{42 : x = 42}",
6585 "{42e-2 : x}",
6586 "{42e-2 : x = 42}",
6587 "{'hi' : x}",
6588 "{'hi' : x = 42}",
6589 "{var: x}",
6590 "{var: x = 42}",
6591 "{var: (x) = 42}",
6592 "{[x] : z}",
6593 "{[1+1] : z}",
6594 "{[1+1] : (z)}",
6595 "{[foo()] : z}",
6596 "{[foo()] : (z)}",
6597 "{[foo()] : foo().bar}",
6598 "{[foo()] : foo()['bar']}",
6599 "{[foo()] : this.bar}",
6600 "{[foo()] : this['bar']}",
6601 "{[foo()] : 'foo'.bar}",
6602 "{[foo()] : 'foo'['bar']}",
6603 "[...x]",
6604 "[x,y,...z]",
6605 "[x,,...z]",
6606 "{ x: y } = z",
6607 "[x, y] = z",
6608 "{ x: y } = { z }",
6609 "[x, y] = { z }",
6610 "{ x: y } = [ z ]",
6611 "[x, y] = [ z ]",
6612 NULL};
6613 // clang-format on
6614 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals,
6615 kAllowHarmonyComputedPropertyNames,
6616 kAllowHarmonyDestructuring};
6617 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
6618 arraysize(always_flags));
6619 }
6620
6621
6622 TEST(DestructuringAssignmentNegativeTests) {
6623 i::FLAG_harmony_destructuring = true;
6624 i::FLAG_harmony_computed_property_names = true;
6625
6626 const char* context_data[][2] = {
6627 {"'use strict'; let x, y, z; (", " = {});"},
6628 {"var x, y, z; (", " = {});"},
6629 {"'use strict'; let x, y, z; for (x in ", " = {});"},
6630 {"'use strict'; let x, y, z; for (x of ", " = {});"},
6631 {"var x, y, z; for (x in ", " = {});"},
6632 {"var x, y, z; for (x of ", " = {});"},
6633 {NULL, NULL}};
6634
6635 // clang-format off
6636 const char* data[] = {
6637 "{ x : ++y }",
6638 "{ x : y * 2 }",
6639 "{ ...x }",
6640 "{ get x() {} }",
6641 "{ set x() {} }",
6642 "{ x: y() }",
6643 "{ this }",
6644 "{ x: this }",
6645 "{ x: this = 1 }",
6646 "{ super }",
6647 "{ x: super }",
6648 "{ x: super = 1 }",
6649 "{ new.target }",
6650 "{ x: new.target }",
6651 "{ x: new.target = 1 }",
6652 "[x--]",
6653 "[--x = 1]",
6654 "[x()]",
6655 "[this]",
6656 "[this = 1]",
6657 "[new.target]",
6658 "[new.target = 1]",
6659 "[super]",
6660 "[super = 1]",
6661 "[function f() {}]",
6662 "[50]",
6663 "[(50)]",
6664 "[(function() {})]",
6665 "[(foo())]",
6666 "{ x: 50 }",
6667 "{ x: (50) }",
6668 "['str']",
6669 "{ x: 'str' }",
6670 "{ x: ('str') }",
6671 "{ x: (foo()) }",
6672 "{ x: (function() {}) }",
6673 "{ x: y } = 'str'",
6674 "[x, y] = 'str'",
6675 NULL};
6676 // clang-format on
6677 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals,
6678 kAllowHarmonyComputedPropertyNames,
6679 kAllowHarmonyDestructuring};
6680 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6681 arraysize(always_flags));
6682 }
6683
6684
6547 TEST(DestructuringDisallowPatternsInForVarIn) { 6685 TEST(DestructuringDisallowPatternsInForVarIn) {
6548 i::FLAG_harmony_destructuring = true; 6686 i::FLAG_harmony_destructuring = true;
6549 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring}; 6687 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
6550 const char* context_data[][2] = { 6688 const char* context_data[][2] = {
6551 {"", ""}, {"function f() {", "}"}, {NULL, NULL}}; 6689 {"", ""}, {"function f() {", "}"}, {NULL, NULL}};
6552 // clang-format off 6690 // clang-format off
6553 const char* error_data[] = { 6691 const char* error_data[] = {
6554 "for (var {x} = {} in null);", 6692 "for (var {x} = {} in null);",
6555 "for (var {x} = {} of null);", 6693 "for (var {x} = {} of null);",
6556 "for (let x = {} in null);", 6694 "for (let x = {} in null);",
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
6608 "[a, ...]", 6746 "[a, ...]",
6609 "[..., ]", 6747 "[..., ]",
6610 "[..., ...]", 6748 "[..., ...]",
6611 "[ (...a)]", 6749 "[ (...a)]",
6612 NULL}; 6750 NULL};
6613 // clang-format on 6751 // clang-format on
6614 static const ParserFlag always_flags[] = {kAllowHarmonySpreadArrays}; 6752 static const ParserFlag always_flags[] = {kAllowHarmonySpreadArrays};
6615 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 6753 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6616 arraysize(always_flags)); 6754 arraysize(always_flags));
6617 } 6755 }
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698