inspected-context.h 2.42 KB
Newer Older
1 2 3 4
// Copyright 2016 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_INSPECTOR_INSPECTED_CONTEXT_H_
#define V8_INSPECTOR_INSPECTED_CONTEXT_H_
7

8
#include <memory>
9
#include <unordered_map>
10 11
#include <unordered_set>

12
#include "include/v8.h"
13
#include "src/base/macros.h"
14
#include "src/debug/debug-interface.h"
15
#include "src/inspector/string-16.h"
16
#include "src/inspector/v8-debugger-id.h"
17 18 19 20 21 22 23 24

namespace v8_inspector {

class InjectedScript;
class InjectedScriptHost;
class V8ContextInfo;
class V8InspectorImpl;

25 26
enum class V8InternalValueType { kNone, kEntry, kScope, kScopeList };

27 28 29
class InspectedContext {
 public:
  ~InspectedContext();
30 31
  InspectedContext(const InspectedContext&) = delete;
  InspectedContext& operator=(const InspectedContext&) = delete;
32

33 34
  static int contextId(v8::Local<v8::Context>);

35 36 37 38 39
  v8::Local<v8::Context> context() const;
  int contextId() const { return m_contextId; }
  int contextGroupId() const { return m_contextGroupId; }
  String16 origin() const { return m_origin; }
  String16 humanReadableName() const { return m_humanReadableName; }
40
  V8DebuggerId uniqueId() const { return m_uniqueId; }
41 42
  String16 auxData() const { return m_auxData; }

43 44
  bool isReported(int sessionId) const;
  void setReported(int sessionId, bool reported);
45 46 47 48

  v8::Isolate* isolate() const;
  V8InspectorImpl* inspector() const { return m_inspector; }

49
  InjectedScript* getInjectedScript(int sessionId);
50
  InjectedScript* createInjectedScript(int sessionId);
51
  void discardInjectedScript(int sessionId);
52

53 54 55 56
  bool addInternalObject(v8::Local<v8::Object> object,
                         V8InternalValueType type);
  V8InternalValueType getInternalType(v8::Local<v8::Object> object);

57 58 59 60
 private:
  friend class V8InspectorImpl;
  InspectedContext(V8InspectorImpl*, const V8ContextInfo&, int contextId);

61 62
  class WeakCallbackData;

63 64 65 66 67 68 69
  V8InspectorImpl* m_inspector;
  v8::Global<v8::Context> m_context;
  int m_contextId;
  int m_contextGroupId;
  const String16 m_origin;
  const String16 m_humanReadableName;
  const String16 m_auxData;
70
  const V8DebuggerId m_uniqueId;
71
  std::unordered_set<int> m_reportedSessionIds;
72
  std::unordered_map<int, std::unique_ptr<InjectedScript>> m_injectedScripts;
73
  WeakCallbackData* m_weakCallbackData;
74
  v8::Global<v8::debug::WeakMap> m_internalObjects;
75 76 77 78
};

}  // namespace v8_inspector

79
#endif  // V8_INSPECTOR_INSPECTED_CONTEXT_H_