V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
wasm-translation.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_INSPECTOR_WASM_TRANSLATION_H_
6 #define V8_INSPECTOR_WASM_TRANSLATION_H_
7 
8 #include <unordered_map>
9 
10 #include "include/v8.h"
11 #include "src/base/macros.h"
12 #include "src/debug/debug-interface.h"
13 #include "src/inspector/string-16.h"
14 
15 namespace v8_inspector {
16 
17 // Forward declarations.
18 class V8DebuggerAgentImpl;
19 
21  public:
22  explicit WasmTranslation(v8::Isolate* isolate);
23  ~WasmTranslation();
24 
25  // Make a wasm script known to the translation. This will trigger a number of
26  // didParseScript calls to the given debugger agent.
27  // Only locations referencing a registered script will be translated by the
28  // Translate functions below.
29  void AddScript(v8::Local<v8::debug::WasmScript> script,
30  V8DebuggerAgentImpl* agent);
31 
32  // Clear all registered scripts.
33  void Clear();
34 
35  // Clear all registered scripts for context group.
36  void Clear(v8::Isolate* isolate, const std::vector<int>& contextIdsToClear);
37 
38  // Translate a location as generated by V8 to a location that should be sent
39  // over protocol.
40  // Does nothing for locations referencing a script which was not registered
41  // before via AddScript.
42  // Line and column are 0-based.
43  // Returns true if the location was translated, false otherwise.
44  bool TranslateWasmScriptLocationToProtocolLocation(String16* script_id,
45  int* line_number,
46  int* column_number);
47 
48  // Translate back from protocol locations (potentially referencing artificial
49  // scripts for individual wasm functions) to locations that make sense to V8.
50  // Does nothing if the location was not generated by the translate method
51  // above.
52  // Returns true if the location was translated, false otherwise.
53  bool TranslateProtocolLocationToWasmScriptLocation(String16* script_id,
54  int* line_number,
55  int* column_number);
56 
57  const String16& GetSource(const String16& script_id, int func_index);
58  int GetStartLine(const String16& script_id, int func_index) { return 0; }
59  int GetStartColumn(const String16& script_id, int func_index) { return 0; }
60  int GetEndLine(const String16& script_id, int func_index);
61  int GetEndColumn(const String16& script_id, int func_index);
62  String16 GetHash(const String16& script_id, int func_index);
63 
64  private:
65  class TranslatorImpl;
66  friend class TranslatorImpl;
67 
68  void AddFakeScript(const String16& scriptId, TranslatorImpl* translator);
69 
70  v8::Isolate* isolate_;
71  std::unordered_map<int, std::unique_ptr<TranslatorImpl>> wasm_translators_;
72  std::unordered_map<String16, TranslatorImpl*> fake_scripts_;
73 
74  DISALLOW_COPY_AND_ASSIGN(WasmTranslation);
75 };
76 
77 } // namespace v8_inspector
78 
79 #endif // V8_INSPECTOR_WASM_TRANSLATION_H_
Definition: v8.h:85