| 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 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 #include "ast.h" | 30 #include "ast.h" |
| 31 #include "jump-target-inl.h" | 31 #include "jump-target-inl.h" |
| 32 #include "parser.h" | 32 #include "parser.h" |
| 33 #include "scopes.h" | 33 #include "scopes.h" |
| 34 #include "string-stream.h" | 34 #include "string-stream.h" |
| 35 | 35 |
| 36 namespace v8 { | 36 namespace v8 { |
| 37 namespace internal { | 37 namespace internal { |
| 38 | 38 |
| 39 unsigned AstNode::current_id_ = 0; | 39 AstSentinels::AstSentinels() |
| 40 unsigned AstNode::count_ = 0; | 40 : this_proxy_(true), |
| 41 VariableProxySentinel VariableProxySentinel::this_proxy_(true); | 41 identifier_proxy_(false), |
| 42 VariableProxySentinel VariableProxySentinel::identifier_proxy_(false); | 42 valid_left_hand_side_sentinel_(), |
| 43 ValidLeftHandSideSentinel ValidLeftHandSideSentinel::instance_; | 43 this_property_(&this_proxy_, NULL, 0), |
| 44 Property Property::this_property_(VariableProxySentinel::this_proxy(), NULL, 0); | 44 call_sentinel_(NULL, NULL, 0) { |
| 45 Call Call::sentinel_(NULL, NULL, 0); | 45 } |
| 46 | 46 |
| 47 | 47 |
| 48 // ---------------------------------------------------------------------------- | 48 // ---------------------------------------------------------------------------- |
| 49 // All the Accept member functions for each syntax tree node type. | 49 // All the Accept member functions for each syntax tree node type. |
| 50 | 50 |
| 51 void Slot::Accept(AstVisitor* v) { v->VisitSlot(this); } | 51 void Slot::Accept(AstVisitor* v) { v->VisitSlot(this); } |
| 52 | 52 |
| 53 #define DECL_ACCEPT(type) \ | 53 #define DECL_ACCEPT(type) \ |
| 54 void type::Accept(AstVisitor* v) { v->Visit##type(this); } | 54 void type::Accept(AstVisitor* v) { v->Visit##type(this); } |
| 55 AST_NODE_LIST(DECL_ACCEPT) | 55 AST_NODE_LIST(DECL_ACCEPT) |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 bool FunctionLiteral::AllowsLazyCompilation() { | 163 bool FunctionLiteral::AllowsLazyCompilation() { |
| 164 return scope()->AllowsLazyCompilation(); | 164 return scope()->AllowsLazyCompilation(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 | 167 |
| 168 ObjectLiteral::Property::Property(Literal* key, Expression* value) { | 168 ObjectLiteral::Property::Property(Literal* key, Expression* value) { |
| 169 emit_store_ = true; | 169 emit_store_ = true; |
| 170 key_ = key; | 170 key_ = key; |
| 171 value_ = value; | 171 value_ = value; |
| 172 Object* k = *key->handle(); | 172 Object* k = *key->handle(); |
| 173 if (k->IsSymbol() && Heap::Proto_symbol()->Equals(String::cast(k))) { | 173 if (k->IsSymbol() && HEAP->Proto_symbol()->Equals(String::cast(k))) { |
| 174 kind_ = PROTOTYPE; | 174 kind_ = PROTOTYPE; |
| 175 } else if (value_->AsMaterializedLiteral() != NULL) { | 175 } else if (value_->AsMaterializedLiteral() != NULL) { |
| 176 kind_ = MATERIALIZED_LITERAL; | 176 kind_ = MATERIALIZED_LITERAL; |
| 177 } else if (value_->AsLiteral() != NULL) { | 177 } else if (value_->AsLiteral() != NULL) { |
| 178 kind_ = CONSTANT; | 178 kind_ = CONSTANT; |
| 179 } else { | 179 } else { |
| 180 kind_ = COMPUTED; | 180 kind_ = COMPUTED; |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 Literal* literal = property->key(); | 242 Literal* literal = property->key(); |
| 243 Handle<Object> handle = literal->handle(); | 243 Handle<Object> handle = literal->handle(); |
| 244 | 244 |
| 245 if (handle->IsNull()) { | 245 if (handle->IsNull()) { |
| 246 continue; | 246 continue; |
| 247 } | 247 } |
| 248 | 248 |
| 249 uint32_t hash; | 249 uint32_t hash; |
| 250 HashMap* table; | 250 HashMap* table; |
| 251 void* key; | 251 void* key; |
| 252 Factory* factory = Isolate::Current()->factory(); |
| 252 if (handle->IsSymbol()) { | 253 if (handle->IsSymbol()) { |
| 253 Handle<String> name(String::cast(*handle)); | 254 Handle<String> name(String::cast(*handle)); |
| 254 if (name->AsArrayIndex(&hash)) { | 255 if (name->AsArrayIndex(&hash)) { |
| 255 Handle<Object> key_handle = Factory::NewNumberFromUint(hash); | 256 Handle<Object> key_handle = factory->NewNumberFromUint(hash); |
| 256 key = key_handle.location(); | 257 key = key_handle.location(); |
| 257 table = &elements; | 258 table = &elements; |
| 258 } else { | 259 } else { |
| 259 key = name.location(); | 260 key = name.location(); |
| 260 hash = name->Hash(); | 261 hash = name->Hash(); |
| 261 table = &properties; | 262 table = &properties; |
| 262 } | 263 } |
| 263 } else if (handle->ToArrayIndex(&hash)) { | 264 } else if (handle->ToArrayIndex(&hash)) { |
| 264 key = handle.location(); | 265 key = handle.location(); |
| 265 table = &elements; | 266 table = &elements; |
| 266 } else { | 267 } else { |
| 267 ASSERT(handle->IsNumber()); | 268 ASSERT(handle->IsNumber()); |
| 268 double num = handle->Number(); | 269 double num = handle->Number(); |
| 269 char arr[100]; | 270 char arr[100]; |
| 270 Vector<char> buffer(arr, ARRAY_SIZE(arr)); | 271 Vector<char> buffer(arr, ARRAY_SIZE(arr)); |
| 271 const char* str = DoubleToCString(num, buffer); | 272 const char* str = DoubleToCString(num, buffer); |
| 272 Handle<String> name = Factory::NewStringFromAscii(CStrVector(str)); | 273 Handle<String> name = factory->NewStringFromAscii(CStrVector(str)); |
| 273 key = name.location(); | 274 key = name.location(); |
| 274 hash = name->Hash(); | 275 hash = name->Hash(); |
| 275 table = &properties; | 276 table = &properties; |
| 276 } | 277 } |
| 277 // If the key of a computed property is in the table, do not emit | 278 // If the key of a computed property is in the table, do not emit |
| 278 // a store for the property later. | 279 // a store for the property later. |
| 279 if (property->kind() == ObjectLiteral::Property::COMPUTED) { | 280 if (property->kind() == ObjectLiteral::Property::COMPUTED) { |
| 280 if (table->Lookup(key, hash, false) != NULL) { | 281 if (table->Lookup(key, hash, false) != NULL) { |
| 281 property->set_emit_store(false); | 282 property->set_emit_store(false); |
| 282 } | 283 } |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 LookupResult lookup; | 628 LookupResult lookup; |
| 628 global->Lookup(*name, &lookup); | 629 global->Lookup(*name, &lookup); |
| 629 if (lookup.IsProperty() && | 630 if (lookup.IsProperty() && |
| 630 lookup.type() == NORMAL && | 631 lookup.type() == NORMAL && |
| 631 lookup.holder() == *global) { | 632 lookup.holder() == *global) { |
| 632 cell_ = Handle<JSGlobalPropertyCell>(global->GetPropertyCell(&lookup)); | 633 cell_ = Handle<JSGlobalPropertyCell>(global->GetPropertyCell(&lookup)); |
| 633 if (cell_->value()->IsJSFunction()) { | 634 if (cell_->value()->IsJSFunction()) { |
| 634 Handle<JSFunction> candidate(JSFunction::cast(cell_->value())); | 635 Handle<JSFunction> candidate(JSFunction::cast(cell_->value())); |
| 635 // If the function is in new space we assume it's more likely to | 636 // If the function is in new space we assume it's more likely to |
| 636 // change and thus prefer the general IC code. | 637 // change and thus prefer the general IC code. |
| 637 if (!Heap::InNewSpace(*candidate) && | 638 if (!HEAP->InNewSpace(*candidate) && |
| 638 CanCallWithoutIC(candidate, arguments()->length())) { | 639 CanCallWithoutIC(candidate, arguments()->length())) { |
| 639 target_ = candidate; | 640 target_ = candidate; |
| 640 return true; | 641 return true; |
| 641 } | 642 } |
| 642 } | 643 } |
| 643 } | 644 } |
| 644 return false; | 645 return false; |
| 645 } | 646 } |
| 646 | 647 |
| 647 | 648 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 ASSERT(compare_type_ == NONE); | 693 ASSERT(compare_type_ == NONE); |
| 693 } | 694 } |
| 694 } | 695 } |
| 695 | 696 |
| 696 | 697 |
| 697 // ---------------------------------------------------------------------------- | 698 // ---------------------------------------------------------------------------- |
| 698 // Implementation of AstVisitor | 699 // Implementation of AstVisitor |
| 699 | 700 |
| 700 bool AstVisitor::CheckStackOverflow() { | 701 bool AstVisitor::CheckStackOverflow() { |
| 701 if (stack_overflow_) return true; | 702 if (stack_overflow_) return true; |
| 702 StackLimitCheck check; | 703 StackLimitCheck check(Isolate::Current()); |
| 703 if (!check.HasOverflowed()) return false; | 704 if (!check.HasOverflowed()) return false; |
| 704 return (stack_overflow_ = true); | 705 return (stack_overflow_ = true); |
| 705 } | 706 } |
| 706 | 707 |
| 707 | 708 |
| 708 void AstVisitor::VisitDeclarations(ZoneList<Declaration*>* declarations) { | 709 void AstVisitor::VisitDeclarations(ZoneList<Declaration*>* declarations) { |
| 709 for (int i = 0; i < declarations->length(); i++) { | 710 for (int i = 0; i < declarations->length(); i++) { |
| 710 Visit(declarations->at(i)); | 711 Visit(declarations->at(i)); |
| 711 } | 712 } |
| 712 } | 713 } |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 ZoneList<Statement*>* statements, | 1069 ZoneList<Statement*>* statements, |
| 1069 int pos) | 1070 int pos) |
| 1070 : label_(label), | 1071 : label_(label), |
| 1071 statements_(statements), | 1072 statements_(statements), |
| 1072 position_(pos), | 1073 position_(pos), |
| 1073 compare_type_(NONE), | 1074 compare_type_(NONE), |
| 1074 entry_id_(AstNode::GetNextId()) { | 1075 entry_id_(AstNode::GetNextId()) { |
| 1075 } | 1076 } |
| 1076 | 1077 |
| 1077 } } // namespace v8::internal | 1078 } } // namespace v8::internal |
| OLD | NEW |