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

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

Issue 1847543002: Expose a lower bound of malloc'd memory via heap statistics (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 4 years, 8 months 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
« no previous file with comments | « test/cctest/test-liveedit.cc ('k') | test/cctest/test-regexp.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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 CcTest::i_isolate()->stack_guard()->SetStackLimit( 146 CcTest::i_isolate()->stack_guard()->SetStackLimit(
147 i::GetCurrentStackPosition() - 128 * 1024); 147 i::GetCurrentStackPosition() - 128 * 1024);
148 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 148 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
149 for (int i = 0; tests[i]; i++) { 149 for (int i = 0; tests[i]; i++) {
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::Zone zone; 156 i::Zone zone(CcTest::i_isolate()->allocator());
157 i::AstValueFactory ast_value_factory( 157 i::AstValueFactory ast_value_factory(
158 &zone, CcTest::i_isolate()->heap()->HashSeed()); 158 &zone, CcTest::i_isolate()->heap()->HashSeed());
159 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 159 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
160 stack_limit); 160 stack_limit);
161 preparser.set_allow_lazy(true); 161 preparser.set_allow_lazy(true);
162 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 162 i::PreParser::PreParseResult result = preparser.PreParseProgram();
163 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 163 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
164 CHECK(!log.HasError()); 164 CHECK(!log.HasError());
165 } 165 }
166 166
167 for (int i = 0; fail_tests[i]; i++) { 167 for (int i = 0; fail_tests[i]; i++) {
168 const i::byte* source = 168 const i::byte* source =
169 reinterpret_cast<const i::byte*>(fail_tests[i]); 169 reinterpret_cast<const i::byte*>(fail_tests[i]);
170 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i])); 170 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i]));
171 i::CompleteParserRecorder log; 171 i::CompleteParserRecorder log;
172 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 172 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
173 scanner.Initialize(&stream); 173 scanner.Initialize(&stream);
174 i::Zone zone; 174 i::Zone zone(CcTest::i_isolate()->allocator());
175 i::AstValueFactory ast_value_factory( 175 i::AstValueFactory ast_value_factory(
176 &zone, CcTest::i_isolate()->heap()->HashSeed()); 176 &zone, CcTest::i_isolate()->heap()->HashSeed());
177 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 177 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
178 stack_limit); 178 stack_limit);
179 preparser.set_allow_lazy(true); 179 preparser.set_allow_lazy(true);
180 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 180 i::PreParser::PreParseResult result = preparser.PreParseProgram();
181 // Even in the case of a syntax error, kPreParseSuccess is returned. 181 // Even in the case of a syntax error, kPreParseSuccess is returned.
182 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 182 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
183 CHECK(log.HasError()); 183 CHECK(log.HasError());
184 } 184 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 325 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
326 for (int i = 0; programs[i]; i++) { 326 for (int i = 0; programs[i]; i++) {
327 const char* program = programs[i]; 327 const char* program = programs[i];
328 i::Utf8ToUtf16CharacterStream stream( 328 i::Utf8ToUtf16CharacterStream stream(
329 reinterpret_cast<const i::byte*>(program), 329 reinterpret_cast<const i::byte*>(program),
330 static_cast<unsigned>(strlen(program))); 330 static_cast<unsigned>(strlen(program)));
331 i::CompleteParserRecorder log; 331 i::CompleteParserRecorder log;
332 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 332 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
333 scanner.Initialize(&stream); 333 scanner.Initialize(&stream);
334 334
335 i::Zone zone; 335 i::Zone zone(CcTest::i_isolate()->allocator());
336 i::AstValueFactory ast_value_factory( 336 i::AstValueFactory ast_value_factory(
337 &zone, CcTest::i_isolate()->heap()->HashSeed()); 337 &zone, CcTest::i_isolate()->heap()->HashSeed());
338 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 338 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
339 stack_limit); 339 stack_limit);
340 preparser.set_allow_lazy(true); 340 preparser.set_allow_lazy(true);
341 preparser.set_allow_natives(true); 341 preparser.set_allow_natives(true);
342 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 342 i::PreParser::PreParseResult result = preparser.PreParseProgram();
343 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 343 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
344 CHECK(!log.HasError()); 344 CHECK(!log.HasError());
345 } 345 }
(...skipping 16 matching lines...) Expand all
362 for (int i = 0; programs[i]; i++) { 362 for (int i = 0; programs[i]; i++) {
363 const char* program = programs[i]; 363 const char* program = programs[i];
364 i::Utf8ToUtf16CharacterStream stream( 364 i::Utf8ToUtf16CharacterStream stream(
365 reinterpret_cast<const i::byte*>(program), 365 reinterpret_cast<const i::byte*>(program),
366 static_cast<unsigned>(strlen(program))); 366 static_cast<unsigned>(strlen(program)));
367 i::CompleteParserRecorder log; 367 i::CompleteParserRecorder log;
368 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 368 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
369 scanner.Initialize(&stream); 369 scanner.Initialize(&stream);
370 370
371 // Preparser defaults to disallowing natives syntax. 371 // Preparser defaults to disallowing natives syntax.
372 i::Zone zone; 372 i::Zone zone(CcTest::i_isolate()->allocator());
373 i::AstValueFactory ast_value_factory( 373 i::AstValueFactory ast_value_factory(
374 &zone, CcTest::i_isolate()->heap()->HashSeed()); 374 &zone, CcTest::i_isolate()->heap()->HashSeed());
375 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 375 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
376 stack_limit); 376 stack_limit);
377 preparser.set_allow_lazy(true); 377 preparser.set_allow_lazy(true);
378 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 378 i::PreParser::PreParseResult result = preparser.PreParseProgram();
379 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 379 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
380 CHECK(log.HasError()); 380 CHECK(log.HasError());
381 } 381 }
382 } 382 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), 431 // Before fix, didn't check *ok after Expect(Token::Identifier, ok),
432 // and then used the invalid currently scanned literal. This always 432 // and then used the invalid currently scanned literal. This always
433 // failed in debug mode, and sometimes crashed in release mode. 433 // failed in debug mode, and sometimes crashed in release mode.
434 434
435 i::Utf8ToUtf16CharacterStream stream( 435 i::Utf8ToUtf16CharacterStream stream(
436 reinterpret_cast<const i::byte*>(program), 436 reinterpret_cast<const i::byte*>(program),
437 static_cast<unsigned>(strlen(program))); 437 static_cast<unsigned>(strlen(program)));
438 i::CompleteParserRecorder log; 438 i::CompleteParserRecorder log;
439 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 439 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
440 scanner.Initialize(&stream); 440 scanner.Initialize(&stream);
441 i::Zone zone; 441 i::Zone zone(CcTest::i_isolate()->allocator());
442 i::AstValueFactory ast_value_factory(&zone, 442 i::AstValueFactory ast_value_factory(&zone,
443 CcTest::i_isolate()->heap()->HashSeed()); 443 CcTest::i_isolate()->heap()->HashSeed());
444 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 444 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
445 CcTest::i_isolate()->stack_guard()->real_climit()); 445 CcTest::i_isolate()->stack_guard()->real_climit());
446 preparser.set_allow_lazy(true); 446 preparser.set_allow_lazy(true);
447 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 447 i::PreParser::PreParseResult result = preparser.PreParseProgram();
448 // Even in the case of a syntax error, kPreParseSuccess is returned. 448 // Even in the case of a syntax error, kPreParseSuccess is returned.
449 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 449 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
450 CHECK(log.HasError()); 450 CHECK(log.HasError());
451 } 451 }
(...skipping 14 matching lines...) Expand all
466 const char* program = 466 const char* program =
467 "try { } catch (e) { var foo = function () { /* first */ } }" 467 "try { } catch (e) { var foo = function () { /* first */ } }"
468 "var bar = function () { /* second */ }"; 468 "var bar = function () { /* second */ }";
469 469
470 v8::HandleScope handles(CcTest::isolate()); 470 v8::HandleScope handles(CcTest::isolate());
471 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(program); 471 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(program);
472 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); 472 i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
473 i::CompleteParserRecorder log; 473 i::CompleteParserRecorder log;
474 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 474 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
475 scanner.Initialize(&stream); 475 scanner.Initialize(&stream);
476 i::Zone zone; 476 i::Zone zone(CcTest::i_isolate()->allocator());
477 i::AstValueFactory ast_value_factory(&zone, 477 i::AstValueFactory ast_value_factory(&zone,
478 CcTest::i_isolate()->heap()->HashSeed()); 478 CcTest::i_isolate()->heap()->HashSeed());
479 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 479 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
480 CcTest::i_isolate()->stack_guard()->real_climit()); 480 CcTest::i_isolate()->stack_guard()->real_climit());
481 preparser.set_allow_lazy(true); 481 preparser.set_allow_lazy(true);
482 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 482 i::PreParser::PreParseResult result = preparser.PreParseProgram();
483 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 483 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
484 i::ScriptData* sd = log.GetScriptData(); 484 i::ScriptData* sd = log.GetScriptData();
485 i::ParseData* pd = i::ParseData::FromCachedData(sd); 485 i::ParseData* pd = i::ParseData::FromCachedData(sd);
486 pd->Initialize(); 486 pd->Initialize();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 519
520 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 520 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
521 521
522 i::Utf8ToUtf16CharacterStream stream( 522 i::Utf8ToUtf16CharacterStream stream(
523 reinterpret_cast<const i::byte*>(program.get()), 523 reinterpret_cast<const i::byte*>(program.get()),
524 static_cast<unsigned>(kProgramSize)); 524 static_cast<unsigned>(kProgramSize));
525 i::CompleteParserRecorder log; 525 i::CompleteParserRecorder log;
526 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 526 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
527 scanner.Initialize(&stream); 527 scanner.Initialize(&stream);
528 528
529 i::Zone zone; 529 i::Zone zone(CcTest::i_isolate()->allocator());
530 i::AstValueFactory ast_value_factory(&zone, 530 i::AstValueFactory ast_value_factory(&zone,
531 CcTest::i_isolate()->heap()->HashSeed()); 531 CcTest::i_isolate()->heap()->HashSeed());
532 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 532 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
533 stack_limit); 533 stack_limit);
534 preparser.set_allow_lazy(true); 534 preparser.set_allow_lazy(true);
535 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 535 i::PreParser::PreParseResult result = preparser.PreParseProgram();
536 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); 536 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result);
537 } 537 }
538 538
539 539
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 reinterpret_cast<const i::byte*>(re_source), 836 reinterpret_cast<const i::byte*>(re_source),
837 static_cast<unsigned>(strlen(re_source))); 837 static_cast<unsigned>(strlen(re_source)));
838 i::HandleScope scope(CcTest::i_isolate()); 838 i::HandleScope scope(CcTest::i_isolate());
839 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 839 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
840 scanner.Initialize(&stream); 840 scanner.Initialize(&stream);
841 841
842 i::Token::Value start = scanner.peek(); 842 i::Token::Value start = scanner.peek();
843 CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV); 843 CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV);
844 CHECK(scanner.ScanRegExpPattern(start == i::Token::ASSIGN_DIV)); 844 CHECK(scanner.ScanRegExpPattern(start == i::Token::ASSIGN_DIV));
845 scanner.Next(); // Current token is now the regexp literal. 845 scanner.Next(); // Current token is now the regexp literal.
846 i::Zone zone; 846 i::Zone zone(CcTest::i_isolate()->allocator());
847 i::AstValueFactory ast_value_factory(&zone, 847 i::AstValueFactory ast_value_factory(&zone,
848 CcTest::i_isolate()->heap()->HashSeed()); 848 CcTest::i_isolate()->heap()->HashSeed());
849 ast_value_factory.Internalize(CcTest::i_isolate()); 849 ast_value_factory.Internalize(CcTest::i_isolate());
850 i::Handle<i::String> val = 850 i::Handle<i::String> val =
851 scanner.CurrentSymbol(&ast_value_factory)->string(); 851 scanner.CurrentSymbol(&ast_value_factory)->string();
852 i::DisallowHeapAllocation no_alloc; 852 i::DisallowHeapAllocation no_alloc;
853 i::String::FlatContent content = val->GetFlatContent(); 853 i::String::FlatContent content = val->GetFlatContent();
854 CHECK(content.IsOneByte()); 854 CHECK(content.IsOneByte());
855 i::Vector<const uint8_t> actual = content.ToOneByteVector(); 855 i::Vector<const uint8_t> actual = content.ToOneByteVector();
856 for (int i = 0; i < actual.length(); i++) { 856 for (int i = 0; i < actual.length(); i++) {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 int kProgramByteSize = i::StrLength(surroundings[j].prefix) + 1060 int kProgramByteSize = i::StrLength(surroundings[j].prefix) +
1061 i::StrLength(surroundings[j].suffix) + 1061 i::StrLength(surroundings[j].suffix) +
1062 i::StrLength(source_data[i].body); 1062 i::StrLength(source_data[i].body);
1063 i::ScopedVector<char> program(kProgramByteSize + 1); 1063 i::ScopedVector<char> program(kProgramByteSize + 1);
1064 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, 1064 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix,
1065 source_data[i].body, surroundings[j].suffix); 1065 source_data[i].body, surroundings[j].suffix);
1066 i::Handle<i::String> source = 1066 i::Handle<i::String> source =
1067 factory->NewStringFromUtf8(i::CStrVector(program.start())) 1067 factory->NewStringFromUtf8(i::CStrVector(program.start()))
1068 .ToHandleChecked(); 1068 .ToHandleChecked();
1069 i::Handle<i::Script> script = factory->NewScript(source); 1069 i::Handle<i::Script> script = factory->NewScript(source);
1070 i::Zone zone; 1070 i::Zone zone(CcTest::i_isolate()->allocator());
1071 i::ParseInfo info(&zone, script); 1071 i::ParseInfo info(&zone, script);
1072 i::Parser parser(&info); 1072 i::Parser parser(&info);
1073 parser.set_allow_harmony_sloppy(true); 1073 parser.set_allow_harmony_sloppy(true);
1074 info.set_global(); 1074 info.set_global();
1075 CHECK(parser.Parse(&info)); 1075 CHECK(parser.Parse(&info));
1076 CHECK(i::Rewriter::Rewrite(&info)); 1076 CHECK(i::Rewriter::Rewrite(&info));
1077 CHECK(i::Scope::Analyze(&info)); 1077 CHECK(i::Scope::Analyze(&info));
1078 CHECK(info.literal() != NULL); 1078 CHECK(info.literal() != NULL);
1079 1079
1080 i::Scope* script_scope = info.literal()->scope(); 1080 i::Scope* script_scope = info.literal()->scope();
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 i::SNPrintF(program, "%s%s%s", 1378 i::SNPrintF(program, "%s%s%s",
1379 source_data[i].outer_prefix, 1379 source_data[i].outer_prefix,
1380 source_data[i].inner_source, 1380 source_data[i].inner_source,
1381 source_data[i].outer_suffix); 1381 source_data[i].outer_suffix);
1382 1382
1383 // Parse program source. 1383 // Parse program source.
1384 i::Handle<i::String> source = factory->NewStringFromUtf8( 1384 i::Handle<i::String> source = factory->NewStringFromUtf8(
1385 i::CStrVector(program.start())).ToHandleChecked(); 1385 i::CStrVector(program.start())).ToHandleChecked();
1386 CHECK_EQ(source->length(), kProgramSize); 1386 CHECK_EQ(source->length(), kProgramSize);
1387 i::Handle<i::Script> script = factory->NewScript(source); 1387 i::Handle<i::Script> script = factory->NewScript(source);
1388 i::Zone zone; 1388 i::Zone zone(CcTest::i_isolate()->allocator());
1389 i::ParseInfo info(&zone, script); 1389 i::ParseInfo info(&zone, script);
1390 i::Parser parser(&info); 1390 i::Parser parser(&info);
1391 parser.set_allow_lazy(true); 1391 parser.set_allow_lazy(true);
1392 info.set_global(); 1392 info.set_global();
1393 info.set_language_mode(source_data[i].language_mode); 1393 info.set_language_mode(source_data[i].language_mode);
1394 parser.Parse(&info); 1394 parser.Parse(&info);
1395 CHECK(info.literal() != NULL); 1395 CHECK(info.literal() != NULL);
1396 1396
1397 // Check scope types and positions. 1397 // Check scope types and positions.
1398 i::Scope* scope = info.literal()->scope(); 1398 i::Scope* scope = info.literal()->scope();
(...skipping 28 matching lines...) Expand all
1427 i::Isolate* isolate = CcTest::i_isolate(); 1427 i::Isolate* isolate = CcTest::i_isolate();
1428 i::Factory* factory = isolate->factory(); 1428 i::Factory* factory = isolate->factory();
1429 v8::HandleScope handles(CcTest::isolate()); 1429 v8::HandleScope handles(CcTest::isolate());
1430 i::FunctionLiteral* function; 1430 i::FunctionLiteral* function;
1431 1431
1432 for (int i = 0; discard_sources[i]; i++) { 1432 for (int i = 0; discard_sources[i]; i++) {
1433 const char* source = discard_sources[i]; 1433 const char* source = discard_sources[i];
1434 i::Handle<i::String> source_code = 1434 i::Handle<i::String> source_code =
1435 factory->NewStringFromUtf8(i::CStrVector(source)).ToHandleChecked(); 1435 factory->NewStringFromUtf8(i::CStrVector(source)).ToHandleChecked();
1436 i::Handle<i::Script> script = factory->NewScript(source_code); 1436 i::Handle<i::Script> script = factory->NewScript(source_code);
1437 i::Zone zone; 1437 i::Zone zone(CcTest::i_isolate()->allocator());
1438 i::ParseInfo info(&zone, script); 1438 i::ParseInfo info(&zone, script);
1439 info.set_allow_lazy_parsing(); 1439 info.set_allow_lazy_parsing();
1440 i::Parser parser(&info); 1440 i::Parser parser(&info);
1441 parser.set_allow_harmony_sloppy(true); 1441 parser.set_allow_harmony_sloppy(true);
1442 parser.Parse(&info); 1442 parser.Parse(&info);
1443 function = info.literal(); 1443 function = info.literal();
1444 CHECK_NOT_NULL(function); 1444 CHECK_NOT_NULL(function);
1445 CHECK_NOT_NULL(function->body()); 1445 CHECK_NOT_NULL(function->body());
1446 CHECK_EQ(1, function->body()->length()); 1446 CHECK_EQ(1, function->body()->length());
1447 i::FunctionLiteral* inner = 1447 i::FunctionLiteral* inner =
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); 1549 uintptr_t stack_limit = isolate->stack_guard()->real_climit();
1550 int preparser_materialized_literals = -1; 1550 int preparser_materialized_literals = -1;
1551 int parser_materialized_literals = -2; 1551 int parser_materialized_literals = -2;
1552 bool test_preparser = !is_module; 1552 bool test_preparser = !is_module;
1553 1553
1554 // Preparse the data. 1554 // Preparse the data.
1555 i::CompleteParserRecorder log; 1555 i::CompleteParserRecorder log;
1556 if (test_preparser) { 1556 if (test_preparser) {
1557 i::Scanner scanner(isolate->unicode_cache()); 1557 i::Scanner scanner(isolate->unicode_cache());
1558 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); 1558 i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
1559 i::Zone zone; 1559 i::Zone zone(CcTest::i_isolate()->allocator());
1560 i::AstValueFactory ast_value_factory( 1560 i::AstValueFactory ast_value_factory(
1561 &zone, CcTest::i_isolate()->heap()->HashSeed()); 1561 &zone, CcTest::i_isolate()->heap()->HashSeed());
1562 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 1562 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
1563 stack_limit); 1563 stack_limit);
1564 SetParserFlags(&preparser, flags); 1564 SetParserFlags(&preparser, flags);
1565 scanner.Initialize(&stream); 1565 scanner.Initialize(&stream);
1566 i::PreParser::PreParseResult result = preparser.PreParseProgram( 1566 i::PreParser::PreParseResult result = preparser.PreParseProgram(
1567 &preparser_materialized_literals); 1567 &preparser_materialized_literals);
1568 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 1568 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
1569 } 1569 }
1570 bool preparse_error = log.HasError(); 1570 bool preparse_error = log.HasError();
1571 1571
1572 // Parse the data 1572 // Parse the data
1573 i::FunctionLiteral* function; 1573 i::FunctionLiteral* function;
1574 { 1574 {
1575 i::Handle<i::Script> script = factory->NewScript(source); 1575 i::Handle<i::Script> script = factory->NewScript(source);
1576 i::Zone zone; 1576 i::Zone zone(CcTest::i_isolate()->allocator());
1577 i::ParseInfo info(&zone, script); 1577 i::ParseInfo info(&zone, script);
1578 i::Parser parser(&info); 1578 i::Parser parser(&info);
1579 SetParserFlags(&parser, flags); 1579 SetParserFlags(&parser, flags);
1580 if (is_module) { 1580 if (is_module) {
1581 info.set_module(); 1581 info.set_module();
1582 } else { 1582 } else {
1583 info.set_global(); 1583 info.set_global();
1584 } 1584 }
1585 parser.Parse(&info); 1585 parser.Parse(&info);
1586 function = info.literal(); 1586 function = info.literal();
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
2655 {"function lazy() { var x = {get foo(){} } }", 1}, 2655 {"function lazy() { var x = {get foo(){} } }", 1},
2656 {NULL, 0} 2656 {NULL, 0}
2657 }; 2657 };
2658 2658
2659 for (int i = 0; test_cases[i].program; i++) { 2659 for (int i = 0; test_cases[i].program; i++) {
2660 const char* program = test_cases[i].program; 2660 const char* program = test_cases[i].program;
2661 i::Factory* factory = CcTest::i_isolate()->factory(); 2661 i::Factory* factory = CcTest::i_isolate()->factory();
2662 i::Handle<i::String> source = 2662 i::Handle<i::String> source =
2663 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); 2663 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked();
2664 i::Handle<i::Script> script = factory->NewScript(source); 2664 i::Handle<i::Script> script = factory->NewScript(source);
2665 i::Zone zone; 2665 i::Zone zone(CcTest::i_isolate()->allocator());
2666 i::ParseInfo info(&zone, script); 2666 i::ParseInfo info(&zone, script);
2667 i::ScriptData* sd = NULL; 2667 i::ScriptData* sd = NULL;
2668 info.set_cached_data(&sd); 2668 info.set_cached_data(&sd);
2669 info.set_compile_options(v8::ScriptCompiler::kProduceParserCache); 2669 info.set_compile_options(v8::ScriptCompiler::kProduceParserCache);
2670 info.set_allow_lazy_parsing(); 2670 info.set_allow_lazy_parsing();
2671 i::Parser::ParseStatic(&info); 2671 i::Parser::ParseStatic(&info);
2672 i::ParseData* pd = i::ParseData::FromCachedData(sd); 2672 i::ParseData* pd = i::ParseData::FromCachedData(sd);
2673 2673
2674 if (pd->FunctionCount() != test_cases[i].functions) { 2674 if (pd->FunctionCount() != test_cases[i].functions) {
2675 v8::base::OS::Print( 2675 v8::base::OS::Print(
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
3281 " assertResult([2]);" 3281 " assertResult([2]);"
3282 " return f;" 3282 " return f;"
3283 "};" 3283 "};"
3284 "h();"; 3284 "h();";
3285 3285
3286 i::ScopedVector<char> program(Utf8LengthHelper(src) + 1); 3286 i::ScopedVector<char> program(Utf8LengthHelper(src) + 1);
3287 i::SNPrintF(program, "%s", src); 3287 i::SNPrintF(program, "%s", src);
3288 i::Handle<i::String> source = factory->InternalizeUtf8String(program.start()); 3288 i::Handle<i::String> source = factory->InternalizeUtf8String(program.start());
3289 source->PrintOn(stdout); 3289 source->PrintOn(stdout);
3290 printf("\n"); 3290 printf("\n");
3291 i::Zone zone; 3291 i::Zone zone(CcTest::i_isolate()->allocator());
3292 v8::Local<v8::Value> v = CompileRun(src); 3292 v8::Local<v8::Value> v = CompileRun(src);
3293 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); 3293 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v);
3294 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); 3294 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o);
3295 i::Context* context = f->context(); 3295 i::Context* context = f->context();
3296 i::AstValueFactory avf(&zone, isolate->heap()->HashSeed()); 3296 i::AstValueFactory avf(&zone, isolate->heap()->HashSeed());
3297 avf.Internalize(isolate); 3297 avf.Internalize(isolate);
3298 const i::AstRawString* name = avf.GetOneByteString("result"); 3298 const i::AstRawString* name = avf.GetOneByteString("result");
3299 i::Handle<i::String> str = name->string(); 3299 i::Handle<i::String> str = name->string();
3300 CHECK(str->IsInternalizedString()); 3300 CHECK(str->IsInternalizedString());
3301 i::Scope* script_scope = 3301 i::Scope* script_scope =
(...skipping 29 matching lines...) Expand all
3331 " };" 3331 " };"
3332 " return g;" 3332 " return g;"
3333 " }" 3333 " }"
3334 "f(0);"; 3334 "f(0);";
3335 3335
3336 i::ScopedVector<char> program(Utf8LengthHelper(src) + 1); 3336 i::ScopedVector<char> program(Utf8LengthHelper(src) + 1);
3337 i::SNPrintF(program, "%s", src); 3337 i::SNPrintF(program, "%s", src);
3338 i::Handle<i::String> source = factory->InternalizeUtf8String(program.start()); 3338 i::Handle<i::String> source = factory->InternalizeUtf8String(program.start());
3339 source->PrintOn(stdout); 3339 source->PrintOn(stdout);
3340 printf("\n"); 3340 printf("\n");
3341 i::Zone zone; 3341 i::Zone zone(CcTest::i_isolate()->allocator());
3342 v8::Local<v8::Value> v = CompileRun(src); 3342 v8::Local<v8::Value> v = CompileRun(src);
3343 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); 3343 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v);
3344 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); 3344 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o);
3345 i::Context* context = f->context(); 3345 i::Context* context = f->context();
3346 i::AstValueFactory avf(&zone, isolate->heap()->HashSeed()); 3346 i::AstValueFactory avf(&zone, isolate->heap()->HashSeed());
3347 avf.Internalize(isolate); 3347 avf.Internalize(isolate);
3348 3348
3349 i::Scope* script_scope = 3349 i::Scope* script_scope =
3350 new (&zone) i::Scope(&zone, NULL, i::SCRIPT_SCOPE, &avf); 3350 new (&zone) i::Scope(&zone, NULL, i::SCRIPT_SCOPE, &avf);
3351 script_scope->Initialize(); 3351 script_scope->Initialize();
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
3475 i::ScopedVector<char> program(len + 1); 3475 i::ScopedVector<char> program(len + 1);
3476 3476
3477 i::SNPrintF(program, "%s%s%s%s%s%s%s", prefix, outer_comment, outer, 3477 i::SNPrintF(program, "%s%s%s%s%s%s%s", prefix, outer_comment, outer,
3478 midfix, inner_comment, inner, suffix); 3478 midfix, inner_comment, inner, suffix);
3479 i::Handle<i::String> source = 3479 i::Handle<i::String> source =
3480 factory->InternalizeUtf8String(program.start()); 3480 factory->InternalizeUtf8String(program.start());
3481 source->PrintOn(stdout); 3481 source->PrintOn(stdout);
3482 printf("\n"); 3482 printf("\n");
3483 3483
3484 i::Handle<i::Script> script = factory->NewScript(source); 3484 i::Handle<i::Script> script = factory->NewScript(source);
3485 i::Zone zone; 3485 i::Zone zone(CcTest::i_isolate()->allocator());
3486 i::ParseInfo info(&zone, script); 3486 i::ParseInfo info(&zone, script);
3487 i::Parser parser(&info); 3487 i::Parser parser(&info);
3488 CHECK(parser.Parse(&info)); 3488 CHECK(parser.Parse(&info));
3489 CHECK(i::Compiler::Analyze(&info)); 3489 CHECK(i::Compiler::Analyze(&info));
3490 CHECK(info.literal() != NULL); 3490 CHECK(info.literal() != NULL);
3491 3491
3492 i::Scope* scope = info.literal()->scope(); 3492 i::Scope* scope = info.literal()->scope();
3493 CHECK_EQ(scope->inner_scopes()->length(), 1); 3493 CHECK_EQ(scope->inner_scopes()->length(), 1);
3494 i::Scope* inner_scope = scope->inner_scopes()->at(0); 3494 i::Scope* inner_scope = scope->inner_scopes()->at(0);
3495 const i::AstRawString* var_name = 3495 const i::AstRawString* var_name =
(...skipping 2124 matching lines...) Expand 10 before | Expand all | Expand 10 after
5620 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5620 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5621 128 * 1024); 5621 128 * 1024);
5622 5622
5623 for (unsigned i = 0; i < arraysize(kSources); ++i) { 5623 for (unsigned i = 0; i < arraysize(kSources); ++i) {
5624 i::Handle<i::String> source = 5624 i::Handle<i::String> source =
5625 factory->NewStringFromAsciiChecked(kSources[i]); 5625 factory->NewStringFromAsciiChecked(kSources[i]);
5626 5626
5627 // Show that parsing as a module works 5627 // Show that parsing as a module works
5628 { 5628 {
5629 i::Handle<i::Script> script = factory->NewScript(source); 5629 i::Handle<i::Script> script = factory->NewScript(source);
5630 i::Zone zone; 5630 i::Zone zone(CcTest::i_isolate()->allocator());
5631 i::ParseInfo info(&zone, script); 5631 i::ParseInfo info(&zone, script);
5632 i::Parser parser(&info); 5632 i::Parser parser(&info);
5633 info.set_module(); 5633 info.set_module();
5634 if (!parser.Parse(&info)) { 5634 if (!parser.Parse(&info)) {
5635 i::Handle<i::JSObject> exception_handle( 5635 i::Handle<i::JSObject> exception_handle(
5636 i::JSObject::cast(isolate->pending_exception())); 5636 i::JSObject::cast(isolate->pending_exception()));
5637 i::Handle<i::String> message_string = i::Handle<i::String>::cast( 5637 i::Handle<i::String> message_string = i::Handle<i::String>::cast(
5638 i::JSReceiver::GetProperty(isolate, exception_handle, "message") 5638 i::JSReceiver::GetProperty(isolate, exception_handle, "message")
5639 .ToHandleChecked()); 5639 .ToHandleChecked());
5640 5640
5641 v8::base::OS::Print( 5641 v8::base::OS::Print(
5642 "Parser failed on:\n" 5642 "Parser failed on:\n"
5643 "\t%s\n" 5643 "\t%s\n"
5644 "with error:\n" 5644 "with error:\n"
5645 "\t%s\n" 5645 "\t%s\n"
5646 "However, we expected no error.", 5646 "However, we expected no error.",
5647 source->ToCString().get(), message_string->ToCString().get()); 5647 source->ToCString().get(), message_string->ToCString().get());
5648 CHECK(false); 5648 CHECK(false);
5649 } 5649 }
5650 } 5650 }
5651 5651
5652 // And that parsing a script does not. 5652 // And that parsing a script does not.
5653 { 5653 {
5654 i::Handle<i::Script> script = factory->NewScript(source); 5654 i::Handle<i::Script> script = factory->NewScript(source);
5655 i::Zone zone; 5655 i::Zone zone(CcTest::i_isolate()->allocator());
5656 i::ParseInfo info(&zone, script); 5656 i::ParseInfo info(&zone, script);
5657 i::Parser parser(&info); 5657 i::Parser parser(&info);
5658 info.set_global(); 5658 info.set_global();
5659 CHECK(!parser.Parse(&info)); 5659 CHECK(!parser.Parse(&info));
5660 } 5660 }
5661 } 5661 }
5662 } 5662 }
5663 5663
5664 5664
5665 TEST(ImportExportParsingErrors) { 5665 TEST(ImportExportParsingErrors) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
5735 v8::Context::Scope context_scope(context); 5735 v8::Context::Scope context_scope(context);
5736 5736
5737 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5737 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5738 128 * 1024); 5738 128 * 1024);
5739 5739
5740 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { 5740 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) {
5741 i::Handle<i::String> source = 5741 i::Handle<i::String> source =
5742 factory->NewStringFromAsciiChecked(kErrorSources[i]); 5742 factory->NewStringFromAsciiChecked(kErrorSources[i]);
5743 5743
5744 i::Handle<i::Script> script = factory->NewScript(source); 5744 i::Handle<i::Script> script = factory->NewScript(source);
5745 i::Zone zone; 5745 i::Zone zone(CcTest::i_isolate()->allocator());
5746 i::ParseInfo info(&zone, script); 5746 i::ParseInfo info(&zone, script);
5747 i::Parser parser(&info); 5747 i::Parser parser(&info);
5748 info.set_module(); 5748 info.set_module();
5749 CHECK(!parser.Parse(&info)); 5749 CHECK(!parser.Parse(&info));
5750 } 5750 }
5751 } 5751 }
5752 5752
5753 5753
5754 TEST(ModuleParsingInternals) { 5754 TEST(ModuleParsingInternals) {
5755 i::Isolate* isolate = CcTest::i_isolate(); 5755 i::Isolate* isolate = CcTest::i_isolate();
5756 i::Factory* factory = isolate->factory(); 5756 i::Factory* factory = isolate->factory();
5757 v8::HandleScope handles(CcTest::isolate()); 5757 v8::HandleScope handles(CcTest::isolate());
5758 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); 5758 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
5759 v8::Context::Scope context_scope(context); 5759 v8::Context::Scope context_scope(context);
5760 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5760 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5761 128 * 1024); 5761 128 * 1024);
5762 5762
5763 static const char kSource[] = 5763 static const char kSource[] =
5764 "let x = 5;" 5764 "let x = 5;"
5765 "export { x as y };" 5765 "export { x as y };"
5766 "import { q as z } from 'm.js';" 5766 "import { q as z } from 'm.js';"
5767 "import n from 'n.js';" 5767 "import n from 'n.js';"
5768 "export { a as b } from 'm.js';" 5768 "export { a as b } from 'm.js';"
5769 "export * from 'p.js';" 5769 "export * from 'p.js';"
5770 "import 'q.js'"; 5770 "import 'q.js'";
5771 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); 5771 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource);
5772 i::Handle<i::Script> script = factory->NewScript(source); 5772 i::Handle<i::Script> script = factory->NewScript(source);
5773 i::Zone zone; 5773 i::Zone zone(CcTest::i_isolate()->allocator());
5774 i::ParseInfo info(&zone, script); 5774 i::ParseInfo info(&zone, script);
5775 i::Parser parser(&info); 5775 i::Parser parser(&info);
5776 info.set_module(); 5776 info.set_module();
5777 CHECK(parser.Parse(&info)); 5777 CHECK(parser.Parse(&info));
5778 CHECK(i::Compiler::Analyze(&info)); 5778 CHECK(i::Compiler::Analyze(&info));
5779 i::FunctionLiteral* func = info.literal(); 5779 i::FunctionLiteral* func = info.literal();
5780 i::Scope* module_scope = func->scope(); 5780 i::Scope* module_scope = func->scope();
5781 i::Scope* outer_scope = module_scope->outer_scope(); 5781 i::Scope* outer_scope = module_scope->outer_scope();
5782 CHECK(outer_scope->is_script_scope()); 5782 CHECK(outer_scope->is_script_scope());
5783 CHECK_NULL(outer_scope->outer_scope()); 5783 CHECK_NULL(outer_scope->outer_scope());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
5876 i::Isolate* isolate = CcTest::i_isolate(); 5876 i::Isolate* isolate = CcTest::i_isolate();
5877 i::Factory* factory = isolate->factory(); 5877 i::Factory* factory = isolate->factory();
5878 v8::HandleScope handles(CcTest::isolate()); 5878 v8::HandleScope handles(CcTest::isolate());
5879 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); 5879 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
5880 v8::Context::Scope context_scope(context); 5880 v8::Context::Scope context_scope(context);
5881 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5881 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5882 128 * 1024); 5882 128 * 1024);
5883 5883
5884 i::Handle<i::Script> script = 5884 i::Handle<i::Script> script =
5885 factory->NewScript(factory->NewStringFromAsciiChecked(source)); 5885 factory->NewScript(factory->NewStringFromAsciiChecked(source));
5886 i::Zone zone; 5886 i::Zone zone(CcTest::i_isolate()->allocator());
5887 i::ParseInfo info(&zone, script); 5887 i::ParseInfo info(&zone, script);
5888 i::Parser parser(&info); 5888 i::Parser parser(&info);
5889 info.set_global(); 5889 info.set_global();
5890 parser.Parse(&info); 5890 parser.Parse(&info);
5891 CHECK(info.literal() != NULL); 5891 CHECK(info.literal() != NULL);
5892 CHECK_EQ(expected_language_mode, info.literal()->language_mode()); 5892 CHECK_EQ(expected_language_mode, info.literal()->language_mode());
5893 } 5893 }
5894 5894
5895 5895
5896 TEST(LanguageModeDirectives) { 5896 TEST(LanguageModeDirectives) {
(...skipping 1483 matching lines...) Expand 10 before | Expand all | Expand 10 after
7380 // "Array() **= 10", 7380 // "Array() **= 10",
7381 NULL 7381 NULL
7382 }; 7382 };
7383 // clang-format on 7383 // clang-format on
7384 7384
7385 static const ParserFlag always_flags[] = { 7385 static const ParserFlag always_flags[] = {
7386 kAllowHarmonyExponentiationOperator}; 7386 kAllowHarmonyExponentiationOperator};
7387 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, 7387 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
7388 arraysize(always_flags)); 7388 arraysize(always_flags));
7389 } 7389 }
OLDNEW
« no previous file with comments | « test/cctest/test-liveedit.cc ('k') | test/cctest/test-regexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698