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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 Handle<Box> result = Handle<Box>::cast(NewStruct(BOX_TYPE)); | 48 Handle<Box> result = Handle<Box>::cast(NewStruct(BOX_TYPE)); |
49 result->set_value(*value); | 49 result->set_value(*value); |
50 return result; | 50 return result; |
51 } | 51 } |
52 | 52 |
53 | 53 |
54 Handle<Oddball> Factory::NewOddball(Handle<Map> map, | 54 Handle<Oddball> Factory::NewOddball(Handle<Map> map, |
55 const char* to_string, | 55 const char* to_string, |
56 Handle<Object> to_number, | 56 Handle<Object> to_number, |
57 byte kind) { | 57 byte kind) { |
58 Handle<Oddball> oddball = New<Oddball>(map, OLD_POINTER_SPACE); | 58 Handle<Oddball> oddball = New<Oddball>(map, OLD_SPACE); |
59 Oddball::Initialize(isolate(), oddball, to_string, to_number, kind); | 59 Oddball::Initialize(isolate(), oddball, to_string, to_number, kind); |
60 return oddball; | 60 return oddball; |
61 } | 61 } |
62 | 62 |
63 | 63 |
64 Handle<FixedArray> Factory::NewFixedArray(int size, PretenureFlag pretenure) { | 64 Handle<FixedArray> Factory::NewFixedArray(int size, PretenureFlag pretenure) { |
65 DCHECK(0 <= size); | 65 DCHECK(0 <= size); |
66 CALL_HEAP_FUNCTION( | 66 CALL_HEAP_FUNCTION( |
67 isolate(), | 67 isolate(), |
68 isolate()->heap()->AllocateFixedArray(size, pretenure), | 68 isolate()->heap()->AllocateFixedArray(size, pretenure), |
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 | 927 |
928 Handle<WeakCell> Factory::NewWeakCell(Handle<HeapObject> value) { | 928 Handle<WeakCell> Factory::NewWeakCell(Handle<HeapObject> value) { |
929 AllowDeferredHandleDereference convert_to_cell; | 929 AllowDeferredHandleDereference convert_to_cell; |
930 CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateWeakCell(*value), | 930 CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateWeakCell(*value), |
931 WeakCell); | 931 WeakCell); |
932 } | 932 } |
933 | 933 |
934 | 934 |
935 Handle<AllocationSite> Factory::NewAllocationSite() { | 935 Handle<AllocationSite> Factory::NewAllocationSite() { |
936 Handle<Map> map = allocation_site_map(); | 936 Handle<Map> map = allocation_site_map(); |
937 Handle<AllocationSite> site = New<AllocationSite>(map, OLD_POINTER_SPACE); | 937 Handle<AllocationSite> site = New<AllocationSite>(map, OLD_SPACE); |
938 site->Initialize(); | 938 site->Initialize(); |
939 | 939 |
940 // Link the site | 940 // Link the site |
941 site->set_weak_next(isolate()->heap()->allocation_sites_list()); | 941 site->set_weak_next(isolate()->heap()->allocation_sites_list()); |
942 isolate()->heap()->set_allocation_sites_list(*site); | 942 isolate()->heap()->set_allocation_sites_list(*site); |
943 return site; | 943 return site; |
944 } | 944 } |
945 | 945 |
946 | 946 |
947 Handle<Map> Factory::NewMap(InstanceType type, | 947 Handle<Map> Factory::NewMap(InstanceType type, |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 function->set_prototype_or_initial_map(*the_hole_value()); | 1240 function->set_prototype_or_initial_map(*the_hole_value()); |
1241 function->set_literals_or_bindings(*empty_fixed_array()); | 1241 function->set_literals_or_bindings(*empty_fixed_array()); |
1242 function->set_next_function_link(*undefined_value()); | 1242 function->set_next_function_link(*undefined_value()); |
1243 } | 1243 } |
1244 | 1244 |
1245 | 1245 |
1246 Handle<JSFunction> Factory::NewFunction(Handle<Map> map, | 1246 Handle<JSFunction> Factory::NewFunction(Handle<Map> map, |
1247 Handle<SharedFunctionInfo> info, | 1247 Handle<SharedFunctionInfo> info, |
1248 Handle<Context> context, | 1248 Handle<Context> context, |
1249 PretenureFlag pretenure) { | 1249 PretenureFlag pretenure) { |
1250 AllocationSpace space = pretenure == TENURED ? OLD_POINTER_SPACE : NEW_SPACE; | 1250 AllocationSpace space = pretenure == TENURED ? OLD_SPACE : NEW_SPACE; |
1251 Handle<JSFunction> result = New<JSFunction>(map, space); | 1251 Handle<JSFunction> result = New<JSFunction>(map, space); |
1252 InitializeFunction(result, info, context); | 1252 InitializeFunction(result, info, context); |
1253 return result; | 1253 return result; |
1254 } | 1254 } |
1255 | 1255 |
1256 | 1256 |
1257 Handle<JSFunction> Factory::NewFunction(Handle<Map> map, | 1257 Handle<JSFunction> Factory::NewFunction(Handle<Map> map, |
1258 Handle<String> name, | 1258 Handle<String> name, |
1259 MaybeHandle<Code> code) { | 1259 MaybeHandle<Code> code) { |
1260 Handle<Context> context(isolate()->native_context()); | 1260 Handle<Context> context(isolate()->native_context()); |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1574 DCHECK_EQ(ACCESSOR_CONSTANT, details.type()); | 1574 DCHECK_EQ(ACCESSOR_CONSTANT, details.type()); |
1575 PropertyDetails d(details.attributes(), ACCESSOR_CONSTANT, i + 1); | 1575 PropertyDetails d(details.attributes(), ACCESSOR_CONSTANT, i + 1); |
1576 Handle<Name> name(descs->GetKey(i)); | 1576 Handle<Name> name(descs->GetKey(i)); |
1577 Handle<Object> value(descs->GetCallbacksObject(i), isolate()); | 1577 Handle<Object> value(descs->GetCallbacksObject(i), isolate()); |
1578 Handle<PropertyCell> cell = NewPropertyCell(value); | 1578 Handle<PropertyCell> cell = NewPropertyCell(value); |
1579 // |dictionary| already contains enough space for all properties. | 1579 // |dictionary| already contains enough space for all properties. |
1580 USE(NameDictionary::Add(dictionary, name, cell, d)); | 1580 USE(NameDictionary::Add(dictionary, name, cell, d)); |
1581 } | 1581 } |
1582 | 1582 |
1583 // Allocate the global object and initialize it with the backing store. | 1583 // Allocate the global object and initialize it with the backing store. |
1584 Handle<GlobalObject> global = New<GlobalObject>(map, OLD_POINTER_SPACE); | 1584 Handle<GlobalObject> global = New<GlobalObject>(map, OLD_SPACE); |
1585 isolate()->heap()->InitializeJSObjectFromMap(*global, *dictionary, *map); | 1585 isolate()->heap()->InitializeJSObjectFromMap(*global, *dictionary, *map); |
1586 | 1586 |
1587 // Create a new map for the global object. | 1587 // Create a new map for the global object. |
1588 Handle<Map> new_map = Map::CopyDropDescriptors(map); | 1588 Handle<Map> new_map = Map::CopyDropDescriptors(map); |
1589 new_map->set_dictionary_map(true); | 1589 new_map->set_dictionary_map(true); |
1590 | 1590 |
1591 // Set up the global object as a normalized object. | 1591 // Set up the global object as a normalized object. |
1592 global->set_map(*new_map); | 1592 global->set_map(*new_map); |
1593 global->set_properties(*dictionary); | 1593 global->set_properties(*dictionary); |
1594 | 1594 |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2057 message->set_script(*script); | 2057 message->set_script(*script); |
2058 message->set_stack_frames(*stack_frames); | 2058 message->set_stack_frames(*stack_frames); |
2059 return message; | 2059 return message; |
2060 } | 2060 } |
2061 | 2061 |
2062 | 2062 |
2063 Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo( | 2063 Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo( |
2064 Handle<String> name, | 2064 Handle<String> name, |
2065 MaybeHandle<Code> maybe_code) { | 2065 MaybeHandle<Code> maybe_code) { |
2066 Handle<Map> map = shared_function_info_map(); | 2066 Handle<Map> map = shared_function_info_map(); |
2067 Handle<SharedFunctionInfo> share = New<SharedFunctionInfo>(map, | 2067 Handle<SharedFunctionInfo> share = New<SharedFunctionInfo>(map, OLD_SPACE); |
2068 OLD_POINTER_SPACE); | |
2069 | 2068 |
2070 // Set pointer fields. | 2069 // Set pointer fields. |
2071 share->set_name(*name); | 2070 share->set_name(*name); |
2072 Handle<Code> code; | 2071 Handle<Code> code; |
2073 if (!maybe_code.ToHandle(&code)) { | 2072 if (!maybe_code.ToHandle(&code)) { |
2074 code = handle(isolate()->builtins()->builtin(Builtins::kIllegal)); | 2073 code = handle(isolate()->builtins()->builtin(Builtins::kIllegal)); |
2075 } | 2074 } |
2076 share->set_code(*code); | 2075 share->set_code(*code); |
2077 share->set_optimized_code_map(Smi::FromInt(0)); | 2076 share->set_optimized_code_map(Smi::FromInt(0)); |
2078 share->set_scope_info(ScopeInfo::Empty(isolate())); | 2077 share->set_scope_info(ScopeInfo::Empty(isolate())); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2323 return Handle<Object>::null(); | 2322 return Handle<Object>::null(); |
2324 } | 2323 } |
2325 | 2324 |
2326 | 2325 |
2327 Handle<Object> Factory::ToBoolean(bool value) { | 2326 Handle<Object> Factory::ToBoolean(bool value) { |
2328 return value ? true_value() : false_value(); | 2327 return value ? true_value() : false_value(); |
2329 } | 2328 } |
2330 | 2329 |
2331 | 2330 |
2332 } } // namespace v8::internal | 2331 } } // namespace v8::internal |
OLD | NEW |