v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
inspected-context.cc
Go to the documentation of this file.
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
6
15
16namespace v8_inspector {
17
18// ContextCollected callbacks may invoke JS which cannot run from inside the GC.
20 public:
23
24 void Run() override;
25
26 private:
27 std::unique_ptr<InspectedContext::WeakCallbackData> data_;
28};
29
31 public:
33 int groupId, int contextId)
34 : m_context(context),
36 m_groupId(groupId),
38
40 // InspectedContext is alive here because weak handler is still alive.
41 data.GetParameter()->m_context->m_weakCallbackData = nullptr;
42 data.GetParameter()->m_context->m_context.Reset();
44 ->GetForegroundTaskRunner(data.GetIsolate())
45 ->PostTask(
46 std::make_unique<ContextCollectedCallbacks>(data.GetParameter()));
47 }
48
49 private:
54
56};
57
59 data_->m_inspector->contextCollected(data_->m_groupId, data_->m_contextId);
60}
61
63 const V8ContextInfo& info, int contextId)
65 m_context(info.context->GetIsolate(), info.context),
71 m_uniqueId(internal::V8DebuggerId::generate(inspector)) {
78
79 v8::Context::Scope contextScope(info.context);
80 v8::HandleScope handleScope(info.context->GetIsolate());
81 v8::Local<v8::Object> global = info.context->Global();
83 if (!global
84 ->Get(info.context,
85 toV8String(info.context->GetIsolate(), "console"))
86 .ToLocal(&console) ||
87 !console->IsObject()) {
88 return;
89 }
90
92 console.As<v8::Object>());
93
94 if (info.hasMemoryOnConsole) {
96 console.As<v8::Object>());
97 }
98}
99
101 // If we destory InspectedContext before weak callback is invoked then we need
102 // to delete data here.
103 if (!m_context.IsEmpty()) delete m_weakCallbackData;
104}
105
106// static
110
114
118
119bool InspectedContext::isReported(int sessionId) const {
120 return m_reportedSessionIds.find(sessionId) != m_reportedSessionIds.cend();
121}
122
123void InspectedContext::setReported(int sessionId, bool reported) {
124 if (reported)
125 m_reportedSessionIds.insert(sessionId);
126 else
127 m_reportedSessionIds.erase(sessionId);
128}
129
131 auto it = m_injectedScripts.find(sessionId);
132 return it == m_injectedScripts.end() ? nullptr : it->second.get();
133}
134
136 std::unique_ptr<InjectedScript> injectedScript =
137 std::make_unique<InjectedScript>(this, sessionId);
138 CHECK(m_injectedScripts.find(sessionId) == m_injectedScripts.end());
139 m_injectedScripts[sessionId] = std::move(injectedScript);
140 return getInjectedScript(sessionId);
141}
142
144 m_injectedScripts.erase(sessionId);
145}
146
148 V8InternalValueType type) {
152 }
155 isolate(), object,
156 v8::Integer::New(isolate(), static_cast<int>(type)));
157 m_internalObjects.Reset(isolate(), new_map);
158 return true;
159}
160
162 v8::Local<v8::Object> object) {
164 v8::Local<v8::Value> typeValue;
165 if (!m_internalObjects.Get(isolate())
166 ->Get(isolate(), object)
167 .ToLocal(&typeValue) ||
168 !typeValue->IsUint32()) {
170 }
171 return static_cast<V8InternalValueType>(typeValue.As<v8::Int32>()->Value());
172}
173
174} // namespace v8_inspector
int32_t Value() const
Definition api.cc:6258
static Local< Integer > New(Isolate *isolate, int32_t value)
Definition api.cc:9568
V8_INLINE Local< S > As() const
V8_INLINE Local< T > Get(Isolate *isolate) const
V8_INLINE void SetWeak(P *parameter, typename WeakCallbackInfo< P >::Callback callback, WeakCallbackType type)
std::shared_ptr< v8::TaskRunner > GetForegroundTaskRunner(Isolate *isolate)
void PostTask(std::unique_ptr< Task > task, const SourceLocation &location=SourceLocation::Current())
Definition v8-platform.h:82
static V8_EXPORT_PRIVATE Local< EphemeronTable > New(v8::Isolate *isolate)
std::unique_ptr< InspectedContext::WeakCallbackData > data_
ContextCollectedCallbacks(InspectedContext::WeakCallbackData *data)
WeakCallbackData(InspectedContext *context, V8InspectorImpl *inspector, int groupId, int contextId)
static void resetContext(const v8::WeakCallbackInfo< WeakCallbackData > &data)
void discardInjectedScript(int sessionId)
v8::Local< v8::Context > context() const
v8::Global< v8::debug::EphemeronTable > m_internalObjects
WeakCallbackData * m_weakCallbackData
std::unordered_set< int > m_reportedSessionIds
std::unordered_map< int, std::unique_ptr< InjectedScript > > m_injectedScripts
void setReported(int sessionId, bool reported)
bool isReported(int sessionId) const
InspectedContext(const InspectedContext &)=delete
InjectedScript * getInjectedScript(int sessionId)
V8InternalValueType getInternalType(v8::Local< v8::Object > object)
V8InspectorImpl * inspector() const
v8::Global< v8::Context > m_context
const internal::V8DebuggerId m_uniqueId
bool addInternalObject(v8::Local< v8::Object > object, V8InternalValueType type)
InjectedScript * createInjectedScript(int sessionId)
void installMemoryGetter(v8::Local< v8::Context > context, v8::Local< v8::Object > console)
void installAsyncStackTaggingAPI(v8::Local< v8::Context > context, v8::Local< v8::Object > console)
v8::Isolate * isolate() const
V8_EXPORT_PRIVATE V8Console * console()
refactor address components for immediate indexing make OptimizeMaglevOnNextCall optimize to turbofan instead of maglev filter for tracing turbofan compilation nullptr
int GetContextId(Local< Context > context)
Platform * GetCurrentPlatform()
void SetContextId(Local< Context > context, int id)
v8::Local< v8::String > toV8String(v8::Isolate *isolate, const String16 &string)
String16 toString16(const StringView &string)
#define CHECK(condition)
Definition logging.h:124