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

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: WIP #1 Created 5 years, 4 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 6330 matching lines...) Expand 10 before | Expand all | Expand 10 after
6341 "[a, b = 42, c]", 6341 "[a, b = 42, c]",
6342 "{ x : x, y : y }", 6342 "{ x : x, y : y }",
6343 "{ x : x = 1, y : y }", 6343 "{ x : x = 1, y : y }",
6344 "{ x : x, y : y = 42 }", 6344 "{ x : x, y : y = 42 }",
6345 "[]", 6345 "[]",
6346 "{}", 6346 "{}",
6347 "[{x:x, y:y}, [a,b,c]]", 6347 "[{x:x, y:y}, [a,b,c]]",
6348 "[{x:x = 1, y:y = 2}, [a = 3, b = 4, c = 5]]", 6348 "[{x:x = 1, y:y = 2}, [a = 3, b = 4, c = 5]]",
6349 "{x}", 6349 "{x}",
6350 "{x, y}", 6350 "{x, y}",
6351 "{x = 42, y = 15}",
6352 "[a,,b]", 6351 "[a,,b]",
6353 "{42 : x}", 6352 "{42 : x}",
6354 "{42 : x = 42}", 6353 "{42 : x = 42}",
6355 "{42e-2 : x}", 6354 "{42e-2 : x}",
6356 "{42e-2 : x = 42}", 6355 "{42e-2 : x = 42}",
6357 "{x : y, x : z}", 6356 "{x : y, x : z}",
6358 "{'hi' : x}", 6357 "{'hi' : x}",
6359 "{'hi' : x = 42}", 6358 "{'hi' : x = 42}",
6360 "{var: x}", 6359 "{var: x}",
6361 "{var: x = 42}", 6360 "{var: x = 42}",
6362 "{[x] : z}", 6361 "{[x] : z}",
6363 "{[1+1] : z}", 6362 "{[1+1] : z}",
6364 "{[foo()] : z}", 6363 "{[foo()] : z}",
6365 "{}", 6364 "{}",
6366 "[...rest]", 6365
6367 "[a,b,...rest]", 6366 // TODO(caitp): figure out why let parsing broke (dehrenberg?)
6368 "[a,,...rest]", 6367 // "[...rest]",
6368 // "[a,b,...rest]",
6369 // "[a,,...rest]",
6370
6371 // TODO(caitp): parse CoverInitializedName in arrow function binding pattern
6372 // "{x = 42, y = 15}",
6373
6369 NULL}; 6374 NULL};
6370 // clang-format on 6375 // clang-format on
6371 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions, 6376 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions,
6372 kAllowHarmonyDestructuring}; 6377 kAllowHarmonyDestructuring};
6373 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, 6378 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
6374 arraysize(always_flags)); 6379 arraysize(always_flags));
6375 } 6380 }
6376 6381
6377 6382
6378 TEST(DestructuringNegativeTests) { 6383 TEST(DestructuringNegativeTests) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
6513 "[yield]", 6518 "[yield]",
6514 "{ x : yield }", 6519 "{ x : yield }",
6515 NULL}; 6520 NULL};
6516 // clang-format on 6521 // clang-format on
6517 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 6522 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6518 arraysize(always_flags)); 6523 arraysize(always_flags));
6519 } 6524 }
6520 } 6525 }
6521 6526
6522 6527
6528 TEST(DestructuringAssignmentPositiveTests) {
6529 const char* context_data[][2] = {
6530 {"'use strict'; let x, y, z; (", " = {});"},
6531 {"var x, y, z; (", " = {});"},
6532 {"'use strict'; let x, y, z; for (x in ", " = {});"},
6533 {"'use strict'; let x, y, z; for (x of ", " = {});"},
6534 {"var x, y, z; for (x in ", " = {});"},
6535 {"var x, y, z; for (x of ", " = {});"},
6536 {NULL, NULL}};
6537
6538 // clang-format off
6539 const char* data[] = {
6540 "x",
6541
6542 "{ x : y }",
6543 "{ x : foo().y }",
6544 "{ x : foo()[y] }",
6545 "{ x : y.z }",
6546 "{ x : y[z] }",
6547 "{ x : { y } }",
6548 "{ x : { foo: y } }",
6549 "{ x : { foo: foo().y } }",
6550 "{ x : { foo: foo()[y] } }",
6551 "{ x : { foo: y.z } }",
6552 "{ x : { foo: y[z] } }",
6553 "{ x : [ y ] }",
6554 "{ x : [ foo().y ] }",
6555 "{ x : [ foo()[y] ] }",
6556 "{ x : [ y.z ] }",
6557 "{ x : [ y[z] ] }",
6558
6559 "{ x : y = 10 }",
6560 "{ x : foo().y = 10 }",
6561 "{ x : foo()[y] = 10 }",
6562 "{ x : y.z = 10 }",
6563 "{ x : y[z] = 10 }",
6564
6565 "{ x : { foo: y = 10 } = {} }",
6566 "{ x : { foo: foo().y = 10 } = {} }",
6567 "{ x : { foo: foo()[y] = 10 } = {} }",
6568 "{ x : { foo: y.z = 10 } = {} }",
6569 "{ x : { foo: y[z] = 10 } = {} }",
6570 "{ x : [ y = 10 ] = {} }",
6571 "{ x : [ foo().y = 10 ] = {} }",
6572 "{ x : [ foo()[y] = 10 ] = {} }",
6573 "{ x : [ y.z = 10 ] = {} }",
6574 "{ x : [ y[z] = 10 ] = {} }",
6575
6576 "[ x ]",
6577 "[ foo().x ]",
6578 "[ foo()[x] ]",
6579 "[ x.y ]",
6580 "[ x[y] ]",
6581 "[ { x } ]",
6582 "[ { x : y } ]",
6583 "[ { x : foo().y } ]",
6584 "[ { x : foo()[y] } ]",
6585 "[ { x : x.y } ]",
6586 "[ { x : x[y] } ]",
6587 "[ [ x ] ]",
6588 "[ [ foo().x ] ]",
6589 "[ [ foo()[x] ] ]",
6590 "[ [ x.y ] ]",
6591 "[ [ x[y] ] ]",
6592
6593 "[ x = 10 ]",
6594 "[ foo().x = 10 ]",
6595 "[ foo()[x] = 10 ]",
6596 "[ x.y = 10 ]",
6597 "[ x[y] = 10 ]",
6598 "[ { x : y = 10 } = {} ]",
6599 "[ { x : foo().y = 10 } = {} ]",
6600 "[ { x : foo()[y] = 10 } = {} ]",
6601 "[ { x : x.y = 10 } = {} ]",
6602 "[ { x : x[y] = 10 } = {} ]",
6603 "[ [ x = 10 ] = {} ]",
6604 "[ [ foo().x = 10 ] = {} ]",
6605 "[ [ foo()[x] = 10 ] = {} ]",
6606 "[ [ x.y = 10 ] = {} ]",
6607 "[ [ x[y] = 10 ] = {} ]",
6608
6609 "{ x : y }",
6610 "{ x : y = 1 }",
6611 "{ x }",
6612 "{ x, y, z }",
6613
6614 "[x]",
6615 "[x = 1]",
6616 "[x,y,z]",
6617 "[x, y = 42, z]",
6618 "{ x : x, y : y }",
6619 "{ x : x = 1, y : y }",
6620 "{ x : x, y : y = 42 }",
6621 "[]",
6622 "{}",
6623 "[{x:x, y:y}, [,x,z,]]",
6624 "[{x:x = 1, y:y = 2}, [z = 3, z = 4, z = 5]]",
6625 "[x,,y]",
6626 "[(x),,(y)]",
6627 "[(x)]",
6628 "{42 : x}",
6629 "{42 : x = 42}",
6630 "{42e-2 : x}",
6631 "{42e-2 : x = 42}",
6632 "{'hi' : x}",
6633 "{'hi' : x = 42}",
6634 "{var: x}",
6635 "{var: x = 42}",
6636 "{var: (x) = 42}",
6637 "{[x] : z}",
6638 "{[1+1] : z}",
6639 "{[1+1] : (z)}",
6640 "{[foo()] : z}",
6641 "{[foo()] : (z)}",
6642 "{[foo()] : foo().bar}",
6643 "{[foo()] : foo()['bar']}",
6644 "{[foo()] : this.bar}",
6645 "{[foo()] : this['bar']}",
6646 "{[foo()] : 'foo'.bar}",
6647 "{[foo()] : 'foo'['bar']}",
6648 "{ x: y } = z",
6649 "[x, y] = z",
6650 "{ x: y } = { z }",
6651 "[x, y] = { z }",
6652 "{ x: y } = [ z ]",
6653 "[x, y] = [ z ]",
6654 // "[((x, y) => z).x]",
6655 // "{x: ((y, z) => z).x}",
6656 // "[((x, y) => z)['x']]",
6657 // "{x: ((y, z) => z)['x']}",
6658
6659 // TODO(caitp): support CoverInitializedName in ObjectAssignmentPattern
6660 // "{ x : { y = 10 } = {} }",
6661 // "{ x = 1, y: z, z: y }",
6662 // "{x = 42, y = 15}",
6663 // "[ { x = 10 } = {} ]",
6664
6665 // TODO(caitp): figure out what broke let parsing (dehrenberg?)
6666 // "[...x]",
6667 // "[x,y,...z]",
6668 // "[x,,...z]",
6669
6670 NULL};
6671 // clang-format on
6672 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring,
6673 kAllowHarmonyArrowFunctions};
6674 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
6675 arraysize(always_flags));
6676 }
6677
6678
6679 TEST(DestructuringAssignmentNegativeTests) {
6680 const char* context_data[][2] = {
6681 {"'use strict'; let x, y, z; (", " = {});"},
6682 {"var x, y, z; (", " = {});"},
6683 {"'use strict'; let x, y, z; for (x in ", " = {});"},
6684 {"'use strict'; let x, y, z; for (x of ", " = {});"},
6685 {"var x, y, z; for (x in ", " = {});"},
6686 {"var x, y, z; for (x of ", " = {});"},
6687 {NULL, NULL}};
6688
6689 // clang-format off
6690 const char* data[] = {
6691 "{ x : ++y }",
6692 "{ x : y * 2 }",
6693 "{ ...x }",
6694 "{ get x() {} }",
6695 "{ set x() {} }",
6696 "{ x: y() }",
6697 "{ this }",
6698 "{ x: this }",
6699 "{ x: this = 1 }",
6700 "{ super }",
6701 "{ x: super }",
6702 "{ x: super = 1 }",
6703 "{ new.target }",
6704 "{ x: new.target }",
6705 "{ x: new.target = 1 }",
6706 "[x--]",
6707 "[--x = 1]",
6708 "[x()]",
6709 "[this]",
6710 "[this = 1]",
6711 "[new.target]",
6712 "[new.target = 1]",
6713 "[super]",
6714 "[super = 1]",
6715 "[function f() {}]",
6716 "[50]",
6717 "[(50)]",
6718 "[(function() {})]",
6719 "[(foo())]",
6720 "{ x: 50 }",
6721 "{ x: (50) }",
6722 "['str']",
6723 "{ x: 'str' }",
6724 "{ x: ('str') }",
6725 "{ x: (foo()) }",
6726 "{ x: (function() {}) }",
6727 "{ x: y } = 'str'",
6728 "[x, y] = 'str'",
6729 "[(x,y) => z]",
6730 "{x: (y) => z}",
6731 "[x, ...y, z]",
6732 "[...x,]",
6733 "[x, y, ...z = 1]",
6734 "[...z = 1]",
6735 NULL};
6736 // clang-format on
6737 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring,
6738 kAllowHarmonyArrowFunctions};
6739 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6740 arraysize(always_flags));
6741 }
6742
6743
6523 TEST(DestructuringDisallowPatternsInForVarIn) { 6744 TEST(DestructuringDisallowPatternsInForVarIn) {
6524 i::FLAG_harmony_destructuring = true; 6745 i::FLAG_harmony_destructuring = true;
6525 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring}; 6746 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
6526 const char* context_data[][2] = { 6747 const char* context_data[][2] = {
6527 {"", ""}, {"function f() {", "}"}, {NULL, NULL}}; 6748 {"", ""}, {"function f() {", "}"}, {NULL, NULL}};
6528 // clang-format off 6749 // clang-format off
6529 const char* error_data[] = { 6750 const char* error_data[] = {
6530 "for (let x = {} in null);", 6751 "for (let x = {} in null);",
6531 "for (let x = {} of null);", 6752 "for (let x = {} of null);",
6532 NULL}; 6753 NULL};
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
6811 "for (let x of []) {}", 7032 "for (let x of []) {}",
6812 NULL 7033 NULL
6813 }; 7034 };
6814 // clang-format on 7035 // clang-format on
6815 7036
6816 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, 7037 static const ParserFlag always_flags[] = {kAllowHarmonySloppy,
6817 kAllowHarmonySloppyLet}; 7038 kAllowHarmonySloppyLet};
6818 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, 7039 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
6819 arraysize(always_flags)); 7040 arraysize(always_flags));
6820 } 7041 }
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