OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 1891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1902 set_properties(values); | 1902 set_properties(values); |
1903 } | 1903 } |
1904 | 1904 |
1905 set_map(new_map); | 1905 set_map(new_map); |
1906 | 1906 |
1907 FastPropertyAtPut(field_index, storage); | 1907 FastPropertyAtPut(field_index, storage); |
1908 return value; | 1908 return value; |
1909 } | 1909 } |
1910 | 1910 |
1911 | 1911 |
1912 static bool IsIdentifier(UnicodeCache* cache, Name* name) { | |
1913 // Checks whether the buffer contains an identifier (no escape). | |
1914 if (!name->IsString()) return false; | |
1915 String* string = String::cast(name); | |
1916 if (string->length() == 0) return false; | |
1917 ConsStringIteratorOp op; | |
1918 StringCharacterStream stream(string, &op); | |
1919 if (!cache->IsIdentifierStart(stream.GetNext())) { | |
1920 return false; | |
1921 } | |
1922 while (stream.HasMore()) { | |
1923 if (!cache->IsIdentifierPart(stream.GetNext())) { | |
1924 return false; | |
1925 } | |
1926 } | |
1927 return true; | |
1928 } | |
1929 | |
1930 | |
1931 MaybeObject* JSObject::AddFastProperty(Name* name, | 1912 MaybeObject* JSObject::AddFastProperty(Name* name, |
1932 Object* value, | 1913 Object* value, |
1933 PropertyAttributes attributes, | 1914 PropertyAttributes attributes, |
1934 StoreFromKeyed store_mode, | 1915 StoreFromKeyed store_mode, |
1935 ValueType value_type, | 1916 ValueType value_type, |
1936 TransitionFlag flag) { | 1917 TransitionFlag flag) { |
1937 ASSERT(!IsJSGlobalProxy()); | 1918 ASSERT(!IsJSGlobalProxy()); |
1938 ASSERT(DescriptorArray::kNotFound == | 1919 ASSERT(DescriptorArray::kNotFound == |
1939 map()->instance_descriptors()->Search( | 1920 map()->instance_descriptors()->Search( |
1940 name, map()->NumberOfOwnDescriptors())); | 1921 name, map()->NumberOfOwnDescriptors())); |
1941 | 1922 |
1942 // Normalize the object if the name is an actual name (not the | 1923 // Normalize the object if the name is an actual name (not the |
1943 // hidden strings) and is not a real identifier. | 1924 // hidden strings) and is not a real identifier. |
1944 // Normalize the object if it will have too many fast properties. | 1925 // Normalize the object if it will have too many fast properties. |
1945 Isolate* isolate = GetHeap()->isolate(); | 1926 Isolate* isolate = GetHeap()->isolate(); |
1946 if ((!name->IsSymbol() && | 1927 if (!name->IsCacheable(isolate) || TooManyFastProperties(store_mode)) { |
1947 !IsIdentifier(isolate->unicode_cache(), name) && | |
1948 name != isolate->heap()->hidden_string()) || | |
1949 TooManyFastProperties(store_mode)) { | |
1950 MaybeObject* maybe_failure = | 1928 MaybeObject* maybe_failure = |
1951 NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0); | 1929 NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0); |
1952 if (maybe_failure->IsFailure()) return maybe_failure; | 1930 if (maybe_failure->IsFailure()) return maybe_failure; |
1953 return AddSlowProperty(name, value, attributes); | 1931 return AddSlowProperty(name, value, attributes); |
1954 } | 1932 } |
1955 | 1933 |
1956 // Compute the new index for new field. | 1934 // Compute the new index for new field. |
1957 int index = map()->NextFreePropertyIndex(); | 1935 int index = map()->NextFreePropertyIndex(); |
1958 | 1936 |
1959 // Allocate new instance descriptors with (name, index) added | 1937 // Allocate new instance descriptors with (name, index) added |
(...skipping 5988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7948 if (other->IsEmpty()) return false; | 7926 if (other->IsEmpty()) return false; |
7949 if (length() != other->length()) return false; | 7927 if (length() != other->length()) return false; |
7950 for (int i = 0; i < length(); ++i) { | 7928 for (int i = 0; i < length(); ++i) { |
7951 if (get(i) != other->get(i)) return false; | 7929 if (get(i) != other->get(i)) return false; |
7952 } | 7930 } |
7953 return true; | 7931 return true; |
7954 } | 7932 } |
7955 #endif | 7933 #endif |
7956 | 7934 |
7957 | 7935 |
| 7936 static bool IsIdentifier(UnicodeCache* cache, Name* name) { |
| 7937 // Checks whether the buffer contains an identifier (no escape). |
| 7938 if (!name->IsString()) return false; |
| 7939 String* string = String::cast(name); |
| 7940 if (string->length() == 0) return false; |
| 7941 ConsStringIteratorOp op; |
| 7942 StringCharacterStream stream(string, &op); |
| 7943 if (!cache->IsIdentifierStart(stream.GetNext())) { |
| 7944 return false; |
| 7945 } |
| 7946 while (stream.HasMore()) { |
| 7947 if (!cache->IsIdentifierPart(stream.GetNext())) { |
| 7948 return false; |
| 7949 } |
| 7950 } |
| 7951 return true; |
| 7952 } |
| 7953 |
| 7954 |
| 7955 bool Name::IsCacheable(Isolate* isolate) { |
| 7956 return IsSymbol() || |
| 7957 IsIdentifier(isolate->unicode_cache(), this) || |
| 7958 this == isolate->heap()->hidden_string(); |
| 7959 } |
| 7960 |
| 7961 |
7958 bool String::LooksValid() { | 7962 bool String::LooksValid() { |
7959 if (!Isolate::Current()->heap()->Contains(this)) return false; | 7963 if (!Isolate::Current()->heap()->Contains(this)) return false; |
7960 return true; | 7964 return true; |
7961 } | 7965 } |
7962 | 7966 |
7963 | 7967 |
7964 String::FlatContent String::GetFlatContent() { | 7968 String::FlatContent String::GetFlatContent() { |
7965 ASSERT(!AllowHeapAllocation::IsAllowed()); | 7969 ASSERT(!AllowHeapAllocation::IsAllowed()); |
7966 int length = this->length(); | 7970 int length = this->length(); |
7967 StringShape shape(this); | 7971 StringShape shape(this); |
(...skipping 8000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15968 #define ERROR_MESSAGES_TEXTS(C, T) T, | 15972 #define ERROR_MESSAGES_TEXTS(C, T) T, |
15969 static const char* error_messages_[] = { | 15973 static const char* error_messages_[] = { |
15970 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 15974 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
15971 }; | 15975 }; |
15972 #undef ERROR_MESSAGES_TEXTS | 15976 #undef ERROR_MESSAGES_TEXTS |
15973 return error_messages_[reason]; | 15977 return error_messages_[reason]; |
15974 } | 15978 } |
15975 | 15979 |
15976 | 15980 |
15977 } } // namespace v8::internal | 15981 } } // namespace v8::internal |
OLD | NEW |