1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_HEAP_FACTORY_INL_H_
6 #define V8_HEAP_FACTORY_INL_H_
7 
8 #include "src/heap/factory.h"
9 
10 // Clients of this interface shouldn't depend on lots of heap internals.
11 // Do not include anything from src/heap here!
12 #include "src/execution/isolate-inl.h"
13 #include "src/handles/handles-inl.h"
14 #include "src/heap/factory-base-inl.h"
15 #include "src/objects/feedback-cell.h"
16 #include "src/objects/heap-number-inl.h"
17 #include "src/objects/objects-inl.h"
18 #include "src/objects/oddball.h"
19 #include "src/objects/string-inl.h"
20 #include "src/strings/string-hasher.h"
21 
22 namespace v8 {
23 namespace internal {
24 
25 #define ROOT_ACCESSOR(Type, name, CamelName)                                 \
26   Handle<Type> Factory::name() {                                             \
27     return Handle<Type>(&isolate()->roots_table()[RootIndex::k##CamelName]); \
28   }
ROOT_LIST(ROOT_ACCESSOR)29 ROOT_LIST(ROOT_ACCESSOR)
30 #undef ROOT_ACCESSOR
31 
32 Handle<String> Factory::InternalizeString(Handle<String> string) {
33   if (string->IsInternalizedString()) return string;
34   return StringTable::LookupString(isolate(), string);
35 }
36 
InternalizeName(Handle<Name> name)37 Handle<Name> Factory::InternalizeName(Handle<Name> name) {
38   if (name->IsUniqueName()) return name;
39   return StringTable::LookupString(isolate(), Handle<String>::cast(name));
40 }
41 
NewSubString(Handle<String> str,int begin,int end)42 Handle<String> Factory::NewSubString(Handle<String> str, int begin, int end) {
43   if (begin == 0 && end == str->length()) return str;
44   return NewProperSubString(str, begin, end);
45 }
46 
NewJSArrayWithElements(Handle<FixedArrayBase> elements,ElementsKind elements_kind,AllocationType allocation)47 Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements,
48                                                 ElementsKind elements_kind,
49                                                 AllocationType allocation) {
50   return NewJSArrayWithElements(elements, elements_kind, elements->length(),
51                                 allocation);
52 }
53 
NewFastOrSlowJSObjectFromMap(Handle<Map> map,int number_of_slow_properties,AllocationType allocation,Handle<AllocationSite> allocation_site)54 Handle<JSObject> Factory::NewFastOrSlowJSObjectFromMap(
55     Handle<Map> map, int number_of_slow_properties, AllocationType allocation,
56     Handle<AllocationSite> allocation_site) {
57   return map->is_dictionary_map()
58              ? NewSlowJSObjectFromMap(map, number_of_slow_properties,
59                                       allocation, allocation_site)
60              : NewJSObjectFromMap(map, allocation, allocation_site);
61 }
62 
NewURIError()63 Handle<Object> Factory::NewURIError() {
64   return NewError(isolate()->uri_error_function(),
65                   MessageTemplate::kURIMalformed);
66 }
67 
read_only_roots()68 ReadOnlyRoots Factory::read_only_roots() { return ReadOnlyRoots(isolate()); }
69 
70 }  // namespace internal
71 }  // namespace v8
72 
73 #endif  // V8_HEAP_FACTORY_INL_H_
74