V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
handler-table-builder.h
1 // Copyright 2016 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_INTERPRETER_HANDLER_TABLE_BUILDER_H_
6 #define V8_INTERPRETER_HANDLER_TABLE_BUILDER_H_
7 
8 #include "src/frames.h"
9 #include "src/interpreter/bytecode-register.h"
10 #include "src/interpreter/bytecodes.h"
11 #include "src/zone/zone-containers.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 template <typename T>
17 class Handle;
18 class HandlerTable;
19 class Isolate;
20 
21 namespace interpreter {
22 
23 // A helper class for constructing exception handler tables for the interpreter.
24 class V8_EXPORT_PRIVATE HandlerTableBuilder final {
25  public:
26  explicit HandlerTableBuilder(Zone* zone);
27 
28  // Builds the actual handler table by copying the current values into a heap
29  // object. Any further mutations to the builder won't be reflected.
30  Handle<ByteArray> ToHandlerTable(Isolate* isolate);
31 
32  // Creates a new handler table entry and returns a {hander_id} identifying the
33  // entry, so that it can be referenced by below setter functions.
34  int NewHandlerEntry();
35 
36  // Setter functions that modify certain values within the handler table entry
37  // being referenced by the given {handler_id}. All values will be encoded by
38  // the resulting {HandlerTable} class when copied into the heap.
39  void SetTryRegionStart(int handler_id, size_t offset);
40  void SetTryRegionEnd(int handler_id, size_t offset);
41  void SetHandlerTarget(int handler_id, size_t offset);
42  void SetPrediction(int handler_id, HandlerTable::CatchPrediction prediction);
43  void SetContextRegister(int handler_id, Register reg);
44 
45  private:
46  struct Entry {
47  size_t offset_start; // Bytecode offset starting try-region.
48  size_t offset_end; // Bytecode offset ending try-region.
49  size_t offset_target; // Bytecode offset of handler target.
50  Register context; // Register holding context for handler.
51  // Optimistic prediction for handler.
52  HandlerTable::CatchPrediction catch_prediction_;
53  };
54 
55  ZoneVector<Entry> entries_;
56 
57  DISALLOW_COPY_AND_ASSIGN(HandlerTableBuilder);
58 };
59 
60 } // namespace interpreter
61 } // namespace internal
62 } // namespace v8
63 
64 #endif // V8_INTERPRETER_HANDLER_TABLE_BUILDER_H_
Definition: libplatform.h:13