OLD | NEW |
---|---|
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 1491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1502 | 1502 |
1503 enum ParserFlag { | 1503 enum ParserFlag { |
1504 kAllowLazy, | 1504 kAllowLazy, |
1505 kAllowNatives, | 1505 kAllowNatives, |
1506 kAllowHarmonySloppy, | 1506 kAllowHarmonySloppy, |
1507 kAllowHarmonySloppyLet, | 1507 kAllowHarmonySloppyLet, |
1508 kAllowHarmonyNewTarget, | 1508 kAllowHarmonyNewTarget, |
1509 kNoLegacyConst, | 1509 kNoLegacyConst, |
1510 kAllowHarmonyFunctionSent, | 1510 kAllowHarmonyFunctionSent, |
1511 kAllowHarmonyRestrictiveDeclarations, | 1511 kAllowHarmonyRestrictiveDeclarations, |
1512 kAllowHarmonyExponentiationOperator | |
1512 }; | 1513 }; |
1513 | 1514 |
1514 enum ParserSyncTestResult { | 1515 enum ParserSyncTestResult { |
1515 kSuccessOrError, | 1516 kSuccessOrError, |
1516 kSuccess, | 1517 kSuccess, |
1517 kError | 1518 kError |
1518 }; | 1519 }; |
1519 | 1520 |
1520 template <typename Traits> | 1521 template <typename Traits> |
1521 void SetParserFlags(i::ParserBase<Traits>* parser, | 1522 void SetParserFlags(i::ParserBase<Traits>* parser, |
1522 i::EnumSet<ParserFlag> flags) { | 1523 i::EnumSet<ParserFlag> flags) { |
1523 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1524 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
1524 parser->set_allow_natives(flags.Contains(kAllowNatives)); | 1525 parser->set_allow_natives(flags.Contains(kAllowNatives)); |
1525 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); | 1526 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); |
1526 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet)); | 1527 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet)); |
1527 parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst)); | 1528 parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst)); |
1528 parser->set_allow_harmony_function_sent( | 1529 parser->set_allow_harmony_function_sent( |
1529 flags.Contains(kAllowHarmonyFunctionSent)); | 1530 flags.Contains(kAllowHarmonyFunctionSent)); |
1530 parser->set_allow_harmony_restrictive_declarations( | 1531 parser->set_allow_harmony_restrictive_declarations( |
1531 flags.Contains(kAllowHarmonyRestrictiveDeclarations)); | 1532 flags.Contains(kAllowHarmonyRestrictiveDeclarations)); |
1533 parser->set_allow_harmony_exponentiation_operator( | |
1534 flags.Contains(kAllowHarmonyExponentiationOperator)); | |
1532 } | 1535 } |
1533 | 1536 |
1534 | 1537 |
1535 void TestParserSyncWithFlags(i::Handle<i::String> source, | 1538 void TestParserSyncWithFlags(i::Handle<i::String> source, |
1536 i::EnumSet<ParserFlag> flags, | 1539 i::EnumSet<ParserFlag> flags, |
1537 ParserSyncTestResult result, | 1540 ParserSyncTestResult result, |
1538 bool is_module = false) { | 1541 bool is_module = false) { |
1539 i::Isolate* isolate = CcTest::i_isolate(); | 1542 i::Isolate* isolate = CcTest::i_isolate(); |
1540 i::Factory* factory = isolate->factory(); | 1543 i::Factory* factory = isolate->factory(); |
1541 | 1544 |
(...skipping 5752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7294 RunParserSyncTest(sloppy_context, error_data, kError); | 7297 RunParserSyncTest(sloppy_context, error_data, kError); |
7295 RunParserSyncTest(sloppy_context, error_data, kError, NULL, 0, | 7298 RunParserSyncTest(sloppy_context, error_data, kError, NULL, 0, |
7296 restrictive_flags, arraysize(restrictive_flags)); | 7299 restrictive_flags, arraysize(restrictive_flags)); |
7297 RunParserSyncTest(sloppy_context, unrestricted_data, kSuccess); | 7300 RunParserSyncTest(sloppy_context, unrestricted_data, kSuccess); |
7298 RunParserSyncTest(sloppy_context, unrestricted_data, kError, NULL, 0, | 7301 RunParserSyncTest(sloppy_context, unrestricted_data, kError, NULL, 0, |
7299 restrictive_flags, arraysize(restrictive_flags)); | 7302 restrictive_flags, arraysize(restrictive_flags)); |
7300 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess); | 7303 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess); |
7301 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess, restrictive_flags, | 7304 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess, restrictive_flags, |
7302 arraysize(restrictive_flags)); | 7305 arraysize(restrictive_flags)); |
7303 } | 7306 } |
7307 | |
7308 TEST(ExponentiationOperator) { | |
7309 // clang-format off | |
7310 const char* context_data[][2] = { | |
7311 { "var O = { p: 1 }, x = 10; ; if (", ") { foo(); }" }, | |
7312 { "var O = { p: 1 }, x = 10; ; (", ")" }, | |
7313 { "var O = { p: 1 }, x = 10; foo(", ")" }, | |
7314 { NULL, NULL } | |
7315 }; | |
7316 const char* data[] = { | |
7317 "(delete O.p) ** 10", | |
7318 "(delete x) ** 10", | |
7319 "(~O.p) ** 10", | |
7320 "(~x) ** 10", | |
7321 "(!O.p) ** 10", | |
7322 "(!x) ** 10", | |
7323 "(+O.p) ** 10", | |
7324 "(+x) ** 10", | |
7325 "(-O.p) ** 10", | |
7326 "(-x) ** 10", | |
7327 "(typeof O.p) ** 10", | |
7328 "(typeof x) ** 10", | |
7329 "(void 0) ** 10", | |
7330 "(void O.p) ** 10", | |
7331 "(void x) ** 10", | |
7332 "++O.p ** 10", | |
7333 "++x ** 10", | |
7334 "--O.p ** 10", | |
7335 "--x ** 10", | |
7336 "O.p++ ** 10", | |
7337 "x++ ** 10", | |
7338 "O.p-- ** 10", | |
7339 "x-- ** 10", | |
7340 NULL | |
7341 }; | |
7342 // clang-format on | |
7343 | |
7344 static const ParserFlag always_flags[] = { | |
7345 kAllowHarmonyExponentiationOperator}; | |
7346 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | |
7347 arraysize(always_flags)); | |
7348 } | |
7349 | |
7350 TEST(ExponentiationOperatorErrors) { | |
7351 // clang-format off | |
7352 const char* context_data[][2] = { | |
7353 { "var O = { p: 1 }, x = 10; ; if (", ") { foo(); }" }, | |
7354 { "var O = { p: 1 }, x = 10; ; (", ")" }, | |
7355 { "var O = { p: 1 }, x = 10; foo(", ")" }, | |
7356 { NULL, NULL } | |
7357 }; | |
7358 const char* error_data[] = { | |
7359 "delete O.p ** 10", | |
7360 "delete x ** 10", | |
7361 "~O.p ** 10", | |
7362 "~x ** 10", | |
7363 "!O.p ** 10", | |
7364 "!x ** 10", | |
7365 "+O.p ** 10", | |
7366 "+x ** 10", | |
7367 "-O.p ** 10", | |
7368 "-x ** 10", | |
7369 "typeof O.p ** 10", | |
7370 "typeof x ** 10", | |
7371 "void ** 10", | |
7372 "void O.p ** 10", | |
7373 "void x ** 10", | |
7374 "++delete O.p ** 10", | |
7375 "--delete O.p ** 10", | |
7376 "++~O.p ** 10", | |
7377 "++~x ** 10", | |
7378 "--!O.p ** 10", | |
7379 "--!x ** 10", | |
7380 "++-O.p ** 10", | |
7381 "++-x ** 10", | |
7382 "--+O.p ** 10", | |
7383 "--+x ** 10", | |
Dan Ehrenberg
2016/03/14 20:48:46
Could you add parsing tests for **=, including in
caitp (gmail)
2016/03/14 21:05:14
Done.
| |
7384 NULL | |
7385 }; | |
7386 // clang-format on | |
7387 | |
7388 static const ParserFlag always_flags[] = { | |
7389 kAllowHarmonyExponentiationOperator}; | |
7390 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, | |
7391 arraysize(always_flags)); | |
7392 } | |
OLD | NEW |