| 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 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 i::ScopedVector<char> program(kProgramByteSize + 1); | 851 i::ScopedVector<char> program(kProgramByteSize + 1); |
| 852 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, | 852 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, |
| 853 source_data[i].body, surroundings[j].suffix); | 853 source_data[i].body, surroundings[j].suffix); |
| 854 i::Handle<i::String> source = | 854 i::Handle<i::String> source = |
| 855 factory->NewStringFromUtf8(i::CStrVector(program.start())) | 855 factory->NewStringFromUtf8(i::CStrVector(program.start())) |
| 856 .ToHandleChecked(); | 856 .ToHandleChecked(); |
| 857 i::Handle<i::Script> script = factory->NewScript(source); | 857 i::Handle<i::Script> script = factory->NewScript(source); |
| 858 i::Zone zone(CcTest::i_isolate()->allocator()); | 858 i::Zone zone(CcTest::i_isolate()->allocator()); |
| 859 i::ParseInfo info(&zone, script); | 859 i::ParseInfo info(&zone, script); |
| 860 i::Parser parser(&info); | 860 i::Parser parser(&info); |
| 861 info.set_global(); | |
| 862 CHECK(parser.Parse(&info)); | 861 CHECK(parser.Parse(&info)); |
| 863 CHECK(i::Rewriter::Rewrite(&info)); | 862 CHECK(i::Rewriter::Rewrite(&info)); |
| 864 i::DeclarationScope::Analyze(&info, i::AnalyzeMode::kRegular); | 863 i::DeclarationScope::Analyze(&info, i::AnalyzeMode::kRegular); |
| 865 CHECK(info.literal() != NULL); | 864 CHECK(info.literal() != NULL); |
| 866 | 865 |
| 867 i::DeclarationScope* script_scope = info.literal()->scope(); | 866 i::DeclarationScope* script_scope = info.literal()->scope(); |
| 868 CHECK(script_scope->is_script_scope()); | 867 CHECK(script_scope->is_script_scope()); |
| 869 | 868 |
| 870 i::Scope* scope = script_scope->inner_scope(); | 869 i::Scope* scope = script_scope->inner_scope(); |
| 871 DCHECK_NOT_NULL(scope); | 870 DCHECK_NOT_NULL(scope); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 full_source += "; }"; | 906 full_source += "; }"; |
| 908 | 907 |
| 909 i::Handle<i::String> source_code = | 908 i::Handle<i::String> source_code = |
| 910 factory->NewStringFromUtf8(i::CStrVector(full_source.c_str())) | 909 factory->NewStringFromUtf8(i::CStrVector(full_source.c_str())) |
| 911 .ToHandleChecked(); | 910 .ToHandleChecked(); |
| 912 | 911 |
| 913 i::Handle<i::Script> script = factory->NewScript(source_code); | 912 i::Handle<i::Script> script = factory->NewScript(source_code); |
| 914 | 913 |
| 915 i::ParseInfo info(handles.main_zone(), script); | 914 i::ParseInfo info(handles.main_zone(), script); |
| 916 i::Parser parser(&info); | 915 i::Parser parser(&info); |
| 917 info.set_global(); | |
| 918 info.set_lazy(false); | 916 info.set_lazy(false); |
| 919 info.set_allow_lazy_parsing(false); | 917 info.set_allow_lazy_parsing(false); |
| 920 info.set_toplevel(true); | 918 info.set_toplevel(true); |
| 921 | 919 |
| 922 CHECK(i::Compiler::ParseAndAnalyze(&info)); | 920 CHECK(i::Compiler::ParseAndAnalyze(&info)); |
| 923 | 921 |
| 924 CHECK(info.scope()->declarations()->length() == 1); | 922 CHECK(info.scope()->declarations()->length() == 1); |
| 925 i::FunctionLiteral* fun = | 923 i::FunctionLiteral* fun = |
| 926 info.scope()->declarations()->at(0)->AsFunctionDeclaration()->fun(); | 924 info.scope()->declarations()->at(0)->AsFunctionDeclaration()->fun(); |
| 927 CHECK(fun->body()->length() == 1); | 925 CHECK(fun->body()->length() == 1); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 | 1170 |
| 1173 // Parse program source. | 1171 // Parse program source. |
| 1174 i::Handle<i::String> source = factory->NewStringFromUtf8( | 1172 i::Handle<i::String> source = factory->NewStringFromUtf8( |
| 1175 i::CStrVector(program.start())).ToHandleChecked(); | 1173 i::CStrVector(program.start())).ToHandleChecked(); |
| 1176 CHECK_EQ(source->length(), kProgramSize); | 1174 CHECK_EQ(source->length(), kProgramSize); |
| 1177 i::Handle<i::Script> script = factory->NewScript(source); | 1175 i::Handle<i::Script> script = factory->NewScript(source); |
| 1178 i::Zone zone(CcTest::i_isolate()->allocator()); | 1176 i::Zone zone(CcTest::i_isolate()->allocator()); |
| 1179 i::ParseInfo info(&zone, script); | 1177 i::ParseInfo info(&zone, script); |
| 1180 i::Parser parser(&info); | 1178 i::Parser parser(&info); |
| 1181 parser.set_allow_lazy(true); | 1179 parser.set_allow_lazy(true); |
| 1182 info.set_global(); | |
| 1183 info.set_language_mode(source_data[i].language_mode); | 1180 info.set_language_mode(source_data[i].language_mode); |
| 1184 parser.Parse(&info); | 1181 parser.Parse(&info); |
| 1185 CHECK(info.literal() != NULL); | 1182 CHECK(info.literal() != NULL); |
| 1186 | 1183 |
| 1187 // Check scope types and positions. | 1184 // Check scope types and positions. |
| 1188 i::Scope* scope = info.literal()->scope(); | 1185 i::Scope* scope = info.literal()->scope(); |
| 1189 CHECK(scope->is_script_scope()); | 1186 CHECK(scope->is_script_scope()); |
| 1190 CHECK_EQ(scope->start_position(), 0); | 1187 CHECK_EQ(scope->start_position(), 0); |
| 1191 CHECK_EQ(scope->end_position(), kProgramSize); | 1188 CHECK_EQ(scope->end_position(), kProgramSize); |
| 1192 | 1189 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1367 bool preparse_error = log.HasError(); | 1364 bool preparse_error = log.HasError(); |
| 1368 | 1365 |
| 1369 // Parse the data | 1366 // Parse the data |
| 1370 i::FunctionLiteral* function; | 1367 i::FunctionLiteral* function; |
| 1371 { | 1368 { |
| 1372 i::Handle<i::Script> script = factory->NewScript(source); | 1369 i::Handle<i::Script> script = factory->NewScript(source); |
| 1373 i::Zone zone(CcTest::i_isolate()->allocator()); | 1370 i::Zone zone(CcTest::i_isolate()->allocator()); |
| 1374 i::ParseInfo info(&zone, script); | 1371 i::ParseInfo info(&zone, script); |
| 1375 i::Parser parser(&info); | 1372 i::Parser parser(&info); |
| 1376 SetParserFlags(&parser, flags); | 1373 SetParserFlags(&parser, flags); |
| 1377 if (is_module) { | 1374 if (is_module) info.set_module(); |
| 1378 info.set_module(); | |
| 1379 } else { | |
| 1380 info.set_global(); | |
| 1381 } | |
| 1382 parser.Parse(&info); | 1375 parser.Parse(&info); |
| 1383 function = info.literal(); | 1376 function = info.literal(); |
| 1384 if (function) { | 1377 if (function) { |
| 1385 parser_materialized_literals = function->materialized_literal_count(); | 1378 parser_materialized_literals = function->materialized_literal_count(); |
| 1386 } | 1379 } |
| 1387 } | 1380 } |
| 1388 | 1381 |
| 1389 // Check that preparsing fails iff parsing fails. | 1382 // Check that preparsing fails iff parsing fails. |
| 1390 if (function == NULL) { | 1383 if (function == NULL) { |
| 1391 // Extract exception from the parser. | 1384 // Extract exception from the parser. |
| (...skipping 4291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5683 CHECK(false); | 5676 CHECK(false); |
| 5684 } | 5677 } |
| 5685 } | 5678 } |
| 5686 | 5679 |
| 5687 // And that parsing a script does not. | 5680 // And that parsing a script does not. |
| 5688 { | 5681 { |
| 5689 i::Handle<i::Script> script = factory->NewScript(source); | 5682 i::Handle<i::Script> script = factory->NewScript(source); |
| 5690 i::Zone zone(CcTest::i_isolate()->allocator()); | 5683 i::Zone zone(CcTest::i_isolate()->allocator()); |
| 5691 i::ParseInfo info(&zone, script); | 5684 i::ParseInfo info(&zone, script); |
| 5692 i::Parser parser(&info); | 5685 i::Parser parser(&info); |
| 5693 info.set_global(); | |
| 5694 CHECK(!parser.Parse(&info)); | 5686 CHECK(!parser.Parse(&info)); |
| 5695 isolate->clear_pending_exception(); | 5687 isolate->clear_pending_exception(); |
| 5696 } | 5688 } |
| 5697 } | 5689 } |
| 5698 } | 5690 } |
| 5699 | 5691 |
| 5700 | 5692 |
| 5701 TEST(ImportExportParsingErrors) { | 5693 TEST(ImportExportParsingErrors) { |
| 5702 // clang-format off | 5694 // clang-format off |
| 5703 const char* kErrorSources[] = { | 5695 const char* kErrorSources[] = { |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6262 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); | 6254 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 6263 v8::Context::Scope context_scope(context); | 6255 v8::Context::Scope context_scope(context); |
| 6264 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 6256 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 6265 128 * 1024); | 6257 128 * 1024); |
| 6266 | 6258 |
| 6267 i::Handle<i::Script> script = | 6259 i::Handle<i::Script> script = |
| 6268 factory->NewScript(factory->NewStringFromAsciiChecked(source)); | 6260 factory->NewScript(factory->NewStringFromAsciiChecked(source)); |
| 6269 i::Zone zone(CcTest::i_isolate()->allocator()); | 6261 i::Zone zone(CcTest::i_isolate()->allocator()); |
| 6270 i::ParseInfo info(&zone, script); | 6262 i::ParseInfo info(&zone, script); |
| 6271 i::Parser parser(&info); | 6263 i::Parser parser(&info); |
| 6272 info.set_global(); | |
| 6273 parser.Parse(&info); | 6264 parser.Parse(&info); |
| 6274 CHECK(info.literal() != NULL); | 6265 CHECK(info.literal() != NULL); |
| 6275 CHECK_EQ(expected_language_mode, info.literal()->language_mode()); | 6266 CHECK_EQ(expected_language_mode, info.literal()->language_mode()); |
| 6276 } | 6267 } |
| 6277 | 6268 |
| 6278 | 6269 |
| 6279 TEST(LanguageModeDirectives) { | 6270 TEST(LanguageModeDirectives) { |
| 6280 TestLanguageMode("\"use nothing\"", i::SLOPPY); | 6271 TestLanguageMode("\"use nothing\"", i::SLOPPY); |
| 6281 TestLanguageMode("\"use strict\"", i::STRICT); | 6272 TestLanguageMode("\"use strict\"", i::STRICT); |
| 6282 | 6273 |
| (...skipping 2048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8331 const char* data[] = { | 8322 const char* data[] = { |
| 8332 "const arguments = 1", | 8323 "const arguments = 1", |
| 8333 "let arguments", | 8324 "let arguments", |
| 8334 "var arguments", | 8325 "var arguments", |
| 8335 NULL | 8326 NULL |
| 8336 }; | 8327 }; |
| 8337 // clang-format on | 8328 // clang-format on |
| 8338 RunParserSyncTest(context_data, data, kSuccess); | 8329 RunParserSyncTest(context_data, data, kSuccess); |
| 8339 } | 8330 } |
| 8340 } | 8331 } |
| OLD | NEW |