Chromium Code Reviews| 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 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1337 | 1337 |
| 1338 | 1338 |
| 1339 enum ParserFlag { | 1339 enum ParserFlag { |
| 1340 kAllowLazy, | 1340 kAllowLazy, |
| 1341 kAllowNativesSyntax, | 1341 kAllowNativesSyntax, |
| 1342 kAllowHarmonyScoping, | 1342 kAllowHarmonyScoping, |
| 1343 kAllowModules, | 1343 kAllowModules, |
| 1344 kAllowHarmonyNumericLiterals, | 1344 kAllowHarmonyNumericLiterals, |
| 1345 kAllowArrowFunctions, | 1345 kAllowArrowFunctions, |
| 1346 kAllowClasses, | 1346 kAllowClasses, |
| 1347 kAllowHarmonyObjectLiterals | 1347 kAllowHarmonyObjectLiterals, |
| 1348 kAllowHarmonyUnicode | |
| 1348 }; | 1349 }; |
| 1349 | 1350 |
| 1350 | 1351 |
| 1351 enum ParserSyncTestResult { | 1352 enum ParserSyncTestResult { |
| 1352 kSuccessOrError, | 1353 kSuccessOrError, |
| 1353 kSuccess, | 1354 kSuccess, |
| 1354 kError | 1355 kError |
| 1355 }; | 1356 }; |
| 1356 | 1357 |
| 1357 template <typename Traits> | 1358 template <typename Traits> |
| 1358 void SetParserFlags(i::ParserBase<Traits>* parser, | 1359 void SetParserFlags(i::ParserBase<Traits>* parser, |
| 1359 i::EnumSet<ParserFlag> flags) { | 1360 i::EnumSet<ParserFlag> flags) { |
| 1360 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1361 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
| 1361 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); | 1362 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); |
| 1362 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); | 1363 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); |
| 1363 parser->set_allow_modules(flags.Contains(kAllowModules)); | 1364 parser->set_allow_modules(flags.Contains(kAllowModules)); |
| 1364 parser->set_allow_harmony_numeric_literals( | 1365 parser->set_allow_harmony_numeric_literals( |
| 1365 flags.Contains(kAllowHarmonyNumericLiterals)); | 1366 flags.Contains(kAllowHarmonyNumericLiterals)); |
| 1366 parser->set_allow_harmony_object_literals( | 1367 parser->set_allow_harmony_object_literals( |
| 1367 flags.Contains(kAllowHarmonyObjectLiterals)); | 1368 flags.Contains(kAllowHarmonyObjectLiterals)); |
| 1368 parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions)); | 1369 parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions)); |
| 1369 parser->set_allow_classes(flags.Contains(kAllowClasses)); | 1370 parser->set_allow_classes(flags.Contains(kAllowClasses)); |
| 1371 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); | |
| 1370 } | 1372 } |
| 1371 | 1373 |
| 1372 | 1374 |
| 1373 void TestParserSyncWithFlags(i::Handle<i::String> source, | 1375 void TestParserSyncWithFlags(i::Handle<i::String> source, |
| 1374 i::EnumSet<ParserFlag> flags, | 1376 i::EnumSet<ParserFlag> flags, |
| 1375 ParserSyncTestResult result) { | 1377 ParserSyncTestResult result) { |
| 1376 i::Isolate* isolate = CcTest::i_isolate(); | 1378 i::Isolate* isolate = CcTest::i_isolate(); |
| 1377 i::Factory* factory = isolate->factory(); | 1379 i::Factory* factory = isolate->factory(); |
| 1378 | 1380 |
| 1379 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); | 1381 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1656 | 1658 |
| 1657 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 1659 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
| 1658 i::GetCurrentStackPosition() - 128 * 1024); | 1660 i::GetCurrentStackPosition() - 128 * 1024); |
| 1659 | 1661 |
| 1660 static const ParserFlag default_flags[] = { | 1662 static const ParserFlag default_flags[] = { |
| 1661 kAllowArrowFunctions, | 1663 kAllowArrowFunctions, |
| 1662 kAllowClasses, | 1664 kAllowClasses, |
| 1663 kAllowHarmonyNumericLiterals, | 1665 kAllowHarmonyNumericLiterals, |
| 1664 kAllowHarmonyObjectLiterals, | 1666 kAllowHarmonyObjectLiterals, |
| 1665 kAllowHarmonyScoping, | 1667 kAllowHarmonyScoping, |
| 1668 kAllowHarmonyUnicode, | |
| 1666 kAllowLazy, | 1669 kAllowLazy, |
| 1667 kAllowModules, | 1670 kAllowModules, |
| 1668 kAllowNativesSyntax, | 1671 kAllowNativesSyntax, |
| 1669 }; | 1672 }; |
| 1670 ParserFlag* generated_flags = NULL; | 1673 ParserFlag* generated_flags = NULL; |
| 1671 if (flags == NULL) { | 1674 if (flags == NULL) { |
| 1672 flags = default_flags; | 1675 flags = default_flags; |
| 1673 flags_len = arraysize(default_flags); | 1676 flags_len = arraysize(default_flags); |
| 1674 if (always_true_flags != NULL) { | 1677 if (always_true_flags != NULL) { |
| 1675 // Remove always_true_flags from default_flags. | 1678 // Remove always_true_flags from default_flags. |
| (...skipping 2632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4308 const char* context_data[][2] = {{"", ""}, | 4311 const char* context_data[][2] = {{"", ""}, |
| 4309 {"'use strict';", ""}, | 4312 {"'use strict';", ""}, |
| 4310 {NULL, NULL}}; | 4313 {NULL, NULL}}; |
| 4311 const char* data[] = { | 4314 const char* data[] = { |
| 4312 "var foob\\u123r = 0;", | 4315 "var foob\\u123r = 0;", |
| 4313 "var \\u123roo = 0;", | 4316 "var \\u123roo = 0;", |
| 4314 "\"foob\\u123rr\"", | 4317 "\"foob\\u123rr\"", |
| 4315 // No escapes allowed in regexp flags | 4318 // No escapes allowed in regexp flags |
| 4316 "/regex/\\u0069g", | 4319 "/regex/\\u0069g", |
| 4317 "/regex/\\u006g", | 4320 "/regex/\\u006g", |
| 4321 // Braces gone wrong | |
| 4322 "var foob\\u{c481r = 0;", | |
|
caitp (gmail)
2014/11/13 15:09:18
Might be worth adding a test for `var \\not-u` be
marja
2014/11/13 15:18:05
By var \not-u do you mean var \X where X is some l
marja
2014/12/02 10:26:20
Done.
| |
| 4323 "var foob\\uc481}r = 0;", | |
| 4324 "var \\u{0052oo = 0;", | |
| 4325 "var \\u0052}oo = 0;", | |
| 4326 "\"foob\\u{c481r\"", | |
| 4327 "var foob\\u{}ar = 0;", | |
| 4328 // Too high value for the unicode escape | |
| 4329 "\"\\u{110000}\"", | |
| 4318 NULL}; | 4330 NULL}; |
| 4319 RunParserSyncTest(context_data, data, kError); | 4331 static const ParserFlag always_flags[] = {kAllowHarmonyUnicode}; |
| 4332 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | |
| 4333 arraysize(always_flags)); | |
| 4320 } | 4334 } |
| 4335 | |
| 4336 | |
| 4337 TEST(UnicodeEscapes) { | |
| 4338 const char* context_data[][2] = {{"", ""}, | |
| 4339 {"'use strict';", ""}, | |
| 4340 {NULL, NULL}}; | |
| 4341 const char* data[] = { | |
| 4342 // Identifier starting with escape | |
| 4343 "var \\u0052oo = 0;", | |
| 4344 "var \\u{0052}oo = 0;", | |
| 4345 "var \\u{52}oo = 0;", | |
| 4346 "var \\u{00000000052}oo = 0;", | |
| 4347 // Identifier with an escape but not starting with an escape | |
| 4348 "var foob\\uc481r = 0;", | |
| 4349 "var foob\\u{c481}r = 0;", | |
| 4350 // String with an escape | |
| 4351 "\"foob\\uc481r\"", | |
| 4352 "\"foob\\{uc481}r\"", | |
| 4353 // This character is a valid unicode character, representable as a surrogate | |
| 4354 // pair, not representable as 4 hex digits. | |
| 4355 "\"foo\\u{10e6d}\"", | |
| 4356 // Max value for the unicode escape | |
| 4357 "\"\\u{10ffff}\"", | |
| 4358 NULL}; | |
| 4359 static const ParserFlag always_flags[] = {kAllowHarmonyUnicode}; | |
| 4360 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | |
| 4361 arraysize(always_flags)); | |
| 4362 } | |
| OLD | NEW |