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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 const i::byte* keyword = | 65 const i::byte* keyword = |
66 reinterpret_cast<const i::byte*>(key_token.keyword); | 66 reinterpret_cast<const i::byte*>(key_token.keyword); |
67 int length = i::StrLength(key_token.keyword); | 67 int length = i::StrLength(key_token.keyword); |
68 CHECK(static_cast<int>(sizeof(buffer)) >= length); | 68 CHECK(static_cast<int>(sizeof(buffer)) >= length); |
69 { | 69 { |
70 i::Utf8ToUtf16CharacterStream stream(keyword, length); | 70 i::Utf8ToUtf16CharacterStream stream(keyword, length); |
71 i::Scanner scanner(&unicode_cache); | 71 i::Scanner scanner(&unicode_cache); |
72 // The scanner should parse Harmony keywords for this test. | 72 // The scanner should parse Harmony keywords for this test. |
73 scanner.SetHarmonyScoping(true); | 73 scanner.SetHarmonyScoping(true); |
74 scanner.SetHarmonyModules(true); | 74 scanner.SetHarmonyModules(true); |
| 75 scanner.SetHarmonyClasses(true); |
75 scanner.Initialize(&stream); | 76 scanner.Initialize(&stream); |
76 CHECK_EQ(key_token.token, scanner.Next()); | 77 CHECK_EQ(key_token.token, scanner.Next()); |
77 CHECK_EQ(i::Token::EOS, scanner.Next()); | 78 CHECK_EQ(i::Token::EOS, scanner.Next()); |
78 } | 79 } |
79 // Removing characters will make keyword matching fail. | 80 // Removing characters will make keyword matching fail. |
80 { | 81 { |
81 i::Utf8ToUtf16CharacterStream stream(keyword, length - 1); | 82 i::Utf8ToUtf16CharacterStream stream(keyword, length - 1); |
82 i::Scanner scanner(&unicode_cache); | 83 i::Scanner scanner(&unicode_cache); |
83 scanner.Initialize(&stream); | 84 scanner.Initialize(&stream); |
84 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); | 85 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); |
(...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 } | 1203 } |
1203 | 1204 |
1204 | 1205 |
1205 enum ParserFlag { | 1206 enum ParserFlag { |
1206 kAllowLazy, | 1207 kAllowLazy, |
1207 kAllowNativesSyntax, | 1208 kAllowNativesSyntax, |
1208 kAllowHarmonyScoping, | 1209 kAllowHarmonyScoping, |
1209 kAllowModules, | 1210 kAllowModules, |
1210 kAllowGenerators, | 1211 kAllowGenerators, |
1211 kAllowHarmonyNumericLiterals, | 1212 kAllowHarmonyNumericLiterals, |
1212 kAllowArrowFunctions | 1213 kAllowArrowFunctions, |
| 1214 kAllowClasses |
1213 }; | 1215 }; |
1214 | 1216 |
1215 | 1217 |
1216 enum ParserSyncTestResult { | 1218 enum ParserSyncTestResult { |
1217 kSuccessOrError, | 1219 kSuccessOrError, |
1218 kSuccess, | 1220 kSuccess, |
1219 kError | 1221 kError |
1220 }; | 1222 }; |
1221 | 1223 |
1222 template <typename Traits> | 1224 template <typename Traits> |
1223 void SetParserFlags(i::ParserBase<Traits>* parser, | 1225 void SetParserFlags(i::ParserBase<Traits>* parser, |
1224 i::EnumSet<ParserFlag> flags) { | 1226 i::EnumSet<ParserFlag> flags) { |
1225 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1227 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
1226 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); | 1228 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); |
1227 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); | 1229 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); |
1228 parser->set_allow_modules(flags.Contains(kAllowModules)); | 1230 parser->set_allow_modules(flags.Contains(kAllowModules)); |
1229 parser->set_allow_generators(flags.Contains(kAllowGenerators)); | 1231 parser->set_allow_generators(flags.Contains(kAllowGenerators)); |
1230 parser->set_allow_harmony_numeric_literals( | 1232 parser->set_allow_harmony_numeric_literals( |
1231 flags.Contains(kAllowHarmonyNumericLiterals)); | 1233 flags.Contains(kAllowHarmonyNumericLiterals)); |
1232 parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions)); | 1234 parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions)); |
| 1235 parser->set_allow_classes(flags.Contains(kAllowClasses)); |
1233 } | 1236 } |
1234 | 1237 |
1235 | 1238 |
1236 void TestParserSyncWithFlags(i::Handle<i::String> source, | 1239 void TestParserSyncWithFlags(i::Handle<i::String> source, |
1237 i::EnumSet<ParserFlag> flags, | 1240 i::EnumSet<ParserFlag> flags, |
1238 ParserSyncTestResult result) { | 1241 ParserSyncTestResult result) { |
1239 i::Isolate* isolate = CcTest::i_isolate(); | 1242 i::Isolate* isolate = CcTest::i_isolate(); |
1240 i::Factory* factory = isolate->factory(); | 1243 i::Factory* factory = isolate->factory(); |
1241 | 1244 |
1242 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); | 1245 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1505 int always_true_flags_len = 0) { | 1508 int always_true_flags_len = 0) { |
1506 v8::HandleScope handles(CcTest::isolate()); | 1509 v8::HandleScope handles(CcTest::isolate()); |
1507 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 1510 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); |
1508 v8::Context::Scope context_scope(context); | 1511 v8::Context::Scope context_scope(context); |
1509 | 1512 |
1510 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - | 1513 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - |
1511 128 * 1024); | 1514 128 * 1024); |
1512 | 1515 |
1513 static const ParserFlag default_flags[] = { | 1516 static const ParserFlag default_flags[] = { |
1514 kAllowLazy, kAllowHarmonyScoping, kAllowModules, | 1517 kAllowLazy, kAllowHarmonyScoping, kAllowModules, |
1515 kAllowGenerators, kAllowNativesSyntax, kAllowArrowFunctions}; | 1518 kAllowGenerators, kAllowNativesSyntax, kAllowArrowFunctions, |
| 1519 kAllowClasses}; |
1516 ParserFlag* generated_flags = NULL; | 1520 ParserFlag* generated_flags = NULL; |
1517 if (flags == NULL) { | 1521 if (flags == NULL) { |
1518 flags = default_flags; | 1522 flags = default_flags; |
1519 flags_len = ARRAY_SIZE(default_flags); | 1523 flags_len = ARRAY_SIZE(default_flags); |
1520 if (always_true_flags != NULL) { | 1524 if (always_true_flags != NULL) { |
1521 // Remove always_true_flags from default_flags. | 1525 // Remove always_true_flags from default_flags. |
1522 CHECK(always_true_flags_len < flags_len); | 1526 CHECK(always_true_flags_len < flags_len); |
1523 generated_flags = new ParserFlag[flags_len - always_true_flags_len]; | 1527 generated_flags = new ParserFlag[flags_len - always_true_flags_len]; |
1524 int flag_index = 0; | 1528 int flag_index = 0; |
1525 for (int i = 0; i < flags_len; ++i) { | 1529 for (int i = 0; i < flags_len; ++i) { |
(...skipping 1810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3336 | 3340 |
3337 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {}) | 3341 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {}) |
3338 "foo ? bar : baz => {}", | 3342 "foo ? bar : baz => {}", |
3339 NULL | 3343 NULL |
3340 }; | 3344 }; |
3341 | 3345 |
3342 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; | 3346 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; |
3343 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 3347 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
3344 always_flags, ARRAY_SIZE(always_flags)); | 3348 always_flags, ARRAY_SIZE(always_flags)); |
3345 } | 3349 } |
| 3350 |
| 3351 |
| 3352 TEST(NoErrorsSuper) { |
| 3353 // Tests that parser and preparser accept 'super' keyword in right places. |
| 3354 const char* context_data[][2] = {{"", ";"}, |
| 3355 {"k = ", ";"}, |
| 3356 {"foo(", ");"}, |
| 3357 {NULL, NULL}}; |
| 3358 |
| 3359 const char* statement_data[] = { |
| 3360 "super.x", |
| 3361 "super[27]", |
| 3362 "new super", |
| 3363 "new super()", |
| 3364 "new super(12, 45)", |
| 3365 "new new super", |
| 3366 "new new super()", |
| 3367 "new new super()()", |
| 3368 "z.super", // Ok, property lookup. |
| 3369 NULL}; |
| 3370 |
| 3371 static const ParserFlag always_flags[] = {kAllowClasses}; |
| 3372 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
| 3373 always_flags, ARRAY_SIZE(always_flags)); |
| 3374 } |
| 3375 |
| 3376 |
| 3377 TEST(ErrorsSuper) { |
| 3378 // Tests that parser and preparser generate same errors for 'super'. |
| 3379 const char* context_data[][2] = {{"", ";"}, |
| 3380 {"k = ", ";"}, |
| 3381 {"foo(", ");"}, |
| 3382 {NULL, NULL}}; |
| 3383 |
| 3384 const char* statement_data[] = { |
| 3385 "super = x", |
| 3386 "y = super", |
| 3387 "f(super)", |
| 3388 NULL}; |
| 3389 |
| 3390 static const ParserFlag always_flags[] = {kAllowClasses}; |
| 3391 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, |
| 3392 always_flags, ARRAY_SIZE(always_flags)); |
| 3393 } |
OLD | NEW |