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/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
(...skipping 1868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1879 return obj; | 1879 return obj; |
1880 } | 1880 } |
1881 | 1881 |
1882 | 1882 |
1883 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, | 1883 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, |
1884 Handle<Object> prototype) { | 1884 Handle<Object> prototype) { |
1885 // Allocate map. | 1885 // Allocate map. |
1886 // 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 |
1887 // 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. |
1888 Handle<Map> map = NewMap(JS_PROXY_TYPE, JSProxy::kSize); | 1888 Handle<Map> map = NewMap(JS_PROXY_TYPE, JSProxy::kSize); |
1889 map->SetPrototype(prototype); | 1889 Map::SetPrototype(map, prototype); |
1890 | 1890 |
1891 // Allocate the proxy object. | 1891 // Allocate the proxy object. |
1892 Handle<JSProxy> result = New<JSProxy>(map, NEW_SPACE); | 1892 Handle<JSProxy> result = New<JSProxy>(map, NEW_SPACE); |
1893 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); | 1893 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); |
1894 result->set_handler(*handler); | 1894 result->set_handler(*handler); |
1895 result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER); | 1895 result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER); |
1896 return result; | 1896 return result; |
1897 } | 1897 } |
1898 | 1898 |
1899 | 1899 |
1900 Handle<JSProxy> Factory::NewJSFunctionProxy(Handle<Object> handler, | 1900 Handle<JSProxy> Factory::NewJSFunctionProxy(Handle<Object> handler, |
1901 Handle<Object> call_trap, | 1901 Handle<Object> call_trap, |
1902 Handle<Object> construct_trap, | 1902 Handle<Object> construct_trap, |
1903 Handle<Object> prototype) { | 1903 Handle<Object> prototype) { |
1904 // Allocate map. | 1904 // Allocate map. |
1905 // 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 |
1906 // 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. |
1907 Handle<Map> map = NewMap(JS_FUNCTION_PROXY_TYPE, JSFunctionProxy::kSize); | 1907 Handle<Map> map = NewMap(JS_FUNCTION_PROXY_TYPE, JSFunctionProxy::kSize); |
1908 map->SetPrototype(prototype); | 1908 Map::SetPrototype(map, prototype); |
1909 | 1909 |
1910 // Allocate the proxy object. | 1910 // Allocate the proxy object. |
1911 Handle<JSFunctionProxy> result = New<JSFunctionProxy>(map, NEW_SPACE); | 1911 Handle<JSFunctionProxy> result = New<JSFunctionProxy>(map, NEW_SPACE); |
1912 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); | 1912 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); |
1913 result->set_handler(*handler); | 1913 result->set_handler(*handler); |
1914 result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER); | 1914 result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER); |
1915 result->set_call_trap(*call_trap); | 1915 result->set_call_trap(*call_trap); |
1916 result->set_construct_trap(*construct_trap); | 1916 result->set_construct_trap(*construct_trap); |
1917 return result; | 1917 return result; |
1918 } | 1918 } |
1919 | 1919 |
1920 | 1920 |
1921 void Factory::ReinitializeJSProxy(Handle<JSProxy> proxy, InstanceType type, | 1921 void Factory::ReinitializeJSProxy(Handle<JSProxy> proxy, InstanceType type, |
1922 int size) { | 1922 int size) { |
1923 DCHECK(type == JS_OBJECT_TYPE || type == JS_FUNCTION_TYPE); | 1923 DCHECK(type == JS_OBJECT_TYPE || type == JS_FUNCTION_TYPE); |
1924 | 1924 |
1925 // Allocate fresh map. | 1925 // Allocate fresh map. |
1926 // TODO(rossberg): Once we optimize proxies, cache these maps. | 1926 // TODO(rossberg): Once we optimize proxies, cache these maps. |
1927 Handle<Map> map = NewMap(type, size); | 1927 Handle<Map> map = NewMap(type, size); |
1928 | 1928 |
1929 // 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. |
1930 int size_difference = proxy->map()->instance_size() - map->instance_size(); | 1930 int size_difference = proxy->map()->instance_size() - map->instance_size(); |
1931 DCHECK(size_difference >= 0); | 1931 DCHECK(size_difference >= 0); |
1932 | 1932 |
1933 map->SetPrototype(handle(proxy->map()->prototype(), proxy->GetIsolate())); | 1933 Handle<Object> prototype(proxy->map()->prototype(), isolate()); |
| 1934 Map::SetPrototype(map, prototype); |
1934 | 1935 |
1935 // Allocate the backing storage for the properties. | 1936 // Allocate the backing storage for the properties. |
1936 int prop_size = map->InitialPropertiesLength(); | 1937 int prop_size = map->InitialPropertiesLength(); |
1937 Handle<FixedArray> properties = NewFixedArray(prop_size, TENURED); | 1938 Handle<FixedArray> properties = NewFixedArray(prop_size, TENURED); |
1938 | 1939 |
1939 Heap* heap = isolate()->heap(); | 1940 Heap* heap = isolate()->heap(); |
1940 MaybeHandle<SharedFunctionInfo> shared; | 1941 MaybeHandle<SharedFunctionInfo> shared; |
1941 if (type == JS_FUNCTION_TYPE) { | 1942 if (type == JS_FUNCTION_TYPE) { |
1942 OneByteStringKey key(STATIC_CHAR_VECTOR("<freezing call trap>"), | 1943 OneByteStringKey key(STATIC_CHAR_VECTOR("<freezing call trap>"), |
1943 heap->HashSeed()); | 1944 heap->HashSeed()); |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2348 return Handle<Object>::null(); | 2349 return Handle<Object>::null(); |
2349 } | 2350 } |
2350 | 2351 |
2351 | 2352 |
2352 Handle<Object> Factory::ToBoolean(bool value) { | 2353 Handle<Object> Factory::ToBoolean(bool value) { |
2353 return value ? true_value() : false_value(); | 2354 return value ? true_value() : false_value(); |
2354 } | 2355 } |
2355 | 2356 |
2356 | 2357 |
2357 } } // namespace v8::internal | 2358 } } // namespace v8::internal |
OLD | NEW |