V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
bootstrapper.h
1 // Copyright 2014 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_BOOTSTRAPPER_H_
6 #define V8_BOOTSTRAPPER_H_
7 
8 #include "src/heap/factory.h"
9 #include "src/objects/fixed-array.h"
10 #include "src/objects/shared-function-info.h"
11 #include "src/objects/slots.h"
12 #include "src/snapshot/natives.h"
13 #include "src/visitors.h"
14 
15 namespace v8 {
16 namespace internal {
17 
18 // A SourceCodeCache uses a FixedArray to store pairs of
19 // (OneByteString, JSFunction*), mapping names of native code files
20 // (array.js, etc.) to precompiled functions. Instead of mapping
21 // names to functions it might make sense to let the JS2C tool
22 // generate an index for each native JS file.
23 class SourceCodeCache final {
24  public:
25  explicit SourceCodeCache(Script::Type type) : type_(type) {}
26 
27  void Initialize(Isolate* isolate, bool create_heap_objects);
28 
29  void Iterate(RootVisitor* v);
30 
31  bool Lookup(Isolate* isolate, Vector<const char> name,
33 
34  void Add(Isolate* isolate, Vector<const char> name,
36 
37  private:
38  Script::Type type_;
39  FixedArray cache_;
40  DISALLOW_COPY_AND_ASSIGN(SourceCodeCache);
41 };
42 
43 enum GlobalContextType { FULL_CONTEXT, DEBUG_CONTEXT };
44 
45 // The Boostrapper is the public interface for creating a JavaScript global
46 // context.
47 class Bootstrapper final {
48  public:
49  static void InitializeOncePerProcess();
50  static void TearDownExtensions();
51 
52  // Requires: Heap::SetUp has been called.
53  void Initialize(bool create_heap_objects);
54  void TearDown();
55 
56  // Creates a JavaScript Global Context with initial object graph.
57  // The returned value is a global handle casted to V8Environment*.
58  Handle<Context> CreateEnvironment(
59  MaybeHandle<JSGlobalProxy> maybe_global_proxy,
60  v8::Local<v8::ObjectTemplate> global_object_template,
61  v8::ExtensionConfiguration* extensions, size_t context_snapshot_index,
62  v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer,
63  GlobalContextType context_type = FULL_CONTEXT);
64 
65  Handle<JSGlobalProxy> NewRemoteContext(
66  MaybeHandle<JSGlobalProxy> maybe_global_proxy,
67  v8::Local<v8::ObjectTemplate> global_object_template);
68 
69  // Detach the environment from its outer global object.
70  void DetachGlobal(Handle<Context> env);
71 
72  // Traverses the pointers for memory management.
73  void Iterate(RootVisitor* v);
74 
75  // Accessor for the native scripts source code.
76  Handle<String> GetNativeSource(NativeType type, int index);
77 
78  // Tells whether bootstrapping is active.
79  bool IsActive() const { return nesting_ != 0; }
80 
81  // Support for thread preemption.
82  static int ArchiveSpacePerThread();
83  char* ArchiveState(char* to);
84  char* RestoreState(char* from);
85  void FreeThreadResources();
86 
87  // Used for new context creation.
88  bool InstallExtensions(Handle<Context> native_context,
89  v8::ExtensionConfiguration* extensions);
90 
91  SourceCodeCache* extensions_cache() { return &extensions_cache_; }
92 
93  static bool CompileNative(Isolate* isolate, Vector<const char> name,
94  Handle<String> source, int argc,
95  Handle<Object> argv[], NativesFlag natives_flag);
96  static bool CompileBuiltin(Isolate* isolate, int index);
97  static bool CompileExtraBuiltin(Isolate* isolate, int index);
98  static bool CompileExperimentalExtraBuiltin(Isolate* isolate, int index);
99 
100  static void ExportFromRuntime(Isolate* isolate, Handle<JSObject> container);
101 
102  private:
103  // Log newly created Map objects if no snapshot was used.
104  void LogAllMaps();
105 
106  Isolate* isolate_;
107  typedef int NestingCounterType;
108  NestingCounterType nesting_;
109  SourceCodeCache extensions_cache_;
110 
111  friend class BootstrapperActive;
112  friend class Isolate;
113  friend class NativesExternalStringResource;
114 
115  explicit Bootstrapper(Isolate* isolate);
116 
117  static v8::Extension* free_buffer_extension_;
118  static v8::Extension* gc_extension_;
119  static v8::Extension* externalize_string_extension_;
120  static v8::Extension* statistics_extension_;
121  static v8::Extension* trigger_failure_extension_;
122  static v8::Extension* ignition_statistics_extension_;
123 
124  DISALLOW_COPY_AND_ASSIGN(Bootstrapper);
125 };
126 
127 class BootstrapperActive final {
128  public:
129  explicit BootstrapperActive(Bootstrapper* bootstrapper)
130  : bootstrapper_(bootstrapper) {
131  ++bootstrapper_->nesting_;
132  }
133 
134  ~BootstrapperActive() {
135  --bootstrapper_->nesting_;
136  }
137 
138  private:
139  Bootstrapper* bootstrapper_;
140 
141  DISALLOW_COPY_AND_ASSIGN(BootstrapperActive);
142 };
143 
144 } // namespace internal
145 } // namespace v8
146 
147 #endif // V8_BOOTSTRAPPER_H_
Definition: v8.h:85
Definition: libplatform.h:13