OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/allocation-site-scopes.h" | 8 #include "src/allocation-site-scopes.h" |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
(...skipping 1789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1800 TransitionFlag flag) { | 1800 TransitionFlag flag) { |
1801 ASSERT(DescriptorArray::kNotFound == | 1801 ASSERT(DescriptorArray::kNotFound == |
1802 map->instance_descriptors()->Search( | 1802 map->instance_descriptors()->Search( |
1803 *name, map->NumberOfOwnDescriptors())); | 1803 *name, map->NumberOfOwnDescriptors())); |
1804 | 1804 |
1805 // Ensure the descriptor array does not get too big. | 1805 // Ensure the descriptor array does not get too big. |
1806 if (map->NumberOfOwnDescriptors() >= kMaxNumberOfDescriptors) { | 1806 if (map->NumberOfOwnDescriptors() >= kMaxNumberOfDescriptors) { |
1807 return MaybeHandle<Map>(); | 1807 return MaybeHandle<Map>(); |
1808 } | 1808 } |
1809 | 1809 |
1810 // Normalize the object if the name is an actual name (not the | |
1811 // hidden strings) and is not a real identifier. | |
1812 // Normalize the object if it will have too many fast properties. | |
1813 Isolate* isolate = map->GetIsolate(); | 1810 Isolate* isolate = map->GetIsolate(); |
1814 if (!name->IsCacheable(isolate)) return MaybeHandle<Map>(); | |
1815 | 1811 |
1816 // Compute the new index for new field. | 1812 // Compute the new index for new field. |
1817 int index = map->NextFreePropertyIndex(); | 1813 int index = map->NextFreePropertyIndex(); |
1818 | 1814 |
1819 if (map->instance_type() == JS_CONTEXT_EXTENSION_OBJECT_TYPE) { | 1815 if (map->instance_type() == JS_CONTEXT_EXTENSION_OBJECT_TYPE) { |
1820 representation = Representation::Tagged(); | 1816 representation = Representation::Tagged(); |
1821 type = HeapType::Any(isolate); | 1817 type = HeapType::Any(isolate); |
1822 } | 1818 } |
1823 | 1819 |
1824 FieldDescriptor new_field_desc(name, index, type, attributes, representation); | 1820 FieldDescriptor new_field_desc(name, index, type, attributes, representation); |
(...skipping 6631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8456 if (other->IsEmpty()) return false; | 8452 if (other->IsEmpty()) return false; |
8457 if (length() != other->length()) return false; | 8453 if (length() != other->length()) return false; |
8458 for (int i = 0; i < length(); ++i) { | 8454 for (int i = 0; i < length(); ++i) { |
8459 if (get(i) != other->get(i)) return false; | 8455 if (get(i) != other->get(i)) return false; |
8460 } | 8456 } |
8461 return true; | 8457 return true; |
8462 } | 8458 } |
8463 #endif | 8459 #endif |
8464 | 8460 |
8465 | 8461 |
8466 static bool IsIdentifier(UnicodeCache* cache, Name* name) { | |
8467 // Checks whether the buffer contains an identifier (no escape). | |
8468 if (!name->IsString()) return false; | |
8469 String* string = String::cast(name); | |
8470 if (string->length() == 0) return true; | |
8471 ConsStringIteratorOp op; | |
8472 StringCharacterStream stream(string, &op); | |
8473 if (!cache->IsIdentifierStart(stream.GetNext())) { | |
8474 return false; | |
8475 } | |
8476 while (stream.HasMore()) { | |
8477 if (!cache->IsIdentifierPart(stream.GetNext())) { | |
8478 return false; | |
8479 } | |
8480 } | |
8481 return true; | |
8482 } | |
8483 | |
8484 | |
8485 bool Name::IsCacheable(Isolate* isolate) { | |
8486 return IsSymbol() || IsIdentifier(isolate->unicode_cache(), this); | |
8487 } | |
8488 | |
8489 | |
8490 bool String::LooksValid() { | 8462 bool String::LooksValid() { |
8491 if (!GetIsolate()->heap()->Contains(this)) return false; | 8463 if (!GetIsolate()->heap()->Contains(this)) return false; |
8492 return true; | 8464 return true; |
8493 } | 8465 } |
8494 | 8466 |
8495 | 8467 |
8496 String::FlatContent String::GetFlatContent() { | 8468 String::FlatContent String::GetFlatContent() { |
8497 ASSERT(!AllowHeapAllocation::IsAllowed()); | 8469 ASSERT(!AllowHeapAllocation::IsAllowed()); |
8498 int length = this->length(); | 8470 int length = this->length(); |
8499 StringShape shape(this); | 8471 StringShape shape(this); |
(...skipping 8594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17094 #define ERROR_MESSAGES_TEXTS(C, T) T, | 17066 #define ERROR_MESSAGES_TEXTS(C, T) T, |
17095 static const char* error_messages_[] = { | 17067 static const char* error_messages_[] = { |
17096 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 17068 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
17097 }; | 17069 }; |
17098 #undef ERROR_MESSAGES_TEXTS | 17070 #undef ERROR_MESSAGES_TEXTS |
17099 return error_messages_[reason]; | 17071 return error_messages_[reason]; |
17100 } | 17072 } |
17101 | 17073 |
17102 | 17074 |
17103 } } // namespace v8::internal | 17075 } } // namespace v8::internal |
OLD | NEW |