Commit 2082afcf authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[inspector] added check that context always survives inspected context

Inspected context is created in V8InspectorImpl::contextCreated method and destroyed in V8InspectorImpl::contextDestroyed.
Both methods takes valid v8::Local<v8::Context> handle to the same context, it means that context is created before InspectedContext constructor and is always destroyed after InspectedContext destructor therefore context weak callback in inspected context should be never called.
It's possible only if inspector client doesn't call contextDestroyed which is considered an error.

Therefore CHECK(false) is added into context weak callback to be sure that v8::Context always survives inspected context.

BUG=chromium:652548
R=dgozman@chromium.org

Review-Url: https://codereview.chromium.org/2413583002
Cr-Commit-Position: refs/heads/master@{#40290}
parent 6882c91e
......@@ -14,23 +14,23 @@
namespace v8_inspector {
void InspectedContext::weakCallback(
const v8::WeakCallbackInfo<InspectedContext>& data) {
InspectedContext* context = data.GetParameter();
if (!context->m_context.IsEmpty()) {
context->m_context.Reset();
data.SetSecondPassCallback(&InspectedContext::weakCallback);
} else {
context->m_inspector->discardInspectedContext(context->m_contextGroupId,
context->m_contextId);
}
}
namespace {
void InspectedContext::consoleWeakCallback(
const v8::WeakCallbackInfo<InspectedContext>& data) {
data.GetParameter()->m_console.Reset();
void clearContext(const v8::WeakCallbackInfo<v8::Global<v8::Context>>& data) {
// Inspected context is created in V8InspectorImpl::contextCreated method
// and destroyed in V8InspectorImpl::contextDestroyed.
// Both methods takes valid v8::Local<v8::Context> handle to the same context,
// it means that context is created before InspectedContext constructor and is
// always destroyed after InspectedContext destructor therefore this callback
// should be never called.
// It's possible only if inspector client doesn't call contextDestroyed which
// is considered an error.
CHECK(false);
data.GetParameter()->Reset();
}
} // namespace
InspectedContext::InspectedContext(V8InspectorImpl* inspector,
const V8ContextInfo& info, int contextId)
: m_inspector(inspector),
......@@ -41,7 +41,7 @@ InspectedContext::InspectedContext(V8InspectorImpl* inspector,
m_humanReadableName(toString16(info.humanReadableName)),
m_auxData(toString16(info.auxData)),
m_reported(false) {
m_context.SetWeak(this, &InspectedContext::weakCallback,
m_context.SetWeak(&m_context, &clearContext,
v8::WeakCallbackType::kParameter);
v8::Isolate* isolate = m_inspector->isolate();
......@@ -54,12 +54,11 @@ InspectedContext::InspectedContext(V8InspectorImpl* inspector,
.FromMaybe(false))
return;
m_console.Reset(isolate, console);
m_console.SetWeak(this, &InspectedContext::consoleWeakCallback,
v8::WeakCallbackType::kParameter);
m_console.SetWeak();
}
InspectedContext::~InspectedContext() {
if (!m_context.IsEmpty() && !m_console.IsEmpty()) {
if (!m_console.IsEmpty()) {
v8::HandleScope scope(isolate());
V8Console::clearInspectedContextIfNeeded(context(),
m_console.Get(isolate()));
......
......@@ -41,9 +41,6 @@ class InspectedContext {
private:
friend class V8InspectorImpl;
InspectedContext(V8InspectorImpl*, const V8ContextInfo&, int contextId);
static void weakCallback(const v8::WeakCallbackInfo<InspectedContext>&);
static void consoleWeakCallback(
const v8::WeakCallbackInfo<InspectedContext>&);
V8InspectorImpl* m_inspector;
v8::Global<v8::Context> m_context;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment