local-factory.h 2.97 KB
Newer Older
1 2 3 4
// Copyright 2020 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_LOCAL_FACTORY_H_
#define V8_HEAP_LOCAL_FACTORY_H_
7

8
#include "src/base/logging.h"
9 10 11 12 13 14 15
#include "src/common/globals.h"
#include "src/handles/handles.h"
#include "src/heap/factory-base.h"
#include "src/heap/heap.h"
#include "src/heap/read-only-heap.h"
#include "src/heap/spaces.h"
#include "src/objects/heap-object.h"
16
#include "src/objects/map.h"
17
#include "src/objects/objects.h"
18
#include "src/objects/shared-function-info.h"
19 20 21 22 23 24 25 26
#include "src/roots/roots.h"

namespace v8 {
namespace internal {

class AstValueFactory;
class AstRawString;
class AstConsString;
27
class LocalIsolate;
28

29
class V8_EXPORT_PRIVATE LocalFactory : public FactoryBase<LocalFactory> {
30
 public:
31
  explicit LocalFactory(Isolate* isolate);
32 33 34

  ReadOnlyRoots read_only_roots() const { return roots_; }

35
#define ROOT_ACCESSOR(Type, name, CamelName) inline Handle<Type> name();
36
  READ_ONLY_ROOT_LIST(ROOT_ACCESSOR)
37 38 39 40 41
  // AccessorInfos appear mutable, but they're actually not mutated once they
  // finish initializing. In particular, the root accessors are not mutated and
  // are safe to access (as long as the off-thread job doesn't try to mutate
  // them).
  ACCESSOR_INFO_ROOT_LIST(ROOT_ACCESSOR)
42 43
#undef ROOT_ACCESSOR

44
  // The parser shouldn't allow the LocalFactory to get into a state where
45
  // it generates errors.
46 47
  Handle<Object> NewInvalidStringLengthError() { UNREACHABLE(); }
  Handle<Object> NewRangeError(MessageTemplate template_index) {
48 49
    UNREACHABLE();
  }
50 51

 private:
52
  friend class FactoryBase<LocalFactory>;
53 54 55 56

  // ------
  // Customization points for FactoryBase.
  HeapObject AllocateRaw(int size, AllocationType allocation,
57
                         AllocationAlignment alignment = kTaggedAligned);
58

59
  LocalIsolate* isolate() {
60 61 62 63
    // Downcast to the privately inherited sub-class using c-style casts to
    // avoid undefined behavior (as static_cast cannot cast across private
    // bases).
    // NOLINTNEXTLINE (google-readability-casting)
64
    return (LocalIsolate*)this;  // NOLINT(readability/casting)
65
  }
66 67

  // This is the real Isolate that will be used for allocating and accessing
Samuel Groß's avatar
Samuel Groß committed
68
  // external pointer entries when V8_SANDBOXED_EXTERNAL_POINTERS is enabled.
69
  Isolate* isolate_for_sandbox() {
Samuel Groß's avatar
Samuel Groß committed
70
#ifdef V8_SANDBOXED_EXTERNAL_POINTERS
71
    return isolate_for_sandbox_;
72 73
#else
    return nullptr;
Samuel Groß's avatar
Samuel Groß committed
74
#endif  // V8_SANDBOXED_EXTERNAL_POINTERS
75 76
  }

77 78
  inline bool CanAllocateInReadOnlySpace() { return false; }
  inline bool EmptyStringRootIsInitialized() { return true; }
79
  inline AllocationType AllocationTypeForInPlaceInternalizableString();
80 81
  // ------

82
  void AddToScriptList(Handle<Script> shared);
83
  // ------
84

85
  ReadOnlyRoots roots_;
Samuel Groß's avatar
Samuel Groß committed
86
#ifdef V8_SANDBOXED_EXTERNAL_POINTERS
87
  Isolate* isolate_for_sandbox_;
88
#endif
89 90 91
#ifdef DEBUG
  bool a_script_was_added_to_the_script_list_ = false;
#endif
92 93 94 95 96
};

}  // namespace internal
}  // namespace v8

97
#endif  // V8_HEAP_LOCAL_FACTORY_H_