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/objects/string-table-inl.h"
21 #include "src/strings/string-hasher.h"
22
23 namespace v8 {
24 namespace internal {
25
26 #define ROOT_ACCESSOR(Type, name, CamelName) \
27 Handle<Type> Factory::name() { \
28 return Handle<Type>(&isolate()->roots_table()[RootIndex::k##CamelName]); \
29 }
ROOT_LIST(ROOT_ACCESSOR)30 ROOT_LIST(ROOT_ACCESSOR)
31 #undef ROOT_ACCESSOR
32
33 Handle<String> Factory::InternalizeString(Handle<String> string) {
34 if (string->IsInternalizedString()) return string;
35 return isolate()->string_table()->LookupString(isolate(), string);
36 }
37
InternalizeName(Handle<Name> name)38 Handle<Name> Factory::InternalizeName(Handle<Name> name) {
39 if (name->IsUniqueName()) return name;
40 return isolate()->string_table()->LookupString(isolate(),
41 Handle<String>::cast(name));
42 }
43
NewSubString(Handle<String> str,int begin,int end)44 Handle<String> Factory::NewSubString(Handle<String> str, int begin, int end) {
45 if (begin == 0 && end == str->length()) return str;
46 return NewProperSubString(str, begin, end);
47 }
48
NewJSArrayWithElements(Handle<FixedArrayBase> elements,ElementsKind elements_kind,AllocationType allocation)49 Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements,
50 ElementsKind elements_kind,
51 AllocationType allocation) {
52 return NewJSArrayWithElements(elements, elements_kind, elements->length(),
53 allocation);
54 }
55
NewFastOrSlowJSObjectFromMap(Handle<Map> map,int number_of_slow_properties,AllocationType allocation,Handle<AllocationSite> allocation_site)56 Handle<JSObject> Factory::NewFastOrSlowJSObjectFromMap(
57 Handle<Map> map, int number_of_slow_properties, AllocationType allocation,
58 Handle<AllocationSite> allocation_site) {
59 return map->is_dictionary_map()
60 ? NewSlowJSObjectFromMap(map, number_of_slow_properties,
61 allocation, allocation_site)
62 : NewJSObjectFromMap(map, allocation, allocation_site);
63 }
64
NewURIError()65 Handle<Object> Factory::NewURIError() {
66 return NewError(isolate()->uri_error_function(),
67 MessageTemplate::kURIMalformed);
68 }
69
read_only_roots()70 ReadOnlyRoots Factory::read_only_roots() { return ReadOnlyRoots(isolate()); }
71
72 } // namespace internal
73 } // namespace v8
74
75 #endif // V8_HEAP_FACTORY_INL_H_
76