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 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 i::Handle<i::Script> script = factory->NewScript(source); | 1063 i::Handle<i::Script> script = factory->NewScript(source); |
1064 i::Zone zone; | 1064 i::Zone zone; |
1065 i::ParseInfo info(&zone, script); | 1065 i::ParseInfo info(&zone, script); |
1066 i::Parser parser(&info); | 1066 i::Parser parser(&info); |
1067 parser.set_allow_harmony_arrow_functions(true); | 1067 parser.set_allow_harmony_arrow_functions(true); |
1068 parser.set_allow_harmony_sloppy(true); | 1068 parser.set_allow_harmony_sloppy(true); |
1069 info.set_global(); | 1069 info.set_global(); |
1070 CHECK(parser.Parse(&info)); | 1070 CHECK(parser.Parse(&info)); |
1071 CHECK(i::Rewriter::Rewrite(&info)); | 1071 CHECK(i::Rewriter::Rewrite(&info)); |
1072 CHECK(i::Scope::Analyze(&info)); | 1072 CHECK(i::Scope::Analyze(&info)); |
1073 CHECK(info.function() != NULL); | 1073 CHECK(info.literal() != NULL); |
1074 | 1074 |
1075 i::Scope* script_scope = info.function()->scope(); | 1075 i::Scope* script_scope = info.literal()->scope(); |
1076 CHECK(script_scope->is_script_scope()); | 1076 CHECK(script_scope->is_script_scope()); |
1077 CHECK_EQ(1, script_scope->inner_scopes()->length()); | 1077 CHECK_EQ(1, script_scope->inner_scopes()->length()); |
1078 | 1078 |
1079 i::Scope* scope = script_scope->inner_scopes()->at(0); | 1079 i::Scope* scope = script_scope->inner_scopes()->at(0); |
1080 // Adjust for constructor scope. | 1080 // Adjust for constructor scope. |
1081 if (j == 2) { | 1081 if (j == 2) { |
1082 CHECK_EQ(1, scope->inner_scopes()->length()); | 1082 CHECK_EQ(1, scope->inner_scopes()->length()); |
1083 scope = scope->inner_scopes()->at(0); | 1083 scope = scope->inner_scopes()->at(0); |
1084 } | 1084 } |
1085 CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0, | 1085 CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0, |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1362 CHECK_EQ(source->length(), kProgramSize); | 1362 CHECK_EQ(source->length(), kProgramSize); |
1363 i::Handle<i::Script> script = factory->NewScript(source); | 1363 i::Handle<i::Script> script = factory->NewScript(source); |
1364 i::Zone zone; | 1364 i::Zone zone; |
1365 i::ParseInfo info(&zone, script); | 1365 i::ParseInfo info(&zone, script); |
1366 i::Parser parser(&info); | 1366 i::Parser parser(&info); |
1367 parser.set_allow_lazy(true); | 1367 parser.set_allow_lazy(true); |
1368 parser.set_allow_harmony_arrow_functions(true); | 1368 parser.set_allow_harmony_arrow_functions(true); |
1369 info.set_global(); | 1369 info.set_global(); |
1370 info.set_language_mode(source_data[i].language_mode); | 1370 info.set_language_mode(source_data[i].language_mode); |
1371 parser.Parse(&info); | 1371 parser.Parse(&info); |
1372 CHECK(info.function() != NULL); | 1372 CHECK(info.literal() != NULL); |
1373 | 1373 |
1374 // Check scope types and positions. | 1374 // Check scope types and positions. |
1375 i::Scope* scope = info.function()->scope(); | 1375 i::Scope* scope = info.literal()->scope(); |
1376 CHECK(scope->is_script_scope()); | 1376 CHECK(scope->is_script_scope()); |
1377 CHECK_EQ(scope->start_position(), 0); | 1377 CHECK_EQ(scope->start_position(), 0); |
1378 CHECK_EQ(scope->end_position(), kProgramSize); | 1378 CHECK_EQ(scope->end_position(), kProgramSize); |
1379 CHECK_EQ(scope->inner_scopes()->length(), 1); | 1379 CHECK_EQ(scope->inner_scopes()->length(), 1); |
1380 | 1380 |
1381 i::Scope* inner_scope = scope->inner_scopes()->at(0); | 1381 i::Scope* inner_scope = scope->inner_scopes()->at(0); |
1382 CHECK_EQ(inner_scope->scope_type(), source_data[i].scope_type); | 1382 CHECK_EQ(inner_scope->scope_type(), source_data[i].scope_type); |
1383 CHECK_EQ(inner_scope->start_position(), kPrefixLen); | 1383 CHECK_EQ(inner_scope->start_position(), kPrefixLen); |
1384 // The end position of a token is one position after the last | 1384 // The end position of a token is one position after the last |
1385 // character belonging to that token. | 1385 // character belonging to that token. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1499 // Parse the data | 1499 // Parse the data |
1500 i::FunctionLiteral* function; | 1500 i::FunctionLiteral* function; |
1501 { | 1501 { |
1502 i::Handle<i::Script> script = factory->NewScript(source); | 1502 i::Handle<i::Script> script = factory->NewScript(source); |
1503 i::Zone zone; | 1503 i::Zone zone; |
1504 i::ParseInfo info(&zone, script); | 1504 i::ParseInfo info(&zone, script); |
1505 i::Parser parser(&info); | 1505 i::Parser parser(&info); |
1506 SetParserFlags(&parser, flags); | 1506 SetParserFlags(&parser, flags); |
1507 info.set_global(); | 1507 info.set_global(); |
1508 parser.Parse(&info); | 1508 parser.Parse(&info); |
1509 function = info.function(); | 1509 function = info.literal(); |
1510 if (function) { | 1510 if (function) { |
1511 parser_materialized_literals = function->materialized_literal_count(); | 1511 parser_materialized_literals = function->materialized_literal_count(); |
1512 } | 1512 } |
1513 } | 1513 } |
1514 | 1514 |
1515 // Check that preparsing fails iff parsing fails. | 1515 // Check that preparsing fails iff parsing fails. |
1516 if (function == NULL) { | 1516 if (function == NULL) { |
1517 // Extract exception from the parser. | 1517 // Extract exception from the parser. |
1518 CHECK(isolate->has_pending_exception()); | 1518 CHECK(isolate->has_pending_exception()); |
1519 i::Handle<i::JSObject> exception_handle( | 1519 i::Handle<i::JSObject> exception_handle( |
(...skipping 1917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3437 factory->InternalizeUtf8String(program.start()); | 3437 factory->InternalizeUtf8String(program.start()); |
3438 source->PrintOn(stdout); | 3438 source->PrintOn(stdout); |
3439 printf("\n"); | 3439 printf("\n"); |
3440 | 3440 |
3441 i::Handle<i::Script> script = factory->NewScript(source); | 3441 i::Handle<i::Script> script = factory->NewScript(source); |
3442 i::Zone zone; | 3442 i::Zone zone; |
3443 i::ParseInfo info(&zone, script); | 3443 i::ParseInfo info(&zone, script); |
3444 i::Parser parser(&info); | 3444 i::Parser parser(&info); |
3445 CHECK(parser.Parse(&info)); | 3445 CHECK(parser.Parse(&info)); |
3446 CHECK(i::Compiler::Analyze(&info)); | 3446 CHECK(i::Compiler::Analyze(&info)); |
3447 CHECK(info.function() != NULL); | 3447 CHECK(info.literal() != NULL); |
3448 | 3448 |
3449 i::Scope* scope = info.function()->scope(); | 3449 i::Scope* scope = info.literal()->scope(); |
3450 CHECK_EQ(scope->inner_scopes()->length(), 1); | 3450 CHECK_EQ(scope->inner_scopes()->length(), 1); |
3451 i::Scope* inner_scope = scope->inner_scopes()->at(0); | 3451 i::Scope* inner_scope = scope->inner_scopes()->at(0); |
3452 const i::AstRawString* var_name = | 3452 const i::AstRawString* var_name = |
3453 info.ast_value_factory()->GetOneByteString("x"); | 3453 info.ast_value_factory()->GetOneByteString("x"); |
3454 i::Variable* var = inner_scope->Lookup(var_name); | 3454 i::Variable* var = inner_scope->Lookup(var_name); |
3455 bool expected = outers[i].assigned || inners[j].assigned; | 3455 bool expected = outers[i].assigned || inners[j].assigned; |
3456 CHECK(var != NULL); | 3456 CHECK(var != NULL); |
3457 CHECK(var->is_used() || !expected); | 3457 CHECK(var->is_used() || !expected); |
3458 CHECK((var->maybe_assigned() == i::kMaybeAssigned) == expected); | 3458 CHECK((var->maybe_assigned() == i::kMaybeAssigned) == expected); |
3459 } | 3459 } |
(...skipping 2039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5499 "export * from 'p.js';" | 5499 "export * from 'p.js';" |
5500 "import 'q.js'"; | 5500 "import 'q.js'"; |
5501 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); | 5501 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); |
5502 i::Handle<i::Script> script = factory->NewScript(source); | 5502 i::Handle<i::Script> script = factory->NewScript(source); |
5503 i::Zone zone; | 5503 i::Zone zone; |
5504 i::ParseInfo info(&zone, script); | 5504 i::ParseInfo info(&zone, script); |
5505 i::Parser parser(&info); | 5505 i::Parser parser(&info); |
5506 info.set_module(); | 5506 info.set_module(); |
5507 CHECK(parser.Parse(&info)); | 5507 CHECK(parser.Parse(&info)); |
5508 CHECK(i::Compiler::Analyze(&info)); | 5508 CHECK(i::Compiler::Analyze(&info)); |
5509 i::FunctionLiteral* func = info.function(); | 5509 i::FunctionLiteral* func = info.literal(); |
5510 i::Scope* module_scope = func->scope(); | 5510 i::Scope* module_scope = func->scope(); |
5511 i::Scope* outer_scope = module_scope->outer_scope(); | 5511 i::Scope* outer_scope = module_scope->outer_scope(); |
5512 CHECK(outer_scope->is_script_scope()); | 5512 CHECK(outer_scope->is_script_scope()); |
5513 CHECK_NULL(outer_scope->outer_scope()); | 5513 CHECK_NULL(outer_scope->outer_scope()); |
5514 CHECK_EQ(1, outer_scope->num_modules()); | 5514 CHECK_EQ(1, outer_scope->num_modules()); |
5515 CHECK(module_scope->is_module_scope()); | 5515 CHECK(module_scope->is_module_scope()); |
5516 CHECK_NOT_NULL(module_scope->module_var()); | 5516 CHECK_NOT_NULL(module_scope->module_var()); |
5517 CHECK_EQ(i::TEMPORARY, module_scope->module_var()->mode()); | 5517 CHECK_EQ(i::TEMPORARY, module_scope->module_var()->mode()); |
5518 i::ModuleDescriptor* descriptor = module_scope->module(); | 5518 i::ModuleDescriptor* descriptor = module_scope->module(); |
5519 CHECK_NOT_NULL(descriptor); | 5519 CHECK_NOT_NULL(descriptor); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5623 128 * 1024); | 5623 128 * 1024); |
5624 | 5624 |
5625 i::Handle<i::Script> script = | 5625 i::Handle<i::Script> script = |
5626 factory->NewScript(factory->NewStringFromAsciiChecked(source)); | 5626 factory->NewScript(factory->NewStringFromAsciiChecked(source)); |
5627 i::Zone zone; | 5627 i::Zone zone; |
5628 i::ParseInfo info(&zone, script); | 5628 i::ParseInfo info(&zone, script); |
5629 i::Parser parser(&info); | 5629 i::Parser parser(&info); |
5630 parser.set_allow_strong_mode(true); | 5630 parser.set_allow_strong_mode(true); |
5631 info.set_global(); | 5631 info.set_global(); |
5632 parser.Parse(&info); | 5632 parser.Parse(&info); |
5633 CHECK(info.function() != NULL); | 5633 CHECK(info.literal() != NULL); |
5634 CHECK_EQ(expected_language_mode, info.function()->language_mode()); | 5634 CHECK_EQ(expected_language_mode, info.literal()->language_mode()); |
5635 } | 5635 } |
5636 | 5636 |
5637 | 5637 |
5638 TEST(LanguageModeDirectives) { | 5638 TEST(LanguageModeDirectives) { |
5639 TestLanguageMode("\"use nothing\"", i::SLOPPY); | 5639 TestLanguageMode("\"use nothing\"", i::SLOPPY); |
5640 TestLanguageMode("\"use strict\"", i::STRICT); | 5640 TestLanguageMode("\"use strict\"", i::STRICT); |
5641 TestLanguageMode("\"use strong\"", i::STRONG); | 5641 TestLanguageMode("\"use strong\"", i::STRONG); |
5642 | 5642 |
5643 TestLanguageMode("var x = 1; \"use strict\"", i::SLOPPY); | 5643 TestLanguageMode("var x = 1; \"use strict\"", i::SLOPPY); |
5644 TestLanguageMode("var x = 1; \"use strong\"", i::SLOPPY); | 5644 TestLanguageMode("var x = 1; \"use strong\"", i::SLOPPY); |
(...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6811 "for (let x of []) {}", | 6811 "for (let x of []) {}", |
6812 NULL | 6812 NULL |
6813 }; | 6813 }; |
6814 // clang-format on | 6814 // clang-format on |
6815 | 6815 |
6816 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, | 6816 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, |
6817 kAllowHarmonySloppyLet}; | 6817 kAllowHarmonySloppyLet}; |
6818 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | 6818 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
6819 arraysize(always_flags)); | 6819 arraysize(always_flags)); |
6820 } | 6820 } |
OLD | NEW |