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 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 CHECK(scope->LookupThis()->is_used()); | 1093 CHECK(scope->LookupThis()->is_used()); |
1094 } | 1094 } |
1095 CHECK_EQ((source_data[i].expected & INNER_ARGUMENTS) != 0, | 1095 CHECK_EQ((source_data[i].expected & INNER_ARGUMENTS) != 0, |
1096 scope->inner_uses_arguments()); | 1096 scope->inner_uses_arguments()); |
1097 CHECK_EQ((source_data[i].expected & EVAL) != 0, scope->calls_eval()); | 1097 CHECK_EQ((source_data[i].expected & EVAL) != 0, scope->calls_eval()); |
1098 } | 1098 } |
1099 } | 1099 } |
1100 } | 1100 } |
1101 | 1101 |
1102 | 1102 |
| 1103 static void CheckParsesToNumber(const char* source, bool with_dot) { |
| 1104 v8::V8::Initialize(); |
| 1105 HandleAndZoneScope handles; |
| 1106 |
| 1107 i::Isolate* isolate = CcTest::i_isolate(); |
| 1108 i::Factory* factory = isolate->factory(); |
| 1109 |
| 1110 std::string full_source = "function f() { return "; |
| 1111 full_source += source; |
| 1112 full_source += "; }"; |
| 1113 |
| 1114 i::Handle<i::String> source_code = |
| 1115 factory->NewStringFromUtf8(i::CStrVector(full_source.c_str())) |
| 1116 .ToHandleChecked(); |
| 1117 |
| 1118 i::Handle<i::Script> script = factory->NewScript(source_code); |
| 1119 |
| 1120 i::ParseInfo info(handles.main_zone(), script); |
| 1121 i::Parser parser(&info); |
| 1122 parser.set_allow_harmony_arrow_functions(true); |
| 1123 parser.set_allow_harmony_sloppy(true); |
| 1124 info.set_global(); |
| 1125 info.set_lazy(false); |
| 1126 info.set_allow_lazy_parsing(false); |
| 1127 info.set_toplevel(true); |
| 1128 |
| 1129 i::CompilationInfo compilation_info(&info); |
| 1130 CHECK(i::Compiler::ParseAndAnalyze(&info)); |
| 1131 |
| 1132 CHECK(info.scope()->declarations()->length() == 1); |
| 1133 i::FunctionLiteral* fun = |
| 1134 info.scope()->declarations()->at(0)->AsFunctionDeclaration()->fun(); |
| 1135 CHECK(fun->body()->length() == 1); |
| 1136 CHECK(fun->body()->at(0)->IsReturnStatement()); |
| 1137 i::ReturnStatement* ret = fun->body()->at(0)->AsReturnStatement(); |
| 1138 CHECK(ret->expression()->IsLiteral()); |
| 1139 i::Literal* lit = ret->expression()->AsLiteral(); |
| 1140 const i::AstValue* val = lit->raw_value(); |
| 1141 CHECK(with_dot == val->ContainsDot()); |
| 1142 } |
| 1143 |
| 1144 |
| 1145 TEST(ParseNumbers) { |
| 1146 CheckParsesToNumber("1.34", true); |
| 1147 CheckParsesToNumber("134", false); |
| 1148 CheckParsesToNumber("134e44", false); |
| 1149 CheckParsesToNumber("134.e44", true); |
| 1150 CheckParsesToNumber("134.44e44", true); |
| 1151 CheckParsesToNumber(".44", true); |
| 1152 } |
| 1153 |
| 1154 |
1103 TEST(ScopePositions) { | 1155 TEST(ScopePositions) { |
1104 // Test the parser for correctly setting the start and end positions | 1156 // Test the parser for correctly setting the start and end positions |
1105 // of a scope. We check the scope positions of exactly one scope | 1157 // of a scope. We check the scope positions of exactly one scope |
1106 // nested in the global scope of a program. 'inner source' is the | 1158 // nested in the global scope of a program. 'inner source' is the |
1107 // source code that determines the part of the source belonging | 1159 // source code that determines the part of the source belonging |
1108 // to the nested scope. 'outer_prefix' and 'outer_suffix' are | 1160 // to the nested scope. 'outer_prefix' and 'outer_suffix' are |
1109 // parts of the source that belong to the global scope. | 1161 // parts of the source that belong to the global scope. |
1110 struct SourceData { | 1162 struct SourceData { |
1111 const char* outer_prefix; | 1163 const char* outer_prefix; |
1112 const char* inner_source; | 1164 const char* inner_source; |
(...skipping 5590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6703 kAllowHarmonyNewTarget, | 6755 kAllowHarmonyNewTarget, |
6704 kAllowHarmonySloppy, | 6756 kAllowHarmonySloppy, |
6705 }; | 6757 }; |
6706 // clang-format on | 6758 // clang-format on |
6707 | 6759 |
6708 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags, | 6760 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags, |
6709 arraysize(always_flags)); | 6761 arraysize(always_flags)); |
6710 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags, | 6762 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags, |
6711 arraysize(always_flags)); | 6763 arraysize(always_flags)); |
6712 } | 6764 } |
OLD | NEW |