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

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

Issue 1678303002: [es7] implement exponentiation operator proposal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase 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
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 1493 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 kAllowLazy, 1504 kAllowLazy,
1505 kAllowNatives, 1505 kAllowNatives,
1506 kAllowHarmonyDefaultParameters, 1506 kAllowHarmonyDefaultParameters,
1507 kAllowHarmonySloppy, 1507 kAllowHarmonySloppy,
1508 kAllowHarmonySloppyLet, 1508 kAllowHarmonySloppyLet,
1509 kAllowHarmonyDestructuring, 1509 kAllowHarmonyDestructuring,
1510 kAllowHarmonyDestructuringAssignment, 1510 kAllowHarmonyDestructuringAssignment,
1511 kAllowHarmonyNewTarget, 1511 kAllowHarmonyNewTarget,
1512 kAllowStrongMode, 1512 kAllowStrongMode,
1513 kNoLegacyConst, 1513 kNoLegacyConst,
1514 kAllowHarmonyFunctionSent 1514 kAllowHarmonyFunctionSent,
1515 kAllowHarmonyExponentiationOperator
1515 }; 1516 };
1516 1517
1517 enum ParserSyncTestResult { 1518 enum ParserSyncTestResult {
1518 kSuccessOrError, 1519 kSuccessOrError,
1519 kSuccess, 1520 kSuccess,
1520 kError 1521 kError
1521 }; 1522 };
1522 1523
1523 template <typename Traits> 1524 template <typename Traits>
1524 void SetParserFlags(i::ParserBase<Traits>* parser, 1525 void SetParserFlags(i::ParserBase<Traits>* parser,
1525 i::EnumSet<ParserFlag> flags) { 1526 i::EnumSet<ParserFlag> flags) {
1526 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1527 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1527 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1528 parser->set_allow_natives(flags.Contains(kAllowNatives));
1528 parser->set_allow_harmony_default_parameters( 1529 parser->set_allow_harmony_default_parameters(
1529 flags.Contains(kAllowHarmonyDefaultParameters)); 1530 flags.Contains(kAllowHarmonyDefaultParameters));
1530 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); 1531 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy));
1531 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet)); 1532 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet));
1532 parser->set_allow_harmony_destructuring_bind( 1533 parser->set_allow_harmony_destructuring_bind(
1533 flags.Contains(kAllowHarmonyDestructuring)); 1534 flags.Contains(kAllowHarmonyDestructuring));
1534 parser->set_allow_harmony_destructuring_assignment( 1535 parser->set_allow_harmony_destructuring_assignment(
1535 flags.Contains(kAllowHarmonyDestructuringAssignment)); 1536 flags.Contains(kAllowHarmonyDestructuringAssignment));
1536 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); 1537 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode));
1537 parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst)); 1538 parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst));
1538 parser->set_allow_harmony_function_sent( 1539 parser->set_allow_harmony_function_sent(
1539 flags.Contains(kAllowHarmonyFunctionSent)); 1540 flags.Contains(kAllowHarmonyFunctionSent));
1541 parser->set_allow_harmony_exponentiation_operator(
1542 flags.Contains(kAllowHarmonyExponentiationOperator));
1540 } 1543 }
1541 1544
1542 1545
1543 void TestParserSyncWithFlags(i::Handle<i::String> source, 1546 void TestParserSyncWithFlags(i::Handle<i::String> source,
1544 i::EnumSet<ParserFlag> flags, 1547 i::EnumSet<ParserFlag> flags,
1545 ParserSyncTestResult result, 1548 ParserSyncTestResult result,
1546 bool is_module = false) { 1549 bool is_module = false) {
1547 i::Isolate* isolate = CcTest::i_isolate(); 1550 i::Isolate* isolate = CcTest::i_isolate();
1548 i::Factory* factory = isolate->factory(); 1551 i::Factory* factory = isolate->factory();
1549 1552
(...skipping 6431 matching lines...) Expand 10 before | Expand all | Expand 10 after
7981 { NULL, NULL } 7984 { NULL, NULL }
7982 }; 7985 };
7983 const char* error_data[] = { 7986 const char* error_data[] = {
7984 "var x = new.target", 7987 "var x = new.target",
7985 "function f() { return new.t\\u0061rget; }", 7988 "function f() { return new.t\\u0061rget; }",
7986 NULL 7989 NULL
7987 }; 7990 };
7988 // clang-format on 7991 // clang-format on
7989 RunParserSyncTest(context_data, error_data, kError); 7992 RunParserSyncTest(context_data, error_data, kError);
7990 } 7993 }
7994
7995 TEST(ExponentiationOperator) {
7996 // clang-format off
7997 const char* context_data[][2] = {
7998 { "var O = { p: 1 }, x = 10; ; if (", ") { foo(); }" },
7999 { "var O = { p: 1 }, x = 10; ; (", ")" },
8000 { "var O = { p: 1 }, x = 10; foo(", ")" },
8001 { NULL, NULL }
8002 };
8003 const char* data[] = {
8004 "(delete O.p) ** 10",
8005 "(delete x) ** 10",
8006 "(~O.p) ** 10",
8007 "(~x) ** 10",
8008 "(!O.p) ** 10",
8009 "(!x) ** 10",
8010 "(+O.p) ** 10",
8011 "(+x) ** 10",
8012 "(-O.p) ** 10",
8013 "(-x) ** 10",
8014 "(typeof O.p) ** 10",
8015 "(typeof x) ** 10",
8016 "(void 0) ** 10",
8017 "(void O.p) ** 10",
8018 "(void x) ** 10",
8019 "++O.p ** 10",
8020 "++x ** 10",
8021 "--O.p ** 10",
8022 "--x ** 10",
8023 "O.p++ ** 10",
8024 "x++ ** 10",
8025 "O.p-- ** 10",
8026 "x-- ** 10",
8027 NULL
8028 };
8029 // clang-format on
8030
8031 static const ParserFlag always_flags[] = {
8032 kAllowHarmonyExponentiationOperator};
8033 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
8034 arraysize(always_flags));
8035 }
8036
8037 TEST(ExponentiationOperatorErrors) {
8038 // clang-format off
8039 const char* context_data[][2] = {
8040 { "var O = { p: 1 }, x = 10; ; if (", ") { foo(); }" },
8041 { "var O = { p: 1 }, x = 10; ; (", ")" },
8042 { "var O = { p: 1 }, x = 10; foo(", ")" },
8043 { NULL, NULL }
8044 };
8045 const char* error_data[] = {
8046 "delete O.p ** 10",
8047 "delete x ** 10",
8048 "~O.p ** 10",
8049 "~x ** 10",
8050 "!O.p ** 10",
8051 "!x ** 10",
8052 "+O.p ** 10",
8053 "+x ** 10",
8054 "-O.p ** 10",
8055 "-x ** 10",
8056 "typeof O.p ** 10",
8057 "typeof x ** 10",
8058 "void ** 10",
8059 "void O.p ** 10",
8060 "void x ** 10",
8061 "++delete O.p ** 10",
8062 "--delete O.p ** 10",
8063 "++~O.p ** 10",
8064 "++~x ** 10",
8065 "--!O.p ** 10",
8066 "--!x ** 10",
8067 "++-O.p ** 10",
8068 "++-x ** 10",
8069 "--+O.p ** 10",
8070 "--+x ** 10",
8071 NULL
8072 };
8073 // clang-format on
8074
8075 static const ParserFlag always_flags[] = {
8076 kAllowHarmonyExponentiationOperator};
8077 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
8078 arraysize(always_flags));
8079 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698