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

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

Issue 477263002: ES6: Add support for method shorthand in object literals (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add strict formal param checking Created 6 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 | Annotate | Revision Log
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 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 1204
1205 1205
1206 enum ParserFlag { 1206 enum ParserFlag {
1207 kAllowLazy, 1207 kAllowLazy,
1208 kAllowNativesSyntax, 1208 kAllowNativesSyntax,
1209 kAllowHarmonyScoping, 1209 kAllowHarmonyScoping,
1210 kAllowModules, 1210 kAllowModules,
1211 kAllowGenerators, 1211 kAllowGenerators,
1212 kAllowHarmonyNumericLiterals, 1212 kAllowHarmonyNumericLiterals,
1213 kAllowArrowFunctions, 1213 kAllowArrowFunctions,
1214 kAllowClasses 1214 kAllowClasses,
1215 kAllowHarmonyObjectLiterals
1215 }; 1216 };
1216 1217
1217 1218
1218 enum ParserSyncTestResult { 1219 enum ParserSyncTestResult {
1219 kSuccessOrError, 1220 kSuccessOrError,
1220 kSuccess, 1221 kSuccess,
1221 kError 1222 kError
1222 }; 1223 };
1223 1224
1224 template <typename Traits> 1225 template <typename Traits>
1225 void SetParserFlags(i::ParserBase<Traits>* parser, 1226 void SetParserFlags(i::ParserBase<Traits>* parser,
1226 i::EnumSet<ParserFlag> flags) { 1227 i::EnumSet<ParserFlag> flags) {
1227 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1228 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1228 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); 1229 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax));
1229 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); 1230 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping));
1230 parser->set_allow_modules(flags.Contains(kAllowModules)); 1231 parser->set_allow_modules(flags.Contains(kAllowModules));
1231 parser->set_allow_generators(flags.Contains(kAllowGenerators)); 1232 parser->set_allow_generators(flags.Contains(kAllowGenerators));
1232 parser->set_allow_harmony_numeric_literals( 1233 parser->set_allow_harmony_numeric_literals(
1233 flags.Contains(kAllowHarmonyNumericLiterals)); 1234 flags.Contains(kAllowHarmonyNumericLiterals));
1235 parser->set_allow_harmony_object_literals(
1236 flags.Contains(kAllowHarmonyObjectLiterals));
1234 parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions)); 1237 parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions));
1235 parser->set_allow_classes(flags.Contains(kAllowClasses)); 1238 parser->set_allow_classes(flags.Contains(kAllowClasses));
1236 } 1239 }
1237 1240
1238 1241
1239 void TestParserSyncWithFlags(i::Handle<i::String> source, 1242 void TestParserSyncWithFlags(i::Handle<i::String> source,
1240 i::EnumSet<ParserFlag> flags, 1243 i::EnumSet<ParserFlag> flags,
1241 ParserSyncTestResult result) { 1244 ParserSyncTestResult result) {
1242 i::Isolate* isolate = CcTest::i_isolate(); 1245 i::Isolate* isolate = CcTest::i_isolate();
1243 i::Factory* factory = isolate->factory(); 1246 i::Factory* factory = isolate->factory();
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 NULL 1433 NULL
1431 }; 1434 };
1432 1435
1433 v8::HandleScope handles(CcTest::isolate()); 1436 v8::HandleScope handles(CcTest::isolate());
1434 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1437 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1435 v8::Context::Scope context_scope(context); 1438 v8::Context::Scope context_scope(context);
1436 1439
1437 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - 1440 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() -
1438 128 * 1024); 1441 128 * 1024);
1439 1442
1440 static const ParserFlag flags1[] = {kAllowLazy, kAllowHarmonyScoping, 1443 static const ParserFlag flags1[] = {
1441 kAllowModules, kAllowGenerators, 1444 kAllowLazy, kAllowHarmonyScoping,
1442 kAllowArrowFunctions}; 1445 kAllowModules, kAllowGenerators,
1446 kAllowArrowFunctions, kAllowHarmonyNumericLiterals,
1447 kAllowHarmonyObjectLiterals};
1443 for (int i = 0; context_data[i][0] != NULL; ++i) { 1448 for (int i = 0; context_data[i][0] != NULL; ++i) {
1444 for (int j = 0; statement_data[j] != NULL; ++j) { 1449 for (int j = 0; statement_data[j] != NULL; ++j) {
1445 for (int k = 0; termination_data[k] != NULL; ++k) { 1450 for (int k = 0; termination_data[k] != NULL; ++k) {
1446 int kPrefixLen = i::StrLength(context_data[i][0]); 1451 int kPrefixLen = i::StrLength(context_data[i][0]);
1447 int kStatementLen = i::StrLength(statement_data[j]); 1452 int kStatementLen = i::StrLength(statement_data[j]);
1448 int kTerminationLen = i::StrLength(termination_data[k]); 1453 int kTerminationLen = i::StrLength(termination_data[k]);
1449 int kSuffixLen = i::StrLength(context_data[i][1]); 1454 int kSuffixLen = i::StrLength(context_data[i][1]);
1450 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen 1455 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen
1451 + kSuffixLen + i::StrLength("label: for (;;) { }"); 1456 + kSuffixLen + i::StrLength("label: for (;;) { }");
1452 1457
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 const ParserFlag* always_true_flags = NULL, 1512 const ParserFlag* always_true_flags = NULL,
1508 int always_true_flags_len = 0) { 1513 int always_true_flags_len = 0) {
1509 v8::HandleScope handles(CcTest::isolate()); 1514 v8::HandleScope handles(CcTest::isolate());
1510 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1515 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1511 v8::Context::Scope context_scope(context); 1516 v8::Context::Scope context_scope(context);
1512 1517
1513 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - 1518 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() -
1514 128 * 1024); 1519 128 * 1024);
1515 1520
1516 static const ParserFlag default_flags[] = { 1521 static const ParserFlag default_flags[] = {
1517 kAllowLazy, kAllowHarmonyScoping, kAllowModules, 1522 kAllowArrowFunctions, kAllowClasses,
1518 kAllowGenerators, kAllowNativesSyntax, kAllowArrowFunctions, 1523 kAllowGenerators, kAllowHarmonyNumericLiterals,
1519 kAllowClasses}; 1524 kAllowHarmonyObjectLiterals, kAllowHarmonyScoping,
1525 kAllowLazy, kAllowModules,
1526 kAllowNativesSyntax,
1527 };
1520 ParserFlag* generated_flags = NULL; 1528 ParserFlag* generated_flags = NULL;
1521 if (flags == NULL) { 1529 if (flags == NULL) {
1522 flags = default_flags; 1530 flags = default_flags;
1523 flags_len = ARRAY_SIZE(default_flags); 1531 flags_len = ARRAY_SIZE(default_flags);
1524 if (always_true_flags != NULL) { 1532 if (always_true_flags != NULL) {
1525 // Remove always_true_flags from default_flags. 1533 // Remove always_true_flags from default_flags.
1526 CHECK(always_true_flags_len < flags_len); 1534 CHECK(always_true_flags_len < flags_len);
1527 generated_flags = new ParserFlag[flags_len - always_true_flags_len]; 1535 generated_flags = new ParserFlag[flags_len - always_true_flags_len];
1528 int flag_index = 0; 1536 int flag_index = 0;
1529 for (int i = 0; i < flags_len; ++i) { 1537 for (int i = 0; i < flags_len; ++i) {
(...skipping 1843 matching lines...) Expand 10 before | Expand all | Expand 10 after
3373 const char* statement_data[] = { 3381 const char* statement_data[] = {
3374 "super = x", 3382 "super = x",
3375 "y = super", 3383 "y = super",
3376 "f(super)", 3384 "f(super)",
3377 NULL}; 3385 NULL};
3378 3386
3379 static const ParserFlag always_flags[] = {kAllowClasses}; 3387 static const ParserFlag always_flags[] = {kAllowClasses};
3380 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, 3388 RunParserSyncTest(context_data, statement_data, kError, NULL, 0,
3381 always_flags, ARRAY_SIZE(always_flags)); 3389 always_flags, ARRAY_SIZE(always_flags));
3382 } 3390 }
3391
3392
3393 TEST(NoErrorsMethodDefinition) {
3394 const char* context_data[][2] = {{"({", "});"},
marja 2014/08/22 08:22:46 Is there a reason why you do ({ stuff }); and no
rossberg 2014/08/22 09:34:31 Yes, because then it would be a block, not an obje
3395 {NULL, NULL}};
3396
3397 const char* statement_data[] = {
rossberg 2014/08/22 09:34:31 Nit: statement_data seems like the wrong name in t
arv (Not doing code reviews) 2014/08/22 23:16:03 Done.
3398 "m() {}",
3399 "m(x) { return x; }",
3400 "m(x, y) {}, n() {}",
3401 "set(x, y) {}",
3402 "get(x, y) {}",
3403 NULL
3404 };
3405
3406 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals};
3407 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
3408 always_flags, ARRAY_SIZE(always_flags));
3409 }
3410
3411
3412 TEST(MethodDefinitionNames) {
3413 const char* context_data[][2] = {{"({", "(x, y) {}});"},
3414 {NULL, NULL}};
3415
3416 const char* statement_data[] = {
rossberg 2014/08/22 09:34:31 Nit: name_data?
arv (Not doing code reviews) 2014/08/22 23:16:03 Done.
3417 "m",
3418 "'m'",
3419 "\"m\"",
3420 "true",
3421 "false",
3422 "null",
3423 "0",
3424 "1.2",
3425 "1e1",
3426 "1E1",
3427 "1e+1",
3428 "1e-1",
3429
3430 // Keywords
3431 "async",
3432 "await",
3433 "break",
3434 "case",
3435 "catch",
3436 "class",
3437 "const",
3438 "continue",
3439 "debugger",
3440 "default",
3441 "delete",
3442 "do",
3443 "else",
3444 "enum",
3445 "export",
3446 "extends",
3447 "finally",
3448 "for",
3449 "function",
3450 "if",
3451 "implements",
3452 "import",
3453 "in",
3454 "instanceof",
3455 "interface",
3456 "let",
3457 "new",
3458 "package",
3459 "private",
3460 "protected",
3461 "public",
3462 "return",
3463 "static",
3464 "super",
3465 "switch",
3466 "this",
3467 "throw",
3468 "try",
3469 "typeof",
3470 "var",
3471 "void",
3472 "while",
3473 "with",
3474 "yield",
3475 NULL
3476 };
3477
3478 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals};
3479 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
3480 always_flags, ARRAY_SIZE(always_flags));
3481 }
3482
3483
3484 TEST(MethodDefinitionstrictFormalParamereters) {
3485 const char* context_data[][2] = {{"({method(", "){}});"},
3486 {NULL, NULL}};
3487
3488 const char* statement_data[] = {
rossberg 2014/08/22 09:34:31 Nit: parameter_data?
arv (Not doing code reviews) 2014/08/22 23:16:03 Done.
3489 "x, x",
3490 "x, y, x",
3491 "eval",
3492 "arguments",
3493 "var",
3494 "const",
3495 NULL
3496 };
3497
3498 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals};
3499 RunParserSyncTest(context_data, statement_data, kError, NULL, 0,
3500 always_flags, ARRAY_SIZE(always_flags));
3501 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698