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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 | 383 |
384 TEST(PreParseOverflow) { | 384 TEST(PreParseOverflow) { |
385 v8::V8::Initialize(); | 385 v8::V8::Initialize(); |
386 | 386 |
387 int marker; | 387 int marker; |
388 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 388 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
389 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 389 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
390 | 390 |
391 size_t kProgramSize = 1024 * 1024; | 391 size_t kProgramSize = 1024 * 1024; |
392 i::SmartArrayPointer<char> program(i::NewArray<char>(kProgramSize + 1)); | 392 i::SmartArrayPointer<char> program(i::NewArray<char>(kProgramSize + 1)); |
393 memset(*program, '(', kProgramSize); | 393 memset(program.get(), '(', kProgramSize); |
394 program[kProgramSize] = '\0'; | 394 program[kProgramSize] = '\0'; |
395 | 395 |
396 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); | 396 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); |
397 | 397 |
398 i::Utf8ToUtf16CharacterStream stream( | 398 i::Utf8ToUtf16CharacterStream stream( |
399 reinterpret_cast<const i::byte*>(*program), | 399 reinterpret_cast<const i::byte*>(program.get()), |
400 static_cast<unsigned>(kProgramSize)); | 400 static_cast<unsigned>(kProgramSize)); |
401 i::CompleteParserRecorder log; | 401 i::CompleteParserRecorder log; |
402 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 402 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
403 scanner.Initialize(&stream); | 403 scanner.Initialize(&stream); |
404 | 404 |
405 i::PreParser preparser(&scanner, &log, stack_limit); | 405 i::PreParser preparser(&scanner, &log, stack_limit); |
406 preparser.set_allow_lazy(true); | 406 preparser.set_allow_lazy(true); |
407 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 407 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
408 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); | 408 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); |
409 } | 409 } |
(...skipping 30 matching lines...) Expand all Loading... |
440 i::Isolate* isolate = CcTest::i_isolate(); | 440 i::Isolate* isolate = CcTest::i_isolate(); |
441 i::Factory* factory = isolate->factory(); | 441 i::Factory* factory = isolate->factory(); |
442 i::HandleScope test_scope(isolate); | 442 i::HandleScope test_scope(isolate); |
443 i::SmartArrayPointer<i::uc16> uc16_buffer(new i::uc16[length]); | 443 i::SmartArrayPointer<i::uc16> uc16_buffer(new i::uc16[length]); |
444 for (unsigned i = 0; i < length; i++) { | 444 for (unsigned i = 0; i < length; i++) { |
445 uc16_buffer[i] = static_cast<i::uc16>(ascii_source[i]); | 445 uc16_buffer[i] = static_cast<i::uc16>(ascii_source[i]); |
446 } | 446 } |
447 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)); |
448 i::Handle<i::String> ascii_string( | 448 i::Handle<i::String> ascii_string( |
449 factory->NewStringFromAscii(ascii_vector)); | 449 factory->NewStringFromAscii(ascii_vector)); |
450 TestExternalResource resource(*uc16_buffer, length); | 450 TestExternalResource resource(uc16_buffer.get(), length); |
451 i::Handle<i::String> uc16_string( | 451 i::Handle<i::String> uc16_string( |
452 factory->NewExternalStringFromTwoByte(&resource)); | 452 factory->NewExternalStringFromTwoByte(&resource)); |
453 | 453 |
454 i::ExternalTwoByteStringUtf16CharacterStream uc16_stream( | 454 i::ExternalTwoByteStringUtf16CharacterStream uc16_stream( |
455 i::Handle<i::ExternalTwoByteString>::cast(uc16_string), start, end); | 455 i::Handle<i::ExternalTwoByteString>::cast(uc16_string), start, end); |
456 i::GenericStringUtf16CharacterStream string_stream(ascii_string, start, end); | 456 i::GenericStringUtf16CharacterStream string_stream(ascii_string, start, end); |
457 i::Utf8ToUtf16CharacterStream utf8_stream( | 457 i::Utf8ToUtf16CharacterStream utf8_stream( |
458 reinterpret_cast<const i::byte*>(ascii_source), end); | 458 reinterpret_cast<const i::byte*>(ascii_source), end); |
459 utf8_stream.SeekForward(start); | 459 utf8_stream.SeekForward(start); |
460 | 460 |
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 i::Handle<i::String> message_string = | 1145 i::Handle<i::String> message_string = |
1146 i::Handle<i::String>::cast(i::GetProperty(exception_handle, "message")); | 1146 i::Handle<i::String>::cast(i::GetProperty(exception_handle, "message")); |
1147 | 1147 |
1148 if (!data.has_error()) { | 1148 if (!data.has_error()) { |
1149 i::OS::Print( | 1149 i::OS::Print( |
1150 "Parser failed on:\n" | 1150 "Parser failed on:\n" |
1151 "\t%s\n" | 1151 "\t%s\n" |
1152 "with error:\n" | 1152 "with error:\n" |
1153 "\t%s\n" | 1153 "\t%s\n" |
1154 "However, the preparser succeeded", | 1154 "However, the preparser succeeded", |
1155 *source->ToCString(), *message_string->ToCString()); | 1155 source->ToCString().get(), message_string->ToCString().get()); |
1156 CHECK(false); | 1156 CHECK(false); |
1157 } | 1157 } |
1158 // Check that preparser and parser produce the same error. | 1158 // Check that preparser and parser produce the same error. |
1159 i::Handle<i::String> preparser_message = FormatMessage(&data); | 1159 i::Handle<i::String> preparser_message = FormatMessage(&data); |
1160 if (!message_string->Equals(*preparser_message)) { | 1160 if (!message_string->Equals(*preparser_message)) { |
1161 i::OS::Print( | 1161 i::OS::Print( |
1162 "Expected parser and preparser to produce the same error on:\n" | 1162 "Expected parser and preparser to produce the same error on:\n" |
1163 "\t%s\n" | 1163 "\t%s\n" |
1164 "However, found the following error messages\n" | 1164 "However, found the following error messages\n" |
1165 "\tparser: %s\n" | 1165 "\tparser: %s\n" |
1166 "\tpreparser: %s\n", | 1166 "\tpreparser: %s\n", |
1167 *source->ToCString(), | 1167 source->ToCString().get(), |
1168 *message_string->ToCString(), | 1168 message_string->ToCString().get(), |
1169 *preparser_message->ToCString()); | 1169 preparser_message->ToCString().get()); |
1170 CHECK(false); | 1170 CHECK(false); |
1171 } | 1171 } |
1172 } else if (data.has_error()) { | 1172 } else if (data.has_error()) { |
1173 i::OS::Print( | 1173 i::OS::Print( |
1174 "Preparser failed on:\n" | 1174 "Preparser failed on:\n" |
1175 "\t%s\n" | 1175 "\t%s\n" |
1176 "with error:\n" | 1176 "with error:\n" |
1177 "\t%s\n" | 1177 "\t%s\n" |
1178 "However, the parser succeeded", | 1178 "However, the parser succeeded", |
1179 *source->ToCString(), *FormatMessage(&data)->ToCString()); | 1179 source->ToCString().get(), FormatMessage(&data)->ToCString().get()); |
1180 CHECK(false); | 1180 CHECK(false); |
1181 } | 1181 } |
1182 } | 1182 } |
1183 | 1183 |
1184 | 1184 |
1185 void TestParserSync(const char* source, | 1185 void TestParserSync(const char* source, |
1186 const ParserFlag* flag_list, | 1186 const ParserFlag* flag_list, |
1187 size_t flag_list_length) { | 1187 size_t flag_list_length) { |
1188 i::Handle<i::String> str = | 1188 i::Handle<i::String> str = |
1189 CcTest::i_isolate()->factory()->NewStringFromAscii(i::CStrVector(source)); | 1189 CcTest::i_isolate()->factory()->NewStringFromAscii(i::CStrVector(source)); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1329 " b = function() { \n" | 1329 " b = function() { \n" |
1330 " 01; \n" | 1330 " 01; \n" |
1331 " }; \n" | 1331 " }; \n" |
1332 "}; \n"; | 1332 "}; \n"; |
1333 v8::Script::Compile(v8::String::NewFromUtf8(CcTest::isolate(), script)); | 1333 v8::Script::Compile(v8::String::NewFromUtf8(CcTest::isolate(), script)); |
1334 CHECK(try_catch.HasCaught()); | 1334 CHECK(try_catch.HasCaught()); |
1335 v8::String::Utf8Value exception(try_catch.Exception()); | 1335 v8::String::Utf8Value exception(try_catch.Exception()); |
1336 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", | 1336 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", |
1337 *exception); | 1337 *exception); |
1338 } | 1338 } |
OLD | NEW |