OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 "factory.h" | 5 #include "factory.h" |
6 | 6 |
7 #include "isolate-inl.h" | 7 #include "isolate-inl.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 JSObject::SetLocalPropertyIgnoreAttributes(prototype, | 806 JSObject::SetLocalPropertyIgnoreAttributes(prototype, |
807 constructor_string(), | 807 constructor_string(), |
808 function, | 808 function, |
809 DONT_ENUM); | 809 DONT_ENUM); |
810 } | 810 } |
811 | 811 |
812 return prototype; | 812 return prototype; |
813 } | 813 } |
814 | 814 |
815 | 815 |
816 Handle<Map> Factory::CopyWithPreallocatedFieldDescriptors(Handle<Map> src) { | |
817 CALL_HEAP_FUNCTION( | |
818 isolate(), src->CopyWithPreallocatedFieldDescriptors(), Map); | |
819 } | |
820 | |
821 | |
822 Handle<Map> Factory::CopyMap(Handle<Map> src, | |
823 int extra_inobject_properties) { | |
824 Handle<Map> copy = CopyWithPreallocatedFieldDescriptors(src); | |
825 // Check that we do not overflow the instance size when adding the | |
826 // extra inobject properties. | |
827 int instance_size_delta = extra_inobject_properties * kPointerSize; | |
828 int max_instance_size_delta = | |
829 JSObject::kMaxInstanceSize - copy->instance_size(); | |
830 int max_extra_properties = max_instance_size_delta >> kPointerSizeLog2; | |
831 if (extra_inobject_properties > max_extra_properties) { | |
832 // If the instance size overflows, we allocate as many properties | |
833 // as we can as inobject properties. | |
834 instance_size_delta = max_instance_size_delta; | |
835 extra_inobject_properties = max_extra_properties; | |
836 } | |
837 // Adjust the map with the extra inobject properties. | |
838 int inobject_properties = | |
839 copy->inobject_properties() + extra_inobject_properties; | |
840 copy->set_inobject_properties(inobject_properties); | |
841 copy->set_unused_property_fields(inobject_properties); | |
842 copy->set_instance_size(copy->instance_size() + instance_size_delta); | |
843 copy->set_visitor_id(StaticVisitorBase::GetVisitorId(*copy)); | |
844 return copy; | |
845 } | |
846 | |
847 | |
848 Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) { | 816 Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) { |
849 CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedArray); | 817 CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedArray); |
850 } | 818 } |
851 | 819 |
852 | 820 |
853 Handle<FixedArray> Factory::CopyAndTenureFixedCOWArray( | 821 Handle<FixedArray> Factory::CopyAndTenureFixedCOWArray( |
854 Handle<FixedArray> array) { | 822 Handle<FixedArray> array) { |
855 ASSERT(isolate()->heap()->InNewSpace(*array)); | 823 ASSERT(isolate()->heap()->InNewSpace(*array)); |
856 CALL_HEAP_FUNCTION(isolate(), | 824 CALL_HEAP_FUNCTION(isolate(), |
857 isolate()->heap()->CopyAndTenureFixedCOWArray(*array), | 825 isolate()->heap()->CopyAndTenureFixedCOWArray(*array), |
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1904 // Allocate the new map cache for the native context. | 1872 // Allocate the new map cache for the native context. |
1905 Handle<MapCache> new_cache = NewMapCache(24); | 1873 Handle<MapCache> new_cache = NewMapCache(24); |
1906 context->set_map_cache(*new_cache); | 1874 context->set_map_cache(*new_cache); |
1907 } | 1875 } |
1908 // Check to see whether there is a matching element in the cache. | 1876 // Check to see whether there is a matching element in the cache. |
1909 Handle<MapCache> cache = | 1877 Handle<MapCache> cache = |
1910 Handle<MapCache>(MapCache::cast(context->map_cache())); | 1878 Handle<MapCache>(MapCache::cast(context->map_cache())); |
1911 Handle<Object> result = Handle<Object>(cache->Lookup(*keys), isolate()); | 1879 Handle<Object> result = Handle<Object>(cache->Lookup(*keys), isolate()); |
1912 if (result->IsMap()) return Handle<Map>::cast(result); | 1880 if (result->IsMap()) return Handle<Map>::cast(result); |
1913 // Create a new map and add it to the cache. | 1881 // Create a new map and add it to the cache. |
1914 Handle<Map> map = | 1882 Handle<Map> map = Map::Create( |
1915 CopyMap(Handle<Map>(context->object_function()->initial_map()), | 1883 handle(context->object_function()), keys->length()); |
1916 keys->length()); | |
1917 AddToMapCache(context, keys, map); | 1884 AddToMapCache(context, keys, map); |
1918 return Handle<Map>(map); | 1885 return map; |
1919 } | 1886 } |
1920 | 1887 |
1921 | 1888 |
1922 void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp, | 1889 void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp, |
1923 JSRegExp::Type type, | 1890 JSRegExp::Type type, |
1924 Handle<String> source, | 1891 Handle<String> source, |
1925 JSRegExp::Flags flags, | 1892 JSRegExp::Flags flags, |
1926 Handle<Object> data) { | 1893 Handle<Object> data) { |
1927 Handle<FixedArray> store = NewFixedArray(JSRegExp::kAtomDataSize); | 1894 Handle<FixedArray> store = NewFixedArray(JSRegExp::kAtomDataSize); |
1928 | 1895 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1979 if (name->Equals(h->infinity_string())) return infinity_value(); | 1946 if (name->Equals(h->infinity_string())) return infinity_value(); |
1980 return Handle<Object>::null(); | 1947 return Handle<Object>::null(); |
1981 } | 1948 } |
1982 | 1949 |
1983 | 1950 |
1984 Handle<Object> Factory::ToBoolean(bool value) { | 1951 Handle<Object> Factory::ToBoolean(bool value) { |
1985 return value ? true_value() : false_value(); | 1952 return value ? true_value() : false_value(); |
1986 } | 1953 } |
1987 | 1954 |
1988 } } // namespace v8::internal | 1955 } } // namespace v8::internal |
OLD | NEW |