• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 bool Factory::CodeBuilder::CompiledWithConcurrentBaseline() const {
34   return FLAG_concurrent_sparkplug && kind_ == CodeKind::BASELINE &&
35          !local_isolate_->is_main_thread();
36 }
37 
InternalizeString(Handle<String> string)38 Handle<String> Factory::InternalizeString(Handle<String> string) {
39   if (string->IsInternalizedString()) return string;
40   return isolate()->string_table()->LookupString(isolate(), string);
41 }
42 
InternalizeName(Handle<Name> name)43 Handle<Name> Factory::InternalizeName(Handle<Name> name) {
44   if (name->IsUniqueName()) return name;
45   return isolate()->string_table()->LookupString(isolate(),
46                                                  Handle<String>::cast(name));
47 }
48 
NewSubString(Handle<String> str,int begin,int end)49 Handle<String> Factory::NewSubString(Handle<String> str, int begin, int end) {
50   if (begin == 0 && end == str->length()) return str;
51   return NewProperSubString(str, begin, end);
52 }
53 
NewJSArrayWithElements(Handle<FixedArrayBase> elements,ElementsKind elements_kind,AllocationType allocation)54 Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements,
55                                                 ElementsKind elements_kind,
56                                                 AllocationType allocation) {
57   return NewJSArrayWithElements(elements, elements_kind, elements->length(),
58                                 allocation);
59 }
60 
NewFastOrSlowJSObjectFromMap(Handle<Map> map,int number_of_slow_properties,AllocationType allocation,Handle<AllocationSite> allocation_site)61 Handle<JSObject> Factory::NewFastOrSlowJSObjectFromMap(
62     Handle<Map> map, int number_of_slow_properties, AllocationType allocation,
63     Handle<AllocationSite> allocation_site) {
64   return map->is_dictionary_map()
65              ? NewSlowJSObjectFromMap(map, number_of_slow_properties,
66                                       allocation, allocation_site)
67              : NewJSObjectFromMap(map, allocation, allocation_site);
68 }
69 
NewURIError()70 Handle<Object> Factory::NewURIError() {
71   return NewError(isolate()->uri_error_function(),
72                   MessageTemplate::kURIMalformed);
73 }
74 
read_only_roots()75 ReadOnlyRoots Factory::read_only_roots() const {
76   return ReadOnlyRoots(isolate());
77 }
78 
allocator()79 HeapAllocator* Factory::allocator() const {
80   return isolate()->heap()->allocator();
81 }
82 
set_interpreter_data(Handle<HeapObject> interpreter_data)83 Factory::CodeBuilder& Factory::CodeBuilder::set_interpreter_data(
84     Handle<HeapObject> interpreter_data) {
85   // This DCHECK requires this function to be in -inl.h.
86   DCHECK(interpreter_data->IsInterpreterData() ||
87          interpreter_data->IsBytecodeArray());
88   interpreter_data_ = interpreter_data;
89   return *this;
90 }
91 
92 }  // namespace internal
93 }  // namespace v8
94 
95 #endif  // V8_HEAP_FACTORY_INL_H_
96