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

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

Issue 133443009: A64: Synchronize with r17441. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 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
« no previous file with comments | « test/cctest/test-object-observe.cc ('k') | test/cctest/test-types.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 257 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
258 for (int i = 0; programs[i]; i++) { 258 for (int i = 0; programs[i]; i++) {
259 const char* program = programs[i]; 259 const char* program = programs[i];
260 i::Utf8ToUtf16CharacterStream stream( 260 i::Utf8ToUtf16CharacterStream stream(
261 reinterpret_cast<const i::byte*>(program), 261 reinterpret_cast<const i::byte*>(program),
262 static_cast<unsigned>(strlen(program))); 262 static_cast<unsigned>(strlen(program)));
263 i::CompleteParserRecorder log; 263 i::CompleteParserRecorder log;
264 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 264 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
265 scanner.Initialize(&stream); 265 scanner.Initialize(&stream);
266 266
267 v8::preparser::PreParser preparser(&scanner, &log, stack_limit); 267 i::PreParser preparser(&scanner, &log, stack_limit);
268 preparser.set_allow_lazy(true); 268 preparser.set_allow_lazy(true);
269 preparser.set_allow_natives_syntax(true); 269 preparser.set_allow_natives_syntax(true);
270 v8::preparser::PreParser::PreParseResult result = 270 i::PreParser::PreParseResult result = preparser.PreParseProgram();
271 preparser.PreParseProgram(); 271 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
272 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result);
273 i::ScriptDataImpl data(log.ExtractData()); 272 i::ScriptDataImpl data(log.ExtractData());
274 CHECK(!data.has_error()); 273 CHECK(!data.has_error());
275 } 274 }
276 } 275 }
277 276
278 277
279 TEST(StandAlonePreParserNoNatives) { 278 TEST(StandAlonePreParserNoNatives) {
280 v8::V8::Initialize(); 279 v8::V8::Initialize();
281 280
282 int marker; 281 int marker;
(...skipping 10 matching lines...) Expand all
293 for (int i = 0; programs[i]; i++) { 292 for (int i = 0; programs[i]; i++) {
294 const char* program = programs[i]; 293 const char* program = programs[i];
295 i::Utf8ToUtf16CharacterStream stream( 294 i::Utf8ToUtf16CharacterStream stream(
296 reinterpret_cast<const i::byte*>(program), 295 reinterpret_cast<const i::byte*>(program),
297 static_cast<unsigned>(strlen(program))); 296 static_cast<unsigned>(strlen(program)));
298 i::CompleteParserRecorder log; 297 i::CompleteParserRecorder log;
299 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 298 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
300 scanner.Initialize(&stream); 299 scanner.Initialize(&stream);
301 300
302 // Preparser defaults to disallowing natives syntax. 301 // Preparser defaults to disallowing natives syntax.
303 v8::preparser::PreParser preparser(&scanner, &log, stack_limit); 302 i::PreParser preparser(&scanner, &log, stack_limit);
304 preparser.set_allow_lazy(true); 303 preparser.set_allow_lazy(true);
305 v8::preparser::PreParser::PreParseResult result = 304 i::PreParser::PreParseResult result = preparser.PreParseProgram();
306 preparser.PreParseProgram(); 305 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
307 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result);
308 i::ScriptDataImpl data(log.ExtractData()); 306 i::ScriptDataImpl data(log.ExtractData());
309 // Data contains syntax error. 307 // Data contains syntax error.
310 CHECK(data.has_error()); 308 CHECK(data.has_error());
311 } 309 }
312 } 310 }
313 311
314 312
315 TEST(RegressChromium62639) { 313 TEST(RegressChromium62639) {
316 v8::V8::Initialize(); 314 v8::V8::Initialize();
317 i::Isolate* isolate = CcTest::i_isolate(); 315 i::Isolate* isolate = CcTest::i_isolate();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 393
396 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 394 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
397 395
398 i::Utf8ToUtf16CharacterStream stream( 396 i::Utf8ToUtf16CharacterStream stream(
399 reinterpret_cast<const i::byte*>(*program), 397 reinterpret_cast<const i::byte*>(*program),
400 static_cast<unsigned>(kProgramSize)); 398 static_cast<unsigned>(kProgramSize));
401 i::CompleteParserRecorder log; 399 i::CompleteParserRecorder log;
402 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 400 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
403 scanner.Initialize(&stream); 401 scanner.Initialize(&stream);
404 402
405 v8::preparser::PreParser preparser(&scanner, &log, stack_limit); 403 i::PreParser preparser(&scanner, &log, stack_limit);
406 preparser.set_allow_lazy(true); 404 preparser.set_allow_lazy(true);
407 v8::preparser::PreParser::PreParseResult result = 405 i::PreParser::PreParseResult result = preparser.PreParseProgram();
408 preparser.PreParseProgram(); 406 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result);
409 CHECK_EQ(v8::preparser::PreParser::kPreParseStackOverflow, result);
410 } 407 }
411 408
412 409
413 class TestExternalResource: public v8::String::ExternalStringResource { 410 class TestExternalResource: public v8::String::ExternalStringResource {
414 public: 411 public:
415 explicit TestExternalResource(uint16_t* data, int length) 412 explicit TestExternalResource(uint16_t* data, int length)
416 : data_(data), length_(static_cast<size_t>(length)) { } 413 : data_(data), length_(static_cast<size_t>(length)) { }
417 414
418 ~TestExternalResource() { } 415 ~TestExternalResource() { }
419 416
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 } 1078 }
1082 1079
1083 1080
1084 enum ParserFlag { 1081 enum ParserFlag {
1085 kAllowLazy, 1082 kAllowLazy,
1086 kAllowNativesSyntax, 1083 kAllowNativesSyntax,
1087 kAllowHarmonyScoping, 1084 kAllowHarmonyScoping,
1088 kAllowModules, 1085 kAllowModules,
1089 kAllowGenerators, 1086 kAllowGenerators,
1090 kAllowForOf, 1087 kAllowForOf,
1091 kAllowHarmonyNumericLiterals, 1088 kAllowHarmonyNumericLiterals
1092 kParserFlagCount
1093 }; 1089 };
1094 1090
1095 1091
1096 static bool checkParserFlag(unsigned flags, ParserFlag flag) { 1092 void SetParserFlags(i::ParserBase* parser, i::EnumSet<ParserFlag> flags) {
1097 return flags & (1 << flag); 1093 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1094 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax));
1095 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping));
1096 parser->set_allow_modules(flags.Contains(kAllowModules));
1097 parser->set_allow_generators(flags.Contains(kAllowGenerators));
1098 parser->set_allow_for_of(flags.Contains(kAllowForOf));
1099 parser->set_allow_harmony_numeric_literals(
1100 flags.Contains(kAllowHarmonyNumericLiterals));
1098 } 1101 }
1099 1102
1100 1103
1101 #define SET_PARSER_FLAGS(parser, flags) \ 1104 void TestParserSyncWithFlags(i::Handle<i::String> source,
1102 parser.set_allow_lazy(checkParserFlag(flags, kAllowLazy)); \ 1105 i::EnumSet<ParserFlag> flags) {
1103 parser.set_allow_natives_syntax(checkParserFlag(flags, \
1104 kAllowNativesSyntax)); \
1105 parser.set_allow_harmony_scoping(checkParserFlag(flags, \
1106 kAllowHarmonyScoping)); \
1107 parser.set_allow_modules(checkParserFlag(flags, kAllowModules)); \
1108 parser.set_allow_generators(checkParserFlag(flags, kAllowGenerators)); \
1109 parser.set_allow_for_of(checkParserFlag(flags, kAllowForOf)); \
1110 parser.set_allow_harmony_numeric_literals( \
1111 checkParserFlag(flags, kAllowHarmonyNumericLiterals));
1112
1113 void TestParserSyncWithFlags(i::Handle<i::String> source, unsigned flags) {
1114 i::Isolate* isolate = CcTest::i_isolate(); 1106 i::Isolate* isolate = CcTest::i_isolate();
1115 i::Factory* factory = isolate->factory(); 1107 i::Factory* factory = isolate->factory();
1116 1108
1117 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); 1109 uintptr_t stack_limit = isolate->stack_guard()->real_climit();
1118 1110
1119 // Preparse the data. 1111 // Preparse the data.
1120 i::CompleteParserRecorder log; 1112 i::CompleteParserRecorder log;
1121 { 1113 {
1122 i::Scanner scanner(isolate->unicode_cache()); 1114 i::Scanner scanner(isolate->unicode_cache());
1123 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); 1115 i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
1124 v8::preparser::PreParser preparser(&scanner, &log, stack_limit); 1116 i::PreParser preparser(&scanner, &log, stack_limit);
1125 SET_PARSER_FLAGS(preparser, flags); 1117 SetParserFlags(&preparser, flags);
1126 scanner.Initialize(&stream); 1118 scanner.Initialize(&stream);
1127 v8::preparser::PreParser::PreParseResult result = 1119 i::PreParser::PreParseResult result = preparser.PreParseProgram();
1128 preparser.PreParseProgram(); 1120 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
1129 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result);
1130 } 1121 }
1131 i::ScriptDataImpl data(log.ExtractData()); 1122 i::ScriptDataImpl data(log.ExtractData());
1132 1123
1133 // Parse the data 1124 // Parse the data
1134 i::FunctionLiteral* function; 1125 i::FunctionLiteral* function;
1135 { 1126 {
1136 i::Handle<i::Script> script = factory->NewScript(source); 1127 i::Handle<i::Script> script = factory->NewScript(source);
1137 i::CompilationInfoWithZone info(script); 1128 i::CompilationInfoWithZone info(script);
1138 i::Parser parser(&info); 1129 i::Parser parser(&info);
1139 SET_PARSER_FLAGS(parser, flags); 1130 SetParserFlags(&parser, flags);
1140 info.MarkAsGlobal(); 1131 info.MarkAsGlobal();
1141 parser.Parse(); 1132 parser.Parse();
1142 function = info.function(); 1133 function = info.function();
1143 } 1134 }
1144 1135
1145 // Check that preparsing fails iff parsing fails. 1136 // Check that preparsing fails iff parsing fails.
1146 if (function == NULL) { 1137 if (function == NULL) {
1147 // Extract exception from the parser. 1138 // Extract exception from the parser.
1148 CHECK(isolate->has_pending_exception()); 1139 CHECK(isolate->has_pending_exception());
1149 i::MaybeObject* maybe_object = isolate->pending_exception(); 1140 i::MaybeObject* maybe_object = isolate->pending_exception();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 "\t%s\n" 1174 "\t%s\n"
1184 "with error:\n" 1175 "with error:\n"
1185 "\t%s\n" 1176 "\t%s\n"
1186 "However, the parser succeeded", 1177 "However, the parser succeeded",
1187 *source->ToCString(), *FormatMessage(&data)->ToCString()); 1178 *source->ToCString(), *FormatMessage(&data)->ToCString());
1188 CHECK(false); 1179 CHECK(false);
1189 } 1180 }
1190 } 1181 }
1191 1182
1192 1183
1193 void TestParserSync(i::Handle<i::String> source) { 1184 void TestParserSync(const char* source,
1194 for (unsigned flags = 0; flags < (1 << kParserFlagCount); ++flags) { 1185 const ParserFlag* flag_list,
1195 TestParserSyncWithFlags(source, flags); 1186 size_t flag_list_length) {
1187 i::Handle<i::String> str =
1188 CcTest::i_isolate()->factory()->NewStringFromAscii(i::CStrVector(source));
1189 for (int bits = 0; bits < (1 << flag_list_length); bits++) {
1190 i::EnumSet<ParserFlag> flags;
1191 for (size_t flag_index = 0; flag_index < flag_list_length; flag_index++) {
1192 if ((bits & (1 << flag_index)) != 0) flags.Add(flag_list[flag_index]);
1193 }
1194 TestParserSyncWithFlags(str, flags);
1196 } 1195 }
1197 } 1196 }
1198 1197
1199 1198
1200 TEST(ParserSync) { 1199 TEST(ParserSync) {
1201 const char* context_data[][2] = { 1200 const char* context_data[][2] = {
1202 { "", "" }, 1201 { "", "" },
1203 { "{", "}" }, 1202 { "{", "}" },
1204 { "if (true) ", " else {}" }, 1203 { "if (true) ", " else {}" },
1205 { "if (true) {} else ", "" }, 1204 { "if (true) {} else ", "" },
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 1258
1260 const char* termination_data[] = { 1259 const char* termination_data[] = {
1261 "", 1260 "",
1262 ";", 1261 ";",
1263 "\n", 1262 "\n",
1264 ";\n", 1263 ";\n",
1265 "\n;", 1264 "\n;",
1266 NULL 1265 NULL
1267 }; 1266 };
1268 1267
1269 i::Isolate* isolate = CcTest::i_isolate();
1270 i::Factory* factory = isolate->factory();
1271
1272 v8::HandleScope handles(CcTest::isolate()); 1268 v8::HandleScope handles(CcTest::isolate());
1273 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1269 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1274 v8::Context::Scope context_scope(context); 1270 v8::Context::Scope context_scope(context);
1275 1271
1276 int marker; 1272 int marker;
1277 isolate->stack_guard()->SetStackLimit( 1273 CcTest::i_isolate()->stack_guard()->SetStackLimit(
1278 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 1274 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
1279 1275
1276 static const ParserFlag flags1[] = {
1277 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators,
1278 kAllowForOf
1279 };
1280 for (int i = 0; context_data[i][0] != NULL; ++i) { 1280 for (int i = 0; context_data[i][0] != NULL; ++i) {
1281 for (int j = 0; statement_data[j] != NULL; ++j) { 1281 for (int j = 0; statement_data[j] != NULL; ++j) {
1282 for (int k = 0; termination_data[k] != NULL; ++k) { 1282 for (int k = 0; termination_data[k] != NULL; ++k) {
1283 int kPrefixLen = i::StrLength(context_data[i][0]); 1283 int kPrefixLen = i::StrLength(context_data[i][0]);
1284 int kStatementLen = i::StrLength(statement_data[j]); 1284 int kStatementLen = i::StrLength(statement_data[j]);
1285 int kTerminationLen = i::StrLength(termination_data[k]); 1285 int kTerminationLen = i::StrLength(termination_data[k]);
1286 int kSuffixLen = i::StrLength(context_data[i][1]); 1286 int kSuffixLen = i::StrLength(context_data[i][1]);
1287 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen 1287 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen
1288 + kSuffixLen + i::StrLength("label: for (;;) { }"); 1288 + kSuffixLen + i::StrLength("label: for (;;) { }");
1289 1289
1290 // Plug the source code pieces together. 1290 // Plug the source code pieces together.
1291 i::ScopedVector<char> program(kProgramSize + 1); 1291 i::ScopedVector<char> program(kProgramSize + 1);
1292 int length = i::OS::SNPrintF(program, 1292 int length = i::OS::SNPrintF(program,
1293 "label: for (;;) { %s%s%s%s }", 1293 "label: for (;;) { %s%s%s%s }",
1294 context_data[i][0], 1294 context_data[i][0],
1295 statement_data[j], 1295 statement_data[j],
1296 termination_data[k], 1296 termination_data[k],
1297 context_data[i][1]); 1297 context_data[i][1]);
1298 CHECK(length == kProgramSize); 1298 CHECK(length == kProgramSize);
1299 i::Handle<i::String> source = 1299 TestParserSync(program.start(), flags1, ARRAY_SIZE(flags1));
1300 factory->NewStringFromAscii(i::CStrVector(program.start()));
1301 TestParserSync(source);
1302 } 1300 }
1303 } 1301 }
1304 } 1302 }
1303
1304 // Neither Harmony numeric literals nor our natives syntax have any
1305 // interaction with the flags above, so test these separately to reduce
1306 // the combinatorial explosion.
1307 static const ParserFlag flags2[] = { kAllowHarmonyNumericLiterals };
1308 TestParserSync("0o1234", flags2, ARRAY_SIZE(flags2));
1309 TestParserSync("0b1011", flags2, ARRAY_SIZE(flags2));
1310
1311 static const ParserFlag flags3[] = { kAllowNativesSyntax };
1312 TestParserSync("%DebugPrint(123)", flags3, ARRAY_SIZE(flags3));
1305 } 1313 }
1306 1314
1307 1315
1308 TEST(PreparserStrictOctal) { 1316 TEST(PreparserStrictOctal) {
1309 // Test that syntax error caused by octal literal is reported correctly as 1317 // Test that syntax error caused by octal literal is reported correctly as
1310 // such (issue 2220). 1318 // such (issue 2220).
1311 v8::internal::FLAG_min_preparse_length = 1; // Force preparsing. 1319 v8::internal::FLAG_min_preparse_length = 1; // Force preparsing.
1312 v8::V8::Initialize(); 1320 v8::V8::Initialize();
1313 v8::HandleScope scope(CcTest::isolate()); 1321 v8::HandleScope scope(CcTest::isolate());
1314 v8::Context::Scope context_scope( 1322 v8::Context::Scope context_scope(
1315 v8::Context::New(CcTest::isolate())); 1323 v8::Context::New(CcTest::isolate()));
1316 v8::TryCatch try_catch; 1324 v8::TryCatch try_catch;
1317 const char* script = 1325 const char* script =
1318 "\"use strict\"; \n" 1326 "\"use strict\"; \n"
1319 "a = function() { \n" 1327 "a = function() { \n"
1320 " b = function() { \n" 1328 " b = function() { \n"
1321 " 01; \n" 1329 " 01; \n"
1322 " }; \n" 1330 " }; \n"
1323 "}; \n"; 1331 "}; \n";
1324 v8::Script::Compile(v8::String::New(script)); 1332 v8::Script::Compile(v8::String::New(script));
1325 CHECK(try_catch.HasCaught()); 1333 CHECK(try_catch.HasCaught());
1326 v8::String::Utf8Value exception(try_catch.Exception()); 1334 v8::String::Utf8Value exception(try_catch.Exception());
1327 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", 1335 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.",
1328 *exception); 1336 *exception);
1329 } 1337 }
OLDNEW
« no previous file with comments | « test/cctest/test-object-observe.cc ('k') | test/cctest/test-types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698