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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 i::Utf8ToUtf16CharacterStream stream(buffer, length); | 101 i::Utf8ToUtf16CharacterStream stream(buffer, length); |
102 i::Scanner scanner(&unicode_cache); | 102 i::Scanner scanner(&unicode_cache); |
103 scanner.Initialize(&stream); | 103 scanner.Initialize(&stream); |
104 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); | 104 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); |
105 CHECK_EQ(i::Token::EOS, scanner.Next()); | 105 CHECK_EQ(i::Token::EOS, scanner.Next()); |
106 } | 106 } |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 | 110 |
111 bool ParseDataHasError(i::ScriptData* sd) { | |
112 i::ParseData pd(sd); | |
113 bool result = pd.HasError(); | |
114 delete sd; | |
115 return result; | |
116 } | |
117 | |
118 | |
111 TEST(ScanHTMLEndComments) { | 119 TEST(ScanHTMLEndComments) { |
112 v8::V8::Initialize(); | 120 v8::V8::Initialize(); |
113 v8::Isolate* isolate = CcTest::isolate(); | 121 v8::Isolate* isolate = CcTest::isolate(); |
114 v8::HandleScope handles(isolate); | 122 v8::HandleScope handles(isolate); |
115 | 123 |
116 // Regression test. See: | 124 // Regression test. See: |
117 // http://code.google.com/p/chromium/issues/detail?id=53548 | 125 // http://code.google.com/p/chromium/issues/detail?id=53548 |
118 // Tests that --> is correctly interpreted as comment-to-end-of-line if there | 126 // Tests that --> is correctly interpreted as comment-to-end-of-line if there |
119 // is only whitespace before it on the line (with comments considered as | 127 // is only whitespace before it on the line (with comments considered as |
120 // whitespace, even a multiline-comment containing a newline). | 128 // whitespace, even a multiline-comment containing a newline). |
(...skipping 29 matching lines...) Expand all Loading... | |
150 const i::byte* source = | 158 const i::byte* source = |
151 reinterpret_cast<const i::byte*>(tests[i]); | 159 reinterpret_cast<const i::byte*>(tests[i]); |
152 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(tests[i])); | 160 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(tests[i])); |
153 i::CompleteParserRecorder log; | 161 i::CompleteParserRecorder log; |
154 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 162 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
155 scanner.Initialize(&stream); | 163 scanner.Initialize(&stream); |
156 i::PreParser preparser(&scanner, &log, stack_limit); | 164 i::PreParser preparser(&scanner, &log, stack_limit); |
157 preparser.set_allow_lazy(true); | 165 preparser.set_allow_lazy(true); |
158 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 166 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
159 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 167 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
160 i::ScriptData data(log.ExtractData()); | 168 CHECK(!ParseDataHasError(log.GetScriptData())); |
161 CHECK(!data.has_error()); | |
162 } | 169 } |
163 | 170 |
164 for (int i = 0; fail_tests[i]; i++) { | 171 for (int i = 0; fail_tests[i]; i++) { |
165 const i::byte* source = | 172 const i::byte* source = |
166 reinterpret_cast<const i::byte*>(fail_tests[i]); | 173 reinterpret_cast<const i::byte*>(fail_tests[i]); |
167 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i])); | 174 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i])); |
168 i::CompleteParserRecorder log; | 175 i::CompleteParserRecorder log; |
169 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 176 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
170 scanner.Initialize(&stream); | 177 scanner.Initialize(&stream); |
171 i::PreParser preparser(&scanner, &log, stack_limit); | 178 i::PreParser preparser(&scanner, &log, stack_limit); |
172 preparser.set_allow_lazy(true); | 179 preparser.set_allow_lazy(true); |
173 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 180 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
174 // Even in the case of a syntax error, kPreParseSuccess is returned. | 181 // Even in the case of a syntax error, kPreParseSuccess is returned. |
175 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 182 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
176 i::ScriptData data(log.ExtractData()); | 183 CHECK(ParseDataHasError(log.GetScriptData())); |
177 CHECK(data.has_error()); | |
178 } | 184 } |
179 } | 185 } |
180 | 186 |
181 | 187 |
182 class ScriptResource : public v8::String::ExternalAsciiStringResource { | 188 class ScriptResource : public v8::String::ExternalAsciiStringResource { |
183 public: | 189 public: |
184 ScriptResource(const char* data, size_t length) | 190 ScriptResource(const char* data, size_t length) |
185 : data_(data), length_(length) { } | 191 : data_(data), length_(length) { } |
186 | 192 |
187 const char* data() const { return data_; } | 193 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))); | 305 static_cast<unsigned>(strlen(program))); |
300 i::CompleteParserRecorder log; | 306 i::CompleteParserRecorder log; |
301 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 307 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
302 scanner.Initialize(&stream); | 308 scanner.Initialize(&stream); |
303 | 309 |
304 i::PreParser preparser(&scanner, &log, stack_limit); | 310 i::PreParser preparser(&scanner, &log, stack_limit); |
305 preparser.set_allow_lazy(true); | 311 preparser.set_allow_lazy(true); |
306 preparser.set_allow_natives_syntax(true); | 312 preparser.set_allow_natives_syntax(true); |
307 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 313 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
308 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 314 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
309 i::ScriptData data(log.ExtractData()); | 315 i::ScriptData* data = log.GetScriptData(); |
310 CHECK(!data.has_error()); | 316 CHECK(!i::ParseData(data).HasError()); |
317 delete data; | |
311 } | 318 } |
312 } | 319 } |
313 | 320 |
314 | 321 |
315 TEST(StandAlonePreParserNoNatives) { | 322 TEST(StandAlonePreParserNoNatives) { |
316 v8::V8::Initialize(); | 323 v8::V8::Initialize(); |
317 | 324 |
318 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - | 325 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - |
319 128 * 1024); | 326 128 * 1024); |
320 | 327 |
(...skipping 11 matching lines...) Expand all Loading... | |
332 static_cast<unsigned>(strlen(program))); | 339 static_cast<unsigned>(strlen(program))); |
333 i::CompleteParserRecorder log; | 340 i::CompleteParserRecorder log; |
334 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 341 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
335 scanner.Initialize(&stream); | 342 scanner.Initialize(&stream); |
336 | 343 |
337 // Preparser defaults to disallowing natives syntax. | 344 // Preparser defaults to disallowing natives syntax. |
338 i::PreParser preparser(&scanner, &log, stack_limit); | 345 i::PreParser preparser(&scanner, &log, stack_limit); |
339 preparser.set_allow_lazy(true); | 346 preparser.set_allow_lazy(true); |
340 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 347 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
341 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 348 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
342 i::ScriptData data(log.ExtractData()); | 349 i::ScriptData* data = log.GetScriptData(); |
343 // Data contains syntax error. | 350 // Data contains syntax error. |
344 CHECK(data.has_error()); | 351 CHECK(i::ParseData(data).HasError()); |
352 delete data; | |
345 } | 353 } |
346 } | 354 } |
347 | 355 |
348 | 356 |
349 TEST(PreparsingObjectLiterals) { | 357 TEST(PreparsingObjectLiterals) { |
350 // Regression test for a bug where the symbol stream produced by PreParser | 358 // Regression test for a bug where the symbol stream produced by PreParser |
351 // didn't match what Parser wanted to consume. | 359 // didn't match what Parser wanted to consume. |
352 v8::Isolate* isolate = CcTest::isolate(); | 360 v8::Isolate* isolate = CcTest::isolate(); |
353 v8::HandleScope handles(isolate); | 361 v8::HandleScope handles(isolate); |
354 v8::Local<v8::Context> context = v8::Context::New(isolate); | 362 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))); | 408 static_cast<unsigned>(strlen(program))); |
401 i::CompleteParserRecorder log; | 409 i::CompleteParserRecorder log; |
402 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 410 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
403 scanner.Initialize(&stream); | 411 scanner.Initialize(&stream); |
404 i::PreParser preparser(&scanner, &log, | 412 i::PreParser preparser(&scanner, &log, |
405 CcTest::i_isolate()->stack_guard()->real_climit()); | 413 CcTest::i_isolate()->stack_guard()->real_climit()); |
406 preparser.set_allow_lazy(true); | 414 preparser.set_allow_lazy(true); |
407 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 415 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
408 // Even in the case of a syntax error, kPreParseSuccess is returned. | 416 // Even in the case of a syntax error, kPreParseSuccess is returned. |
409 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 417 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
410 i::ScriptData data(log.ExtractData()); | 418 CHECK(ParseDataHasError(log.GetScriptData())); |
411 CHECK(data.has_error()); | |
412 } | 419 } |
413 | 420 |
414 | 421 |
415 TEST(Regress928) { | 422 TEST(Regress928) { |
416 v8::V8::Initialize(); | 423 v8::V8::Initialize(); |
417 i::Isolate* isolate = CcTest::i_isolate(); | 424 i::Isolate* isolate = CcTest::i_isolate(); |
418 i::Factory* factory = isolate->factory(); | 425 i::Factory* factory = isolate->factory(); |
419 | 426 |
420 // Preparsing didn't consider the catch clause of a try statement | 427 // Preparsing didn't consider the catch clause of a try statement |
421 // as with-content, which made it assume that a function inside | 428 // as with-content, which made it assume that a function inside |
422 // the block could be lazily compiled, and an extra, unexpected, | 429 // the block could be lazily compiled, and an extra, unexpected, |
423 // entry was added to the data. | 430 // entry was added to the data. |
424 isolate->stack_guard()->SetStackLimit(GetCurrentStackPosition() - 128 * 1024); | 431 isolate->stack_guard()->SetStackLimit(GetCurrentStackPosition() - 128 * 1024); |
425 | 432 |
426 const char* program = | 433 const char* program = |
427 "try { } catch (e) { var foo = function () { /* first */ } }" | 434 "try { } catch (e) { var foo = function () { /* first */ } }" |
428 "var bar = function () { /* second */ }"; | 435 "var bar = function () { /* second */ }"; |
429 | 436 |
430 v8::HandleScope handles(CcTest::isolate()); | 437 v8::HandleScope handles(CcTest::isolate()); |
431 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(program); | 438 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(program); |
432 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 439 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
433 i::CompleteParserRecorder log; | 440 i::CompleteParserRecorder log; |
434 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 441 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
435 scanner.Initialize(&stream); | 442 scanner.Initialize(&stream); |
436 i::PreParser preparser(&scanner, &log, | 443 i::PreParser preparser(&scanner, &log, |
437 CcTest::i_isolate()->stack_guard()->real_climit()); | 444 CcTest::i_isolate()->stack_guard()->real_climit()); |
438 preparser.set_allow_lazy(true); | 445 preparser.set_allow_lazy(true); |
439 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 446 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
440 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 447 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
441 i::ScriptData data(log.ExtractData()); | 448 i::ScriptData* sd = log.GetScriptData(); |
442 CHECK(!data.has_error()); | 449 i::ParseData pd(sd); |
443 data.Initialize(); | 450 CHECK(!pd.HasError()); |
451 pd.Initialize(); | |
444 | 452 |
445 int first_function = | 453 int first_function = |
446 static_cast<int>(strstr(program, "function") - program); | 454 static_cast<int>(strstr(program, "function") - program); |
447 int first_lbrace = first_function + i::StrLength("function () "); | 455 int first_lbrace = first_function + i::StrLength("function () "); |
448 CHECK_EQ('{', program[first_lbrace]); | 456 CHECK_EQ('{', program[first_lbrace]); |
449 i::FunctionEntry entry1 = data.GetFunctionEntry(first_lbrace); | 457 i::FunctionEntry entry1 = pd.GetFunctionEntry(first_lbrace); |
450 CHECK(!entry1.is_valid()); | 458 CHECK(!entry1.is_valid()); |
451 | 459 |
452 int second_function = | 460 int second_function = |
453 static_cast<int>(strstr(program + first_lbrace, "function") - program); | 461 static_cast<int>(strstr(program + first_lbrace, "function") - program); |
454 int second_lbrace = | 462 int second_lbrace = |
455 second_function + i::StrLength("function () "); | 463 second_function + i::StrLength("function () "); |
456 CHECK_EQ('{', program[second_lbrace]); | 464 CHECK_EQ('{', program[second_lbrace]); |
457 i::FunctionEntry entry2 = data.GetFunctionEntry(second_lbrace); | 465 i::FunctionEntry entry2 = pd.GetFunctionEntry(second_lbrace); |
458 CHECK(entry2.is_valid()); | 466 CHECK(entry2.is_valid()); |
459 CHECK_EQ('}', program[entry2.end_pos() - 1]); | 467 CHECK_EQ('}', program[entry2.end_pos() - 1]); |
468 delete sd; | |
460 } | 469 } |
461 | 470 |
462 | 471 |
463 TEST(PreParseOverflow) { | 472 TEST(PreParseOverflow) { |
464 v8::V8::Initialize(); | 473 v8::V8::Initialize(); |
465 | 474 |
466 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - | 475 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - |
467 128 * 1024); | 476 128 * 1024); |
468 | 477 |
469 size_t kProgramSize = 1024 * 1024; | 478 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); | 1136 i::Scope* inner_scope = scope->inner_scopes()->at(0); |
1128 CHECK_EQ(inner_scope->scope_type(), source_data[i].scope_type); | 1137 CHECK_EQ(inner_scope->scope_type(), source_data[i].scope_type); |
1129 CHECK_EQ(inner_scope->start_position(), kPrefixLen); | 1138 CHECK_EQ(inner_scope->start_position(), kPrefixLen); |
1130 // The end position of a token is one position after the last | 1139 // The end position of a token is one position after the last |
1131 // character belonging to that token. | 1140 // character belonging to that token. |
1132 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); | 1141 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); |
1133 } | 1142 } |
1134 } | 1143 } |
1135 | 1144 |
1136 | 1145 |
1137 i::Handle<i::String> FormatMessage(i::ScriptData* data) { | 1146 i::Handle<i::String> FormatMessage(i::ParseData* pd) { |
1138 i::Isolate* isolate = CcTest::i_isolate(); | 1147 i::Isolate* isolate = CcTest::i_isolate(); |
1139 i::Factory* factory = isolate->factory(); | 1148 i::Factory* factory = isolate->factory(); |
1140 const char* message = data->BuildMessage(); | 1149 const char* message = pd->BuildMessage(); |
1141 i::Handle<i::String> format = v8::Utils::OpenHandle( | 1150 i::Handle<i::String> format = v8::Utils::OpenHandle( |
1142 *v8::String::NewFromUtf8(CcTest::isolate(), message)); | 1151 *v8::String::NewFromUtf8(CcTest::isolate(), message)); |
1143 const char* arg = data->BuildArg(); | 1152 const char* arg = pd->BuildArg(); |
1144 i::Handle<i::JSArray> args_array = factory->NewJSArray(arg == NULL ? 0 : 1); | 1153 i::Handle<i::JSArray> args_array = factory->NewJSArray(arg == NULL ? 0 : 1); |
1145 if (arg != NULL) { | 1154 if (arg != NULL) { |
1146 i::JSArray::SetElement( | 1155 i::JSArray::SetElement( |
1147 args_array, 0, v8::Utils::OpenHandle(*v8::String::NewFromUtf8( | 1156 args_array, 0, v8::Utils::OpenHandle(*v8::String::NewFromUtf8( |
1148 CcTest::isolate(), arg)), | 1157 CcTest::isolate(), arg)), |
1149 NONE, i::SLOPPY).Check(); | 1158 NONE, i::SLOPPY).Check(); |
1150 } | 1159 } |
1151 i::Handle<i::JSObject> builtins(isolate->js_builtins_object()); | 1160 i::Handle<i::JSObject> builtins(isolate->js_builtins_object()); |
1152 i::Handle<i::Object> format_fun = i::Object::GetProperty( | 1161 i::Handle<i::Object> format_fun = i::Object::GetProperty( |
1153 isolate, builtins, "FormatMessage").ToHandleChecked(); | 1162 isolate, builtins, "FormatMessage").ToHandleChecked(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1204 i::CompleteParserRecorder log; | 1213 i::CompleteParserRecorder log; |
1205 { | 1214 { |
1206 i::Scanner scanner(isolate->unicode_cache()); | 1215 i::Scanner scanner(isolate->unicode_cache()); |
1207 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 1216 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
1208 i::PreParser preparser(&scanner, &log, stack_limit); | 1217 i::PreParser preparser(&scanner, &log, stack_limit); |
1209 SetParserFlags(&preparser, flags); | 1218 SetParserFlags(&preparser, flags); |
1210 scanner.Initialize(&stream); | 1219 scanner.Initialize(&stream); |
1211 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 1220 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
1212 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 1221 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
1213 } | 1222 } |
1214 i::ScriptData data(log.ExtractData()); | 1223 |
1224 i::ScriptData* sd = log.GetScriptData(); | |
marja
2014/07/09 17:28:51
Btw, in these tests, would it be possible to extra
Yang
2014/07/10 08:28:46
Done. Also got rid of a bunch of methods from Pars
| |
1225 i::ParseData pd(sd); | |
1215 | 1226 |
1216 // Parse the data | 1227 // Parse the data |
1217 i::FunctionLiteral* function; | 1228 i::FunctionLiteral* function; |
1218 { | 1229 { |
1219 i::Handle<i::Script> script = factory->NewScript(source); | 1230 i::Handle<i::Script> script = factory->NewScript(source); |
1220 i::CompilationInfoWithZone info(script); | 1231 i::CompilationInfoWithZone info(script); |
1221 i::Parser parser(&info); | 1232 i::Parser parser(&info); |
1222 SetParserFlags(&parser, flags); | 1233 SetParserFlags(&parser, flags); |
1223 info.MarkAsGlobal(); | 1234 info.MarkAsGlobal(); |
1224 parser.Parse(); | 1235 parser.Parse(); |
(...skipping 14 matching lines...) Expand all Loading... | |
1239 v8::base::OS::Print( | 1250 v8::base::OS::Print( |
1240 "Parser failed on:\n" | 1251 "Parser failed on:\n" |
1241 "\t%s\n" | 1252 "\t%s\n" |
1242 "with error:\n" | 1253 "with error:\n" |
1243 "\t%s\n" | 1254 "\t%s\n" |
1244 "However, we expected no error.", | 1255 "However, we expected no error.", |
1245 source->ToCString().get(), message_string->ToCString().get()); | 1256 source->ToCString().get(), message_string->ToCString().get()); |
1246 CHECK(false); | 1257 CHECK(false); |
1247 } | 1258 } |
1248 | 1259 |
1249 if (!data.has_error()) { | 1260 if (!pd.HasError()) { |
marja
2014/07/09 14:42:30
Alright, now I remember why I didn't remove the "S
Yang
2014/07/10 08:28:46
Changed to use the log.
| |
1250 v8::base::OS::Print( | 1261 v8::base::OS::Print( |
1251 "Parser failed on:\n" | 1262 "Parser failed on:\n" |
1252 "\t%s\n" | 1263 "\t%s\n" |
1253 "with error:\n" | 1264 "with error:\n" |
1254 "\t%s\n" | 1265 "\t%s\n" |
1255 "However, the preparser succeeded", | 1266 "However, the preparser succeeded", |
1256 source->ToCString().get(), message_string->ToCString().get()); | 1267 source->ToCString().get(), message_string->ToCString().get()); |
1257 CHECK(false); | 1268 CHECK(false); |
1258 } | 1269 } |
1259 // Check that preparser and parser produce the same error. | 1270 // Check that preparser and parser produce the same error. |
1260 i::Handle<i::String> preparser_message = FormatMessage(&data); | 1271 i::Handle<i::String> preparser_message = FormatMessage(&pd); |
1261 if (!i::String::Equals(message_string, preparser_message)) { | 1272 if (!i::String::Equals(message_string, preparser_message)) { |
1262 v8::base::OS::Print( | 1273 v8::base::OS::Print( |
1263 "Expected parser and preparser to produce the same error on:\n" | 1274 "Expected parser and preparser to produce the same error on:\n" |
1264 "\t%s\n" | 1275 "\t%s\n" |
1265 "However, found the following error messages\n" | 1276 "However, found the following error messages\n" |
1266 "\tparser: %s\n" | 1277 "\tparser: %s\n" |
1267 "\tpreparser: %s\n", | 1278 "\tpreparser: %s\n", |
1268 source->ToCString().get(), | 1279 source->ToCString().get(), |
1269 message_string->ToCString().get(), | 1280 message_string->ToCString().get(), |
1270 preparser_message->ToCString().get()); | 1281 preparser_message->ToCString().get()); |
1271 CHECK(false); | 1282 CHECK(false); |
1272 } | 1283 } |
1273 } else if (data.has_error()) { | 1284 } else if (pd.HasError()) { |
1274 v8::base::OS::Print( | 1285 v8::base::OS::Print( |
1275 "Preparser failed on:\n" | 1286 "Preparser failed on:\n" |
1276 "\t%s\n" | 1287 "\t%s\n" |
1277 "with error:\n" | 1288 "with error:\n" |
1278 "\t%s\n" | 1289 "\t%s\n" |
1279 "However, the parser succeeded", | 1290 "However, the parser succeeded", |
1280 source->ToCString().get(), FormatMessage(&data)->ToCString().get()); | 1291 source->ToCString().get(), FormatMessage(&pd)->ToCString().get()); |
1281 CHECK(false); | 1292 CHECK(false); |
1282 } else if (result == kError) { | 1293 } else if (result == kError) { |
1283 v8::base::OS::Print( | 1294 v8::base::OS::Print( |
1284 "Expected error on:\n" | 1295 "Expected error on:\n" |
1285 "\t%s\n" | 1296 "\t%s\n" |
1286 "However, parser and preparser succeeded", | 1297 "However, parser and preparser succeeded", |
1287 source->ToCString().get()); | 1298 source->ToCString().get()); |
1288 CHECK(false); | 1299 CHECK(false); |
1289 } | 1300 } |
1301 | |
1302 delete sd; | |
1290 } | 1303 } |
1291 | 1304 |
1292 | 1305 |
1293 void TestParserSync(const char* source, | 1306 void TestParserSync(const char* source, |
1294 const ParserFlag* varying_flags, | 1307 const ParserFlag* varying_flags, |
1295 size_t varying_flags_length, | 1308 size_t varying_flags_length, |
1296 ParserSyncTestResult result = kSuccessOrError, | 1309 ParserSyncTestResult result = kSuccessOrError, |
1297 const ParserFlag* always_true_flags = NULL, | 1310 const ParserFlag* always_true_flags = NULL, |
1298 size_t always_true_flags_length = 0) { | 1311 size_t always_true_flags_length = 0) { |
1299 i::Handle<i::String> str = | 1312 i::Handle<i::String> str = |
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2158 {NULL, 0} | 2171 {NULL, 0} |
2159 }; | 2172 }; |
2160 | 2173 |
2161 for (int i = 0; test_cases[i].program; i++) { | 2174 for (int i = 0; test_cases[i].program; i++) { |
2162 const char* program = test_cases[i].program; | 2175 const char* program = test_cases[i].program; |
2163 i::Factory* factory = CcTest::i_isolate()->factory(); | 2176 i::Factory* factory = CcTest::i_isolate()->factory(); |
2164 i::Handle<i::String> source = | 2177 i::Handle<i::String> source = |
2165 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); | 2178 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); |
2166 i::Handle<i::Script> script = factory->NewScript(source); | 2179 i::Handle<i::Script> script = factory->NewScript(source); |
2167 i::CompilationInfoWithZone info(script); | 2180 i::CompilationInfoWithZone info(script); |
2168 i::ScriptData* data = NULL; | 2181 i::ScriptData* sd = NULL; |
2169 info.SetCachedData(&data, i::PRODUCE_CACHED_DATA); | 2182 info.SetCachedData(&sd, i::PRODUCE_CACHED_DATA); |
2170 i::Parser::Parse(&info, true); | 2183 i::Parser::Parse(&info, true); |
2171 CHECK(data); | 2184 i::ParseData pd(sd); |
2172 CHECK(!data->HasError()); | 2185 CHECK(!pd.HasError()); |
2173 | 2186 |
2174 if (data->function_count() != test_cases[i].functions) { | 2187 if (pd.FunctionCount() != test_cases[i].functions) { |
2175 v8::base::OS::Print( | 2188 v8::base::OS::Print( |
2176 "Expected preparse data for program:\n" | 2189 "Expected preparse data for program:\n" |
2177 "\t%s\n" | 2190 "\t%s\n" |
2178 "to contain %d functions, however, received %d functions.\n", | 2191 "to contain %d functions, however, received %d functions.\n", |
2179 program, test_cases[i].functions, | 2192 program, test_cases[i].functions, pd.FunctionCount()); |
2180 data->function_count()); | |
2181 CHECK(false); | 2193 CHECK(false); |
2182 } | 2194 } |
2183 delete data; | 2195 delete sd; |
2184 } | 2196 } |
2185 } | 2197 } |
2186 | 2198 |
2187 | 2199 |
2188 TEST(FunctionDeclaresItselfStrict) { | 2200 TEST(FunctionDeclaresItselfStrict) { |
2189 // Tests that we produce the right kinds of errors when a function declares | 2201 // 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 | 2202 // 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 | 2203 // offending identifiers, because we don't know at that point whether the |
2192 // function is strict or not). | 2204 // function is strict or not). |
2193 const char* context_data[][2] = { | 2205 const char* context_data[][2] = { |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2895 LocalContext env; | 2907 LocalContext env; |
2896 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; | 2908 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; |
2897 global_use_counts = use_counts; | 2909 global_use_counts = use_counts; |
2898 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); | 2910 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); |
2899 CompileRun("\"use asm\";\n" | 2911 CompileRun("\"use asm\";\n" |
2900 "var foo = 1;\n" | 2912 "var foo = 1;\n" |
2901 "\"use asm\";\n" // Only the first one counts. | 2913 "\"use asm\";\n" // Only the first one counts. |
2902 "function bar() { \"use asm\"; var baz = 1; }"); | 2914 "function bar() { \"use asm\"; var baz = 1; }"); |
2903 CHECK_EQ(2, use_counts[v8::Isolate::kUseAsm]); | 2915 CHECK_EQ(2, use_counts[v8::Isolate::kUseAsm]); |
2904 } | 2916 } |
OLD | NEW |