| 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 const i::byte* source = | 150 const i::byte* source = |
| 151 reinterpret_cast<const i::byte*>(tests[i]); | 151 reinterpret_cast<const i::byte*>(tests[i]); |
| 152 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(tests[i])); | 152 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(tests[i])); |
| 153 i::CompleteParserRecorder log; | 153 i::CompleteParserRecorder log; |
| 154 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 154 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 155 scanner.Initialize(&stream); | 155 scanner.Initialize(&stream); |
| 156 i::PreParser preparser(&scanner, &log, stack_limit); | 156 i::PreParser preparser(&scanner, &log, stack_limit); |
| 157 preparser.set_allow_lazy(true); | 157 preparser.set_allow_lazy(true); |
| 158 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 158 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 159 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 159 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 160 i::ScriptData data(log.ExtractData()); | 160 CHECK(!log.HasError()); |
| 161 CHECK(!data.has_error()); | |
| 162 } | 161 } |
| 163 | 162 |
| 164 for (int i = 0; fail_tests[i]; i++) { | 163 for (int i = 0; fail_tests[i]; i++) { |
| 165 const i::byte* source = | 164 const i::byte* source = |
| 166 reinterpret_cast<const i::byte*>(fail_tests[i]); | 165 reinterpret_cast<const i::byte*>(fail_tests[i]); |
| 167 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i])); | 166 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i])); |
| 168 i::CompleteParserRecorder log; | 167 i::CompleteParserRecorder log; |
| 169 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 168 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 170 scanner.Initialize(&stream); | 169 scanner.Initialize(&stream); |
| 171 i::PreParser preparser(&scanner, &log, stack_limit); | 170 i::PreParser preparser(&scanner, &log, stack_limit); |
| 172 preparser.set_allow_lazy(true); | 171 preparser.set_allow_lazy(true); |
| 173 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 172 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 174 // Even in the case of a syntax error, kPreParseSuccess is returned. | 173 // Even in the case of a syntax error, kPreParseSuccess is returned. |
| 175 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 174 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 176 i::ScriptData data(log.ExtractData()); | 175 CHECK(log.HasError()); |
| 177 CHECK(data.has_error()); | |
| 178 } | 176 } |
| 179 } | 177 } |
| 180 | 178 |
| 181 | 179 |
| 182 class ScriptResource : public v8::String::ExternalAsciiStringResource { | 180 class ScriptResource : public v8::String::ExternalAsciiStringResource { |
| 183 public: | 181 public: |
| 184 ScriptResource(const char* data, size_t length) | 182 ScriptResource(const char* data, size_t length) |
| 185 : data_(data), length_(length) { } | 183 : data_(data), length_(length) { } |
| 186 | 184 |
| 187 const char* data() const { return data_; } | 185 const char* data() const { return data_; } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 static_cast<unsigned>(strlen(program))); | 297 static_cast<unsigned>(strlen(program))); |
| 300 i::CompleteParserRecorder log; | 298 i::CompleteParserRecorder log; |
| 301 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 299 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 302 scanner.Initialize(&stream); | 300 scanner.Initialize(&stream); |
| 303 | 301 |
| 304 i::PreParser preparser(&scanner, &log, stack_limit); | 302 i::PreParser preparser(&scanner, &log, stack_limit); |
| 305 preparser.set_allow_lazy(true); | 303 preparser.set_allow_lazy(true); |
| 306 preparser.set_allow_natives_syntax(true); | 304 preparser.set_allow_natives_syntax(true); |
| 307 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 305 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 308 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 306 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 309 i::ScriptData data(log.ExtractData()); | 307 CHECK(!log.HasError()); |
| 310 CHECK(!data.has_error()); | |
| 311 } | 308 } |
| 312 } | 309 } |
| 313 | 310 |
| 314 | 311 |
| 315 TEST(StandAlonePreParserNoNatives) { | 312 TEST(StandAlonePreParserNoNatives) { |
| 316 v8::V8::Initialize(); | 313 v8::V8::Initialize(); |
| 317 | 314 |
| 318 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - | 315 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - |
| 319 128 * 1024); | 316 128 * 1024); |
| 320 | 317 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 332 static_cast<unsigned>(strlen(program))); | 329 static_cast<unsigned>(strlen(program))); |
| 333 i::CompleteParserRecorder log; | 330 i::CompleteParserRecorder log; |
| 334 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 331 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 335 scanner.Initialize(&stream); | 332 scanner.Initialize(&stream); |
| 336 | 333 |
| 337 // Preparser defaults to disallowing natives syntax. | 334 // Preparser defaults to disallowing natives syntax. |
| 338 i::PreParser preparser(&scanner, &log, stack_limit); | 335 i::PreParser preparser(&scanner, &log, stack_limit); |
| 339 preparser.set_allow_lazy(true); | 336 preparser.set_allow_lazy(true); |
| 340 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 337 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 341 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 338 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 342 i::ScriptData data(log.ExtractData()); | 339 CHECK(log.HasError()); |
| 343 // Data contains syntax error. | |
| 344 CHECK(data.has_error()); | |
| 345 } | 340 } |
| 346 } | 341 } |
| 347 | 342 |
| 348 | 343 |
| 349 TEST(PreparsingObjectLiterals) { | 344 TEST(PreparsingObjectLiterals) { |
| 350 // Regression test for a bug where the symbol stream produced by PreParser | 345 // Regression test for a bug where the symbol stream produced by PreParser |
| 351 // didn't match what Parser wanted to consume. | 346 // didn't match what Parser wanted to consume. |
| 352 v8::Isolate* isolate = CcTest::isolate(); | 347 v8::Isolate* isolate = CcTest::isolate(); |
| 353 v8::HandleScope handles(isolate); | 348 v8::HandleScope handles(isolate); |
| 354 v8::Local<v8::Context> context = v8::Context::New(isolate); | 349 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 static_cast<unsigned>(strlen(program))); | 395 static_cast<unsigned>(strlen(program))); |
| 401 i::CompleteParserRecorder log; | 396 i::CompleteParserRecorder log; |
| 402 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 397 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 403 scanner.Initialize(&stream); | 398 scanner.Initialize(&stream); |
| 404 i::PreParser preparser(&scanner, &log, | 399 i::PreParser preparser(&scanner, &log, |
| 405 CcTest::i_isolate()->stack_guard()->real_climit()); | 400 CcTest::i_isolate()->stack_guard()->real_climit()); |
| 406 preparser.set_allow_lazy(true); | 401 preparser.set_allow_lazy(true); |
| 407 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 402 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 408 // Even in the case of a syntax error, kPreParseSuccess is returned. | 403 // Even in the case of a syntax error, kPreParseSuccess is returned. |
| 409 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 404 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 410 i::ScriptData data(log.ExtractData()); | 405 CHECK(log.HasError()); |
| 411 CHECK(data.has_error()); | |
| 412 } | 406 } |
| 413 | 407 |
| 414 | 408 |
| 415 TEST(Regress928) { | 409 TEST(Regress928) { |
| 416 v8::V8::Initialize(); | 410 v8::V8::Initialize(); |
| 417 i::Isolate* isolate = CcTest::i_isolate(); | 411 i::Isolate* isolate = CcTest::i_isolate(); |
| 418 i::Factory* factory = isolate->factory(); | 412 i::Factory* factory = isolate->factory(); |
| 419 | 413 |
| 420 // Preparsing didn't consider the catch clause of a try statement | 414 // Preparsing didn't consider the catch clause of a try statement |
| 421 // as with-content, which made it assume that a function inside | 415 // as with-content, which made it assume that a function inside |
| 422 // the block could be lazily compiled, and an extra, unexpected, | 416 // the block could be lazily compiled, and an extra, unexpected, |
| 423 // entry was added to the data. | 417 // entry was added to the data. |
| 424 isolate->stack_guard()->SetStackLimit(GetCurrentStackPosition() - 128 * 1024); | 418 isolate->stack_guard()->SetStackLimit(GetCurrentStackPosition() - 128 * 1024); |
| 425 | 419 |
| 426 const char* program = | 420 const char* program = |
| 427 "try { } catch (e) { var foo = function () { /* first */ } }" | 421 "try { } catch (e) { var foo = function () { /* first */ } }" |
| 428 "var bar = function () { /* second */ }"; | 422 "var bar = function () { /* second */ }"; |
| 429 | 423 |
| 430 v8::HandleScope handles(CcTest::isolate()); | 424 v8::HandleScope handles(CcTest::isolate()); |
| 431 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(program); | 425 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(program); |
| 432 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 426 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
| 433 i::CompleteParserRecorder log; | 427 i::CompleteParserRecorder log; |
| 434 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 428 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 435 scanner.Initialize(&stream); | 429 scanner.Initialize(&stream); |
| 436 i::PreParser preparser(&scanner, &log, | 430 i::PreParser preparser(&scanner, &log, |
| 437 CcTest::i_isolate()->stack_guard()->real_climit()); | 431 CcTest::i_isolate()->stack_guard()->real_climit()); |
| 438 preparser.set_allow_lazy(true); | 432 preparser.set_allow_lazy(true); |
| 439 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 433 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 440 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 434 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 441 i::ScriptData data(log.ExtractData()); | 435 i::ScriptData* sd = log.GetScriptData(); |
| 442 CHECK(!data.has_error()); | 436 i::ParseData pd(sd); |
| 443 data.Initialize(); | 437 pd.Initialize(); |
| 444 | 438 |
| 445 int first_function = | 439 int first_function = |
| 446 static_cast<int>(strstr(program, "function") - program); | 440 static_cast<int>(strstr(program, "function") - program); |
| 447 int first_lbrace = first_function + i::StrLength("function () "); | 441 int first_lbrace = first_function + i::StrLength("function () "); |
| 448 CHECK_EQ('{', program[first_lbrace]); | 442 CHECK_EQ('{', program[first_lbrace]); |
| 449 i::FunctionEntry entry1 = data.GetFunctionEntry(first_lbrace); | 443 i::FunctionEntry entry1 = pd.GetFunctionEntry(first_lbrace); |
| 450 CHECK(!entry1.is_valid()); | 444 CHECK(!entry1.is_valid()); |
| 451 | 445 |
| 452 int second_function = | 446 int second_function = |
| 453 static_cast<int>(strstr(program + first_lbrace, "function") - program); | 447 static_cast<int>(strstr(program + first_lbrace, "function") - program); |
| 454 int second_lbrace = | 448 int second_lbrace = |
| 455 second_function + i::StrLength("function () "); | 449 second_function + i::StrLength("function () "); |
| 456 CHECK_EQ('{', program[second_lbrace]); | 450 CHECK_EQ('{', program[second_lbrace]); |
| 457 i::FunctionEntry entry2 = data.GetFunctionEntry(second_lbrace); | 451 i::FunctionEntry entry2 = pd.GetFunctionEntry(second_lbrace); |
| 458 CHECK(entry2.is_valid()); | 452 CHECK(entry2.is_valid()); |
| 459 CHECK_EQ('}', program[entry2.end_pos() - 1]); | 453 CHECK_EQ('}', program[entry2.end_pos() - 1]); |
| 454 delete sd; |
| 460 } | 455 } |
| 461 | 456 |
| 462 | 457 |
| 463 TEST(PreParseOverflow) { | 458 TEST(PreParseOverflow) { |
| 464 v8::V8::Initialize(); | 459 v8::V8::Initialize(); |
| 465 | 460 |
| 466 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - | 461 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - |
| 467 128 * 1024); | 462 128 * 1024); |
| 468 | 463 |
| 469 size_t kProgramSize = 1024 * 1024; | 464 size_t kProgramSize = 1024 * 1024; |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 i::Scope* inner_scope = scope->inner_scopes()->at(0); | 1122 i::Scope* inner_scope = scope->inner_scopes()->at(0); |
| 1128 CHECK_EQ(inner_scope->scope_type(), source_data[i].scope_type); | 1123 CHECK_EQ(inner_scope->scope_type(), source_data[i].scope_type); |
| 1129 CHECK_EQ(inner_scope->start_position(), kPrefixLen); | 1124 CHECK_EQ(inner_scope->start_position(), kPrefixLen); |
| 1130 // The end position of a token is one position after the last | 1125 // The end position of a token is one position after the last |
| 1131 // character belonging to that token. | 1126 // character belonging to that token. |
| 1132 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); | 1127 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); |
| 1133 } | 1128 } |
| 1134 } | 1129 } |
| 1135 | 1130 |
| 1136 | 1131 |
| 1137 i::Handle<i::String> FormatMessage(i::ScriptData* data) { | 1132 const char* ReadString(unsigned* start) { |
| 1133 int length = start[0]; |
| 1134 char* result = i::NewArray<char>(length + 1); |
| 1135 for (int i = 0; i < length; i++) { |
| 1136 result[i] = start[i + 1]; |
| 1137 } |
| 1138 result[length] = '\0'; |
| 1139 return result; |
| 1140 } |
| 1141 |
| 1142 |
| 1143 i::Handle<i::String> FormatMessage(i::Vector<unsigned> data) { |
| 1138 i::Isolate* isolate = CcTest::i_isolate(); | 1144 i::Isolate* isolate = CcTest::i_isolate(); |
| 1139 i::Factory* factory = isolate->factory(); | 1145 i::Factory* factory = isolate->factory(); |
| 1140 const char* message = data->BuildMessage(); | 1146 const char* message = |
| 1147 ReadString(&data[i::PreparseDataConstants::kMessageTextPos]); |
| 1141 i::Handle<i::String> format = v8::Utils::OpenHandle( | 1148 i::Handle<i::String> format = v8::Utils::OpenHandle( |
| 1142 *v8::String::NewFromUtf8(CcTest::isolate(), message)); | 1149 *v8::String::NewFromUtf8(CcTest::isolate(), message)); |
| 1143 const char* arg = data->BuildArg(); | 1150 int arg_count = data[i::PreparseDataConstants::kMessageArgCountPos]; |
| 1144 i::Handle<i::JSArray> args_array = factory->NewJSArray(arg == NULL ? 0 : 1); | 1151 const char* arg = NULL; |
| 1145 if (arg != NULL) { | 1152 i::Handle<i::JSArray> args_array; |
| 1146 i::JSArray::SetElement( | 1153 if (arg_count == 1) { |
| 1147 args_array, 0, v8::Utils::OpenHandle(*v8::String::NewFromUtf8( | 1154 // Position after text found by skipping past length field and |
| 1148 CcTest::isolate(), arg)), | 1155 // length field content words. |
| 1149 NONE, i::SLOPPY).Check(); | 1156 int pos = i::PreparseDataConstants::kMessageTextPos + 1 + |
| 1157 data[i::PreparseDataConstants::kMessageTextPos]; |
| 1158 arg = ReadString(&data[pos]); |
| 1159 args_array = factory->NewJSArray(1); |
| 1160 i::JSArray::SetElement(args_array, 0, v8::Utils::OpenHandle(*v8_str(arg)), |
| 1161 NONE, i::SLOPPY).Check(); |
| 1162 } else { |
| 1163 CHECK_EQ(0, arg_count); |
| 1164 args_array = factory->NewJSArray(0); |
| 1150 } | 1165 } |
| 1166 |
| 1151 i::Handle<i::JSObject> builtins(isolate->js_builtins_object()); | 1167 i::Handle<i::JSObject> builtins(isolate->js_builtins_object()); |
| 1152 i::Handle<i::Object> format_fun = i::Object::GetProperty( | 1168 i::Handle<i::Object> format_fun = i::Object::GetProperty( |
| 1153 isolate, builtins, "FormatMessage").ToHandleChecked(); | 1169 isolate, builtins, "FormatMessage").ToHandleChecked(); |
| 1154 i::Handle<i::Object> arg_handles[] = { format, args_array }; | 1170 i::Handle<i::Object> arg_handles[] = { format, args_array }; |
| 1155 i::Handle<i::Object> result = i::Execution::Call( | 1171 i::Handle<i::Object> result = i::Execution::Call( |
| 1156 isolate, format_fun, builtins, 2, arg_handles).ToHandleChecked(); | 1172 isolate, format_fun, builtins, 2, arg_handles).ToHandleChecked(); |
| 1157 CHECK(result->IsString()); | 1173 CHECK(result->IsString()); |
| 1158 i::DeleteArray(message); | 1174 i::DeleteArray(message); |
| 1159 i::DeleteArray(arg); | 1175 i::DeleteArray(arg); |
| 1176 data.Dispose(); |
| 1160 return i::Handle<i::String>::cast(result); | 1177 return i::Handle<i::String>::cast(result); |
| 1161 } | 1178 } |
| 1162 | 1179 |
| 1163 | 1180 |
| 1164 enum ParserFlag { | 1181 enum ParserFlag { |
| 1165 kAllowLazy, | 1182 kAllowLazy, |
| 1166 kAllowNativesSyntax, | 1183 kAllowNativesSyntax, |
| 1167 kAllowHarmonyScoping, | 1184 kAllowHarmonyScoping, |
| 1168 kAllowModules, | 1185 kAllowModules, |
| 1169 kAllowGenerators, | 1186 kAllowGenerators, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1204 i::CompleteParserRecorder log; | 1221 i::CompleteParserRecorder log; |
| 1205 { | 1222 { |
| 1206 i::Scanner scanner(isolate->unicode_cache()); | 1223 i::Scanner scanner(isolate->unicode_cache()); |
| 1207 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 1224 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
| 1208 i::PreParser preparser(&scanner, &log, stack_limit); | 1225 i::PreParser preparser(&scanner, &log, stack_limit); |
| 1209 SetParserFlags(&preparser, flags); | 1226 SetParserFlags(&preparser, flags); |
| 1210 scanner.Initialize(&stream); | 1227 scanner.Initialize(&stream); |
| 1211 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 1228 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 1212 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 1229 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 1213 } | 1230 } |
| 1214 i::ScriptData data(log.ExtractData()); | 1231 |
| 1232 bool preparse_error = log.HasError(); |
| 1215 | 1233 |
| 1216 // Parse the data | 1234 // Parse the data |
| 1217 i::FunctionLiteral* function; | 1235 i::FunctionLiteral* function; |
| 1218 { | 1236 { |
| 1219 i::Handle<i::Script> script = factory->NewScript(source); | 1237 i::Handle<i::Script> script = factory->NewScript(source); |
| 1220 i::CompilationInfoWithZone info(script); | 1238 i::CompilationInfoWithZone info(script); |
| 1221 i::Parser parser(&info); | 1239 i::Parser parser(&info); |
| 1222 SetParserFlags(&parser, flags); | 1240 SetParserFlags(&parser, flags); |
| 1223 info.MarkAsGlobal(); | 1241 info.MarkAsGlobal(); |
| 1224 parser.Parse(); | 1242 parser.Parse(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1239 v8::base::OS::Print( | 1257 v8::base::OS::Print( |
| 1240 "Parser failed on:\n" | 1258 "Parser failed on:\n" |
| 1241 "\t%s\n" | 1259 "\t%s\n" |
| 1242 "with error:\n" | 1260 "with error:\n" |
| 1243 "\t%s\n" | 1261 "\t%s\n" |
| 1244 "However, we expected no error.", | 1262 "However, we expected no error.", |
| 1245 source->ToCString().get(), message_string->ToCString().get()); | 1263 source->ToCString().get(), message_string->ToCString().get()); |
| 1246 CHECK(false); | 1264 CHECK(false); |
| 1247 } | 1265 } |
| 1248 | 1266 |
| 1249 if (!data.has_error()) { | 1267 if (!preparse_error) { |
| 1250 v8::base::OS::Print( | 1268 v8::base::OS::Print( |
| 1251 "Parser failed on:\n" | 1269 "Parser failed on:\n" |
| 1252 "\t%s\n" | 1270 "\t%s\n" |
| 1253 "with error:\n" | 1271 "with error:\n" |
| 1254 "\t%s\n" | 1272 "\t%s\n" |
| 1255 "However, the preparser succeeded", | 1273 "However, the preparser succeeded", |
| 1256 source->ToCString().get(), message_string->ToCString().get()); | 1274 source->ToCString().get(), message_string->ToCString().get()); |
| 1257 CHECK(false); | 1275 CHECK(false); |
| 1258 } | 1276 } |
| 1259 // Check that preparser and parser produce the same error. | 1277 // Check that preparser and parser produce the same error. |
| 1260 i::Handle<i::String> preparser_message = FormatMessage(&data); | 1278 i::Handle<i::String> preparser_message = |
| 1279 FormatMessage(log.ErrorMessageData()); |
| 1261 if (!i::String::Equals(message_string, preparser_message)) { | 1280 if (!i::String::Equals(message_string, preparser_message)) { |
| 1262 v8::base::OS::Print( | 1281 v8::base::OS::Print( |
| 1263 "Expected parser and preparser to produce the same error on:\n" | 1282 "Expected parser and preparser to produce the same error on:\n" |
| 1264 "\t%s\n" | 1283 "\t%s\n" |
| 1265 "However, found the following error messages\n" | 1284 "However, found the following error messages\n" |
| 1266 "\tparser: %s\n" | 1285 "\tparser: %s\n" |
| 1267 "\tpreparser: %s\n", | 1286 "\tpreparser: %s\n", |
| 1268 source->ToCString().get(), | 1287 source->ToCString().get(), |
| 1269 message_string->ToCString().get(), | 1288 message_string->ToCString().get(), |
| 1270 preparser_message->ToCString().get()); | 1289 preparser_message->ToCString().get()); |
| 1271 CHECK(false); | 1290 CHECK(false); |
| 1272 } | 1291 } |
| 1273 } else if (data.has_error()) { | 1292 } else if (preparse_error) { |
| 1274 v8::base::OS::Print( | 1293 v8::base::OS::Print( |
| 1275 "Preparser failed on:\n" | 1294 "Preparser failed on:\n" |
| 1276 "\t%s\n" | 1295 "\t%s\n" |
| 1277 "with error:\n" | 1296 "with error:\n" |
| 1278 "\t%s\n" | 1297 "\t%s\n" |
| 1279 "However, the parser succeeded", | 1298 "However, the parser succeeded", |
| 1280 source->ToCString().get(), FormatMessage(&data)->ToCString().get()); | 1299 source->ToCString().get(), FormatMessage(log.ErrorMessageData())); |
| 1281 CHECK(false); | 1300 CHECK(false); |
| 1282 } else if (result == kError) { | 1301 } else if (result == kError) { |
| 1283 v8::base::OS::Print( | 1302 v8::base::OS::Print( |
| 1284 "Expected error on:\n" | 1303 "Expected error on:\n" |
| 1285 "\t%s\n" | 1304 "\t%s\n" |
| 1286 "However, parser and preparser succeeded", | 1305 "However, parser and preparser succeeded", |
| 1287 source->ToCString().get()); | 1306 source->ToCString().get()); |
| 1288 CHECK(false); | 1307 CHECK(false); |
| 1289 } | 1308 } |
| 1290 } | 1309 } |
| (...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2158 {NULL, 0} | 2177 {NULL, 0} |
| 2159 }; | 2178 }; |
| 2160 | 2179 |
| 2161 for (int i = 0; test_cases[i].program; i++) { | 2180 for (int i = 0; test_cases[i].program; i++) { |
| 2162 const char* program = test_cases[i].program; | 2181 const char* program = test_cases[i].program; |
| 2163 i::Factory* factory = CcTest::i_isolate()->factory(); | 2182 i::Factory* factory = CcTest::i_isolate()->factory(); |
| 2164 i::Handle<i::String> source = | 2183 i::Handle<i::String> source = |
| 2165 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); | 2184 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); |
| 2166 i::Handle<i::Script> script = factory->NewScript(source); | 2185 i::Handle<i::Script> script = factory->NewScript(source); |
| 2167 i::CompilationInfoWithZone info(script); | 2186 i::CompilationInfoWithZone info(script); |
| 2168 i::ScriptData* data = NULL; | 2187 i::ScriptData* sd = NULL; |
| 2169 info.SetCachedData(&data, i::PRODUCE_CACHED_DATA); | 2188 info.SetCachedData(&sd, i::PRODUCE_CACHED_DATA); |
| 2170 i::Parser::Parse(&info, true); | 2189 i::Parser::Parse(&info, true); |
| 2171 CHECK(data); | 2190 i::ParseData pd(sd); |
| 2172 CHECK(!data->HasError()); | |
| 2173 | 2191 |
| 2174 if (data->function_count() != test_cases[i].functions) { | 2192 if (pd.FunctionCount() != test_cases[i].functions) { |
| 2175 v8::base::OS::Print( | 2193 v8::base::OS::Print( |
| 2176 "Expected preparse data for program:\n" | 2194 "Expected preparse data for program:\n" |
| 2177 "\t%s\n" | 2195 "\t%s\n" |
| 2178 "to contain %d functions, however, received %d functions.\n", | 2196 "to contain %d functions, however, received %d functions.\n", |
| 2179 program, test_cases[i].functions, | 2197 program, test_cases[i].functions, pd.FunctionCount()); |
| 2180 data->function_count()); | |
| 2181 CHECK(false); | 2198 CHECK(false); |
| 2182 } | 2199 } |
| 2183 delete data; | 2200 delete sd; |
| 2184 } | 2201 } |
| 2185 } | 2202 } |
| 2186 | 2203 |
| 2187 | 2204 |
| 2188 TEST(FunctionDeclaresItselfStrict) { | 2205 TEST(FunctionDeclaresItselfStrict) { |
| 2189 // Tests that we produce the right kinds of errors when a function declares | 2206 // Tests that we produce the right kinds of errors when a function declares |
| 2190 // itself strict (we cannot produce there errors as soon as we see the | 2207 // itself strict (we cannot produce there errors as soon as we see the |
| 2191 // offending identifiers, because we don't know at that point whether the | 2208 // offending identifiers, because we don't know at that point whether the |
| 2192 // function is strict or not). | 2209 // function is strict or not). |
| 2193 const char* context_data[][2] = { | 2210 const char* context_data[][2] = { |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2895 LocalContext env; | 2912 LocalContext env; |
| 2896 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; | 2913 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; |
| 2897 global_use_counts = use_counts; | 2914 global_use_counts = use_counts; |
| 2898 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); | 2915 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); |
| 2899 CompileRun("\"use asm\";\n" | 2916 CompileRun("\"use asm\";\n" |
| 2900 "var foo = 1;\n" | 2917 "var foo = 1;\n" |
| 2901 "\"use asm\";\n" // Only the first one counts. | 2918 "\"use asm\";\n" // Only the first one counts. |
| 2902 "function bar() { \"use asm\"; var baz = 1; }"); | 2919 "function bar() { \"use asm\"; var baz = 1; }"); |
| 2903 CHECK_EQ(2, use_counts[v8::Isolate::kUseAsm]); | 2920 CHECK_EQ(2, use_counts[v8::Isolate::kUseAsm]); |
| 2904 } | 2921 } |
| OLD | NEW |