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

Side by Side Diff: src/factory.cc

Issue 1427743011: [proxies] Remove "fix" functionality, add (still unused) target property. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Test Created 5 years, 1 month 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
« no previous file with comments | « src/factory.h ('k') | src/js/proxy.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/bootstrapper.h" 9 #include "src/bootstrapper.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
(...skipping 1918 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 1929
1930 Handle<JSDataView> Factory::NewJSDataView(Handle<JSArrayBuffer> buffer, 1930 Handle<JSDataView> Factory::NewJSDataView(Handle<JSArrayBuffer> buffer,
1931 size_t byte_offset, 1931 size_t byte_offset,
1932 size_t byte_length) { 1932 size_t byte_length) {
1933 Handle<JSDataView> obj = NewJSDataView(); 1933 Handle<JSDataView> obj = NewJSDataView();
1934 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length); 1934 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length);
1935 return obj; 1935 return obj;
1936 } 1936 }
1937 1937
1938 1938
1939 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, 1939 Handle<JSProxy> Factory::NewJSProxy(Handle<JSReceiver> target,
1940 Handle<JSReceiver> handler,
1940 Handle<Object> prototype) { 1941 Handle<Object> prototype) {
1941 // Allocate map. 1942 // Allocate map.
1942 // TODO(rossberg): Once we optimize proxies, think about a scheme to share 1943 // TODO(rossberg): Once we optimize proxies, think about a scheme to share
1943 // maps. Will probably depend on the identity of the handler object, too. 1944 // maps. Will probably depend on the identity of the handler object, too.
1944 Handle<Map> map = NewMap(JS_PROXY_TYPE, JSProxy::kSize); 1945 Handle<Map> map = NewMap(JS_PROXY_TYPE, JSProxy::kSize);
1945 Map::SetPrototype(map, prototype); 1946 Map::SetPrototype(map, prototype);
1946 1947
1947 // Allocate the proxy object. 1948 // Allocate the proxy object.
1948 Handle<JSProxy> result = New<JSProxy>(map, NEW_SPACE); 1949 Handle<JSProxy> result = New<JSProxy>(map, NEW_SPACE);
1949 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); 1950 result->set_target(*target);
1950 result->set_handler(*handler); 1951 result->set_handler(*handler);
1951 result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER); 1952 result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER);
1952 return result; 1953 return result;
1953 } 1954 }
1954 1955
1955 1956
1956 Handle<JSProxy> Factory::NewJSFunctionProxy(Handle<Object> handler, 1957 Handle<JSProxy> Factory::NewJSFunctionProxy(Handle<JSReceiver> target,
1958 Handle<JSReceiver> handler,
1957 Handle<JSReceiver> call_trap, 1959 Handle<JSReceiver> call_trap,
1958 Handle<Object> construct_trap, 1960 Handle<Object> construct_trap,
1959 Handle<Object> prototype) { 1961 Handle<Object> prototype) {
1960 // Allocate map. 1962 // Allocate map.
1961 // TODO(rossberg): Once we optimize proxies, think about a scheme to share 1963 // TODO(rossberg): Once we optimize proxies, think about a scheme to share
1962 // maps. Will probably depend on the identity of the handler object, too. 1964 // maps. Will probably depend on the identity of the handler object, too.
1963 Handle<Map> map = NewMap(JS_FUNCTION_PROXY_TYPE, JSFunctionProxy::kSize); 1965 Handle<Map> map = NewMap(JS_FUNCTION_PROXY_TYPE, JSFunctionProxy::kSize);
1964 Map::SetPrototype(map, prototype); 1966 Map::SetPrototype(map, prototype);
1965 map->set_is_callable(); 1967 map->set_is_callable();
1966 map->set_is_constructor(construct_trap->IsCallable()); 1968 map->set_is_constructor(construct_trap->IsCallable());
1967 1969
1968 // Allocate the proxy object. 1970 // Allocate the proxy object.
1969 Handle<JSFunctionProxy> result = New<JSFunctionProxy>(map, NEW_SPACE); 1971 Handle<JSFunctionProxy> result = New<JSFunctionProxy>(map, NEW_SPACE);
1970 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); 1972 result->set_target(*target);
1971 result->set_handler(*handler); 1973 result->set_handler(*handler);
1972 result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER); 1974 result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER);
1973 result->set_call_trap(*call_trap); 1975 result->set_call_trap(*call_trap);
1974 result->set_construct_trap(*construct_trap); 1976 result->set_construct_trap(*construct_trap);
1975 return result; 1977 return result;
1976 } 1978 }
1977 1979
1978 1980
1979 void Factory::ReinitializeJSProxy(Handle<JSProxy> proxy, InstanceType type,
1980 int size) {
1981 DCHECK(type == JS_OBJECT_TYPE || type == JS_FUNCTION_TYPE);
1982
1983 Handle<Map> proxy_map(proxy->map());
1984 Handle<Map> map = Map::FixProxy(proxy_map, type, size);
1985
1986 // Check that the receiver has at least the size of the fresh object.
1987 int size_difference = proxy_map->instance_size() - map->instance_size();
1988 DCHECK(size_difference >= 0);
1989
1990 // Allocate the backing storage for the properties.
1991 Handle<FixedArray> properties = empty_fixed_array();
1992
1993 Heap* heap = isolate()->heap();
1994 MaybeHandle<SharedFunctionInfo> shared;
1995 if (type == JS_FUNCTION_TYPE) {
1996 OneByteStringKey key(STATIC_CHAR_VECTOR("<freezing call trap>"),
1997 heap->HashSeed());
1998 Handle<String> name = InternalizeStringWithKey(&key);
1999 shared = NewSharedFunctionInfo(name, MaybeHandle<Code>());
2000 }
2001
2002 // In order to keep heap in consistent state there must be no allocations
2003 // before object re-initialization is finished and filler object is installed.
2004 DisallowHeapAllocation no_allocation;
2005
2006 // Put in filler if the new object is smaller than the old.
2007 if (size_difference > 0) {
2008 Address address = proxy->address();
2009 heap->CreateFillerObjectAt(address + map->instance_size(), size_difference);
2010 heap->AdjustLiveBytes(*proxy, -size_difference,
2011 Heap::CONCURRENT_TO_SWEEPER);
2012 }
2013
2014 // Reset the map for the object.
2015 proxy->synchronized_set_map(*map);
2016 Handle<JSObject> jsobj = Handle<JSObject>::cast(proxy);
2017
2018 // Reinitialize the object from the constructor map.
2019 heap->InitializeJSObjectFromMap(*jsobj, *properties, *map);
2020
2021 // The current native context is used to set up certain bits.
2022 // TODO(adamk): Using the current context seems wrong, it should be whatever
2023 // context the JSProxy originated in. But that context isn't stored anywhere.
2024 Handle<Context> context(isolate()->native_context());
2025
2026 // Functions require some minimal initialization.
2027 if (type == JS_FUNCTION_TYPE) {
2028 map->set_is_constructor(true);
2029 map->set_is_callable();
2030 Handle<JSFunction> js_function = Handle<JSFunction>::cast(proxy);
2031 InitializeFunction(js_function, shared.ToHandleChecked(), context);
2032 } else {
2033 // Provide JSObjects with a constructor.
2034 map->SetConstructor(context->object_function());
2035 }
2036 }
2037
2038
2039 Handle<JSGlobalProxy> Factory::NewUninitializedJSGlobalProxy() { 1981 Handle<JSGlobalProxy> Factory::NewUninitializedJSGlobalProxy() {
2040 // Create an empty shell of a JSGlobalProxy that needs to be reinitialized 1982 // Create an empty shell of a JSGlobalProxy that needs to be reinitialized
2041 // via ReinitializeJSGlobalProxy later. 1983 // via ReinitializeJSGlobalProxy later.
2042 Handle<Map> map = NewMap(JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize); 1984 Handle<Map> map = NewMap(JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize);
2043 // Maintain invariant expected from any JSGlobalProxy. 1985 // Maintain invariant expected from any JSGlobalProxy.
2044 map->set_is_access_check_needed(true); 1986 map->set_is_access_check_needed(true);
2045 CALL_HEAP_FUNCTION( 1987 CALL_HEAP_FUNCTION(
2046 isolate(), isolate()->heap()->AllocateJSObjectFromMap(*map, NOT_TENURED), 1988 isolate(), isolate()->heap()->AllocateJSObjectFromMap(*map, NOT_TENURED),
2047 JSGlobalProxy); 1989 JSGlobalProxy);
2048 } 1990 }
(...skipping 24 matching lines...) Expand all
2073 2015
2074 Heap* heap = isolate()->heap(); 2016 Heap* heap = isolate()->heap();
2075 // Reinitialize the object from the constructor map. 2017 // Reinitialize the object from the constructor map.
2076 heap->InitializeJSObjectFromMap(*object, *properties, *map); 2018 heap->InitializeJSObjectFromMap(*object, *properties, *map);
2077 2019
2078 // Restore the saved hash. 2020 // Restore the saved hash.
2079 object->set_hash(*hash); 2021 object->set_hash(*hash);
2080 } 2022 }
2081 2023
2082 2024
2083 void Factory::BecomeJSObject(Handle<JSProxy> proxy) {
2084 ReinitializeJSProxy(proxy, JS_OBJECT_TYPE, JSObject::kHeaderSize);
2085 }
2086
2087
2088 void Factory::BecomeJSFunction(Handle<JSProxy> proxy) {
2089 ReinitializeJSProxy(proxy, JS_FUNCTION_TYPE, JSFunction::kSize);
2090 }
2091
2092
2093 Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo( 2025 Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
2094 Handle<String> name, int number_of_literals, FunctionKind kind, 2026 Handle<String> name, int number_of_literals, FunctionKind kind,
2095 Handle<Code> code, Handle<ScopeInfo> scope_info, 2027 Handle<Code> code, Handle<ScopeInfo> scope_info,
2096 Handle<TypeFeedbackVector> feedback_vector) { 2028 Handle<TypeFeedbackVector> feedback_vector) {
2097 DCHECK(IsValidFunctionKind(kind)); 2029 DCHECK(IsValidFunctionKind(kind));
2098 Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name, code); 2030 Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name, code);
2099 shared->set_scope_info(*scope_info); 2031 shared->set_scope_info(*scope_info);
2100 shared->set_feedback_vector(*feedback_vector); 2032 shared->set_feedback_vector(*feedback_vector);
2101 shared->set_kind(kind); 2033 shared->set_kind(kind);
2102 shared->set_num_literals(number_of_literals); 2034 shared->set_num_literals(number_of_literals);
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
2403 } 2335 }
2404 2336
2405 2337
2406 Handle<Object> Factory::ToBoolean(bool value) { 2338 Handle<Object> Factory::ToBoolean(bool value) {
2407 return value ? true_value() : false_value(); 2339 return value ? true_value() : false_value();
2408 } 2340 }
2409 2341
2410 2342
2411 } // namespace internal 2343 } // namespace internal
2412 } // namespace v8 2344 } // namespace v8
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/js/proxy.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698