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

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

Issue 1841543003: [esnext] implement frontend changes for async/await proposal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase over generator change cl Created 4 years, 8 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
« src/parsing/parser.cc ('K') | « src/parsing/scanner.cc ('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 1490 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 data.Dispose(); 1501 data.Dispose();
1502 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); 1502 return i::MessageTemplate::FormatMessage(isolate, message, arg_object);
1503 } 1503 }
1504 1504
1505 enum ParserFlag { 1505 enum ParserFlag {
1506 kAllowLazy, 1506 kAllowLazy,
1507 kAllowNatives, 1507 kAllowNatives,
1508 kAllowHarmonyNewTarget, 1508 kAllowHarmonyNewTarget,
1509 kAllowHarmonyFunctionSent, 1509 kAllowHarmonyFunctionSent,
1510 kAllowHarmonyRestrictiveDeclarations, 1510 kAllowHarmonyRestrictiveDeclarations,
1511 kAllowHarmonyExponentiationOperator 1511 kAllowHarmonyExponentiationOperator,
1512 kAllowHarmonyAsyncAwait
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_function_sent( 1526 parser->set_allow_harmony_function_sent(
1526 flags.Contains(kAllowHarmonyFunctionSent)); 1527 flags.Contains(kAllowHarmonyFunctionSent));
1527 parser->set_allow_harmony_restrictive_declarations( 1528 parser->set_allow_harmony_restrictive_declarations(
1528 flags.Contains(kAllowHarmonyRestrictiveDeclarations)); 1529 flags.Contains(kAllowHarmonyRestrictiveDeclarations));
1529 parser->set_allow_harmony_exponentiation_operator( 1530 parser->set_allow_harmony_exponentiation_operator(
1530 flags.Contains(kAllowHarmonyExponentiationOperator)); 1531 flags.Contains(kAllowHarmonyExponentiationOperator));
1532 parser->set_allow_harmony_async_await(
1533 flags.Contains(kAllowHarmonyAsyncAwait));
1531 } 1534 }
1532 1535
1533 1536
1534 void TestParserSyncWithFlags(i::Handle<i::String> source, 1537 void TestParserSyncWithFlags(i::Handle<i::String> source,
1535 i::EnumSet<ParserFlag> flags, 1538 i::EnumSet<ParserFlag> flags,
1536 ParserSyncTestResult result, 1539 ParserSyncTestResult result,
1537 bool is_module = false) { 1540 bool is_module = false) {
1538 i::Isolate* isolate = CcTest::i_isolate(); 1541 i::Isolate* isolate = CcTest::i_isolate();
1539 i::Factory* factory = isolate->factory(); 1542 i::Factory* factory = isolate->factory();
1540 1543
(...skipping 5682 matching lines...) Expand 10 before | Expand all | Expand 10 after
7223 // "Array() **= 10", 7226 // "Array() **= 10",
7224 NULL 7227 NULL
7225 }; 7228 };
7226 // clang-format on 7229 // clang-format on
7227 7230
7228 static const ParserFlag always_flags[] = { 7231 static const ParserFlag always_flags[] = {
7229 kAllowHarmonyExponentiationOperator}; 7232 kAllowHarmonyExponentiationOperator};
7230 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, 7233 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
7231 arraysize(always_flags)); 7234 arraysize(always_flags));
7232 } 7235 }
7236
7237
7238 TEST(AsyncAwait) {
7239 // clang-format off
7240 const char* context_data[][2] = {
7241 { "'use strict';", "" },
7242 { "", "" },
7243 { NULL, NULL }
7244 };
7245
7246 const char* data[] = {
7247 "var asyncFn = async function() {};",
7248 "var asyncFn = async function withName() {};",
7249 "var asyncFn = async () => 'test';",
7250 "var asyncFn = async x => x + 'test';",
7251 "async function asyncFn() {}",
7252 "var O = { async method() {} }",
7253 "var O = { async ['meth' + 'od']() {} }",
7254 "var O = { async 'method'() {} }",
7255 "var O = { async 0() {} }",
7256 "var async\nfunction await() {}",
7257 NULL
7258 };
7259 // clang-format on
7260
7261 static const ParserFlag always_flags[] = { kAllowHarmonyAsyncAwait };
7262 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
7263 arraysize(always_flags));
7264 }
7265
7266
7267 TEST(AsyncAwaitErrors) {
7268 // clang-format off
7269 const char* context_data[][2] = {
7270 { "'use strict';", "" },
7271 { "", "" },
7272 { NULL, NULL }
7273 };
7274
7275 const char* strict_context_data[][2] = {
7276 { "'use strict';", "" },
7277 { NULL, NULL }
7278 };
7279
7280 const char* error_data[] = {
7281 "var asyncFn = async function() { var await = 1; };",
7282 "var asyncFn = async function() { var { await } = 1; };",
7283 "var asyncFn = async function() { var [ await ] = 1; };",
7284 "var asyncFn = async function await() {};",
7285 "var asyncFn = async () => var await = 'test';",
7286 "var asyncFn = async await => await + 'test';",
7287 "var asyncFn = async function(await) {};",
7288 "var asyncFn = async function() { return async (await) => {}; }",
7289 "var asyncFn = async (await) => 'test';",
7290 "var asyncFn = async x => { var await = 1; }",
7291 "var asyncFn = async x => { var { await } = 1; }",
7292 "var asyncFn = async x => { var [ await ] = 1; }",
7293 "async function f(await) {}",
7294 "async function f() { var await = 1; }",
7295 "async function f() { var { await } = 1; }",
7296 "async function f() { var [ await ] = 1; }",
7297
7298 "var O = { async method(a, a) {} }",
7299 "var O = { async ['meth' + 'od'](a, a) {} }",
7300 "var O = { async 'method'(a, a) {} }",
7301 "var O = { async 0(a, a) {} }",
7302
7303 "async function f() { var O = { async [await](a, a) {} } }",
7304 NULL
7305 };
7306
7307 const char* strict_error_data[] = {
7308 "var O = { async method(eval) {} }",
7309 "var O = { async ['meth' + 'od'](eval) {} }",
7310 "var O = { async 'method'(eval) {} }",
7311 "var O = { async 0(eval) {} }",
7312
7313 "var O = { async method(arguments) {} }",
7314 "var O = { async ['meth' + 'od'](arguments) {} }",
7315 "var O = { async 'method'(arguments) {} }",
7316 "var O = { async 0(arguments) {} }",
7317 NULL
7318 };
7319 // clang-format on
7320
7321 static const ParserFlag always_flags[] = { kAllowHarmonyAsyncAwait };
7322 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
7323 arraysize(always_flags));
7324 RunParserSyncTest(strict_context_data, strict_error_data, kError, NULL, 0,
7325 always_flags, arraysize(always_flags));
7326 }
OLDNEW
« src/parsing/parser.cc ('K') | « src/parsing/scanner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698