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

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

Issue 112863002: Merge bleeding_edge 18021:18297 (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 | « test/cctest/test-object-observe.cc ('k') | test/cctest/test-profile-generator.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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 const char* error_source = "var x = y z;"; 199 const char* error_source = "var x = y z;";
200 int error_source_length = i::StrLength(error_source); 200 int error_source_length = i::StrLength(error_source);
201 201
202 v8::ScriptData* preparse = 202 v8::ScriptData* preparse =
203 v8::ScriptData::PreCompile(isolate, source, source_length); 203 v8::ScriptData::PreCompile(isolate, source, source_length);
204 CHECK(!preparse->HasError()); 204 CHECK(!preparse->HasError());
205 bool lazy_flag = i::FLAG_lazy; 205 bool lazy_flag = i::FLAG_lazy;
206 { 206 {
207 i::FLAG_lazy = true; 207 i::FLAG_lazy = true;
208 ScriptResource* resource = new ScriptResource(source, source_length); 208 ScriptResource* resource = new ScriptResource(source, source_length);
209 v8::Local<v8::String> script_source = v8::String::NewExternal(resource); 209 v8::Local<v8::String> script_source =
210 v8::String::NewExternal(isolate, resource);
210 v8::Script::Compile(script_source, NULL, preparse); 211 v8::Script::Compile(script_source, NULL, preparse);
211 } 212 }
212 213
213 { 214 {
214 i::FLAG_lazy = false; 215 i::FLAG_lazy = false;
215 216
216 ScriptResource* resource = new ScriptResource(source, source_length); 217 ScriptResource* resource = new ScriptResource(source, source_length);
217 v8::Local<v8::String> script_source = v8::String::NewExternal(resource); 218 v8::Local<v8::String> script_source =
219 v8::String::NewExternal(isolate, resource);
218 v8::Script::New(script_source, NULL, preparse, v8::Local<v8::String>()); 220 v8::Script::New(script_source, NULL, preparse, v8::Local<v8::String>());
219 } 221 }
220 delete preparse; 222 delete preparse;
221 i::FLAG_lazy = lazy_flag; 223 i::FLAG_lazy = lazy_flag;
222 224
223 // Syntax error. 225 // Syntax error.
224 v8::ScriptData* error_preparse = 226 v8::ScriptData* error_preparse =
225 v8::ScriptData::PreCompile(isolate, error_source, error_source_length); 227 v8::ScriptData::PreCompile(isolate, error_source, error_source_length);
226 CHECK(error_preparse->HasError()); 228 CHECK(error_preparse->HasError());
227 i::ScriptDataImpl *pre_impl = 229 i::ScriptDataImpl *pre_impl =
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 382
381 TEST(PreParseOverflow) { 383 TEST(PreParseOverflow) {
382 v8::V8::Initialize(); 384 v8::V8::Initialize();
383 385
384 int marker; 386 int marker;
385 CcTest::i_isolate()->stack_guard()->SetStackLimit( 387 CcTest::i_isolate()->stack_guard()->SetStackLimit(
386 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 388 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
387 389
388 size_t kProgramSize = 1024 * 1024; 390 size_t kProgramSize = 1024 * 1024;
389 i::SmartArrayPointer<char> program(i::NewArray<char>(kProgramSize + 1)); 391 i::SmartArrayPointer<char> program(i::NewArray<char>(kProgramSize + 1));
390 memset(*program, '(', kProgramSize); 392 memset(program.get(), '(', kProgramSize);
391 program[kProgramSize] = '\0'; 393 program[kProgramSize] = '\0';
392 394
393 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 395 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
394 396
395 i::HandleScope handle_scope(CcTest::i_isolate()); 397 i::HandleScope handle_scope(CcTest::i_isolate());
396 i::Handle<i::String> source = 398 i::Handle<i::String> source =
397 CcTest::i_isolate()->factory()->NewStringFromAscii( 399 CcTest::i_isolate()->factory()->NewStringFromAscii(
398 i::Vector<const char>(*program, kProgramSize)); 400 i::Vector<const char>(program.get(), kProgramSize));
399 i::CompleteParserRecorder log; 401 i::CompleteParserRecorder log;
400 i::ExperimentalScanner<uint8_t> scanner(source, CcTest::i_isolate()); 402 i::ExperimentalScanner<uint8_t> scanner(source, CcTest::i_isolate());
401 scanner.Init(); 403 scanner.Init();
402 404
403 i::PreParser preparser(&scanner, &log, stack_limit); 405 i::PreParser preparser(&scanner, &log, stack_limit);
404 preparser.set_allow_lazy(true); 406 preparser.set_allow_lazy(true);
405 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 407 i::PreParser::PreParseResult result = preparser.PreParseProgram();
406 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); 408 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result);
407 } 409 }
408 410
(...skipping 29 matching lines...) Expand all
438 i::Isolate* isolate = CcTest::i_isolate(); 440 i::Isolate* isolate = CcTest::i_isolate();
439 i::Factory* factory = isolate->factory(); 441 i::Factory* factory = isolate->factory();
440 i::HandleScope test_scope(isolate); 442 i::HandleScope test_scope(isolate);
441 i::SmartArrayPointer<i::uc16> uc16_buffer(new i::uc16[length]); 443 i::SmartArrayPointer<i::uc16> uc16_buffer(new i::uc16[length]);
442 for (unsigned i = 0; i < length; i++) { 444 for (unsigned i = 0; i < length; i++) {
443 uc16_buffer[i] = static_cast<i::uc16>(ascii_source[i]); 445 uc16_buffer[i] = static_cast<i::uc16>(ascii_source[i]);
444 } 446 }
445 i::Vector<const char> ascii_vector(ascii_source, static_cast<int>(length)); 447 i::Vector<const char> ascii_vector(ascii_source, static_cast<int>(length));
446 i::Handle<i::String> ascii_string( 448 i::Handle<i::String> ascii_string(
447 factory->NewStringFromAscii(ascii_vector)); 449 factory->NewStringFromAscii(ascii_vector));
448 TestExternalResource resource(*uc16_buffer, length); 450 TestExternalResource resource(uc16_buffer.get(), length);
449 i::Handle<i::String> uc16_string( 451 i::Handle<i::String> uc16_string(
450 factory->NewExternalStringFromTwoByte(&resource)); 452 factory->NewExternalStringFromTwoByte(&resource));
451 453
452 i::ExternalTwoByteStringUtf16CharacterStream uc16_stream( 454 i::ExternalTwoByteStringUtf16CharacterStream uc16_stream(
453 i::Handle<i::ExternalTwoByteString>::cast(uc16_string), start, end); 455 i::Handle<i::ExternalTwoByteString>::cast(uc16_string), start, end);
454 i::GenericStringUtf16CharacterStream string_stream(ascii_string, start, end); 456 i::GenericStringUtf16CharacterStream string_stream(ascii_string, start, end);
455 i::Utf8ToUtf16CharacterStream utf8_stream( 457 i::Utf8ToUtf16CharacterStream utf8_stream(
456 reinterpret_cast<const i::byte*>(ascii_source), end); 458 reinterpret_cast<const i::byte*>(ascii_source), end);
457 utf8_stream.SeekForward(start); 459 utf8_stream.SeekForward(start);
458 460
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 i::Handle<i::String> message_string = 1144 i::Handle<i::String> message_string =
1143 i::Handle<i::String>::cast(i::GetProperty(exception_handle, "message")); 1145 i::Handle<i::String>::cast(i::GetProperty(exception_handle, "message"));
1144 1146
1145 if (!data.has_error()) { 1147 if (!data.has_error()) {
1146 i::OS::Print( 1148 i::OS::Print(
1147 "Parser failed on:\n" 1149 "Parser failed on:\n"
1148 "\t%s\n" 1150 "\t%s\n"
1149 "with error:\n" 1151 "with error:\n"
1150 "\t%s\n" 1152 "\t%s\n"
1151 "However, the preparser succeeded", 1153 "However, the preparser succeeded",
1152 *source->ToCString(), *message_string->ToCString()); 1154 source->ToCString().get(), message_string->ToCString().get());
1153 CHECK(false); 1155 CHECK(false);
1154 } 1156 }
1155 // Check that preparser and parser produce the same error. 1157 // Check that preparser and parser produce the same error.
1156 i::Handle<i::String> preparser_message = FormatMessage(&data); 1158 i::Handle<i::String> preparser_message = FormatMessage(&data);
1157 if (!message_string->Equals(*preparser_message)) { 1159 if (!message_string->Equals(*preparser_message)) {
1158 i::OS::Print( 1160 i::OS::Print(
1159 "Expected parser and preparser to produce the same error on:\n" 1161 "Expected parser and preparser to produce the same error on:\n"
1160 "\t%s\n" 1162 "\t%s\n"
1161 "However, found the following error messages\n" 1163 "However, found the following error messages\n"
1162 "\tparser: %s\n" 1164 "\tparser: %s\n"
1163 "\tpreparser: %s\n", 1165 "\tpreparser: %s\n",
1164 *source->ToCString(), 1166 source->ToCString().get(),
1165 *message_string->ToCString(), 1167 message_string->ToCString().get(),
1166 *preparser_message->ToCString()); 1168 preparser_message->ToCString().get());
1167 CHECK(false); 1169 CHECK(false);
1168 } 1170 }
1169 } else if (data.has_error()) { 1171 } else if (data.has_error()) {
1170 i::OS::Print( 1172 i::OS::Print(
1171 "Preparser failed on:\n" 1173 "Preparser failed on:\n"
1172 "\t%s\n" 1174 "\t%s\n"
1173 "with error:\n" 1175 "with error:\n"
1174 "\t%s\n" 1176 "\t%s\n"
1175 "However, the parser succeeded", 1177 "However, the parser succeeded",
1176 *source->ToCString(), *FormatMessage(&data)->ToCString()); 1178 source->ToCString().get(), FormatMessage(&data)->ToCString().get());
1177 CHECK(false); 1179 CHECK(false);
1178 } 1180 }
1179 } 1181 }
1180 1182
1181 1183
1182 void TestParserSync(const char* source, 1184 void TestParserSync(const char* source,
1183 const ParserFlag* flag_list, 1185 const ParserFlag* flag_list,
1184 size_t flag_list_length) { 1186 size_t flag_list_length) {
1185 i::Handle<i::String> str = 1187 i::Handle<i::String> str =
1186 CcTest::i_isolate()->factory()->NewStringFromAscii(i::CStrVector(source)); 1188 CcTest::i_isolate()->factory()->NewStringFromAscii(i::CStrVector(source));
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 " b = function() { \n" 1328 " b = function() { \n"
1327 " 01; \n" 1329 " 01; \n"
1328 " }; \n" 1330 " }; \n"
1329 "}; \n"; 1331 "}; \n";
1330 v8::Script::Compile(v8::String::NewFromUtf8(CcTest::isolate(), script)); 1332 v8::Script::Compile(v8::String::NewFromUtf8(CcTest::isolate(), script));
1331 CHECK(try_catch.HasCaught()); 1333 CHECK(try_catch.HasCaught());
1332 v8::String::Utf8Value exception(try_catch.Exception()); 1334 v8::String::Utf8Value exception(try_catch.Exception());
1333 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", 1335 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.",
1334 *exception); 1336 *exception);
1335 } 1337 }
OLDNEW
« no previous file with comments | « test/cctest/test-object-observe.cc ('k') | test/cctest/test-profile-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698