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

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 1855 matching lines...) Expand 10 before | Expand all | Expand 10 after
3385 const char* statement_data[] = { 3393 const char* statement_data[] = {
3386 "super = x", 3394 "super = x",
3387 "y = super", 3395 "y = super",
3388 "f(super)", 3396 "f(super)",
3389 NULL}; 3397 NULL};
3390 3398
3391 static const ParserFlag always_flags[] = {kAllowClasses}; 3399 static const ParserFlag always_flags[] = {kAllowClasses};
3392 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, 3400 RunParserSyncTest(context_data, statement_data, kError, NULL, 0,
3393 always_flags, ARRAY_SIZE(always_flags)); 3401 always_flags, ARRAY_SIZE(always_flags));
3394 } 3402 }
3403
3404
3405 TEST(NoErrorsMethodDefinition) {
3406 const char* context_data[][2] = {{"({", "});"}, {NULL, NULL}};
3407
3408 const char* statement_data[] = {"m() {}", "m(x) { return x; }",
3409 "m(x, y) {}, n() {}", "set(x, y) {}",
3410 "get(x, y) {}", NULL};
3411
3412 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals};
3413 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
3414 always_flags, ARRAY_SIZE(always_flags));
3415 }
3416
3417
3418 TEST(MethodDefinitionNames) {
3419 const char* context_data[][2] = {{"({", "(x, y) {}});"}, {NULL, NULL}};
3420
3421 const char* statement_data[] = {"m", "'m'", "\"m\"", "true", "false",
3422 "null", "0", "1.2", "1e1", "1E1",
3423 "1e+1", "1e-1", NULL};
3424
3425 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals};
3426 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
3427 always_flags, ARRAY_SIZE(always_flags));
3428 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698