5 #include "src/inspector/inspected-context.h" 7 #include "src/debug/debug-interface.h" 8 #include "src/inspector/injected-script.h" 9 #include "src/inspector/string-util.h" 10 #include "src/inspector/v8-console.h" 11 #include "src/inspector/v8-inspector-impl.h" 13 #include "include/v8-inspector.h" 20 int groupId,
int contextId)
22 m_inspector(inspector),
24 m_contextId(contextId) {}
28 data.GetParameter()->m_context->m_weakCallbackData =
nullptr;
29 data.GetParameter()->m_context->m_context.Reset();
30 data.SetSecondPassCallback(&callContextCollected);
33 static void callContextCollected(
38 callbackData->m_inspector->contextCollected(callbackData->m_groupId,
39 callbackData->m_contextId);
52 : m_inspector(inspector),
53 m_context(info.context->GetIsolate(), info.context),
54 m_contextId(contextId),
55 m_contextGroupId(info.contextGroupId),
56 m_origin(toString16(info.origin)),
57 m_humanReadableName(toString16(info.humanReadableName)),
58 m_auxData(toString16(info.auxData)) {
59 v8::debug::SetContextId(info.context, contextId);
62 m_context.SetWeak(m_weakCallbackData,
63 &InspectedContext::WeakCallbackData::resetContext,
64 v8::WeakCallbackType::kParameter);
65 if (!info.hasMemoryOnConsole)
return;
69 if (global->Get(info.context, toV8String(m_inspector->isolate(),
"console"))
72 m_inspector->console()->installMemoryGetter(
77 InspectedContext::~InspectedContext() {
80 if (!m_context.IsEmpty())
delete m_weakCallbackData;
85 return v8::debug::GetContextId(context);
89 return m_context.Get(isolate());
92 v8::Isolate* InspectedContext::isolate()
const {
93 return m_inspector->isolate();
96 bool InspectedContext::isReported(
int sessionId)
const {
97 return m_reportedSessionIds.find(sessionId) != m_reportedSessionIds.cend();
100 void InspectedContext::setReported(
int sessionId,
bool reported) {
102 m_reportedSessionIds.insert(sessionId);
104 m_reportedSessionIds.erase(sessionId);
107 InjectedScript* InspectedContext::getInjectedScript(
int sessionId) {
108 auto it = m_injectedScripts.find(sessionId);
109 return it == m_injectedScripts.end() ? nullptr : it->second.get();
112 InjectedScript* InspectedContext::createInjectedScript(
int sessionId) {
113 std::unique_ptr<InjectedScript> injectedScript =
114 v8::base::make_unique<InjectedScript>(
this, sessionId);
115 CHECK(m_injectedScripts.find(sessionId) == m_injectedScripts.end());
116 m_injectedScripts[sessionId] = std::move(injectedScript);
117 return getInjectedScript(sessionId);
120 void InspectedContext::discardInjectedScript(
int sessionId) {
121 m_injectedScripts.erase(sessionId);
125 V8InternalValueType type) {
126 if (m_internalObjects.IsEmpty()) {
127 m_internalObjects.
Reset(isolate(), v8::debug::WeakMap::New(isolate()));
129 return !m_internalObjects.Get(isolate())
130 ->Set(m_context.Get(isolate()), object,
131 v8::Integer::New(isolate(), static_cast<int>(type)))
135 V8InternalValueType InspectedContext::getInternalType(
137 if (m_internalObjects.IsEmpty())
return V8InternalValueType::kNone;
139 if (!m_internalObjects.Get(isolate())
140 ->Get(m_context.Get(isolate()), object)
141 .ToLocal(&typeValue) ||
143 return V8InternalValueType::kNone;
145 return static_cast<V8InternalValueType
>(typeValue.
As<
v8::Int32>()->
Value());
V8_INLINE Local< S > As() const
V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local< S > *out) const