| 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 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 i::StrLength(surroundings[j].suffix) + | 1047 i::StrLength(surroundings[j].suffix) + |
| 1048 i::StrLength(source_data[i].body); | 1048 i::StrLength(source_data[i].body); |
| 1049 i::ScopedVector<char> program(kProgramByteSize + 1); | 1049 i::ScopedVector<char> program(kProgramByteSize + 1); |
| 1050 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, | 1050 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, |
| 1051 source_data[i].body, surroundings[j].suffix); | 1051 source_data[i].body, surroundings[j].suffix); |
| 1052 i::Handle<i::String> source = | 1052 i::Handle<i::String> source = |
| 1053 factory->NewStringFromUtf8(i::CStrVector(program.start())) | 1053 factory->NewStringFromUtf8(i::CStrVector(program.start())) |
| 1054 .ToHandleChecked(); | 1054 .ToHandleChecked(); |
| 1055 i::Handle<i::Script> script = factory->NewScript(source); | 1055 i::Handle<i::Script> script = factory->NewScript(source); |
| 1056 i::CompilationInfoWithZone info(script); | 1056 i::CompilationInfoWithZone info(script); |
| 1057 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), | 1057 i::Parser parser(&info, isolate->stack_guard()->real_climit(), |
| 1058 isolate->heap()->HashSeed(), | 1058 isolate->heap()->HashSeed(), isolate->unicode_cache()); |
| 1059 isolate->unicode_cache()}; | |
| 1060 i::Parser parser(&info, &parse_info); | |
| 1061 parser.set_allow_harmony_arrow_functions(true); | 1059 parser.set_allow_harmony_arrow_functions(true); |
| 1062 parser.set_allow_harmony_classes(true); | 1060 parser.set_allow_harmony_classes(true); |
| 1063 parser.set_allow_harmony_object_literals(true); | 1061 parser.set_allow_harmony_object_literals(true); |
| 1064 parser.set_allow_harmony_scoping(true); | 1062 parser.set_allow_harmony_scoping(true); |
| 1065 parser.set_allow_harmony_sloppy(true); | 1063 parser.set_allow_harmony_sloppy(true); |
| 1066 info.MarkAsGlobal(); | 1064 info.MarkAsGlobal(); |
| 1067 CHECK(parser.Parse()); | 1065 CHECK(parser.Parse()); |
| 1068 CHECK(i::Rewriter::Rewrite(&info)); | 1066 CHECK(i::Rewriter::Rewrite(&info)); |
| 1069 CHECK(i::Scope::Analyze(&info)); | 1067 CHECK(i::Scope::Analyze(&info)); |
| 1070 CHECK(info.function() != NULL); | 1068 CHECK(info.function() != NULL); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1305 source_data[i].outer_prefix, | 1303 source_data[i].outer_prefix, |
| 1306 source_data[i].inner_source, | 1304 source_data[i].inner_source, |
| 1307 source_data[i].outer_suffix); | 1305 source_data[i].outer_suffix); |
| 1308 | 1306 |
| 1309 // Parse program source. | 1307 // Parse program source. |
| 1310 i::Handle<i::String> source = factory->NewStringFromUtf8( | 1308 i::Handle<i::String> source = factory->NewStringFromUtf8( |
| 1311 i::CStrVector(program.start())).ToHandleChecked(); | 1309 i::CStrVector(program.start())).ToHandleChecked(); |
| 1312 CHECK_EQ(source->length(), kProgramSize); | 1310 CHECK_EQ(source->length(), kProgramSize); |
| 1313 i::Handle<i::Script> script = factory->NewScript(source); | 1311 i::Handle<i::Script> script = factory->NewScript(source); |
| 1314 i::CompilationInfoWithZone info(script); | 1312 i::CompilationInfoWithZone info(script); |
| 1315 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), | 1313 i::Parser parser(&info, isolate->stack_guard()->real_climit(), |
| 1316 isolate->heap()->HashSeed(), | 1314 isolate->heap()->HashSeed(), isolate->unicode_cache()); |
| 1317 isolate->unicode_cache()}; | |
| 1318 i::Parser parser(&info, &parse_info); | |
| 1319 parser.set_allow_lazy(true); | 1315 parser.set_allow_lazy(true); |
| 1320 parser.set_allow_harmony_scoping(true); | 1316 parser.set_allow_harmony_scoping(true); |
| 1321 parser.set_allow_harmony_arrow_functions(true); | 1317 parser.set_allow_harmony_arrow_functions(true); |
| 1322 info.MarkAsGlobal(); | 1318 info.MarkAsGlobal(); |
| 1323 info.SetLanguageMode(source_data[i].language_mode); | 1319 info.SetLanguageMode(source_data[i].language_mode); |
| 1324 parser.Parse(); | 1320 parser.Parse(); |
| 1325 CHECK(info.function() != NULL); | 1321 CHECK(info.function() != NULL); |
| 1326 | 1322 |
| 1327 // Check scope types and positions. | 1323 // Check scope types and positions. |
| 1328 i::Scope* scope = info.function()->scope(); | 1324 i::Scope* scope = info.function()->scope(); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 1462 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 1467 } | 1463 } |
| 1468 | 1464 |
| 1469 bool preparse_error = log.HasError(); | 1465 bool preparse_error = log.HasError(); |
| 1470 | 1466 |
| 1471 // Parse the data | 1467 // Parse the data |
| 1472 i::FunctionLiteral* function; | 1468 i::FunctionLiteral* function; |
| 1473 { | 1469 { |
| 1474 i::Handle<i::Script> script = factory->NewScript(source); | 1470 i::Handle<i::Script> script = factory->NewScript(source); |
| 1475 i::CompilationInfoWithZone info(script); | 1471 i::CompilationInfoWithZone info(script); |
| 1476 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), | 1472 i::Parser parser(&info, isolate->stack_guard()->real_climit(), |
| 1477 isolate->heap()->HashSeed(), | 1473 isolate->heap()->HashSeed(), isolate->unicode_cache()); |
| 1478 isolate->unicode_cache()}; | |
| 1479 i::Parser parser(&info, &parse_info); | |
| 1480 SetParserFlags(&parser, flags); | 1474 SetParserFlags(&parser, flags); |
| 1481 info.MarkAsGlobal(); | 1475 info.MarkAsGlobal(); |
| 1482 parser.Parse(); | 1476 parser.Parse(); |
| 1483 function = info.function(); | 1477 function = info.function(); |
| 1484 if (function) { | 1478 if (function) { |
| 1485 parser_materialized_literals = function->materialized_literal_count(); | 1479 parser_materialized_literals = function->materialized_literal_count(); |
| 1486 } | 1480 } |
| 1487 } | 1481 } |
| 1488 | 1482 |
| 1489 // Check that preparsing fails iff parsing fails. | 1483 // Check that preparsing fails iff parsing fails. |
| (...skipping 1942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3432 | 3426 |
| 3433 i::SNPrintF(program, "%s%s%s%s%s%s%s", prefix, outer_comment, outer, | 3427 i::SNPrintF(program, "%s%s%s%s%s%s%s", prefix, outer_comment, outer, |
| 3434 midfix, inner_comment, inner, suffix); | 3428 midfix, inner_comment, inner, suffix); |
| 3435 i::Handle<i::String> source = | 3429 i::Handle<i::String> source = |
| 3436 factory->InternalizeUtf8String(program.start()); | 3430 factory->InternalizeUtf8String(program.start()); |
| 3437 source->PrintOn(stdout); | 3431 source->PrintOn(stdout); |
| 3438 printf("\n"); | 3432 printf("\n"); |
| 3439 | 3433 |
| 3440 i::Handle<i::Script> script = factory->NewScript(source); | 3434 i::Handle<i::Script> script = factory->NewScript(source); |
| 3441 i::CompilationInfoWithZone info(script); | 3435 i::CompilationInfoWithZone info(script); |
| 3442 i::Parser::ParseInfo parse_info = { | 3436 i::Parser parser(&info, isolate->stack_guard()->real_climit(), |
| 3443 isolate->stack_guard()->real_climit(), | 3437 isolate->heap()->HashSeed(), |
| 3444 isolate->heap()->HashSeed(), isolate->unicode_cache()}; | 3438 isolate->unicode_cache()); |
| 3445 i::Parser parser(&info, &parse_info); | |
| 3446 parser.set_allow_harmony_scoping(true); | 3439 parser.set_allow_harmony_scoping(true); |
| 3447 CHECK(parser.Parse()); | 3440 CHECK(parser.Parse()); |
| 3448 CHECK(i::Compiler::Analyze(&info)); | 3441 CHECK(i::Compiler::Analyze(&info)); |
| 3449 CHECK(info.function() != NULL); | 3442 CHECK(info.function() != NULL); |
| 3450 | 3443 |
| 3451 i::Scope* scope = info.function()->scope(); | 3444 i::Scope* scope = info.function()->scope(); |
| 3452 CHECK_EQ(scope->inner_scopes()->length(), 1); | 3445 CHECK_EQ(scope->inner_scopes()->length(), 1); |
| 3453 i::Scope* inner_scope = scope->inner_scopes()->at(0); | 3446 i::Scope* inner_scope = scope->inner_scopes()->at(0); |
| 3454 const i::AstRawString* var_name = | 3447 const i::AstRawString* var_name = |
| 3455 info.ast_value_factory()->GetOneByteString("x"); | 3448 info.ast_value_factory()->GetOneByteString("x"); |
| (...skipping 1589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5045 i::ScopedVector<char> program(kProgramByteSize + 1); | 5038 i::ScopedVector<char> program(kProgramByteSize + 1); |
| 5046 i::SNPrintF(program, "%s", kSources[i]); | 5039 i::SNPrintF(program, "%s", kSources[i]); |
| 5047 i::Handle<i::String> source = | 5040 i::Handle<i::String> source = |
| 5048 factory->NewStringFromUtf8(i::CStrVector(program.start())) | 5041 factory->NewStringFromUtf8(i::CStrVector(program.start())) |
| 5049 .ToHandleChecked(); | 5042 .ToHandleChecked(); |
| 5050 | 5043 |
| 5051 // Show that parsing as a module works | 5044 // Show that parsing as a module works |
| 5052 { | 5045 { |
| 5053 i::Handle<i::Script> script = factory->NewScript(source); | 5046 i::Handle<i::Script> script = factory->NewScript(source); |
| 5054 i::CompilationInfoWithZone info(script); | 5047 i::CompilationInfoWithZone info(script); |
| 5055 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), | 5048 i::Parser parser(&info, isolate->stack_guard()->real_climit(), |
| 5056 isolate->heap()->HashSeed(), | 5049 isolate->heap()->HashSeed(), isolate->unicode_cache()); |
| 5057 isolate->unicode_cache()}; | |
| 5058 i::Parser parser(&info, &parse_info); | |
| 5059 parser.set_allow_harmony_classes(true); | 5050 parser.set_allow_harmony_classes(true); |
| 5060 parser.set_allow_harmony_modules(true); | 5051 parser.set_allow_harmony_modules(true); |
| 5061 parser.set_allow_harmony_scoping(true); | 5052 parser.set_allow_harmony_scoping(true); |
| 5062 info.MarkAsModule(); | 5053 info.MarkAsModule(); |
| 5063 if (!parser.Parse()) { | 5054 if (!parser.Parse()) { |
| 5064 i::Handle<i::JSObject> exception_handle( | 5055 i::Handle<i::JSObject> exception_handle( |
| 5065 i::JSObject::cast(isolate->pending_exception())); | 5056 i::JSObject::cast(isolate->pending_exception())); |
| 5066 i::Handle<i::String> message_string = | 5057 i::Handle<i::String> message_string = |
| 5067 i::Handle<i::String>::cast(i::Object::GetProperty( | 5058 i::Handle<i::String>::cast(i::Object::GetProperty( |
| 5068 isolate, exception_handle, "message").ToHandleChecked()); | 5059 isolate, exception_handle, "message").ToHandleChecked()); |
| 5069 | 5060 |
| 5070 v8::base::OS::Print( | 5061 v8::base::OS::Print( |
| 5071 "Parser failed on:\n" | 5062 "Parser failed on:\n" |
| 5072 "\t%s\n" | 5063 "\t%s\n" |
| 5073 "with error:\n" | 5064 "with error:\n" |
| 5074 "\t%s\n" | 5065 "\t%s\n" |
| 5075 "However, we expected no error.", | 5066 "However, we expected no error.", |
| 5076 source->ToCString().get(), message_string->ToCString().get()); | 5067 source->ToCString().get(), message_string->ToCString().get()); |
| 5077 CHECK(false); | 5068 CHECK(false); |
| 5078 } | 5069 } |
| 5079 } | 5070 } |
| 5080 | 5071 |
| 5081 // And that parsing a script does not. | 5072 // And that parsing a script does not. |
| 5082 { | 5073 { |
| 5083 i::Handle<i::Script> script = factory->NewScript(source); | 5074 i::Handle<i::Script> script = factory->NewScript(source); |
| 5084 i::CompilationInfoWithZone info(script); | 5075 i::CompilationInfoWithZone info(script); |
| 5085 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), | 5076 i::Parser parser(&info, isolate->stack_guard()->real_climit(), |
| 5086 isolate->heap()->HashSeed(), | 5077 isolate->heap()->HashSeed(), isolate->unicode_cache()); |
| 5087 isolate->unicode_cache()}; | |
| 5088 i::Parser parser(&info, &parse_info); | |
| 5089 parser.set_allow_harmony_classes(true); | 5078 parser.set_allow_harmony_classes(true); |
| 5090 parser.set_allow_harmony_modules(true); | 5079 parser.set_allow_harmony_modules(true); |
| 5091 parser.set_allow_harmony_scoping(true); | 5080 parser.set_allow_harmony_scoping(true); |
| 5092 info.MarkAsGlobal(); | 5081 info.MarkAsGlobal(); |
| 5093 CHECK(!parser.Parse()); | 5082 CHECK(!parser.Parse()); |
| 5094 } | 5083 } |
| 5095 } | 5084 } |
| 5096 } | 5085 } |
| 5097 | 5086 |
| 5098 | 5087 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5167 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { | 5156 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { |
| 5168 int kProgramByteSize = i::StrLength(kErrorSources[i]); | 5157 int kProgramByteSize = i::StrLength(kErrorSources[i]); |
| 5169 i::ScopedVector<char> program(kProgramByteSize + 1); | 5158 i::ScopedVector<char> program(kProgramByteSize + 1); |
| 5170 i::SNPrintF(program, "%s", kErrorSources[i]); | 5159 i::SNPrintF(program, "%s", kErrorSources[i]); |
| 5171 i::Handle<i::String> source = | 5160 i::Handle<i::String> source = |
| 5172 factory->NewStringFromUtf8(i::CStrVector(program.start())) | 5161 factory->NewStringFromUtf8(i::CStrVector(program.start())) |
| 5173 .ToHandleChecked(); | 5162 .ToHandleChecked(); |
| 5174 | 5163 |
| 5175 i::Handle<i::Script> script = factory->NewScript(source); | 5164 i::Handle<i::Script> script = factory->NewScript(source); |
| 5176 i::CompilationInfoWithZone info(script); | 5165 i::CompilationInfoWithZone info(script); |
| 5177 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), | 5166 i::Parser parser(&info, isolate->stack_guard()->real_climit(), |
| 5178 isolate->heap()->HashSeed(), | 5167 isolate->heap()->HashSeed(), isolate->unicode_cache()); |
| 5179 isolate->unicode_cache()}; | |
| 5180 i::Parser parser(&info, &parse_info); | |
| 5181 parser.set_allow_harmony_classes(true); | 5168 parser.set_allow_harmony_classes(true); |
| 5182 parser.set_allow_harmony_modules(true); | 5169 parser.set_allow_harmony_modules(true); |
| 5183 parser.set_allow_harmony_scoping(true); | 5170 parser.set_allow_harmony_scoping(true); |
| 5184 info.MarkAsModule(); | 5171 info.MarkAsModule(); |
| 5185 CHECK(!parser.Parse()); | 5172 CHECK(!parser.Parse()); |
| 5186 } | 5173 } |
| 5187 } | 5174 } |
| 5188 | 5175 |
| 5189 | 5176 |
| 5190 TEST(DuplicateProtoError) { | 5177 TEST(DuplicateProtoError) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5263 i::Factory* factory = isolate->factory(); | 5250 i::Factory* factory = isolate->factory(); |
| 5264 v8::HandleScope handles(CcTest::isolate()); | 5251 v8::HandleScope handles(CcTest::isolate()); |
| 5265 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 5252 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 5266 v8::Context::Scope context_scope(context); | 5253 v8::Context::Scope context_scope(context); |
| 5267 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 5254 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 5268 128 * 1024); | 5255 128 * 1024); |
| 5269 | 5256 |
| 5270 i::Handle<i::Script> script = | 5257 i::Handle<i::Script> script = |
| 5271 factory->NewScript(factory->NewStringFromAsciiChecked(source)); | 5258 factory->NewScript(factory->NewStringFromAsciiChecked(source)); |
| 5272 i::CompilationInfoWithZone info(script); | 5259 i::CompilationInfoWithZone info(script); |
| 5273 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), | 5260 i::Parser parser(&info, isolate->stack_guard()->real_climit(), |
| 5274 isolate->heap()->HashSeed(), | 5261 isolate->heap()->HashSeed(), isolate->unicode_cache()); |
| 5275 isolate->unicode_cache()}; | |
| 5276 i::Parser parser(&info, &parse_info); | |
| 5277 parser.set_allow_strong_mode(true); | 5262 parser.set_allow_strong_mode(true); |
| 5278 info.MarkAsGlobal(); | 5263 info.MarkAsGlobal(); |
| 5279 parser.Parse(); | 5264 parser.Parse(); |
| 5280 CHECK(info.function() != NULL); | 5265 CHECK(info.function() != NULL); |
| 5281 CHECK_EQ(expected_language_mode, info.function()->language_mode()); | 5266 CHECK_EQ(expected_language_mode, info.function()->language_mode()); |
| 5282 } | 5267 } |
| 5283 | 5268 |
| 5284 | 5269 |
| 5285 TEST(LanguageModeDirectives) { | 5270 TEST(LanguageModeDirectives) { |
| 5286 TestLanguageMode("\"use nothing\"", i::SLOPPY); | 5271 TestLanguageMode("\"use nothing\"", i::SLOPPY); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5336 "class C {static set arguments(_) {}}", | 5321 "class C {static set arguments(_) {}}", |
| 5337 | 5322 |
| 5338 NULL}; | 5323 NULL}; |
| 5339 | 5324 |
| 5340 static const ParserFlag always_flags[] = { | 5325 static const ParserFlag always_flags[] = { |
| 5341 kAllowHarmonyClasses, kAllowHarmonyObjectLiterals, kAllowHarmonyScoping, | 5326 kAllowHarmonyClasses, kAllowHarmonyObjectLiterals, kAllowHarmonyScoping, |
| 5342 kAllowStrongMode}; | 5327 kAllowStrongMode}; |
| 5343 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 5328 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
| 5344 always_flags, arraysize(always_flags)); | 5329 always_flags, arraysize(always_flags)); |
| 5345 } | 5330 } |
| OLD | NEW |