OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 virtual ~ParserLog() { } | 870 virtual ~ParserLog() { } |
871 | 871 |
872 // Records the occurrence of a function. | 872 // Records the occurrence of a function. |
873 virtual FunctionEntry LogFunction(int start) { return FunctionEntry(); } | 873 virtual FunctionEntry LogFunction(int start) { return FunctionEntry(); } |
874 virtual void LogSymbol(int start, Vector<const char> symbol) {} | 874 virtual void LogSymbol(int start, Vector<const char> symbol) {} |
875 virtual void LogError() { } | 875 virtual void LogError() { } |
876 // Return the current position in the function entry log. | 876 // Return the current position in the function entry log. |
877 virtual int function_position() { return 0; } | 877 virtual int function_position() { return 0; } |
878 virtual int symbol_position() { return 0; } | 878 virtual int symbol_position() { return 0; } |
879 virtual int symbol_ids() { return 0; } | 879 virtual int symbol_ids() { return 0; } |
| 880 virtual void PauseRecording() {} |
| 881 virtual void ResumeRecording() {} |
880 virtual Vector<unsigned> ExtractData() { | 882 virtual Vector<unsigned> ExtractData() { |
881 return Vector<unsigned>(); | 883 return Vector<unsigned>(); |
882 }; | 884 }; |
883 }; | 885 }; |
884 | 886 |
885 | 887 |
| 888 |
| 889 class ConditionalLogPauseScope { |
| 890 public: |
| 891 ConditionalLogPauseScope(bool pause, ParserLog* log) |
| 892 : log_(log), pause_(pause) { |
| 893 if (pause) log->PauseRecording(); |
| 894 } |
| 895 ~ConditionalLogPauseScope() { |
| 896 if (pause_) log_->ResumeRecording(); |
| 897 } |
| 898 private: |
| 899 ParserLog* log_; |
| 900 bool pause_; |
| 901 }; |
| 902 |
| 903 |
886 class AstBuildingParserFactory : public ParserFactory { | 904 class AstBuildingParserFactory : public ParserFactory { |
887 public: | 905 public: |
888 explicit AstBuildingParserFactory(int expected_symbols) | 906 explicit AstBuildingParserFactory(int expected_symbols) |
889 : ParserFactory(false), symbol_cache_(expected_symbols) { } | 907 : ParserFactory(false), symbol_cache_(expected_symbols) { } |
890 | 908 |
891 virtual Scope* NewScope(Scope* parent, Scope::Type type, bool inside_with); | 909 virtual Scope* NewScope(Scope* parent, Scope::Type type, bool inside_with); |
892 | 910 |
893 virtual Handle<String> LookupSymbol(int symbol_id, | 911 virtual Handle<String> LookupSymbol(int symbol_id, |
894 Vector<const char> string) { | 912 Vector<const char> string) { |
895 // Length of symbol cache is the number of identified symbols. | 913 // Length of symbol cache is the number of identified symbols. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 preamble_[ScriptDataImpl::kSymbolCountOffset] = 0; | 981 preamble_[ScriptDataImpl::kSymbolCountOffset] = 0; |
964 memcpy(data.start(), preamble_, sizeof(preamble_)); | 982 memcpy(data.start(), preamble_, sizeof(preamble_)); |
965 int symbol_start = ScriptDataImpl::kHeaderSize + function_size; | 983 int symbol_start = ScriptDataImpl::kHeaderSize + function_size; |
966 if (function_size > 0) { | 984 if (function_size > 0) { |
967 function_store_.WriteTo(data.SubVector(ScriptDataImpl::kHeaderSize, | 985 function_store_.WriteTo(data.SubVector(ScriptDataImpl::kHeaderSize, |
968 symbol_start)); | 986 symbol_start)); |
969 } | 987 } |
970 return data; | 988 return data; |
971 } | 989 } |
972 | 990 |
| 991 virtual void PauseRecording() { |
| 992 pause_count_++; |
| 993 is_recording_ = false; |
| 994 } |
| 995 |
| 996 virtual void ResumeRecording() { |
| 997 ASSERT(pause_count_ > 0); |
| 998 if (--pause_count_ == 0) is_recording_ = !has_error(); |
| 999 } |
| 1000 |
973 protected: | 1001 protected: |
974 bool has_error() { | 1002 bool has_error() { |
975 return static_cast<bool>(preamble_[ScriptDataImpl::kHasErrorOffset]); | 1003 return static_cast<bool>(preamble_[ScriptDataImpl::kHasErrorOffset]); |
976 } | 1004 } |
| 1005 bool is_recording() { |
| 1006 return is_recording_; |
| 1007 } |
977 | 1008 |
978 void WriteString(Vector<const char> str); | 1009 void WriteString(Vector<const char> str); |
979 | 1010 |
980 Collector<unsigned> function_store_; | 1011 Collector<unsigned> function_store_; |
981 unsigned preamble_[ScriptDataImpl::kHeaderSize]; | 1012 unsigned preamble_[ScriptDataImpl::kHeaderSize]; |
| 1013 bool is_recording_; |
| 1014 int pause_count_; |
| 1015 |
982 #ifdef DEBUG | 1016 #ifdef DEBUG |
983 int prev_start; | 1017 int prev_start; |
984 #endif | 1018 #endif |
985 }; | 1019 }; |
986 | 1020 |
987 | 1021 |
988 // Record both functions and symbols. | 1022 // Record both functions and symbols. |
989 class CompleteParserRecorder: public PartialParserRecorder { | 1023 class CompleteParserRecorder: public PartialParserRecorder { |
990 public: | 1024 public: |
991 CompleteParserRecorder(); | 1025 CompleteParserRecorder(); |
992 | 1026 |
993 virtual void LogSymbol(int start, Vector<const char> literal) { | 1027 virtual void LogSymbol(int start, Vector<const char> literal) { |
| 1028 if (!is_recording_) return; |
994 int hash = vector_hash(literal); | 1029 int hash = vector_hash(literal); |
995 HashMap::Entry* entry = symbol_table_.Lookup(&literal, hash, true); | 1030 HashMap::Entry* entry = symbol_table_.Lookup(&literal, hash, true); |
996 int id = static_cast<int>(reinterpret_cast<intptr_t>(entry->value)); | 1031 int id = static_cast<int>(reinterpret_cast<intptr_t>(entry->value)); |
997 if (id == 0) { | 1032 if (id == 0) { |
998 // Put (symbol_id_ + 1) into entry and increment it. | 1033 // Put (symbol_id_ + 1) into entry and increment it. |
999 id = ++symbol_id_; | 1034 id = ++symbol_id_; |
1000 entry->value = reinterpret_cast<void*>(id); | 1035 entry->value = reinterpret_cast<void*>(id); |
1001 Vector<Vector<const char> > symbol = symbol_entries_.AddBlock(1, literal); | 1036 Vector<Vector<const char> > symbol = symbol_entries_.AddBlock(1, literal); |
1002 entry->key = &symbol[0]; | 1037 entry->key = &symbol[0]; |
1003 } | 1038 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 // Write a non-negative number to the symbol store. | 1089 // Write a non-negative number to the symbol store. |
1055 void WriteNumber(int number); | 1090 void WriteNumber(int number); |
1056 | 1091 |
1057 Collector<byte> symbol_store_; | 1092 Collector<byte> symbol_store_; |
1058 Collector<Vector<const char> > symbol_entries_; | 1093 Collector<Vector<const char> > symbol_entries_; |
1059 HashMap symbol_table_; | 1094 HashMap symbol_table_; |
1060 int symbol_id_; | 1095 int symbol_id_; |
1061 }; | 1096 }; |
1062 | 1097 |
1063 | 1098 |
1064 void ScriptDataImpl::SkipFunctionEntry(int start) { | |
1065 ASSERT(function_index_ + FunctionEntry::kSize <= store_.length()); | |
1066 ASSERT(static_cast<int>(store_[function_index_]) == start); | |
1067 function_index_ += FunctionEntry::kSize; | |
1068 } | |
1069 | |
1070 | |
1071 FunctionEntry ScriptDataImpl::GetFunctionEntry(int start) { | 1099 FunctionEntry ScriptDataImpl::GetFunctionEntry(int start) { |
1072 // The current pre-data entry must be a FunctionEntry with the given | 1100 // The current pre-data entry must be a FunctionEntry with the given |
1073 // start position. | 1101 // start position. |
1074 if ((function_index_ + FunctionEntry::kSize <= store_.length()) | 1102 if ((function_index_ + FunctionEntry::kSize <= store_.length()) |
1075 && (static_cast<int>(store_[function_index_]) == start)) { | 1103 && (static_cast<int>(store_[function_index_]) == start)) { |
1076 int index = function_index_; | 1104 int index = function_index_; |
1077 function_index_ += FunctionEntry::kSize; | 1105 function_index_ += FunctionEntry::kSize; |
1078 return FunctionEntry(store_.SubVector(index, | 1106 return FunctionEntry(store_.SubVector(index, |
1079 index + FunctionEntry::kSize)); | 1107 index + FunctionEntry::kSize)); |
1080 } | 1108 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1119 if (symbol_count < 0) return false; | 1147 if (symbol_count < 0) return false; |
1120 // Check that the total size has room for header and function entries. | 1148 // Check that the total size has room for header and function entries. |
1121 int minimum_size = | 1149 int minimum_size = |
1122 ScriptDataImpl::kHeaderSize + functions_size; | 1150 ScriptDataImpl::kHeaderSize + functions_size; |
1123 if (store_.length() < minimum_size) return false; | 1151 if (store_.length() < minimum_size) return false; |
1124 return true; | 1152 return true; |
1125 } | 1153 } |
1126 | 1154 |
1127 | 1155 |
1128 | 1156 |
1129 PartialParserRecorder::PartialParserRecorder() : function_store_(0) { | 1157 PartialParserRecorder::PartialParserRecorder() |
| 1158 : function_store_(0), |
| 1159 is_recording_(true), |
| 1160 pause_count_(0) { |
1130 preamble_[ScriptDataImpl::kMagicOffset] = ScriptDataImpl::kMagicNumber; | 1161 preamble_[ScriptDataImpl::kMagicOffset] = ScriptDataImpl::kMagicNumber; |
1131 preamble_[ScriptDataImpl::kVersionOffset] = ScriptDataImpl::kCurrentVersion; | 1162 preamble_[ScriptDataImpl::kVersionOffset] = ScriptDataImpl::kCurrentVersion; |
1132 preamble_[ScriptDataImpl::kHasErrorOffset] = false; | 1163 preamble_[ScriptDataImpl::kHasErrorOffset] = false; |
1133 preamble_[ScriptDataImpl::kFunctionsSizeOffset] = 0; | 1164 preamble_[ScriptDataImpl::kFunctionsSizeOffset] = 0; |
1134 preamble_[ScriptDataImpl::kSymbolCountOffset] = 0; | 1165 preamble_[ScriptDataImpl::kSymbolCountOffset] = 0; |
1135 preamble_[ScriptDataImpl::kSizeOffset] = 0; | 1166 preamble_[ScriptDataImpl::kSizeOffset] = 0; |
1136 ASSERT_EQ(6, ScriptDataImpl::kHeaderSize); | 1167 ASSERT_EQ(6, ScriptDataImpl::kHeaderSize); |
1137 #ifdef DEBUG | 1168 #ifdef DEBUG |
1138 prev_start = -1; | 1169 prev_start = -1; |
1139 #endif | 1170 #endif |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 function_store_.Add(loc.beg_pos); | 1226 function_store_.Add(loc.beg_pos); |
1196 STATIC_ASSERT(ScriptDataImpl::kMessageEndPos == 1); | 1227 STATIC_ASSERT(ScriptDataImpl::kMessageEndPos == 1); |
1197 function_store_.Add(loc.end_pos); | 1228 function_store_.Add(loc.end_pos); |
1198 STATIC_ASSERT(ScriptDataImpl::kMessageArgCountPos == 2); | 1229 STATIC_ASSERT(ScriptDataImpl::kMessageArgCountPos == 2); |
1199 function_store_.Add(args.length()); | 1230 function_store_.Add(args.length()); |
1200 STATIC_ASSERT(ScriptDataImpl::kMessageTextPos == 3); | 1231 STATIC_ASSERT(ScriptDataImpl::kMessageTextPos == 3); |
1201 WriteString(CStrVector(message)); | 1232 WriteString(CStrVector(message)); |
1202 for (int i = 0; i < args.length(); i++) { | 1233 for (int i = 0; i < args.length(); i++) { |
1203 WriteString(CStrVector(args[i])); | 1234 WriteString(CStrVector(args[i])); |
1204 } | 1235 } |
| 1236 is_recording_ = false; |
1205 } | 1237 } |
1206 | 1238 |
1207 | 1239 |
1208 Scanner::Location ScriptDataImpl::MessageLocation() { | 1240 Scanner::Location ScriptDataImpl::MessageLocation() { |
1209 int beg_pos = Read(kMessageStartPos); | 1241 int beg_pos = Read(kMessageStartPos); |
1210 int end_pos = Read(kMessageEndPos); | 1242 int end_pos = Read(kMessageEndPos); |
1211 return Scanner::Location(beg_pos, end_pos); | 1243 return Scanner::Location(beg_pos, end_pos); |
1212 } | 1244 } |
1213 | 1245 |
1214 | 1246 |
(...skipping 26 matching lines...) Expand all Loading... |
1241 unsigned* ScriptDataImpl::ReadAddress(int position) { | 1273 unsigned* ScriptDataImpl::ReadAddress(int position) { |
1242 return &store_[ScriptDataImpl::kHeaderSize + position]; | 1274 return &store_[ScriptDataImpl::kHeaderSize + position]; |
1243 } | 1275 } |
1244 | 1276 |
1245 | 1277 |
1246 FunctionEntry PartialParserRecorder::LogFunction(int start) { | 1278 FunctionEntry PartialParserRecorder::LogFunction(int start) { |
1247 #ifdef DEBUG | 1279 #ifdef DEBUG |
1248 ASSERT(start > prev_start); | 1280 ASSERT(start > prev_start); |
1249 prev_start = start; | 1281 prev_start = start; |
1250 #endif | 1282 #endif |
1251 if (has_error()) return FunctionEntry(); | 1283 if (!is_recording_) return FunctionEntry(); |
1252 FunctionEntry result(function_store_.AddBlock(FunctionEntry::kSize, 0)); | 1284 FunctionEntry result(function_store_.AddBlock(FunctionEntry::kSize, 0)); |
1253 result.set_start_pos(start); | 1285 result.set_start_pos(start); |
1254 return result; | 1286 return result; |
1255 } | 1287 } |
1256 | 1288 |
1257 | 1289 |
1258 class AstBuildingParser : public Parser { | 1290 class AstBuildingParser : public Parser { |
1259 public: | 1291 public: |
1260 AstBuildingParser(Handle<Script> script, bool allow_natives_syntax, | 1292 AstBuildingParser(Handle<Script> script, bool allow_natives_syntax, |
1261 v8::Extension* extension, ScriptDataImpl* pre_data) | 1293 v8::Extension* extension, ScriptDataImpl* pre_data) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 // allocating lots and lots of empty statements. | 1368 // allocating lots and lots of empty statements. |
1337 static v8::internal::EmptyStatement empty; | 1369 static v8::internal::EmptyStatement empty; |
1338 return ∅ | 1370 return ∅ |
1339 } | 1371 } |
1340 | 1372 |
1341 | 1373 |
1342 Scope* ParserFactory::NewScope(Scope* parent, Scope::Type type, | 1374 Scope* ParserFactory::NewScope(Scope* parent, Scope::Type type, |
1343 bool inside_with) { | 1375 bool inside_with) { |
1344 ASSERT(parent != NULL); | 1376 ASSERT(parent != NULL); |
1345 parent->type_ = type; | 1377 parent->type_ = type; |
| 1378 // Initialize function is hijacked by DummyScope to increment scope depth. |
| 1379 parent->Initialize(inside_with); |
1346 return parent; | 1380 return parent; |
1347 } | 1381 } |
1348 | 1382 |
1349 | 1383 |
1350 VariableProxy* PreParser::Declare(Handle<String> name, Variable::Mode mode, | 1384 VariableProxy* PreParser::Declare(Handle<String> name, Variable::Mode mode, |
1351 FunctionLiteral* fun, bool resolve, | 1385 FunctionLiteral* fun, bool resolve, |
1352 bool* ok) { | 1386 bool* ok) { |
1353 return NULL; | 1387 return NULL; |
1354 } | 1388 } |
1355 | 1389 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1408 public: | 1442 public: |
1409 LexicalScope(Parser* parser, Scope* scope) | 1443 LexicalScope(Parser* parser, Scope* scope) |
1410 : parser_(parser), | 1444 : parser_(parser), |
1411 prev_scope_(parser->top_scope_), | 1445 prev_scope_(parser->top_scope_), |
1412 prev_level_(parser->with_nesting_level_) { | 1446 prev_level_(parser->with_nesting_level_) { |
1413 parser_->top_scope_ = scope; | 1447 parser_->top_scope_ = scope; |
1414 parser_->with_nesting_level_ = 0; | 1448 parser_->with_nesting_level_ = 0; |
1415 } | 1449 } |
1416 | 1450 |
1417 ~LexicalScope() { | 1451 ~LexicalScope() { |
| 1452 parser_->top_scope_->Leave(); |
1418 parser_->top_scope_ = prev_scope_; | 1453 parser_->top_scope_ = prev_scope_; |
1419 parser_->with_nesting_level_ = prev_level_; | 1454 parser_->with_nesting_level_ = prev_level_; |
1420 } | 1455 } |
1421 | 1456 |
1422 private: | 1457 private: |
1423 Parser* parser_; | 1458 Parser* parser_; |
1424 Scope* prev_scope_; | 1459 Scope* prev_scope_; |
1425 int prev_level_; | 1460 int prev_level_; |
1426 }; | 1461 }; |
1427 | 1462 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1473 | 1508 |
1474 | 1509 |
1475 bool Parser::PreParseProgram(Handle<String> source, | 1510 bool Parser::PreParseProgram(Handle<String> source, |
1476 unibrow::CharacterStream* stream) { | 1511 unibrow::CharacterStream* stream) { |
1477 HistogramTimerScope timer(&Counters::pre_parse); | 1512 HistogramTimerScope timer(&Counters::pre_parse); |
1478 AssertNoZoneAllocation assert_no_zone_allocation; | 1513 AssertNoZoneAllocation assert_no_zone_allocation; |
1479 AssertNoAllocation assert_no_allocation; | 1514 AssertNoAllocation assert_no_allocation; |
1480 NoHandleAllocation no_handle_allocation; | 1515 NoHandleAllocation no_handle_allocation; |
1481 scanner_.Initialize(source, stream, JAVASCRIPT); | 1516 scanner_.Initialize(source, stream, JAVASCRIPT); |
1482 ASSERT(target_stack_ == NULL); | 1517 ASSERT(target_stack_ == NULL); |
1483 mode_ = PARSE_EAGERLY; | 1518 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY; |
| 1519 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; |
1484 DummyScope top_scope; | 1520 DummyScope top_scope; |
1485 LexicalScope scope(this, &top_scope); | 1521 LexicalScope scope(this, &top_scope); |
1486 TemporaryScope temp_scope(this); | 1522 TemporaryScope temp_scope(this); |
1487 ZoneListWrapper<Statement> processor; | 1523 ZoneListWrapper<Statement> processor; |
1488 bool ok = true; | 1524 bool ok = true; |
1489 ParseSourceElements(&processor, Token::EOS, &ok); | 1525 ParseSourceElements(&processor, Token::EOS, &ok); |
1490 return !scanner().stack_overflow(); | 1526 return !scanner().stack_overflow(); |
1491 } | 1527 } |
1492 | 1528 |
1493 | 1529 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1651 return result; | 1687 return result; |
1652 } | 1688 } |
1653 | 1689 |
1654 void Parser::ReportMessage(const char* type, Vector<const char*> args) { | 1690 void Parser::ReportMessage(const char* type, Vector<const char*> args) { |
1655 Scanner::Location source_location = scanner_.location(); | 1691 Scanner::Location source_location = scanner_.location(); |
1656 ReportMessageAt(source_location, type, args); | 1692 ReportMessageAt(source_location, type, args); |
1657 } | 1693 } |
1658 | 1694 |
1659 | 1695 |
1660 Handle<String> Parser::GetSymbol(bool* ok) { | 1696 Handle<String> Parser::GetSymbol(bool* ok) { |
1661 log()->LogSymbol(scanner_.location().beg_pos, scanner_.literal()); | 1697 if (is_pre_parsing_) { |
| 1698 log()->LogSymbol(scanner_.location().beg_pos, scanner_.literal()); |
| 1699 return Handle<String>::null(); |
| 1700 } |
1662 int symbol_id = -1; | 1701 int symbol_id = -1; |
1663 if (pre_data() != NULL) { | 1702 if (pre_data() != NULL) { |
1664 symbol_id = pre_data()->GetSymbolIdentifier(); | 1703 symbol_id = pre_data()->GetSymbolIdentifier(); |
1665 } | 1704 } |
1666 return factory()->LookupSymbol(symbol_id, scanner_.literal()); | 1705 return factory()->LookupSymbol(symbol_id, scanner_.literal()); |
1667 } | 1706 } |
1668 | 1707 |
1669 | 1708 |
1670 void AstBuildingParser::ReportMessageAt(Scanner::Location source_location, | 1709 void AstBuildingParser::ReportMessageAt(Scanner::Location source_location, |
1671 const char* type, | 1710 const char* type, |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1964 block_finder.Update(stat); | 2003 block_finder.Update(stat); |
1965 } | 2004 } |
1966 // Find and mark all assignments to named properties in this (this.x =) | 2005 // Find and mark all assignments to named properties in this (this.x =) |
1967 if (top_scope_->is_function_scope()) { | 2006 if (top_scope_->is_function_scope()) { |
1968 this_property_assignment_finder.Update(top_scope_, stat); | 2007 this_property_assignment_finder.Update(top_scope_, stat); |
1969 } | 2008 } |
1970 processor->Add(stat); | 2009 processor->Add(stat); |
1971 } | 2010 } |
1972 | 2011 |
1973 // Propagate the collected information on this property assignments. | 2012 // Propagate the collected information on this property assignments. |
1974 if (top_scope_->is_function_scope()) { | 2013 if (!is_pre_parsing_ && top_scope_->is_function_scope()) { |
1975 bool only_simple_this_property_assignments = | 2014 bool only_simple_this_property_assignments = |
1976 this_property_assignment_finder.only_simple_this_property_assignments() | 2015 this_property_assignment_finder.only_simple_this_property_assignments() |
1977 && top_scope_->declarations()->length() == 0; | 2016 && top_scope_->declarations()->length() == 0; |
1978 if (only_simple_this_property_assignments) { | 2017 if (only_simple_this_property_assignments) { |
1979 temp_scope_->SetThisPropertyAssignmentInfo( | 2018 temp_scope_->SetThisPropertyAssignmentInfo( |
1980 only_simple_this_property_assignments, | 2019 only_simple_this_property_assignments, |
1981 this_property_assignment_finder.GetThisPropertyAssignments()); | 2020 this_property_assignment_finder.GetThisPropertyAssignments()); |
1982 } | 2021 } |
1983 } | 2022 } |
1984 return 0; | 2023 return 0; |
(...skipping 2131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4116 // that case, we don't have a function name (it's empty). | 4155 // that case, we don't have a function name (it's empty). |
4117 Handle<String> name = is_named ? var_name : factory()->EmptySymbol(); | 4156 Handle<String> name = is_named ? var_name : factory()->EmptySymbol(); |
4118 // The function name, if any. | 4157 // The function name, if any. |
4119 Handle<String> function_name = factory()->EmptySymbol(); | 4158 Handle<String> function_name = factory()->EmptySymbol(); |
4120 if (is_named && (type == EXPRESSION || type == NESTED)) { | 4159 if (is_named && (type == EXPRESSION || type == NESTED)) { |
4121 function_name = name; | 4160 function_name = name; |
4122 } | 4161 } |
4123 | 4162 |
4124 int num_parameters = 0; | 4163 int num_parameters = 0; |
4125 // Parse function body. | 4164 // Parse function body. |
4126 { Scope::Type type = Scope::FUNCTION_SCOPE; | 4165 { Scope* scope = |
4127 Scope* scope = factory()->NewScope(top_scope_, type, inside_with()); | 4166 factory()->NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with()); |
4128 LexicalScope lexical_scope(this, scope); | 4167 LexicalScope lexical_scope(this, scope); |
4129 TemporaryScope temp_scope(this); | 4168 TemporaryScope temp_scope(this); |
4130 top_scope_->SetScopeName(name); | 4169 top_scope_->SetScopeName(name); |
4131 | 4170 |
4132 // FormalParameterList :: | 4171 // FormalParameterList :: |
4133 // '(' (Identifier)*[','] ')' | 4172 // '(' (Identifier)*[','] ')' |
4134 Expect(Token::LPAREN, CHECK_OK); | 4173 Expect(Token::LPAREN, CHECK_OK); |
4135 int start_pos = scanner_.location().beg_pos; | 4174 int start_pos = scanner_.location().beg_pos; |
4136 bool done = (peek() == Token::RPAREN); | 4175 bool done = (peek() == Token::RPAREN); |
4137 while (!done) { | 4176 while (!done) { |
(...skipping 10 matching lines...) Expand all Loading... |
4148 | 4187 |
4149 Expect(Token::LBRACE, CHECK_OK); | 4188 Expect(Token::LBRACE, CHECK_OK); |
4150 ZoneListWrapper<Statement> body = factory()->NewList<Statement>(8); | 4189 ZoneListWrapper<Statement> body = factory()->NewList<Statement>(8); |
4151 | 4190 |
4152 // If we have a named function expression, we add a local variable | 4191 // If we have a named function expression, we add a local variable |
4153 // declaration to the body of the function with the name of the | 4192 // declaration to the body of the function with the name of the |
4154 // function and let it refer to the function itself (closure). | 4193 // function and let it refer to the function itself (closure). |
4155 // NOTE: We create a proxy and resolve it here so that in the | 4194 // NOTE: We create a proxy and resolve it here so that in the |
4156 // future we can change the AST to only refer to VariableProxies | 4195 // future we can change the AST to only refer to VariableProxies |
4157 // instead of Variables and Proxis as is the case now. | 4196 // instead of Variables and Proxis as is the case now. |
4158 if (!function_name.is_null() && function_name->length() > 0) { | 4197 if (!is_pre_parsing_ |
| 4198 && !function_name.is_null() |
| 4199 && function_name->length() > 0) { |
4159 Variable* fvar = top_scope_->DeclareFunctionVar(function_name); | 4200 Variable* fvar = top_scope_->DeclareFunctionVar(function_name); |
4160 VariableProxy* fproxy = | 4201 VariableProxy* fproxy = |
4161 top_scope_->NewUnresolved(function_name, inside_with()); | 4202 top_scope_->NewUnresolved(function_name, inside_with()); |
4162 fproxy->BindTo(fvar); | 4203 fproxy->BindTo(fvar); |
4163 body.Add(new ExpressionStatement( | 4204 body.Add(new ExpressionStatement( |
4164 new Assignment(Token::INIT_CONST, fproxy, | 4205 new Assignment(Token::INIT_CONST, fproxy, |
4165 NEW(ThisFunction()), | 4206 NEW(ThisFunction()), |
4166 RelocInfo::kNoPosition))); | 4207 RelocInfo::kNoPosition))); |
4167 } | 4208 } |
4168 | 4209 |
(...skipping 13 matching lines...) Expand all Loading... |
4182 if (!entry.is_valid()) { | 4223 if (!entry.is_valid()) { |
4183 ReportInvalidPreparseData(name, CHECK_OK); | 4224 ReportInvalidPreparseData(name, CHECK_OK); |
4184 } | 4225 } |
4185 end_pos = entry.end_pos(); | 4226 end_pos = entry.end_pos(); |
4186 if (end_pos <= function_block_pos) { | 4227 if (end_pos <= function_block_pos) { |
4187 // End position greater than end of stream is safe, and hard to check. | 4228 // End position greater than end of stream is safe, and hard to check. |
4188 ReportInvalidPreparseData(name, CHECK_OK); | 4229 ReportInvalidPreparseData(name, CHECK_OK); |
4189 } | 4230 } |
4190 Counters::total_preparse_skipped.Increment(end_pos - function_block_pos); | 4231 Counters::total_preparse_skipped.Increment(end_pos - function_block_pos); |
4191 scanner_.SeekForward(end_pos); | 4232 scanner_.SeekForward(end_pos); |
4192 pre_data()->Skip(entry.predata_function_skip(), | |
4193 entry.predata_symbol_skip()); | |
4194 materialized_literal_count = entry.literal_count(); | 4233 materialized_literal_count = entry.literal_count(); |
4195 expected_property_count = entry.property_count(); | 4234 expected_property_count = entry.property_count(); |
4196 only_simple_this_property_assignments = false; | 4235 only_simple_this_property_assignments = false; |
4197 this_property_assignments = Factory::empty_fixed_array(); | 4236 this_property_assignments = Factory::empty_fixed_array(); |
4198 Expect(Token::RBRACE, CHECK_OK); | 4237 Expect(Token::RBRACE, CHECK_OK); |
4199 } else { | 4238 } else { |
4200 if (pre_data() != NULL) { | 4239 FunctionEntry entry; |
4201 // Skip pre-data entry for non-lazily compiled function. | 4240 if (is_lazily_compiled) entry = log()->LogFunction(function_block_pos); |
4202 pre_data()->SkipFunctionEntry(function_block_pos); | 4241 { |
| 4242 ConditionalLogPauseScope pause_if(is_lazily_compiled, log()); |
| 4243 ParseSourceElements(&body, Token::RBRACE, CHECK_OK); |
4203 } | 4244 } |
4204 FunctionEntry entry = log()->LogFunction(function_block_pos); | |
4205 int predata_function_position_before = log()->function_position(); | |
4206 int predata_symbol_position_before = log()->symbol_position(); | |
4207 ParseSourceElements(&body, Token::RBRACE, CHECK_OK); | |
4208 materialized_literal_count = temp_scope.materialized_literal_count(); | 4245 materialized_literal_count = temp_scope.materialized_literal_count(); |
4209 expected_property_count = temp_scope.expected_property_count(); | 4246 expected_property_count = temp_scope.expected_property_count(); |
4210 only_simple_this_property_assignments = | 4247 only_simple_this_property_assignments = |
4211 temp_scope.only_simple_this_property_assignments(); | 4248 temp_scope.only_simple_this_property_assignments(); |
4212 this_property_assignments = temp_scope.this_property_assignments(); | 4249 this_property_assignments = temp_scope.this_property_assignments(); |
4213 | 4250 |
4214 Expect(Token::RBRACE, CHECK_OK); | 4251 Expect(Token::RBRACE, CHECK_OK); |
4215 end_pos = scanner_.location().end_pos; | 4252 end_pos = scanner_.location().end_pos; |
4216 if (entry.is_valid()) { | 4253 if (entry.is_valid()) { |
| 4254 ASSERT(is_lazily_compiled); |
| 4255 ASSERT(is_pre_parsing_); |
4217 entry.set_end_pos(end_pos); | 4256 entry.set_end_pos(end_pos); |
4218 entry.set_literal_count(materialized_literal_count); | 4257 entry.set_literal_count(materialized_literal_count); |
4219 entry.set_property_count(expected_property_count); | 4258 entry.set_property_count(expected_property_count); |
4220 entry.set_predata_function_skip( | |
4221 log()->function_position() - predata_function_position_before); | |
4222 entry.set_predata_symbol_skip( | |
4223 log()->symbol_position() - predata_symbol_position_before); | |
4224 } | 4259 } |
4225 } | 4260 } |
4226 | 4261 |
4227 FunctionLiteral* function_literal = | 4262 FunctionLiteral* function_literal = |
4228 NEW(FunctionLiteral(name, | 4263 NEW(FunctionLiteral(name, |
4229 top_scope_, | 4264 top_scope_, |
4230 body.elements(), | 4265 body.elements(), |
4231 materialized_literal_count, | 4266 materialized_literal_count, |
4232 expected_property_count, | 4267 expected_property_count, |
4233 only_simple_this_property_assignments, | 4268 only_simple_this_property_assignments, |
(...skipping 1384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5618 AstBuildingParser parser(script, true, NULL, NULL); // always allow | 5653 AstBuildingParser parser(script, true, NULL, NULL); // always allow |
5619 always_allow_natives_syntax = allow_natives_syntax_before; | 5654 always_allow_natives_syntax = allow_natives_syntax_before; |
5620 // Parse the function by pointing to the function source in the script source. | 5655 // Parse the function by pointing to the function source in the script source. |
5621 Handle<String> script_source(String::cast(script->source())); | 5656 Handle<String> script_source(String::cast(script->source())); |
5622 FunctionLiteral* result = | 5657 FunctionLiteral* result = |
5623 parser.ParseLazy(script_source, name, | 5658 parser.ParseLazy(script_source, name, |
5624 start_position, end_position, is_expression); | 5659 start_position, end_position, is_expression); |
5625 return result; | 5660 return result; |
5626 } | 5661 } |
5627 | 5662 |
5628 | |
5629 #undef NEW | 5663 #undef NEW |
5630 | 5664 |
5631 | |
5632 } } // namespace v8::internal | 5665 } } // namespace v8::internal |
OLD | NEW |