Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: src/factory.cc

Issue 768633002: Add infrastructure to keep track of references to prototypes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: addressed comments Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1859 matching lines...) Expand 10 before | Expand all | Expand 10 after
1870 return obj; 1870 return obj;
1871 } 1871 }
1872 1872
1873 1873
1874 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, 1874 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler,
1875 Handle<Object> prototype) { 1875 Handle<Object> prototype) {
1876 // Allocate map. 1876 // Allocate map.
1877 // TODO(rossberg): Once we optimize proxies, think about a scheme to share 1877 // 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. 1878 // maps. Will probably depend on the identity of the handler object, too.
1879 Handle<Map> map = NewMap(JS_PROXY_TYPE, JSProxy::kSize); 1879 Handle<Map> map = NewMap(JS_PROXY_TYPE, JSProxy::kSize);
1880 map->set_prototype(*prototype); 1880 map->SetPrototype(prototype);
1881 1881
1882 // Allocate the proxy object. 1882 // Allocate the proxy object.
1883 Handle<JSProxy> result = New<JSProxy>(map, NEW_SPACE); 1883 Handle<JSProxy> result = New<JSProxy>(map, NEW_SPACE);
1884 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); 1884 result->InitializeBody(map->instance_size(), Smi::FromInt(0));
1885 result->set_handler(*handler); 1885 result->set_handler(*handler);
1886 result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER); 1886 result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER);
1887 return result; 1887 return result;
1888 } 1888 }
1889 1889
1890 1890
1891 Handle<JSProxy> Factory::NewJSFunctionProxy(Handle<Object> handler, 1891 Handle<JSProxy> Factory::NewJSFunctionProxy(Handle<Object> handler,
1892 Handle<Object> call_trap, 1892 Handle<Object> call_trap,
1893 Handle<Object> construct_trap, 1893 Handle<Object> construct_trap,
1894 Handle<Object> prototype) { 1894 Handle<Object> prototype) {
1895 // Allocate map. 1895 // Allocate map.
1896 // TODO(rossberg): Once we optimize proxies, think about a scheme to share 1896 // 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. 1897 // maps. Will probably depend on the identity of the handler object, too.
1898 Handle<Map> map = NewMap(JS_FUNCTION_PROXY_TYPE, JSFunctionProxy::kSize); 1898 Handle<Map> map = NewMap(JS_FUNCTION_PROXY_TYPE, JSFunctionProxy::kSize);
1899 map->set_prototype(*prototype); 1899 map->SetPrototype(prototype);
1900 1900
1901 // Allocate the proxy object. 1901 // Allocate the proxy object.
1902 Handle<JSFunctionProxy> result = New<JSFunctionProxy>(map, NEW_SPACE); 1902 Handle<JSFunctionProxy> result = New<JSFunctionProxy>(map, NEW_SPACE);
1903 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); 1903 result->InitializeBody(map->instance_size(), Smi::FromInt(0));
1904 result->set_handler(*handler); 1904 result->set_handler(*handler);
1905 result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER); 1905 result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER);
1906 result->set_call_trap(*call_trap); 1906 result->set_call_trap(*call_trap);
1907 result->set_construct_trap(*construct_trap); 1907 result->set_construct_trap(*construct_trap);
1908 return result; 1908 return result;
1909 } 1909 }
1910 1910
1911 1911
1912 void Factory::ReinitializeJSProxy(Handle<JSProxy> proxy, InstanceType type, 1912 void Factory::ReinitializeJSProxy(Handle<JSProxy> proxy, InstanceType type,
1913 int size) { 1913 int size) {
1914 DCHECK(type == JS_OBJECT_TYPE || type == JS_FUNCTION_TYPE); 1914 DCHECK(type == JS_OBJECT_TYPE || type == JS_FUNCTION_TYPE);
1915 1915
1916 // Allocate fresh map. 1916 // Allocate fresh map.
1917 // TODO(rossberg): Once we optimize proxies, cache these maps. 1917 // TODO(rossberg): Once we optimize proxies, cache these maps.
1918 Handle<Map> map = NewMap(type, size); 1918 Handle<Map> map = NewMap(type, size);
1919 1919
1920 // Check that the receiver has at least the size of the fresh object. 1920 // Check that the receiver has at least the size of the fresh object.
1921 int size_difference = proxy->map()->instance_size() - map->instance_size(); 1921 int size_difference = proxy->map()->instance_size() - map->instance_size();
1922 DCHECK(size_difference >= 0); 1922 DCHECK(size_difference >= 0);
1923 1923
1924 map->set_prototype(proxy->map()->prototype()); 1924 map->SetPrototype(handle(proxy->map()->prototype(), proxy->GetIsolate()));
1925 1925
1926 // Allocate the backing storage for the properties. 1926 // Allocate the backing storage for the properties.
1927 int prop_size = map->InitialPropertiesLength(); 1927 int prop_size = map->InitialPropertiesLength();
1928 Handle<FixedArray> properties = NewFixedArray(prop_size, TENURED); 1928 Handle<FixedArray> properties = NewFixedArray(prop_size, TENURED);
1929 1929
1930 Heap* heap = isolate()->heap(); 1930 Heap* heap = isolate()->heap();
1931 MaybeHandle<SharedFunctionInfo> shared; 1931 MaybeHandle<SharedFunctionInfo> shared;
1932 if (type == JS_FUNCTION_TYPE) { 1932 if (type == JS_FUNCTION_TYPE) {
1933 OneByteStringKey key(STATIC_CHAR_VECTOR("<freezing call trap>"), 1933 OneByteStringKey key(STATIC_CHAR_VECTOR("<freezing call trap>"),
1934 heap->HashSeed()); 1934 heap->HashSeed());
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
2520 return Handle<Object>::null(); 2520 return Handle<Object>::null();
2521 } 2521 }
2522 2522
2523 2523
2524 Handle<Object> Factory::ToBoolean(bool value) { 2524 Handle<Object> Factory::ToBoolean(bool value) {
2525 return value ? true_value() : false_value(); 2525 return value ? true_value() : false_value();
2526 } 2526 }
2527 2527
2528 2528
2529 } } // namespace v8::internal 2529 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/bootstrapper.cc ('k') | src/flag-definitions.h » ('j') | src/objects.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698