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 1578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1589 | 1589 |
1590 // Make sure result is a global object with properties in dictionary. | 1590 // Make sure result is a global object with properties in dictionary. |
1591 DCHECK(global->IsGlobalObject() && !global->HasFastProperties()); | 1591 DCHECK(global->IsGlobalObject() && !global->HasFastProperties()); |
1592 return global; | 1592 return global; |
1593 } | 1593 } |
1594 | 1594 |
1595 | 1595 |
1596 Handle<JSObject> Factory::NewJSObjectFromMap( | 1596 Handle<JSObject> Factory::NewJSObjectFromMap( |
1597 Handle<Map> map, | 1597 Handle<Map> map, |
1598 PretenureFlag pretenure, | 1598 PretenureFlag pretenure, |
1599 bool alloc_props, | |
1600 Handle<AllocationSite> allocation_site) { | 1599 Handle<AllocationSite> allocation_site) { |
1601 CALL_HEAP_FUNCTION( | 1600 CALL_HEAP_FUNCTION( |
1602 isolate(), | 1601 isolate(), |
1603 isolate()->heap()->AllocateJSObjectFromMap( | 1602 isolate()->heap()->AllocateJSObjectFromMap( |
1604 *map, | 1603 *map, |
1605 pretenure, | 1604 pretenure, |
1606 alloc_props, | |
1607 allocation_site.is_null() ? NULL : *allocation_site), | 1605 allocation_site.is_null() ? NULL : *allocation_site), |
1608 JSObject); | 1606 JSObject); |
1609 } | 1607 } |
1610 | 1608 |
1611 | 1609 |
1612 Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind, | 1610 Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind, |
1613 Strength strength, | 1611 Strength strength, |
1614 PretenureFlag pretenure) { | 1612 PretenureFlag pretenure) { |
1615 Map* map = isolate()->get_initial_js_array_map(elements_kind, strength); | 1613 Map* map = isolate()->get_initial_js_array_map(elements_kind, strength); |
1616 if (map == nullptr) { | 1614 if (map == nullptr) { |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1995 DCHECK(type == JS_OBJECT_TYPE || type == JS_FUNCTION_TYPE); | 1993 DCHECK(type == JS_OBJECT_TYPE || type == JS_FUNCTION_TYPE); |
1996 | 1994 |
1997 Handle<Map> proxy_map(proxy->map()); | 1995 Handle<Map> proxy_map(proxy->map()); |
1998 Handle<Map> map = Map::FixProxy(proxy_map, type, size); | 1996 Handle<Map> map = Map::FixProxy(proxy_map, type, size); |
1999 | 1997 |
2000 // Check that the receiver has at least the size of the fresh object. | 1998 // Check that the receiver has at least the size of the fresh object. |
2001 int size_difference = proxy_map->instance_size() - map->instance_size(); | 1999 int size_difference = proxy_map->instance_size() - map->instance_size(); |
2002 DCHECK(size_difference >= 0); | 2000 DCHECK(size_difference >= 0); |
2003 | 2001 |
2004 // Allocate the backing storage for the properties. | 2002 // Allocate the backing storage for the properties. |
2005 int prop_size = map->InitialPropertiesLength(); | 2003 Handle<FixedArray> properties = empty_fixed_array(); |
2006 Handle<FixedArray> properties = NewFixedArray(prop_size, TENURED); | |
2007 | 2004 |
2008 Heap* heap = isolate()->heap(); | 2005 Heap* heap = isolate()->heap(); |
2009 MaybeHandle<SharedFunctionInfo> shared; | 2006 MaybeHandle<SharedFunctionInfo> shared; |
2010 if (type == JS_FUNCTION_TYPE) { | 2007 if (type == JS_FUNCTION_TYPE) { |
2011 OneByteStringKey key(STATIC_CHAR_VECTOR("<freezing call trap>"), | 2008 OneByteStringKey key(STATIC_CHAR_VECTOR("<freezing call trap>"), |
2012 heap->HashSeed()); | 2009 heap->HashSeed()); |
2013 Handle<String> name = InternalizeStringWithKey(&key); | 2010 Handle<String> name = InternalizeStringWithKey(&key); |
2014 shared = NewSharedFunctionInfo(name, MaybeHandle<Code>()); | 2011 shared = NewSharedFunctionInfo(name, MaybeHandle<Code>()); |
2015 } | 2012 } |
2016 | 2013 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2049 } | 2046 } |
2050 } | 2047 } |
2051 | 2048 |
2052 | 2049 |
2053 Handle<JSGlobalProxy> Factory::NewUninitializedJSGlobalProxy() { | 2050 Handle<JSGlobalProxy> Factory::NewUninitializedJSGlobalProxy() { |
2054 // Create an empty shell of a JSGlobalProxy that needs to be reinitialized | 2051 // Create an empty shell of a JSGlobalProxy that needs to be reinitialized |
2055 // via ReinitializeJSGlobalProxy later. | 2052 // via ReinitializeJSGlobalProxy later. |
2056 Handle<Map> map = NewMap(JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize); | 2053 Handle<Map> map = NewMap(JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize); |
2057 // Maintain invariant expected from any JSGlobalProxy. | 2054 // Maintain invariant expected from any JSGlobalProxy. |
2058 map->set_is_access_check_needed(true); | 2055 map->set_is_access_check_needed(true); |
2059 CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateJSObjectFromMap( | 2056 CALL_HEAP_FUNCTION( |
2060 *map, NOT_TENURED, false), | 2057 isolate(), isolate()->heap()->AllocateJSObjectFromMap(*map, NOT_TENURED), |
2061 JSGlobalProxy); | 2058 JSGlobalProxy); |
2062 } | 2059 } |
2063 | 2060 |
2064 | 2061 |
2065 void Factory::ReinitializeJSGlobalProxy(Handle<JSGlobalProxy> object, | 2062 void Factory::ReinitializeJSGlobalProxy(Handle<JSGlobalProxy> object, |
2066 Handle<JSFunction> constructor) { | 2063 Handle<JSFunction> constructor) { |
2067 DCHECK(constructor->has_initial_map()); | 2064 DCHECK(constructor->has_initial_map()); |
2068 Handle<Map> map(constructor->initial_map(), isolate()); | 2065 Handle<Map> map(constructor->initial_map(), isolate()); |
2069 | 2066 |
2070 // The proxy's hash should be retained across reinitialization. | 2067 // The proxy's hash should be retained across reinitialization. |
2071 Handle<Object> hash(object->hash(), isolate()); | 2068 Handle<Object> hash(object->hash(), isolate()); |
2072 | 2069 |
2073 // Check that the already allocated object has the same size and type as | 2070 // Check that the already allocated object has the same size and type as |
2074 // objects allocated using the constructor. | 2071 // objects allocated using the constructor. |
2075 DCHECK(map->instance_size() == object->map()->instance_size()); | 2072 DCHECK(map->instance_size() == object->map()->instance_size()); |
2076 DCHECK(map->instance_type() == object->map()->instance_type()); | 2073 DCHECK(map->instance_type() == object->map()->instance_type()); |
2077 | 2074 |
2078 // Allocate the backing storage for the properties. | 2075 // Allocate the backing storage for the properties. |
2079 int prop_size = map->InitialPropertiesLength(); | 2076 Handle<FixedArray> properties = empty_fixed_array(); |
2080 Handle<FixedArray> properties = NewFixedArray(prop_size, TENURED); | |
2081 | 2077 |
2082 // In order to keep heap in consistent state there must be no allocations | 2078 // In order to keep heap in consistent state there must be no allocations |
2083 // before object re-initialization is finished. | 2079 // before object re-initialization is finished. |
2084 DisallowHeapAllocation no_allocation; | 2080 DisallowHeapAllocation no_allocation; |
2085 | 2081 |
2086 // Reset the map for the object. | 2082 // Reset the map for the object. |
2087 object->synchronized_set_map(*map); | 2083 object->synchronized_set_map(*map); |
2088 | 2084 |
2089 Heap* heap = isolate()->heap(); | 2085 Heap* heap = isolate()->heap(); |
2090 // Reinitialize the object from the constructor map. | 2086 // Reinitialize the object from the constructor map. |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2431 } | 2427 } |
2432 | 2428 |
2433 | 2429 |
2434 Handle<Object> Factory::ToBoolean(bool value) { | 2430 Handle<Object> Factory::ToBoolean(bool value) { |
2435 return value ? true_value() : false_value(); | 2431 return value ? true_value() : false_value(); |
2436 } | 2432 } |
2437 | 2433 |
2438 | 2434 |
2439 } // namespace internal | 2435 } // namespace internal |
2440 } // namespace v8 | 2436 } // namespace v8 |
OLD | NEW |