• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_INSPECTED_CONTEXT_H_
6 #define V8_INSPECTOR_INSPECTED_CONTEXT_H_
7 
8 #include <memory>
9 #include <unordered_map>
10 #include <unordered_set>
11 
12 #include "include/v8-local-handle.h"
13 #include "include/v8-persistent-handle.h"
14 #include "src/base/macros.h"
15 #include "src/debug/debug-interface.h"
16 #include "src/inspector/string-16.h"
17 #include "src/inspector/v8-debugger-id.h"
18 
19 namespace v8 {
20 class Context;
21 class Object;
22 }  // namespace v8
23 
24 namespace v8_inspector {
25 
26 class InjectedScript;
27 class InjectedScriptHost;
28 class V8ContextInfo;
29 class V8InspectorImpl;
30 
31 enum class V8InternalValueType { kNone, kEntry, kScope, kScopeList };
32 
33 class InspectedContext {
34  public:
35   ~InspectedContext();
36   InspectedContext(const InspectedContext&) = delete;
37   InspectedContext& operator=(const InspectedContext&) = delete;
38 
39   static int contextId(v8::Local<v8::Context>);
40 
41   v8::Local<v8::Context> context() const;
contextId()42   int contextId() const { return m_contextId; }
contextGroupId()43   int contextGroupId() const { return m_contextGroupId; }
origin()44   String16 origin() const { return m_origin; }
humanReadableName()45   String16 humanReadableName() const { return m_humanReadableName; }
uniqueId()46   internal::V8DebuggerId uniqueId() const { return m_uniqueId; }
auxData()47   String16 auxData() const { return m_auxData; }
48 
49   bool isReported(int sessionId) const;
50   void setReported(int sessionId, bool reported);
51 
52   v8::Isolate* isolate() const;
inspector()53   V8InspectorImpl* inspector() const { return m_inspector; }
54 
55   InjectedScript* getInjectedScript(int sessionId);
56   InjectedScript* createInjectedScript(int sessionId);
57   void discardInjectedScript(int sessionId);
58 
59   bool addInternalObject(v8::Local<v8::Object> object,
60                          V8InternalValueType type);
61   V8InternalValueType getInternalType(v8::Local<v8::Object> object);
62 
63  private:
64   friend class V8InspectorImpl;
65   InspectedContext(V8InspectorImpl*, const V8ContextInfo&, int contextId);
66 
67   class WeakCallbackData;
68 
69   V8InspectorImpl* m_inspector;
70   v8::Global<v8::Context> m_context;
71   int m_contextId;
72   int m_contextGroupId;
73   const String16 m_origin;
74   const String16 m_humanReadableName;
75   const String16 m_auxData;
76   const internal::V8DebuggerId m_uniqueId;
77   std::unordered_set<int> m_reportedSessionIds;
78   std::unordered_map<int, std::unique_ptr<InjectedScript>> m_injectedScripts;
79   WeakCallbackData* m_weakCallbackData;
80   v8::Global<v8::debug::EphemeronTable> m_internalObjects;
81 };
82 
83 }  // namespace v8_inspector
84 
85 #endif  // V8_INSPECTOR_INSPECTED_CONTEXT_H_
86