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

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: 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] = {{"({", "});"},
3395 {NULL, NULL}};
3396
3397 const char* object_literal_data[] = {
rossberg 2014/08/25 09:39:30 Hm, well, it's not really object literals in there
arv (Not doing code reviews) 2014/09/09 22:24:27 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, object_literal_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 {"'use strict'; ({", "(x, y) {}});"},
rossberg 2014/08/25 09:39:30 Good idea, you should probably add that to your ot
arv (Not doing code reviews) 2014/09/09 22:24:27 Done.
3415 {NULL, NULL}};
3416
3417 const char* name_data[] = {
3418 "m",
3419 "'m'",
3420 "\"m\"",
3421 "\"m n\"",
3422 "true",
3423 "false",
3424 "null",
3425 "0",
3426 "1.2",
3427 "1e1",
3428 "1E1",
3429 "1e+1",
3430 "1e-1",
3431
3432 // Keywords
3433 "async",
3434 "await",
3435 "break",
3436 "case",
3437 "catch",
3438 "class",
3439 "const",
3440 "continue",
3441 "debugger",
3442 "default",
3443 "delete",
3444 "do",
3445 "else",
3446 "enum",
3447 "export",
3448 "extends",
3449 "finally",
3450 "for",
3451 "function",
3452 "if",
3453 "implements",
3454 "import",
3455 "in",
3456 "instanceof",
3457 "interface",
3458 "let",
3459 "new",
3460 "package",
3461 "private",
3462 "protected",
3463 "public",
3464 "return",
3465 "static",
3466 "super",
3467 "switch",
3468 "this",
3469 "throw",
3470 "try",
3471 "typeof",
3472 "var",
3473 "void",
3474 "while",
3475 "with",
3476 "yield",
3477 NULL
3478 };
3479
3480 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals};
3481 RunParserSyncTest(context_data, name_data, kSuccess, NULL, 0,
3482 always_flags, ARRAY_SIZE(always_flags));
3483 }
3484
3485
3486 TEST(MethodDefinitionStrictFormalParamereters) {
3487 const char* context_data[][2] = {{"({method(", "){}});"},
3488 {NULL, NULL}};
3489
3490 const char* params_data[] = {
3491 "x, x",
3492 "x, y, x",
3493 "eval",
3494 "arguments",
3495 "var",
3496 "const",
3497 NULL
3498 };
3499
3500 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals};
3501 RunParserSyncTest(context_data, params_data, kError, NULL, 0,
3502 always_flags, ARRAY_SIZE(always_flags));
3503 }
3504
3505
3506 TEST(MethodDefinitionDuplicateProperty) {
3507 // Duplicate properties are allowed in ES6 but we haven't removed that check
3508 // yet.
3509 const char* context_data[][2] = {{"'use strict'; ({", "});"},
3510 {NULL, NULL}};
3511
3512 const char* params_data[] = {
3513 "x: 1, x() {}",
3514 "x() {}, x: 1",
3515 "x() {}, get x() {}",
3516 "x() {}, set x(_) {}",
3517 "x() {}, x() {}",
3518 "x() {}, y() {}, x() {}",
3519 "x() {}, \"x\"() {}",
3520 "x() {}, 'x'() {}",
3521 "0() {}, '0'() {}",
3522 "1.0() {}, 1: 1",
3523 NULL
3524 };
3525
3526 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals};
3527 RunParserSyncTest(context_data, params_data, kError, NULL, 0,
3528 always_flags, ARRAY_SIZE(always_flags));
3529 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698