factory-inl.h 2.73 KB
Newer Older
1 2 3 4
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef V8_HEAP_FACTORY_INL_H_
#define V8_HEAP_FACTORY_INL_H_
7

8
#include "src/heap/factory.h"
9

10 11
// Clients of this interface shouldn't depend on lots of heap internals.
// 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 24 25
namespace v8 {
namespace internal {

26 27 28
#define ROOT_ACCESSOR(Type, name, CamelName)                                 \
  Handle<Type> Factory::name() {                                             \
    return Handle<Type>(&isolate()->roots_table()[RootIndex::k##CamelName]); \
29 30
  }
ROOT_LIST(ROOT_ACCESSOR)
31
#undef ROOT_ACCESSOR
32

33 34
Handle<String> Factory::InternalizeString(Handle<String> string) {
  if (string->IsInternalizedString()) return string;
35
  return isolate()->string_table()->LookupString(isolate(), string);
36 37 38 39
}

Handle<Name> Factory::InternalizeName(Handle<Name> name) {
  if (name->IsUniqueName()) return name;
40 41
  return isolate()->string_table()->LookupString(isolate(),
                                                 Handle<String>::cast(name));
42 43 44 45 46 47 48 49 50
}

Handle<String> Factory::NewSubString(Handle<String> str, int begin, int end) {
  if (begin == 0 && end == str->length()) return str;
  return NewProperSubString(str, begin, end);
}

Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements,
                                                ElementsKind elements_kind,
51
                                                AllocationType allocation) {
52
  return NewJSArrayWithElements(elements, elements_kind, elements->length(),
53
                                allocation);
54 55
}

56 57 58 59 60 61 62 63 64
Handle<JSObject> Factory::NewFastOrSlowJSObjectFromMap(
    Handle<Map> map, int number_of_slow_properties, AllocationType allocation,
    Handle<AllocationSite> allocation_site) {
  return map->is_dictionary_map()
             ? NewSlowJSObjectFromMap(map, number_of_slow_properties,
                                      allocation, allocation_site)
             : NewJSObjectFromMap(map, allocation, allocation_site);
}

65 66 67 68 69
Handle<Object> Factory::NewURIError() {
  return NewError(isolate()->uri_error_function(),
                  MessageTemplate::kURIMalformed);
}

70 71 72
ReadOnlyRoots Factory::read_only_roots() const {
  return ReadOnlyRoots(isolate());
}
73

74 75 76
}  // namespace internal
}  // namespace v8

77
#endif  // V8_HEAP_FACTORY_INL_H_