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

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

Issue 2558913004: [inspector] Store interger in context embedder data instead of a string. (Closed)
Patch Set: review comments Created 4 years 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') | src/inspector/v8-debugger.h » ('j') | 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"
(...skipping 23 matching lines...) Expand all
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 v8::Isolate* isolate = m_inspector->isolate();
45 info.context->SetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex),
46 v8::Int32::New(isolate, contextId));
44 m_context.SetWeak(&m_context, &clearContext, 47 m_context.SetWeak(&m_context, &clearContext,
45 v8::WeakCallbackType::kParameter); 48 v8::WeakCallbackType::kParameter);
46 49
47 v8::Isolate* isolate = m_inspector->isolate();
48 v8::Local<v8::Object> global = info.context->Global(); 50 v8::Local<v8::Object> global = info.context->Global();
49 v8::Local<v8::Object> console = 51 v8::Local<v8::Object> console =
50 V8Console::createConsole(this, info.hasMemoryOnConsole); 52 V8Console::createConsole(this, info.hasMemoryOnConsole);
51 if (!global 53 if (!global
52 ->Set(info.context, toV8StringInternalized(isolate, "console"), 54 ->Set(info.context, toV8StringInternalized(isolate, "console"),
53 console) 55 console)
54 .FromMaybe(false)) 56 .FromMaybe(false))
55 return; 57 return;
56 m_console.Reset(isolate, console); 58 m_console.Reset(isolate, console);
57 m_console.SetWeak(); 59 m_console.SetWeak();
58 } 60 }
59 61
60 InspectedContext::~InspectedContext() { 62 InspectedContext::~InspectedContext() {
61 if (!m_console.IsEmpty()) { 63 if (!m_console.IsEmpty()) {
62 v8::HandleScope scope(isolate()); 64 v8::HandleScope scope(isolate());
63 V8Console::clearInspectedContextIfNeeded(context(), 65 V8Console::clearInspectedContextIfNeeded(context(),
64 m_console.Get(isolate())); 66 m_console.Get(isolate()));
65 } 67 }
66 } 68 }
67 69
70 // static
71 int InspectedContext::contextId(v8::Local<v8::Context> context) {
72 v8::Local<v8::Value> data =
73 context->GetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex));
74 if (data.IsEmpty() || !data->IsInt32()) return 0;
75 return static_cast<int>(data.As<v8::Int32>()->Value());
76 }
77
68 v8::Local<v8::Context> InspectedContext::context() const { 78 v8::Local<v8::Context> InspectedContext::context() const {
69 return m_context.Get(isolate()); 79 return m_context.Get(isolate());
70 } 80 }
71 81
72 v8::Isolate* InspectedContext::isolate() const { 82 v8::Isolate* InspectedContext::isolate() const {
73 return m_inspector->isolate(); 83 return m_inspector->isolate();
74 } 84 }
75 85
76 bool InspectedContext::createInjectedScript() { 86 bool InspectedContext::createInjectedScript() {
77 DCHECK(!m_injectedScript); 87 DCHECK(!m_injectedScript);
78 std::unique_ptr<InjectedScript> injectedScript = InjectedScript::create(this); 88 std::unique_ptr<InjectedScript> injectedScript = InjectedScript::create(this);
79 // InjectedScript::create can destroy |this|. 89 // InjectedScript::create can destroy |this|.
80 if (!injectedScript) return false; 90 if (!injectedScript) return false;
81 m_injectedScript = std::move(injectedScript); 91 m_injectedScript = std::move(injectedScript);
82 return true; 92 return true;
83 } 93 }
84 94
85 void InspectedContext::discardInjectedScript() { m_injectedScript.reset(); } 95 void InspectedContext::discardInjectedScript() { m_injectedScript.reset(); }
86 96
87 } // namespace v8_inspector 97 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/inspected-context.h ('k') | src/inspector/v8-debugger.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698