OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/ast.h" | 5 #include "src/ast.h" |
6 | 6 |
7 #include <cmath> // For isfinite. | 7 #include <cmath> // For isfinite. |
8 #include "src/builtins.h" | 8 #include "src/builtins.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/contexts.h" | 10 #include "src/contexts.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 name_(name), | 80 name_(name), |
81 var_(NULL), | 81 var_(NULL), |
82 is_this_(is_this), | 82 is_this_(is_this), |
83 is_assigned_(false), | 83 is_assigned_(false), |
84 interface_(interface), | 84 interface_(interface), |
85 variable_feedback_slot_(kInvalidFeedbackSlot) { | 85 variable_feedback_slot_(kInvalidFeedbackSlot) { |
86 } | 86 } |
87 | 87 |
88 | 88 |
89 void VariableProxy::BindTo(Variable* var) { | 89 void VariableProxy::BindTo(Variable* var) { |
90 ASSERT(var_ == NULL); // must be bound only once | 90 DCHECK(var_ == NULL); // must be bound only once |
91 ASSERT(var != NULL); // must bind | 91 DCHECK(var != NULL); // must bind |
92 ASSERT(!FLAG_harmony_modules || interface_->IsUnified(var->interface())); | 92 DCHECK(!FLAG_harmony_modules || interface_->IsUnified(var->interface())); |
93 ASSERT((is_this() && var->is_this()) || name_ == var->raw_name()); | 93 DCHECK((is_this() && var->is_this()) || name_ == var->raw_name()); |
94 // Ideally CONST-ness should match. However, this is very hard to achieve | 94 // Ideally CONST-ness should match. However, this is very hard to achieve |
95 // because we don't know the exact semantics of conflicting (const and | 95 // because we don't know the exact semantics of conflicting (const and |
96 // non-const) multiple variable declarations, const vars introduced via | 96 // non-const) multiple variable declarations, const vars introduced via |
97 // eval() etc. Const-ness and variable declarations are a complete mess | 97 // eval() etc. Const-ness and variable declarations are a complete mess |
98 // in JS. Sigh... | 98 // in JS. Sigh... |
99 var_ = var; | 99 var_ = var; |
100 var->set_is_used(); | 100 var->set_is_used(); |
101 } | 101 } |
102 | 102 |
103 | 103 |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 } | 395 } |
396 | 396 |
397 | 397 |
398 void MaterializedLiteral::BuildConstants(Isolate* isolate) { | 398 void MaterializedLiteral::BuildConstants(Isolate* isolate) { |
399 if (IsArrayLiteral()) { | 399 if (IsArrayLiteral()) { |
400 return AsArrayLiteral()->BuildConstantElements(isolate); | 400 return AsArrayLiteral()->BuildConstantElements(isolate); |
401 } | 401 } |
402 if (IsObjectLiteral()) { | 402 if (IsObjectLiteral()) { |
403 return AsObjectLiteral()->BuildConstantProperties(isolate); | 403 return AsObjectLiteral()->BuildConstantProperties(isolate); |
404 } | 404 } |
405 ASSERT(IsRegExpLiteral()); | 405 DCHECK(IsRegExpLiteral()); |
406 ASSERT(depth() >= 1); // Depth should be initialized. | 406 DCHECK(depth() >= 1); // Depth should be initialized. |
407 } | 407 } |
408 | 408 |
409 | 409 |
410 void TargetCollector::AddTarget(Label* target, Zone* zone) { | 410 void TargetCollector::AddTarget(Label* target, Zone* zone) { |
411 // Add the label to the collector, but discard duplicates. | 411 // Add the label to the collector, but discard duplicates. |
412 int length = targets_.length(); | 412 int length = targets_.length(); |
413 for (int i = 0; i < length; i++) { | 413 for (int i = 0; i < length; i++) { |
414 if (targets_[i] == target) return; | 414 if (targets_[i] == target) return; |
415 } | 415 } |
416 targets_.Add(target, zone); | 416 targets_.Add(target, zone); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 | 586 |
587 Property* property = expression()->AsProperty(); | 587 Property* property = expression()->AsProperty(); |
588 return property != NULL ? PROPERTY_CALL : OTHER_CALL; | 588 return property != NULL ? PROPERTY_CALL : OTHER_CALL; |
589 } | 589 } |
590 | 590 |
591 | 591 |
592 bool Call::ComputeGlobalTarget(Handle<GlobalObject> global, | 592 bool Call::ComputeGlobalTarget(Handle<GlobalObject> global, |
593 LookupResult* lookup) { | 593 LookupResult* lookup) { |
594 target_ = Handle<JSFunction>::null(); | 594 target_ = Handle<JSFunction>::null(); |
595 cell_ = Handle<Cell>::null(); | 595 cell_ = Handle<Cell>::null(); |
596 ASSERT(lookup->IsFound() && | 596 DCHECK(lookup->IsFound() && |
597 lookup->type() == NORMAL && | 597 lookup->type() == NORMAL && |
598 lookup->holder() == *global); | 598 lookup->holder() == *global); |
599 cell_ = Handle<Cell>(global->GetPropertyCell(lookup)); | 599 cell_ = Handle<Cell>(global->GetPropertyCell(lookup)); |
600 if (cell_->value()->IsJSFunction()) { | 600 if (cell_->value()->IsJSFunction()) { |
601 Handle<JSFunction> candidate(JSFunction::cast(cell_->value())); | 601 Handle<JSFunction> candidate(JSFunction::cast(cell_->value())); |
602 // If the function is in new space we assume it's more likely to | 602 // If the function is in new space we assume it's more likely to |
603 // change and thus prefer the general IC code. | 603 // change and thus prefer the general IC code. |
604 if (!lookup->isolate()->heap()->InNewSpace(*candidate)) { | 604 if (!lookup->isolate()->heap()->InNewSpace(*candidate)) { |
605 target_ = candidate; | 605 target_ = candidate; |
606 return true; | 606 return true; |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 | 953 |
954 OStream& RegExpTree::Print(OStream& os, Zone* zone) { // NOLINT | 954 OStream& RegExpTree::Print(OStream& os, Zone* zone) { // NOLINT |
955 RegExpUnparser unparser(os, zone); | 955 RegExpUnparser unparser(os, zone); |
956 Accept(&unparser, NULL); | 956 Accept(&unparser, NULL); |
957 return os; | 957 return os; |
958 } | 958 } |
959 | 959 |
960 | 960 |
961 RegExpDisjunction::RegExpDisjunction(ZoneList<RegExpTree*>* alternatives) | 961 RegExpDisjunction::RegExpDisjunction(ZoneList<RegExpTree*>* alternatives) |
962 : alternatives_(alternatives) { | 962 : alternatives_(alternatives) { |
963 ASSERT(alternatives->length() > 1); | 963 DCHECK(alternatives->length() > 1); |
964 RegExpTree* first_alternative = alternatives->at(0); | 964 RegExpTree* first_alternative = alternatives->at(0); |
965 min_match_ = first_alternative->min_match(); | 965 min_match_ = first_alternative->min_match(); |
966 max_match_ = first_alternative->max_match(); | 966 max_match_ = first_alternative->max_match(); |
967 for (int i = 1; i < alternatives->length(); i++) { | 967 for (int i = 1; i < alternatives->length(); i++) { |
968 RegExpTree* alternative = alternatives->at(i); | 968 RegExpTree* alternative = alternatives->at(i); |
969 min_match_ = Min(min_match_, alternative->min_match()); | 969 min_match_ = Min(min_match_, alternative->min_match()); |
970 max_match_ = Max(max_match_, alternative->max_match()); | 970 max_match_ = Max(max_match_, alternative->max_match()); |
971 } | 971 } |
972 } | 972 } |
973 | 973 |
974 | 974 |
975 static int IncreaseBy(int previous, int increase) { | 975 static int IncreaseBy(int previous, int increase) { |
976 if (RegExpTree::kInfinity - previous < increase) { | 976 if (RegExpTree::kInfinity - previous < increase) { |
977 return RegExpTree::kInfinity; | 977 return RegExpTree::kInfinity; |
978 } else { | 978 } else { |
979 return previous + increase; | 979 return previous + increase; |
980 } | 980 } |
981 } | 981 } |
982 | 982 |
983 RegExpAlternative::RegExpAlternative(ZoneList<RegExpTree*>* nodes) | 983 RegExpAlternative::RegExpAlternative(ZoneList<RegExpTree*>* nodes) |
984 : nodes_(nodes) { | 984 : nodes_(nodes) { |
985 ASSERT(nodes->length() > 1); | 985 DCHECK(nodes->length() > 1); |
986 min_match_ = 0; | 986 min_match_ = 0; |
987 max_match_ = 0; | 987 max_match_ = 0; |
988 for (int i = 0; i < nodes->length(); i++) { | 988 for (int i = 0; i < nodes->length(); i++) { |
989 RegExpTree* node = nodes->at(i); | 989 RegExpTree* node = nodes->at(i); |
990 int node_min_match = node->min_match(); | 990 int node_min_match = node->min_match(); |
991 min_match_ = IncreaseBy(min_match_, node_min_match); | 991 min_match_ = IncreaseBy(min_match_, node_min_match); |
992 int node_max_match = node->max_match(); | 992 int node_max_match = node->max_match(); |
993 max_match_ = IncreaseBy(max_match_, node_max_match); | 993 max_match_ = IncreaseBy(max_match_, node_max_match); |
994 } | 994 } |
995 } | 995 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 } | 1120 } |
1121 | 1121 |
1122 #undef REGULAR_NODE | 1122 #undef REGULAR_NODE |
1123 #undef DONT_OPTIMIZE_NODE | 1123 #undef DONT_OPTIMIZE_NODE |
1124 #undef DONT_SELFOPTIMIZE_NODE | 1124 #undef DONT_SELFOPTIMIZE_NODE |
1125 #undef DONT_CACHE_NODE | 1125 #undef DONT_CACHE_NODE |
1126 | 1126 |
1127 | 1127 |
1128 Handle<String> Literal::ToString() { | 1128 Handle<String> Literal::ToString() { |
1129 if (value_->IsString()) return value_->AsString()->string(); | 1129 if (value_->IsString()) return value_->AsString()->string(); |
1130 ASSERT(value_->IsNumber()); | 1130 DCHECK(value_->IsNumber()); |
1131 char arr[100]; | 1131 char arr[100]; |
1132 Vector<char> buffer(arr, ARRAY_SIZE(arr)); | 1132 Vector<char> buffer(arr, ARRAY_SIZE(arr)); |
1133 const char* str; | 1133 const char* str; |
1134 if (value()->IsSmi()) { | 1134 if (value()->IsSmi()) { |
1135 // Optimization only, the heap number case would subsume this. | 1135 // Optimization only, the heap number case would subsume this. |
1136 SNPrintF(buffer, "%d", Smi::cast(*value())->value()); | 1136 SNPrintF(buffer, "%d", Smi::cast(*value())->value()); |
1137 str = arr; | 1137 str = arr; |
1138 } else { | 1138 } else { |
1139 str = DoubleToCString(value()->Number(), buffer); | 1139 str = DoubleToCString(value()->Number(), buffer); |
1140 } | 1140 } |
1141 return isolate_->factory()->NewStringFromAsciiChecked(str); | 1141 return isolate_->factory()->NewStringFromAsciiChecked(str); |
1142 } | 1142 } |
1143 | 1143 |
1144 | 1144 |
1145 } } // namespace v8::internal | 1145 } } // namespace v8::internal |
OLD | NEW |