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 "src/factory.h" | 5 #include "src/factory.h" |
6 | 6 |
7 #include "src/allocation-site-scopes.h" | 7 #include "src/allocation-site-scopes.h" |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
9 #include "src/conversions.h" | 9 #include "src/conversions.h" |
10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 Handle<FixedDoubleArray> double_array = | 109 Handle<FixedDoubleArray> double_array = |
110 Handle<FixedDoubleArray>::cast(array); | 110 Handle<FixedDoubleArray>::cast(array); |
111 for (int i = 0; i < size; ++i) { | 111 for (int i = 0; i < size; ++i) { |
112 double_array->set_the_hole(i); | 112 double_array->set_the_hole(i); |
113 } | 113 } |
114 } | 114 } |
115 return array; | 115 return array; |
116 } | 116 } |
117 | 117 |
118 | 118 |
| 119 Handle<WeakFixedArray> Factory::NewWeakFixedArray(int size) { |
| 120 DCHECK(0 <= size); |
| 121 size += WeakFixedArray::kReservedFieldCount; |
| 122 CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateFixedArrayWithFiller( |
| 123 size, NOT_TENURED, Smi::FromInt(0)), |
| 124 WeakFixedArray); |
| 125 } |
| 126 |
| 127 |
119 Handle<ConstantPoolArray> Factory::NewConstantPoolArray( | 128 Handle<ConstantPoolArray> Factory::NewConstantPoolArray( |
120 const ConstantPoolArray::NumberOfEntries& small) { | 129 const ConstantPoolArray::NumberOfEntries& small) { |
121 DCHECK(small.total_count() > 0); | 130 DCHECK(small.total_count() > 0); |
122 CALL_HEAP_FUNCTION( | 131 CALL_HEAP_FUNCTION( |
123 isolate(), | 132 isolate(), |
124 isolate()->heap()->AllocateConstantPoolArray(small), | 133 isolate()->heap()->AllocateConstantPoolArray(small), |
125 ConstantPoolArray); | 134 ConstantPoolArray); |
126 } | 135 } |
127 | 136 |
128 | 137 |
(...skipping 1741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1870 return obj; | 1879 return obj; |
1871 } | 1880 } |
1872 | 1881 |
1873 | 1882 |
1874 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, | 1883 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, |
1875 Handle<Object> prototype) { | 1884 Handle<Object> prototype) { |
1876 // Allocate map. | 1885 // Allocate map. |
1877 // TODO(rossberg): Once we optimize proxies, think about a scheme to share | 1886 // TODO(rossberg): Once we optimize proxies, think about a scheme to share |
1878 // maps. Will probably depend on the identity of the handler object, too. | 1887 // maps. Will probably depend on the identity of the handler object, too. |
1879 Handle<Map> map = NewMap(JS_PROXY_TYPE, JSProxy::kSize); | 1888 Handle<Map> map = NewMap(JS_PROXY_TYPE, JSProxy::kSize); |
1880 map->set_prototype(*prototype); | 1889 map->SetPrototype(prototype); |
1881 | 1890 |
1882 // Allocate the proxy object. | 1891 // Allocate the proxy object. |
1883 Handle<JSProxy> result = New<JSProxy>(map, NEW_SPACE); | 1892 Handle<JSProxy> result = New<JSProxy>(map, NEW_SPACE); |
1884 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); | 1893 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); |
1885 result->set_handler(*handler); | 1894 result->set_handler(*handler); |
1886 result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER); | 1895 result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER); |
1887 return result; | 1896 return result; |
1888 } | 1897 } |
1889 | 1898 |
1890 | 1899 |
1891 Handle<JSProxy> Factory::NewJSFunctionProxy(Handle<Object> handler, | 1900 Handle<JSProxy> Factory::NewJSFunctionProxy(Handle<Object> handler, |
1892 Handle<Object> call_trap, | 1901 Handle<Object> call_trap, |
1893 Handle<Object> construct_trap, | 1902 Handle<Object> construct_trap, |
1894 Handle<Object> prototype) { | 1903 Handle<Object> prototype) { |
1895 // Allocate map. | 1904 // Allocate map. |
1896 // TODO(rossberg): Once we optimize proxies, think about a scheme to share | 1905 // TODO(rossberg): Once we optimize proxies, think about a scheme to share |
1897 // maps. Will probably depend on the identity of the handler object, too. | 1906 // maps. Will probably depend on the identity of the handler object, too. |
1898 Handle<Map> map = NewMap(JS_FUNCTION_PROXY_TYPE, JSFunctionProxy::kSize); | 1907 Handle<Map> map = NewMap(JS_FUNCTION_PROXY_TYPE, JSFunctionProxy::kSize); |
1899 map->set_prototype(*prototype); | 1908 map->SetPrototype(prototype); |
1900 | 1909 |
1901 // Allocate the proxy object. | 1910 // Allocate the proxy object. |
1902 Handle<JSFunctionProxy> result = New<JSFunctionProxy>(map, NEW_SPACE); | 1911 Handle<JSFunctionProxy> result = New<JSFunctionProxy>(map, NEW_SPACE); |
1903 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); | 1912 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); |
1904 result->set_handler(*handler); | 1913 result->set_handler(*handler); |
1905 result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER); | 1914 result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER); |
1906 result->set_call_trap(*call_trap); | 1915 result->set_call_trap(*call_trap); |
1907 result->set_construct_trap(*construct_trap); | 1916 result->set_construct_trap(*construct_trap); |
1908 return result; | 1917 return result; |
1909 } | 1918 } |
1910 | 1919 |
1911 | 1920 |
1912 void Factory::ReinitializeJSProxy(Handle<JSProxy> proxy, InstanceType type, | 1921 void Factory::ReinitializeJSProxy(Handle<JSProxy> proxy, InstanceType type, |
1913 int size) { | 1922 int size) { |
1914 DCHECK(type == JS_OBJECT_TYPE || type == JS_FUNCTION_TYPE); | 1923 DCHECK(type == JS_OBJECT_TYPE || type == JS_FUNCTION_TYPE); |
1915 | 1924 |
1916 // Allocate fresh map. | 1925 // Allocate fresh map. |
1917 // TODO(rossberg): Once we optimize proxies, cache these maps. | 1926 // TODO(rossberg): Once we optimize proxies, cache these maps. |
1918 Handle<Map> map = NewMap(type, size); | 1927 Handle<Map> map = NewMap(type, size); |
1919 | 1928 |
1920 // Check that the receiver has at least the size of the fresh object. | 1929 // Check that the receiver has at least the size of the fresh object. |
1921 int size_difference = proxy->map()->instance_size() - map->instance_size(); | 1930 int size_difference = proxy->map()->instance_size() - map->instance_size(); |
1922 DCHECK(size_difference >= 0); | 1931 DCHECK(size_difference >= 0); |
1923 | 1932 |
1924 map->set_prototype(proxy->map()->prototype()); | 1933 map->SetPrototype(handle(proxy->map()->prototype(), proxy->GetIsolate())); |
1925 | 1934 |
1926 // Allocate the backing storage for the properties. | 1935 // Allocate the backing storage for the properties. |
1927 int prop_size = map->InitialPropertiesLength(); | 1936 int prop_size = map->InitialPropertiesLength(); |
1928 Handle<FixedArray> properties = NewFixedArray(prop_size, TENURED); | 1937 Handle<FixedArray> properties = NewFixedArray(prop_size, TENURED); |
1929 | 1938 |
1930 Heap* heap = isolate()->heap(); | 1939 Heap* heap = isolate()->heap(); |
1931 MaybeHandle<SharedFunctionInfo> shared; | 1940 MaybeHandle<SharedFunctionInfo> shared; |
1932 if (type == JS_FUNCTION_TYPE) { | 1941 if (type == JS_FUNCTION_TYPE) { |
1933 OneByteStringKey key(STATIC_CHAR_VECTOR("<freezing call trap>"), | 1942 OneByteStringKey key(STATIC_CHAR_VECTOR("<freezing call trap>"), |
1934 heap->HashSeed()); | 1943 heap->HashSeed()); |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2520 return Handle<Object>::null(); | 2529 return Handle<Object>::null(); |
2521 } | 2530 } |
2522 | 2531 |
2523 | 2532 |
2524 Handle<Object> Factory::ToBoolean(bool value) { | 2533 Handle<Object> Factory::ToBoolean(bool value) { |
2525 return value ? true_value() : false_value(); | 2534 return value ? true_value() : false_value(); |
2526 } | 2535 } |
2527 | 2536 |
2528 | 2537 |
2529 } } // namespace v8::internal | 2538 } } // namespace v8::internal |
OLD | NEW |