Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/inspector/inspected-context.cc

Issue 2413583002: [inspector] added check that context always survives inspected context (Closed)
Patch Set: improve comment Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/inspector/inspected-context.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/inspector/inspected-context.h" 5 #include "src/inspector/inspected-context.h"
6 6
7 #include "src/inspector/injected-script.h" 7 #include "src/inspector/injected-script.h"
8 #include "src/inspector/string-util.h" 8 #include "src/inspector/string-util.h"
9 #include "src/inspector/v8-console.h" 9 #include "src/inspector/v8-console.h"
10 #include "src/inspector/v8-inspector-impl.h" 10 #include "src/inspector/v8-inspector-impl.h"
11 #include "src/inspector/v8-value-copier.h" 11 #include "src/inspector/v8-value-copier.h"
12 12
13 #include "include/v8-inspector.h" 13 #include "include/v8-inspector.h"
14 14
15 namespace v8_inspector { 15 namespace v8_inspector {
16 16
17 void InspectedContext::weakCallback( 17 namespace {
18 const v8::WeakCallbackInfo<InspectedContext>& data) { 18
19 InspectedContext* context = data.GetParameter(); 19 void clearContext(const v8::WeakCallbackInfo<v8::Global<v8::Context>>& data) {
20 if (!context->m_context.IsEmpty()) { 20 // Inspected context is created in V8InspectorImpl::contextCreated method
21 context->m_context.Reset(); 21 // and destroyed in V8InspectorImpl::contextDestroyed.
22 data.SetSecondPassCallback(&InspectedContext::weakCallback); 22 // Both methods takes valid v8::Local<v8::Context> handle to the same context,
23 } else { 23 // it means that context is created before InspectedContext constructor and is
24 context->m_inspector->discardInspectedContext(context->m_contextGroupId, 24 // always destroyed after InspectedContext destructor therefore this callback
25 context->m_contextId); 25 // should be never called.
26 } 26 // It's possible only if inspector client doesn't call contextDestroyed which
27 // is considered an error.
28 CHECK(false);
29 data.GetParameter()->Reset();
27 } 30 }
28 31
29 void InspectedContext::consoleWeakCallback( 32 } // namespace
30 const v8::WeakCallbackInfo<InspectedContext>& data) {
31 data.GetParameter()->m_console.Reset();
32 }
33 33
34 InspectedContext::InspectedContext(V8InspectorImpl* inspector, 34 InspectedContext::InspectedContext(V8InspectorImpl* inspector,
35 const V8ContextInfo& info, int contextId) 35 const V8ContextInfo& info, int contextId)
36 : m_inspector(inspector), 36 : m_inspector(inspector),
37 m_context(info.context->GetIsolate(), info.context), 37 m_context(info.context->GetIsolate(), info.context),
38 m_contextId(contextId), 38 m_contextId(contextId),
39 m_contextGroupId(info.contextGroupId), 39 m_contextGroupId(info.contextGroupId),
40 m_origin(toString16(info.origin)), 40 m_origin(toString16(info.origin)),
41 m_humanReadableName(toString16(info.humanReadableName)), 41 m_humanReadableName(toString16(info.humanReadableName)),
42 m_auxData(toString16(info.auxData)), 42 m_auxData(toString16(info.auxData)),
43 m_reported(false) { 43 m_reported(false) {
44 m_context.SetWeak(this, &InspectedContext::weakCallback, 44 m_context.SetWeak(&m_context, &clearContext,
45 v8::WeakCallbackType::kParameter); 45 v8::WeakCallbackType::kParameter);
46 46
47 v8::Isolate* isolate = m_inspector->isolate(); 47 v8::Isolate* isolate = m_inspector->isolate();
48 v8::Local<v8::Object> global = info.context->Global(); 48 v8::Local<v8::Object> global = info.context->Global();
49 v8::Local<v8::Object> console = 49 v8::Local<v8::Object> console =
50 V8Console::createConsole(this, info.hasMemoryOnConsole); 50 V8Console::createConsole(this, info.hasMemoryOnConsole);
51 if (!global 51 if (!global
52 ->Set(info.context, toV8StringInternalized(isolate, "console"), 52 ->Set(info.context, toV8StringInternalized(isolate, "console"),
53 console) 53 console)
54 .FromMaybe(false)) 54 .FromMaybe(false))
55 return; 55 return;
56 m_console.Reset(isolate, console); 56 m_console.Reset(isolate, console);
57 m_console.SetWeak(this, &InspectedContext::consoleWeakCallback, 57 m_console.SetWeak();
58 v8::WeakCallbackType::kParameter);
59 } 58 }
60 59
61 InspectedContext::~InspectedContext() { 60 InspectedContext::~InspectedContext() {
62 if (!m_context.IsEmpty() && !m_console.IsEmpty()) { 61 if (!m_console.IsEmpty()) {
63 v8::HandleScope scope(isolate()); 62 v8::HandleScope scope(isolate());
64 V8Console::clearInspectedContextIfNeeded(context(), 63 V8Console::clearInspectedContextIfNeeded(context(),
65 m_console.Get(isolate())); 64 m_console.Get(isolate()));
66 } 65 }
67 } 66 }
68 67
69 v8::Local<v8::Context> InspectedContext::context() const { 68 v8::Local<v8::Context> InspectedContext::context() const {
70 return m_context.Get(isolate()); 69 return m_context.Get(isolate());
71 } 70 }
72 71
73 v8::Isolate* InspectedContext::isolate() const { 72 v8::Isolate* InspectedContext::isolate() const {
74 return m_inspector->isolate(); 73 return m_inspector->isolate();
75 } 74 }
76 75
77 void InspectedContext::createInjectedScript() { 76 void InspectedContext::createInjectedScript() {
78 DCHECK(!m_injectedScript); 77 DCHECK(!m_injectedScript);
79 m_injectedScript = InjectedScript::create(this); 78 m_injectedScript = InjectedScript::create(this);
80 } 79 }
81 80
82 void InspectedContext::discardInjectedScript() { m_injectedScript.reset(); } 81 void InspectedContext::discardInjectedScript() { m_injectedScript.reset(); }
83 82
84 } // namespace v8_inspector 83 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/inspected-context.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698