OLD | NEW |
(Empty) | |
| 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 |
| 5 #include "src/inspector/InspectedContext.h" |
| 6 |
| 7 #include "src/inspector/InjectedScript.h" |
| 8 #include "src/inspector/StringUtil.h" |
| 9 #include "src/inspector/V8Console.h" |
| 10 #include "src/inspector/V8InspectorImpl.h" |
| 11 #include "src/inspector/V8ValueCopier.h" |
| 12 #include "src/inspector/public/V8ContextInfo.h" |
| 13 #include "src/inspector/public/V8InspectorClient.h" |
| 14 |
| 15 namespace v8_inspector { |
| 16 |
| 17 void InspectedContext::weakCallback( |
| 18 const v8::WeakCallbackInfo<InspectedContext>& data) { |
| 19 InspectedContext* context = data.GetParameter(); |
| 20 if (!context->m_context.IsEmpty()) { |
| 21 context->m_context.Reset(); |
| 22 data.SetSecondPassCallback(&InspectedContext::weakCallback); |
| 23 } else { |
| 24 context->m_inspector->discardInspectedContext(context->m_contextGroupId, |
| 25 context->m_contextId); |
| 26 } |
| 27 } |
| 28 |
| 29 void InspectedContext::consoleWeakCallback( |
| 30 const v8::WeakCallbackInfo<InspectedContext>& data) { |
| 31 data.GetParameter()->m_console.Reset(); |
| 32 } |
| 33 |
| 34 InspectedContext::InspectedContext(V8InspectorImpl* inspector, |
| 35 const V8ContextInfo& info, int contextId) |
| 36 : m_inspector(inspector), |
| 37 m_context(info.context->GetIsolate(), info.context), |
| 38 m_contextId(contextId), |
| 39 m_contextGroupId(info.contextGroupId), |
| 40 m_origin(toString16(info.origin)), |
| 41 m_humanReadableName(toString16(info.humanReadableName)), |
| 42 m_auxData(toString16(info.auxData)), |
| 43 m_reported(false) { |
| 44 m_context.SetWeak(this, &InspectedContext::weakCallback, |
| 45 v8::WeakCallbackType::kParameter); |
| 46 |
| 47 v8::Isolate* isolate = m_inspector->isolate(); |
| 48 v8::Local<v8::Object> global = info.context->Global(); |
| 49 v8::Local<v8::Object> console = |
| 50 V8Console::createConsole(this, info.hasMemoryOnConsole); |
| 51 if (!global |
| 52 ->Set(info.context, toV8StringInternalized(isolate, "console"), |
| 53 console) |
| 54 .FromMaybe(false)) |
| 55 return; |
| 56 m_console.Reset(isolate, console); |
| 57 m_console.SetWeak(this, &InspectedContext::consoleWeakCallback, |
| 58 v8::WeakCallbackType::kParameter); |
| 59 } |
| 60 |
| 61 InspectedContext::~InspectedContext() { |
| 62 if (!m_context.IsEmpty() && !m_console.IsEmpty()) { |
| 63 v8::HandleScope scope(isolate()); |
| 64 V8Console::clearInspectedContextIfNeeded(context(), |
| 65 m_console.Get(isolate())); |
| 66 } |
| 67 } |
| 68 |
| 69 v8::Local<v8::Context> InspectedContext::context() const { |
| 70 return m_context.Get(isolate()); |
| 71 } |
| 72 |
| 73 v8::Isolate* InspectedContext::isolate() const { |
| 74 return m_inspector->isolate(); |
| 75 } |
| 76 |
| 77 void InspectedContext::createInjectedScript() { |
| 78 DCHECK(!m_injectedScript); |
| 79 m_injectedScript = InjectedScript::create(this); |
| 80 } |
| 81 |
| 82 void InspectedContext::discardInjectedScript() { m_injectedScript.reset(); } |
| 83 |
| 84 } // namespace v8_inspector |
OLD | NEW |