| 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 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 i::ParseInfo info(&zone, script); | 1087 i::ParseInfo info(&zone, script); |
| 1088 i::Parser parser(&info); | 1088 i::Parser parser(&info); |
| 1089 info.set_global(); | 1089 info.set_global(); |
| 1090 CHECK(parser.Parse(&info)); | 1090 CHECK(parser.Parse(&info)); |
| 1091 CHECK(i::Rewriter::Rewrite(&info)); | 1091 CHECK(i::Rewriter::Rewrite(&info)); |
| 1092 CHECK(i::Scope::Analyze(&info)); | 1092 CHECK(i::Scope::Analyze(&info)); |
| 1093 CHECK(info.literal() != NULL); | 1093 CHECK(info.literal() != NULL); |
| 1094 | 1094 |
| 1095 i::Scope* script_scope = info.literal()->scope(); | 1095 i::Scope* script_scope = info.literal()->scope(); |
| 1096 CHECK(script_scope->is_script_scope()); | 1096 CHECK(script_scope->is_script_scope()); |
| 1097 CHECK_EQ(1, script_scope->inner_scopes()->length()); | |
| 1098 | 1097 |
| 1099 i::Scope* scope = script_scope->inner_scopes()->at(0); | 1098 i::Scope* scope = script_scope->inner_scope(); |
| 1099 DCHECK_NOT_NULL(scope); |
| 1100 DCHECK_NULL(scope->sibling()); |
| 1100 // Adjust for constructor scope. | 1101 // Adjust for constructor scope. |
| 1101 if (j == 2) { | 1102 if (j == 2) { |
| 1102 CHECK_EQ(1, scope->inner_scopes()->length()); | 1103 scope = scope->inner_scope(); |
| 1103 scope = scope->inner_scopes()->at(0); | 1104 DCHECK_NOT_NULL(scope); |
| 1105 DCHECK_NULL(scope->sibling()); |
| 1104 } | 1106 } |
| 1105 CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0, | 1107 CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0, |
| 1106 scope->uses_arguments()); | 1108 scope->uses_arguments()); |
| 1107 CHECK_EQ((source_data[i].expected & SUPER_PROPERTY) != 0, | 1109 CHECK_EQ((source_data[i].expected & SUPER_PROPERTY) != 0, |
| 1108 scope->uses_super_property()); | 1110 scope->uses_super_property()); |
| 1109 if ((source_data[i].expected & THIS) != 0) { | 1111 if ((source_data[i].expected & THIS) != 0) { |
| 1110 // Currently the is_used() flag is conservative; all variables in a | 1112 // Currently the is_used() flag is conservative; all variables in a |
| 1111 // script scope are marked as used. | 1113 // script scope are marked as used. |
| 1112 CHECK( | 1114 CHECK( |
| 1113 scope->Lookup(info.ast_value_factory()->this_string())->is_used()); | 1115 scope->Lookup(info.ast_value_factory()->this_string())->is_used()); |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1405 info.set_global(); | 1407 info.set_global(); |
| 1406 info.set_language_mode(source_data[i].language_mode); | 1408 info.set_language_mode(source_data[i].language_mode); |
| 1407 parser.Parse(&info); | 1409 parser.Parse(&info); |
| 1408 CHECK(info.literal() != NULL); | 1410 CHECK(info.literal() != NULL); |
| 1409 | 1411 |
| 1410 // Check scope types and positions. | 1412 // Check scope types and positions. |
| 1411 i::Scope* scope = info.literal()->scope(); | 1413 i::Scope* scope = info.literal()->scope(); |
| 1412 CHECK(scope->is_script_scope()); | 1414 CHECK(scope->is_script_scope()); |
| 1413 CHECK_EQ(scope->start_position(), 0); | 1415 CHECK_EQ(scope->start_position(), 0); |
| 1414 CHECK_EQ(scope->end_position(), kProgramSize); | 1416 CHECK_EQ(scope->end_position(), kProgramSize); |
| 1415 CHECK_EQ(scope->inner_scopes()->length(), 1); | |
| 1416 | 1417 |
| 1417 i::Scope* inner_scope = scope->inner_scopes()->at(0); | 1418 i::Scope* inner_scope = scope->inner_scope(); |
| 1419 DCHECK_NOT_NULL(inner_scope); |
| 1420 DCHECK_NULL(inner_scope->sibling()); |
| 1418 CHECK_EQ(inner_scope->scope_type(), source_data[i].scope_type); | 1421 CHECK_EQ(inner_scope->scope_type(), source_data[i].scope_type); |
| 1419 CHECK_EQ(inner_scope->start_position(), kPrefixLen); | 1422 CHECK_EQ(inner_scope->start_position(), kPrefixLen); |
| 1420 // The end position of a token is one position after the last | 1423 // The end position of a token is one position after the last |
| 1421 // character belonging to that token. | 1424 // character belonging to that token. |
| 1422 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); | 1425 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); |
| 1423 } | 1426 } |
| 1424 } | 1427 } |
| 1425 | 1428 |
| 1426 | 1429 |
| 1427 TEST(DiscardFunctionBody) { | 1430 TEST(DiscardFunctionBody) { |
| (...skipping 2115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3543 | 3546 |
| 3544 i::Handle<i::Script> script = factory->NewScript(source); | 3547 i::Handle<i::Script> script = factory->NewScript(source); |
| 3545 i::Zone zone(CcTest::i_isolate()->allocator()); | 3548 i::Zone zone(CcTest::i_isolate()->allocator()); |
| 3546 i::ParseInfo info(&zone, script); | 3549 i::ParseInfo info(&zone, script); |
| 3547 i::Parser parser(&info); | 3550 i::Parser parser(&info); |
| 3548 CHECK(parser.Parse(&info)); | 3551 CHECK(parser.Parse(&info)); |
| 3549 CHECK(i::Compiler::Analyze(&info)); | 3552 CHECK(i::Compiler::Analyze(&info)); |
| 3550 CHECK(info.literal() != NULL); | 3553 CHECK(info.literal() != NULL); |
| 3551 | 3554 |
| 3552 i::Scope* scope = info.literal()->scope(); | 3555 i::Scope* scope = info.literal()->scope(); |
| 3553 CHECK_EQ(scope->inner_scopes()->length(), 1); | 3556 i::Scope* inner_scope = scope->inner_scope(); |
| 3554 i::Scope* inner_scope = scope->inner_scopes()->at(0); | 3557 DCHECK_NOT_NULL(inner_scope); |
| 3558 DCHECK_NULL(inner_scope->sibling()); |
| 3555 const i::AstRawString* var_name = | 3559 const i::AstRawString* var_name = |
| 3556 info.ast_value_factory()->GetOneByteString("x"); | 3560 info.ast_value_factory()->GetOneByteString("x"); |
| 3557 i::Variable* var = inner_scope->Lookup(var_name); | 3561 i::Variable* var = inner_scope->Lookup(var_name); |
| 3558 bool expected = outers[i].assigned || inners[j].assigned; | 3562 bool expected = outers[i].assigned || inners[j].assigned; |
| 3559 CHECK(var != NULL); | 3563 CHECK(var != NULL); |
| 3560 CHECK(var->is_used() || !expected); | 3564 CHECK(var->is_used() || !expected); |
| 3561 CHECK((var->maybe_assigned() == i::kMaybeAssigned) == expected); | 3565 CHECK((var->maybe_assigned() == i::kMaybeAssigned) == expected); |
| 3562 } | 3566 } |
| 3563 } | 3567 } |
| 3564 } | 3568 } |
| (...skipping 4386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7951 "(a,);", | 7955 "(a,);", |
| 7952 "(a,b,c,);", | 7956 "(a,b,c,);", |
| 7953 NULL | 7957 NULL |
| 7954 }; | 7958 }; |
| 7955 // clang-format on | 7959 // clang-format on |
| 7956 | 7960 |
| 7957 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; | 7961 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; |
| 7958 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 7962 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| 7959 arraysize(always_flags)); | 7963 arraysize(always_flags)); |
| 7960 } | 7964 } |
| OLD | NEW |