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

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

Issue 101923002: Experimental scanner: enable tests which were commented out. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years 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 | « no previous file | no next file » | 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 CHECK_EQ(10, error_location.beg_pos); 232 CHECK_EQ(10, error_location.beg_pos);
233 CHECK_EQ(11, error_location.end_pos); 233 CHECK_EQ(11, error_location.end_pos);
234 // Should not crash. 234 // Should not crash.
235 const char* message = pre_impl->BuildMessage(); 235 const char* message = pre_impl->BuildMessage();
236 pre_impl->BuildArgs(); 236 pre_impl->BuildArgs();
237 CHECK_GT(strlen(message), 0); 237 CHECK_GT(strlen(message), 0);
238 } 238 }
239 239
240 240
241 TEST(StandAlonePreParser) { 241 TEST(StandAlonePreParser) {
242 // FIXME(experimental-scanner): 242 v8::V8::Initialize();
243 // v8::V8::Initialize();
244 243
245 // int marker; 244 int marker;
246 // CcTest::i_isolate()->stack_guard()->SetStackLimit( 245 CcTest::i_isolate()->stack_guard()->SetStackLimit(
247 // reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 246 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
248 247
249 // const char* programs[] = { 248 const char* programs[] = {
250 // "{label: 42}", 249 "{label: 42}",
251 // "var x = 42;", 250 "var x = 42;",
252 // "function foo(x, y) { return x + y; }", 251 "function foo(x, y) { return x + y; }",
253 // "%ArgleBargle(glop);", 252 "%ArgleBargle(glop);",
254 // "var x = new new Function('this.x = 42');", 253 "var x = new new Function('this.x = 42');",
255 // NULL 254 NULL
256 // }; 255 };
257 256
258 // uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 257 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
259 // for (int i = 0; programs[i]; i++) { 258 for (int i = 0; programs[i]; i++) {
260 // const char* program = programs[i]; 259 i::HandleScope handle_scope(CcTest::i_isolate());
261 // i::Utf8ToUtf16CharacterStream stream( 260 i::Handle<i::String> source =
262 // reinterpret_cast<const i::byte*>(program), 261 CcTest::i_isolate()->factory()->NewStringFromAscii(
263 // static_cast<unsigned>(strlen(program))); 262 i::Vector<const char>(programs[i], strlen(programs[i])));
264 // i::CompleteParserRecorder log; 263 i::CompleteParserRecorder log;
265 // i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 264 i::ExperimentalScanner<uint8_t> scanner(source, CcTest::i_isolate());
266 // scanner.Initialize(&stream); 265 scanner.Init();
267 266
268 // i::PreParser preparser(&scanner, &log, stack_limit); 267 i::PreParser preparser(&scanner, &log, stack_limit);
269 // preparser.set_allow_lazy(true); 268 preparser.set_allow_lazy(true);
270 // preparser.set_allow_natives_syntax(true); 269 preparser.set_allow_natives_syntax(true);
271 // i::PreParser::PreParseResult result = preparser.PreParseProgram(); 270 i::PreParser::PreParseResult result = preparser.PreParseProgram();
272 // CHECK_EQ(i::PreParser::kPreParseSuccess, result); 271 CHECK_EQ(i::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 // FIXME(experimental-scanner): 279 v8::V8::Initialize();
281 // v8::V8::Initialize();
282 280
283 // int marker; 281 int marker;
284 // CcTest::i_isolate()->stack_guard()->SetStackLimit( 282 CcTest::i_isolate()->stack_guard()->SetStackLimit(
285 // reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 283 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
286 284
287 // const char* programs[] = { 285 const char* programs[] = {
288 // "%ArgleBargle(glop);", 286 "%ArgleBargle(glop);",
289 // "var x = %_IsSmi(42);", 287 "var x = %_IsSmi(42);",
290 // NULL 288 NULL
291 // }; 289 };
292 290
293 // uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 291 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
294 // for (int i = 0; programs[i]; i++) { 292 for (int i = 0; programs[i]; i++) {
295 // const char* program = programs[i]; 293 i::HandleScope handle_scope(CcTest::i_isolate());
296 // i::Utf8ToUtf16CharacterStream stream( 294 i::Handle<i::String> source =
297 // reinterpret_cast<const i::byte*>(program), 295 CcTest::i_isolate()->factory()->NewStringFromAscii(
298 // static_cast<unsigned>(strlen(program))); 296 i::Vector<const char>(programs[i], strlen(programs[i])));
299 // i::CompleteParserRecorder log; 297 i::CompleteParserRecorder log;
300 // i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 298 i::ExperimentalScanner<uint8_t> scanner(source, CcTest::i_isolate());
301 // scanner.Initialize(&stream); 299 scanner.Init();
302 300 // Preparser defaults to disallowing natives syntax.
303 // // Preparser defaults to disallowing natives syntax. 301 i::PreParser preparser(&scanner, &log, stack_limit);
304 // i::PreParser preparser(&scanner, &log, stack_limit); 302 preparser.set_allow_lazy(true);
305 // preparser.set_allow_lazy(true); 303 i::PreParser::PreParseResult result = preparser.PreParseProgram();
306 // i::PreParser::PreParseResult result = preparser.PreParseProgram(); 304 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
307 // CHECK_EQ(i::PreParser::kPreParseSuccess, result); 305 i::ScriptDataImpl data(log.ExtractData());
308 // i::ScriptDataImpl data(log.ExtractData()); 306 // Data contains syntax error.
309 // // Data contains syntax error. 307 CHECK(data.has_error());
310 // CHECK(data.has_error()); 308 }
311 // }
312 } 309 }
313 310
314 311
315 TEST(RegressChromium62639) { 312 TEST(RegressChromium62639) {
316 v8::V8::Initialize(); 313 v8::V8::Initialize();
317 i::Isolate* isolate = CcTest::i_isolate(); 314 i::Isolate* isolate = CcTest::i_isolate();
318 315
319 int marker; 316 int marker;
320 isolate->stack_guard()->SetStackLimit( 317 isolate->stack_guard()->SetStackLimit(
321 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 318 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 second_function + i::StrLength("function () "); 372 second_function + i::StrLength("function () ");
376 CHECK_EQ('{', program[second_lbrace]); 373 CHECK_EQ('{', program[second_lbrace]);
377 i::FunctionEntry entry2 = data->GetFunctionEntry(second_lbrace); 374 i::FunctionEntry entry2 = data->GetFunctionEntry(second_lbrace);
378 CHECK(entry2.is_valid()); 375 CHECK(entry2.is_valid());
379 CHECK_EQ('}', program[entry2.end_pos() - 1]); 376 CHECK_EQ('}', program[entry2.end_pos() - 1]);
380 delete data; 377 delete data;
381 } 378 }
382 379
383 380
384 TEST(PreParseOverflow) { 381 TEST(PreParseOverflow) {
385 // FIXME(experimental-scanner): 382 v8::V8::Initialize();
386 // v8::V8::Initialize();
387 383
388 // int marker; 384 int marker;
389 // CcTest::i_isolate()->stack_guard()->SetStackLimit( 385 CcTest::i_isolate()->stack_guard()->SetStackLimit(
390 // reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 386 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
391 387
392 // size_t kProgramSize = 1024 * 1024; 388 size_t kProgramSize = 1024 * 1024;
393 // i::SmartArrayPointer<char> program(i::NewArray<char>(kProgramSize + 1)); 389 i::SmartArrayPointer<char> program(i::NewArray<char>(kProgramSize + 1));
394 // memset(*program, '(', kProgramSize); 390 memset(*program, '(', kProgramSize);
395 // program[kProgramSize] = '\0'; 391 program[kProgramSize] = '\0';
396 392
397 // uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 393 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
398 394
399 // i::Utf8ToUtf16CharacterStream stream( 395 i::HandleScope handle_scope(CcTest::i_isolate());
400 // reinterpret_cast<const i::byte*>(*program), 396 i::Handle<i::String> source =
401 // static_cast<unsigned>(kProgramSize)); 397 CcTest::i_isolate()->factory()->NewStringFromAscii(
402 // i::CompleteParserRecorder log; 398 i::Vector<const char>(*program, kProgramSize));
403 // i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 399 i::CompleteParserRecorder log;
404 // scanner.Initialize(&stream); 400 i::ExperimentalScanner<uint8_t> scanner(source, CcTest::i_isolate());
401 scanner.Init();
405 402
406 // i::PreParser preparser(&scanner, &log, stack_limit); 403 i::PreParser preparser(&scanner, &log, stack_limit);
407 // preparser.set_allow_lazy(true); 404 preparser.set_allow_lazy(true);
408 // i::PreParser::PreParseResult result = preparser.PreParseProgram(); 405 i::PreParser::PreParseResult result = preparser.PreParseProgram();
409 // CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); 406 CHECK_EQ(i::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 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 parser->set_allow_modules(flags.Contains(kAllowModules)); 1096 parser->set_allow_modules(flags.Contains(kAllowModules));
1100 parser->set_allow_generators(flags.Contains(kAllowGenerators)); 1097 parser->set_allow_generators(flags.Contains(kAllowGenerators));
1101 parser->set_allow_for_of(flags.Contains(kAllowForOf)); 1098 parser->set_allow_for_of(flags.Contains(kAllowForOf));
1102 parser->set_allow_harmony_numeric_literals( 1099 parser->set_allow_harmony_numeric_literals(
1103 flags.Contains(kAllowHarmonyNumericLiterals)); 1100 flags.Contains(kAllowHarmonyNumericLiterals));
1104 } 1101 }
1105 1102
1106 1103
1107 void TestParserSyncWithFlags(i::Handle<i::String> source, 1104 void TestParserSyncWithFlags(i::Handle<i::String> source,
1108 i::EnumSet<ParserFlag> flags) { 1105 i::EnumSet<ParserFlag> flags) {
1109 // FIXME(experimental-scanner): 1106 i::Isolate* isolate = CcTest::i_isolate();
1110 // i::Isolate* isolate = CcTest::i_isolate(); 1107 i::Factory* factory = isolate->factory();
1111 // i::Factory* factory = isolate->factory();
1112 1108
1113 // uintptr_t stack_limit = isolate->stack_guard()->real_climit(); 1109 uintptr_t stack_limit = isolate->stack_guard()->real_climit();
1114 1110
1115 // // Preparse the data. 1111 // Preparse the data.
1116 // i::CompleteParserRecorder log; 1112 i::CompleteParserRecorder log;
1117 // { 1113 {
1118 // i::Scanner scanner(isolate->unicode_cache()); 1114 i::ExperimentalScanner<uint8_t> scanner(source, CcTest::i_isolate());
1119 // i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); 1115 i::PreParser preparser(&scanner, &log, stack_limit);
1120 // i::PreParser preparser(&scanner, &log, stack_limit); 1116 SetParserFlags(&preparser, flags);
1121 // SetParserFlags(&preparser, flags); 1117 scanner.Init();
1122 // scanner.Initialize(&stream); 1118 i::PreParser::PreParseResult result = preparser.PreParseProgram();
1123 // i::PreParser::PreParseResult result = preparser.PreParseProgram(); 1119 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
1124 // CHECK_EQ(i::PreParser::kPreParseSuccess, result); 1120 }
1125 // } 1121 i::ScriptDataImpl data(log.ExtractData());
1126 // i::ScriptDataImpl data(log.ExtractData());
1127 1122
1128 // // Parse the data 1123 // Parse the data
1129 // i::FunctionLiteral* function; 1124 i::FunctionLiteral* function;
1130 // { 1125 {
1131 // i::Handle<i::Script> script = factory->NewScript(source); 1126 i::Handle<i::Script> script = factory->NewScript(source);
1132 // i::CompilationInfoWithZone info(script); 1127 i::CompilationInfoWithZone info(script);
1133 // i::Parser parser(&info); 1128 i::Parser parser(&info);
1134 // SetParserFlags(&parser, flags); 1129 SetParserFlags(&parser, flags);
1135 // info.MarkAsGlobal(); 1130 info.MarkAsGlobal();
1136 // parser.Parse(); 1131 parser.Parse();
1137 // function = info.function(); 1132 function = info.function();
1138 // } 1133 }
1139 1134
1140 // // Check that preparsing fails iff parsing fails. 1135 // Check that preparsing fails iff parsing fails.
1141 // if (function == NULL) { 1136 if (function == NULL) {
1142 // // Extract exception from the parser. 1137 // Extract exception from the parser.
1143 // CHECK(isolate->has_pending_exception()); 1138 CHECK(isolate->has_pending_exception());
1144 // i::MaybeObject* maybe_object = isolate->pending_exception(); 1139 i::MaybeObject* maybe_object = isolate->pending_exception();
1145 // i::JSObject* exception = NULL; 1140 i::JSObject* exception = NULL;
1146 // CHECK(maybe_object->To(&exception)); 1141 CHECK(maybe_object->To(&exception));
1147 // i::Handle<i::JSObject> exception_handle(exception); 1142 i::Handle<i::JSObject> exception_handle(exception);
1148 // i::Handle<i::String> message_string = 1143 i::Handle<i::String> message_string =
1149 // i::Handle<i::String>::cast(i::GetProperty(exception_handle, "message")); 1144 i::Handle<i::String>::cast(i::GetProperty(exception_handle, "message"));
1150 1145
1151 // if (!data.has_error()) { 1146 if (!data.has_error()) {
1152 // i::OS::Print( 1147 i::OS::Print(
1153 // "Parser failed on:\n" 1148 "Parser failed on:\n"
1154 // "\t%s\n" 1149 "\t%s\n"
1155 // "with error:\n" 1150 "with error:\n"
1156 // "\t%s\n" 1151 "\t%s\n"
1157 // "However, the preparser succeeded", 1152 "However, the preparser succeeded",
1158 // *source->ToCString(), *message_string->ToCString()); 1153 *source->ToCString(), *message_string->ToCString());
1159 // CHECK(false); 1154 CHECK(false);
1160 // } 1155 }
1161 // // Check that preparser and parser produce the same error. 1156 // Check that preparser and parser produce the same error.
1162 // i::Handle<i::String> preparser_message = FormatMessage(&data); 1157 i::Handle<i::String> preparser_message = FormatMessage(&data);
1163 // if (!message_string->Equals(*preparser_message)) { 1158 if (!message_string->Equals(*preparser_message)) {
1164 // i::OS::Print( 1159 i::OS::Print(
1165 // "Expected parser and preparser to produce the same error on:\n" 1160 "Expected parser and preparser to produce the same error on:\n"
1166 // "\t%s\n" 1161 "\t%s\n"
1167 // "However, found the following error messages\n" 1162 "However, found the following error messages\n"
1168 // "\tparser: %s\n" 1163 "\tparser: %s\n"
1169 // "\tpreparser: %s\n", 1164 "\tpreparser: %s\n",
1170 // *source->ToCString(), 1165 *source->ToCString(),
1171 // *message_string->ToCString(), 1166 *message_string->ToCString(),
1172 // *preparser_message->ToCString()); 1167 *preparser_message->ToCString());
1173 // CHECK(false); 1168 CHECK(false);
1174 // } 1169 }
1175 // } else if (data.has_error()) { 1170 } else if (data.has_error()) {
1176 // i::OS::Print( 1171 i::OS::Print(
1177 // "Preparser failed on:\n" 1172 "Preparser failed on:\n"
1178 // "\t%s\n" 1173 "\t%s\n"
1179 // "with error:\n" 1174 "with error:\n"
1180 // "\t%s\n" 1175 "\t%s\n"
1181 // "However, the parser succeeded", 1176 "However, the parser succeeded",
1182 // *source->ToCString(), *FormatMessage(&data)->ToCString()); 1177 *source->ToCString(), *FormatMessage(&data)->ToCString());
1183 // CHECK(false); 1178 CHECK(false);
1184 // } 1179 }
1185 } 1180 }
1186 1181
1187 1182
1188 void TestParserSync(const char* source, 1183 void TestParserSync(const char* source,
1189 const ParserFlag* flag_list, 1184 const ParserFlag* flag_list,
1190 size_t flag_list_length) { 1185 size_t flag_list_length) {
1191 i::Handle<i::String> str = 1186 i::Handle<i::String> str =
1192 CcTest::i_isolate()->factory()->NewStringFromAscii(i::CStrVector(source)); 1187 CcTest::i_isolate()->factory()->NewStringFromAscii(i::CStrVector(source));
1193 for (int bits = 0; bits < (1 << flag_list_length); bits++) { 1188 for (int bits = 0; bits < (1 << flag_list_length); bits++) {
1194 i::EnumSet<ParserFlag> flags; 1189 i::EnumSet<ParserFlag> flags;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 " b = function() { \n" 1327 " b = function() { \n"
1333 " 01; \n" 1328 " 01; \n"
1334 " }; \n" 1329 " }; \n"
1335 "}; \n"; 1330 "}; \n";
1336 v8::Script::Compile(v8::String::New(script)); 1331 v8::Script::Compile(v8::String::New(script));
1337 CHECK(try_catch.HasCaught()); 1332 CHECK(try_catch.HasCaught());
1338 v8::String::Utf8Value exception(try_catch.Exception()); 1333 v8::String::Utf8Value exception(try_catch.Exception());
1339 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", 1334 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.",
1340 *exception); 1335 *exception);
1341 } 1336 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698