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

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

Issue 1696603002: Remove AssignmentExpressionFlags enum, handle error checking in callers (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Eliminate early return Created 4 years, 10 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/parsing/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 6694 matching lines...) Expand 10 before | Expand all | Expand 10 after
6705 CHECK(try_catch2.HasCaught()); 6705 CHECK(try_catch2.HasCaught());
6706 v8::String::Utf8Value exception(try_catch2.Exception()); 6706 v8::String::Utf8Value exception(try_catch2.Exception());
6707 CHECK_EQ(0, 6707 CHECK_EQ(0,
6708 strcmp( 6708 strcmp(
6709 "ReferenceError: In strong mode, using an undeclared global " 6709 "ReferenceError: In strong mode, using an undeclared global "
6710 "variable 'not_there3' is not allowed", 6710 "variable 'not_there3' is not allowed",
6711 *exception)); 6711 *exception));
6712 } 6712 }
6713 } 6713 }
6714 6714
6715 static const ParserFlag kAllDestructuringFlags[] = {
6716 kAllowHarmonyDestructuring, kAllowHarmonyDestructuringAssignment,
6717 kAllowHarmonyDefaultParameters};
6715 6718
6716 TEST(DestructuringPositiveTests) { 6719 TEST(DestructuringPositiveTests) {
6717 i::FLAG_harmony_destructuring_bind = true; 6720 i::FLAG_harmony_destructuring_bind = true;
6718 6721
6719 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6722 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6720 {"var ", " = {};"}, 6723 {"var ", " = {};"},
6721 {"'use strict'; const ", " = {};"}, 6724 {"'use strict'; const ", " = {};"},
6722 {"function f(", ") {}"}, 6725 {"function f(", ") {}"},
6723 {"function f(argument1, ", ") {}"}, 6726 {"function f(argument1, ", ") {}"},
6724 {"var f = (", ") => {};"}, 6727 {"var f = (", ") => {};"},
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
6762 "{[foo()] : z}", 6765 "{[foo()] : z}",
6763 "{}", 6766 "{}",
6764 "[...rest]", 6767 "[...rest]",
6765 "[a,b,...rest]", 6768 "[a,b,...rest]",
6766 "[a,,...rest]", 6769 "[a,,...rest]",
6767 NULL}; 6770 NULL};
6768 // clang-format on 6771 // clang-format on
6769 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring}; 6772 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
6770 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, 6773 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
6771 arraysize(always_flags)); 6774 arraysize(always_flags));
6775 RunParserSyncTest(context_data, data, kSuccess, NULL, 0,
6776 kAllDestructuringFlags, arraysize(kAllDestructuringFlags));
6772 } 6777 }
6773 6778
6774 6779
6775 TEST(DestructuringNegativeTests) { 6780 TEST(DestructuringNegativeTests) {
6776 i::FLAG_harmony_destructuring_bind = true; 6781 i::FLAG_harmony_destructuring_bind = true;
6777 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring}; 6782 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
6778 6783
6779 { // All modes. 6784 { // All modes.
6780 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6785 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6781 {"var ", " = {};"}, 6786 {"var ", " = {};"},
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
6839 "{[1+1]}", 6844 "{[1+1]}",
6840 "[...rest, x]", 6845 "[...rest, x]",
6841 "[a,b,...rest, x]", 6846 "[a,b,...rest, x]",
6842 "[a,,...rest, x]", 6847 "[a,,...rest, x]",
6843 "[...rest,]", 6848 "[...rest,]",
6844 "[a,b,...rest,]", 6849 "[a,b,...rest,]",
6845 "[a,,...rest,]", 6850 "[a,,...rest,]",
6846 "[...rest,...rest1]", 6851 "[...rest,...rest1]",
6847 "[a,b,...rest,...rest1]", 6852 "[a,b,...rest,...rest1]",
6848 "[a,,..rest,...rest1]", 6853 "[a,,..rest,...rest1]",
6854 "[x, y, ...z = 1]",
6855 "[...z = 1]",
6856 "[x, y, ...[z] = [1]]",
6857 "[...[z] = [1]]",
6849 "{ x : 3 }", 6858 "{ x : 3 }",
6850 "{ x : 'foo' }", 6859 "{ x : 'foo' }",
6851 "{ x : /foo/ }", 6860 "{ x : /foo/ }",
6852 "{ x : `foo` }", 6861 "{ x : `foo` }",
6853 "{ get a() {} }", 6862 "{ get a() {} }",
6854 "{ set a() {} }", 6863 "{ set a() {} }",
6855 "{ method() {} }", 6864 "{ method() {} }",
6856 "{ *method() {} }", 6865 "{ *method() {} }",
6857 NULL}; 6866 NULL};
6858 // clang-format on 6867 // clang-format on
6859 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 6868 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6860 arraysize(always_flags)); 6869 arraysize(always_flags));
6870 RunParserSyncTest(context_data, data, kError, NULL, 0,
6871 kAllDestructuringFlags,
6872 arraysize(kAllDestructuringFlags));
6861 } 6873 }
6862 6874
6863 { // All modes. 6875 { // All modes.
6864 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6876 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6865 {"var ", " = {};"}, 6877 {"var ", " = {};"},
6866 {"'use strict'; const ", " = {};"}, 6878 {"'use strict'; const ", " = {};"},
6867 {"function f(", ") {}"}, 6879 {"function f(", ") {}"},
6868 {"function f(argument1, ", ") {}"}, 6880 {"function f(argument1, ", ") {}"},
6869 {"var f = (", ") => {};"}, 6881 {"var f = (", ") => {};"},
6870 {"var f = (argument1,", ") => {};"}, 6882 {"var f = (argument1,", ") => {};"},
6871 {NULL, NULL}}; 6883 {NULL, NULL}};
6872 6884
6873 // clang-format off 6885 // clang-format off
6874 const char* data[] = { 6886 const char* data[] = {
6875 "x => x", 6887 "x => x",
6876 "() => x", 6888 "() => x",
6877 NULL}; 6889 NULL};
6878 // clang-format on 6890 // clang-format on
6879 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 6891 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6880 arraysize(always_flags)); 6892 arraysize(always_flags));
6893 RunParserSyncTest(context_data, data, kError, NULL, 0,
6894 kAllDestructuringFlags,
6895 arraysize(kAllDestructuringFlags));
6881 } 6896 }
6882 6897
6883 { // Strict mode. 6898 { // Strict mode.
6884 const char* context_data[][2] = { 6899 const char* context_data[][2] = {
6885 {"'use strict'; let ", " = {};"}, 6900 {"'use strict'; let ", " = {};"},
6886 {"'use strict'; const ", " = {};"}, 6901 {"'use strict'; const ", " = {};"},
6887 {"'use strict'; function f(", ") {}"}, 6902 {"'use strict'; function f(", ") {}"},
6888 {"'use strict'; function f(argument1, ", ") {}"}, 6903 {"'use strict'; function f(argument1, ", ") {}"},
6889 {NULL, NULL}}; 6904 {NULL, NULL}};
6890 6905
6891 // clang-format off 6906 // clang-format off
6892 const char* data[] = { 6907 const char* data[] = {
6893 "[eval]", 6908 "[eval]",
6894 "{ a : arguments }", 6909 "{ a : arguments }",
6895 "[public]", 6910 "[public]",
6896 "{ x : private }", 6911 "{ x : private }",
6897 NULL}; 6912 NULL};
6898 // clang-format on 6913 // clang-format on
6899 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 6914 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6900 arraysize(always_flags)); 6915 arraysize(always_flags));
6916 RunParserSyncTest(context_data, data, kError, NULL, 0,
6917 kAllDestructuringFlags,
6918 arraysize(kAllDestructuringFlags));
6901 } 6919 }
6902 6920
6903 { // 'yield' in generators. 6921 { // 'yield' in generators.
6904 const char* context_data[][2] = { 6922 const char* context_data[][2] = {
6905 {"function*() { var ", " = {};"}, 6923 {"function*() { var ", " = {};"},
6906 {"function*() { 'use strict'; let ", " = {};"}, 6924 {"function*() { 'use strict'; let ", " = {};"},
6907 {"function*() { 'use strict'; const ", " = {};"}, 6925 {"function*() { 'use strict'; const ", " = {};"},
6908 {NULL, NULL}}; 6926 {NULL, NULL}};
6909 6927
6910 // clang-format off 6928 // clang-format off
6911 const char* data[] = { 6929 const char* data[] = {
6912 "yield", 6930 "yield",
6913 "[yield]", 6931 "[yield]",
6914 "{ x : yield }", 6932 "{ x : yield }",
6915 NULL}; 6933 NULL};
6916 // clang-format on 6934 // clang-format on
6917 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 6935 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6918 arraysize(always_flags)); 6936 arraysize(always_flags));
6937 RunParserSyncTest(context_data, data, kError, NULL, 0,
6938 kAllDestructuringFlags,
6939 arraysize(kAllDestructuringFlags));
6919 } 6940 }
6920 6941
6921 { // Declaration-specific errors 6942 { // Declaration-specific errors
6922 const char* context_data[][2] = {{"'use strict'; var ", ""}, 6943 const char* context_data[][2] = {{"'use strict'; var ", ""},
6923 {"'use strict'; let ", ""}, 6944 {"'use strict'; let ", ""},
6924 {"'use strict'; const ", ""}, 6945 {"'use strict'; const ", ""},
6925 {"'use strict'; for (var ", ";;) {}"}, 6946 {"'use strict'; for (var ", ";;) {}"},
6926 {"'use strict'; for (let ", ";;) {}"}, 6947 {"'use strict'; for (let ", ";;) {}"},
6927 {"'use strict'; for (const ", ";;) {}"}, 6948 {"'use strict'; for (const ", ";;) {}"},
6928 {"var ", ""}, 6949 {"var ", ""},
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
7195 "{ x: (foo()) }", 7216 "{ x: (foo()) }",
7196 "{ x: (function() {}) }", 7217 "{ x: (function() {}) }",
7197 "{ x: y } = 'str'", 7218 "{ x: y } = 'str'",
7198 "[x, y] = 'str'", 7219 "[x, y] = 'str'",
7199 "[(x,y) => z]", 7220 "[(x,y) => z]",
7200 "{x: (y) => z}", 7221 "{x: (y) => z}",
7201 "[x, ...y, z]", 7222 "[x, ...y, z]",
7202 "[...x,]", 7223 "[...x,]",
7203 "[x, y, ...z = 1]", 7224 "[x, y, ...z = 1]",
7204 "[...z = 1]", 7225 "[...z = 1]",
7226 "[x, y, ...[z] = [1]]",
7227 "[...[z] = [1]]",
7205 7228
7206 // v8:4657 7229 // v8:4657
7207 "({ x: x4, x: (x+=1e4) })", 7230 "({ x: x4, x: (x+=1e4) })",
7208 "(({ x: x4, x: (x+=1e4) }))", 7231 "(({ x: x4, x: (x+=1e4) }))",
7209 "({ x: x4, x: (x+=1e4) } = {})", 7232 "({ x: x4, x: (x+=1e4) } = {})",
7210 "(({ x: x4, x: (x+=1e4) } = {}))", 7233 "(({ x: x4, x: (x+=1e4) } = {}))",
7211 "(({ x: x4, x: (x+=1e4) }) = {})", 7234 "(({ x: x4, x: (x+=1e4) }) = {})",
7212 "({ x: y } = {})", 7235 "({ x: y } = {})",
7213 "(({ x: y } = {}))", 7236 "(({ x: y } = {}))",
7214 "(({ x: y }) = {})", 7237 "(({ x: y }) = {})",
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
7445 7468
7446 "x=(yield)", 7469 "x=(yield)",
7447 "x, y=(yield)", 7470 "x, y=(yield)",
7448 "{x=(yield)}", 7471 "{x=(yield)}",
7449 "[x=(yield)]", 7472 "[x=(yield)]",
7450 7473
7451 "x=f(yield)", 7474 "x=f(yield)",
7452 "x, y=f(yield)", 7475 "x, y=f(yield)",
7453 "{x=f(yield)}", 7476 "{x=f(yield)}",
7454 "[x=f(yield)]", 7477 "[x=f(yield)]",
7455 NULL
7456 };
7457 7478
7458 // TODO(wingo): These aren't really destructuring assignment patterns; we're
7459 // just splitting them for now until the parser gets support for arrow
7460 // function arguments that look like destructuring assignments. When that
7461 // happens we should unify destructuring_assignment_data and parameter_data.
7462 const char* destructuring_assignment_data[] = {
7463 "{x}=yield", 7479 "{x}=yield",
7464 "[x]=yield", 7480 "[x]=yield",
7465 7481
7466 "{x}=(yield)", 7482 "{x}=(yield)",
7467 "[x]=(yield)", 7483 "[x]=(yield)",
7468 7484
7469 "{x}=f(yield)", 7485 "{x}=f(yield)",
7470 "[x]=f(yield)", 7486 "[x]=f(yield)",
7471 NULL 7487 NULL
7472 }; 7488 };
7473 7489
7474 // clang-format on 7490 // clang-format on
7475 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring, 7491 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring,
7476 kAllowHarmonyDefaultParameters, 7492 kAllowHarmonyDefaultParameters,
7477 kAllowStrongMode}; 7493 kAllowStrongMode};
7478 7494
7479 RunParserSyncTest(sloppy_function_context_data, parameter_data, kSuccess, 7495 RunParserSyncTest(sloppy_function_context_data, parameter_data, kSuccess,
7480 NULL, 0, always_flags, arraysize(always_flags)); 7496 NULL, 0, always_flags, arraysize(always_flags));
7481 RunParserSyncTest(sloppy_function_context_data, destructuring_assignment_data,
7482 kSuccess, NULL, 0, always_flags, arraysize(always_flags));
7483 RunParserSyncTest(sloppy_arrow_context_data, parameter_data, kSuccess, NULL, 7497 RunParserSyncTest(sloppy_arrow_context_data, parameter_data, kSuccess, NULL,
7484 0, always_flags, arraysize(always_flags)); 7498 0, always_flags, arraysize(always_flags));
7485 RunParserSyncTest(sloppy_arrow_context_data, destructuring_assignment_data,
7486 kSuccess, NULL, 0, always_flags, arraysize(always_flags));
7487 7499
7488 RunParserSyncTest(strict_function_context_data, parameter_data, kError, NULL, 7500 RunParserSyncTest(strict_function_context_data, parameter_data, kError, NULL,
7489 0, always_flags, arraysize(always_flags)); 7501 0, always_flags, arraysize(always_flags));
7490 RunParserSyncTest(strict_function_context_data, destructuring_assignment_data,
7491 kError, NULL, 0, always_flags, arraysize(always_flags));
7492 RunParserSyncTest(strict_arrow_context_data, parameter_data, kError, NULL, 0, 7502 RunParserSyncTest(strict_arrow_context_data, parameter_data, kError, NULL, 0,
7493 always_flags, arraysize(always_flags)); 7503 always_flags, arraysize(always_flags));
7494 RunParserSyncTest(strict_arrow_context_data, destructuring_assignment_data,
7495 kError, NULL, 0, always_flags, arraysize(always_flags));
7496 7504
7497 RunParserSyncTest(generator_context_data, parameter_data, kError, NULL, 0, 7505 RunParserSyncTest(generator_context_data, parameter_data, kError, NULL, 0,
7498 always_flags, arraysize(always_flags)); 7506 always_flags, arraysize(always_flags));
7499 RunParserSyncTest(generator_context_data, destructuring_assignment_data,
7500 kError, NULL, 0, always_flags, arraysize(always_flags));
7501 } 7507 }
7502 7508
7503 7509
7504 TEST(SpreadArray) { 7510 TEST(SpreadArray) {
7505 const char* context_data[][2] = { 7511 const char* context_data[][2] = {
7506 {"'use strict';", ""}, {"", ""}, {NULL, NULL}}; 7512 {"'use strict';", ""}, {"", ""}, {NULL, NULL}};
7507 7513
7508 // clang-format off 7514 // clang-format off
7509 const char* data[] = { 7515 const char* data[] = {
7510 "[...a]", 7516 "[...a]",
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
7994 "for (();;) {}", 8000 "for (();;) {}",
7995 8001
7996 // crbug.com/582626 8002 // crbug.com/582626
7997 "{ NaN ,chA((evarA=new t ( l = !.0[((... co -a0([1]))=> greturnkf", 8003 "{ NaN ,chA((evarA=new t ( l = !.0[((... co -a0([1]))=> greturnkf",
7998 NULL 8004 NULL
7999 }; 8005 };
8000 // clang-format on 8006 // clang-format on
8001 8007
8002 RunParserSyncTest(context_data, error_data, kError, NULL, 0, NULL, 0); 8008 RunParserSyncTest(context_data, error_data, kError, NULL, 0, NULL, 0);
8003 } 8009 }
OLDNEW
« no previous file with comments | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698