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

Side by Side Diff: sky/engine/v8_inspector/PageScriptDebugServer.cpp

Issue 922053002: Remove unused V8 integration code in Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2011 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "sky/engine/config.h"
32 #include "sky/engine/v8_inspector/PageScriptDebugServer.h"
33
34 #include "gen/sky/bindings/core/v8/V8Window.h"
35 #include "sky/engine/bindings/core/v8/DOMWrapperWorld.h"
36 #include "sky/engine/bindings/core/v8/ScriptController.h"
37 #include "sky/engine/bindings/core/v8/ScriptSourceCode.h"
38 #include "sky/engine/bindings/core/v8/V8Binding.h"
39 #include "sky/engine/bindings/core/v8/V8ScriptRunner.h"
40 #include "sky/engine/bindings/core/v8/WindowProxy.h"
41 #include "sky/engine/core/dom/ExecutionContext.h"
42 #include "sky/engine/core/frame/FrameConsole.h"
43 #include "sky/engine/core/frame/LocalFrame.h"
44 #include "sky/engine/v8_inspector/inspector_host.h"
45 #include "sky/engine/v8_inspector/ScriptDebugListener.h"
46 #include "sky/engine/wtf/OwnPtr.h"
47 #include "sky/engine/wtf/PassOwnPtr.h"
48 #include "sky/engine/wtf/StdLibExtras.h"
49 #include "sky/engine/wtf/TemporaryChange.h"
50
51 namespace blink {
52
53 PageScriptDebugServer& PageScriptDebugServer::shared()
54 {
55 DEFINE_STATIC_LOCAL(PageScriptDebugServer, server, ());
56 return server;
57 }
58
59 v8::Isolate* PageScriptDebugServer::s_mainThreadIsolate = 0;
60
61 void PageScriptDebugServer::setMainThreadIsolate(v8::Isolate* isolate)
62 {
63 s_mainThreadIsolate = isolate;
64 }
65
66 PageScriptDebugServer::PageScriptDebugServer()
67 : ScriptDebugServer(s_mainThreadIsolate)
68 , m_pausedHost(0)
69 {
70 }
71
72 PageScriptDebugServer::~PageScriptDebugServer()
73 {
74 }
75
76 void PageScriptDebugServer::addListener(ScriptDebugListener* listener, inspector ::InspectorHost* host)
77 {
78 v8::HandleScope scope(m_isolate);
79
80 if (!m_listenersMap.size()) {
81 v8::Debug::SetDebugEventListener(&PageScriptDebugServer::v8DebugEventCal lback, v8::External::New(m_isolate, this));
82 ensureDebuggerScriptCompiled();
83 }
84
85 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext();
86 v8::Context::Scope contextScope(debuggerContext);
87
88 v8::Local<v8::Object> debuggerScript = m_debuggerScript.newLocal(m_isolate);
89 ASSERT(!debuggerScript->IsUndefined());
90 m_listenersMap.set(host, listener);
91
92 v8::Local<v8::Context> context = host->GetContext();
93 v8::Handle<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast( debuggerScript->Get(v8AtomicString(m_isolate, "getScripts")));
94 v8::Handle<v8::Value> argv[] = { context->GetEmbedderData(0) };
95 v8::Handle<v8::Value> value = V8ScriptRunner::callInternalFunction(getScript sFunction, debuggerScript, WTF_ARRAY_LENGTH(argv), argv, m_isolate);
96 if (value.IsEmpty())
97 return;
98 ASSERT(!value->IsUndefined() && value->IsArray());
99 v8::Handle<v8::Array> scriptsArray = v8::Handle<v8::Array>::Cast(value);
100 for (unsigned i = 0; i < scriptsArray->Length(); ++i)
101 dispatchDidParseSource(listener, v8::Handle<v8::Object>::Cast(scriptsArr ay->Get(v8::Integer::New(m_isolate, i))), CompileSuccess);
102 }
103
104 void PageScriptDebugServer::removeListener(ScriptDebugListener* listener, inspec tor::InspectorHost* host)
105 {
106 if (!m_listenersMap.contains(host))
107 return;
108
109 if (m_pausedHost == host)
110 continueProgram();
111
112 m_listenersMap.remove(host);
113
114 if (m_listenersMap.isEmpty()) {
115 discardDebuggerScript();
116 v8::Debug::SetDebugEventListener(0);
117 // FIXME: Remove all breakpoints set by the agent.
118 }
119 }
120
121 void PageScriptDebugServer::interruptAndRun(PassOwnPtr<Task> task)
122 {
123 ScriptDebugServer::interruptAndRun(task, s_mainThreadIsolate);
124 }
125
126 void PageScriptDebugServer::setClientMessageLoop(PassOwnPtr<ClientMessageLoop> c lientMessageLoop)
127 {
128 m_clientMessageLoop = clientMessageLoop;
129 }
130
131 void PageScriptDebugServer::setInspectorHostResolver(PassOwnPtr<InspectorHostRes olver> resolver)
132 {
133 m_inspectorHostResolver = resolver;
134 }
135
136 void PageScriptDebugServer::compileScript(ScriptState* scriptState, const String & expression, const String& sourceURL, String* scriptId, String* exceptionDetail sText, int* lineNumber, int* columnNumber, RefPtr<ScriptCallStack>* stackTrace)
137 {
138 ExecutionContext* executionContext = scriptState->executionContext();
139 RefPtr<LocalFrame> protect = executionContext->executingWindow()->frame();
140 ScriptDebugServer::compileScript(scriptState, expression, sourceURL, scriptI d, exceptionDetailsText, lineNumber, columnNumber, stackTrace);
141 if (!scriptId->isNull())
142 m_compiledScriptURLs.set(*scriptId, sourceURL);
143 }
144
145 void PageScriptDebugServer::clearCompiledScripts()
146 {
147 ScriptDebugServer::clearCompiledScripts();
148 m_compiledScriptURLs.clear();
149 }
150
151 void PageScriptDebugServer::runScript(ScriptState* scriptState, const String& sc riptId, ScriptValue* result, bool* wasThrown, String* exceptionDetailsText, int* lineNumber, int* columnNumber, RefPtr<ScriptCallStack>* stackTrace)
152 {
153 String sourceURL = m_compiledScriptURLs.take(scriptId);
154
155 ExecutionContext* executionContext = scriptState->executionContext();
156 LocalFrame* frame = executionContext->executingWindow()->frame();
157
158 RefPtr<LocalFrame> protect = frame;
159 ScriptDebugServer::runScript(scriptState, scriptId, result, wasThrown, excep tionDetailsText, lineNumber, columnNumber, stackTrace);
160 }
161
162 ScriptDebugListener* PageScriptDebugServer::getDebugListenerForContext(v8::Handl e<v8::Context> context)
163 {
164 inspector::InspectorHost* inspectorHost = m_inspectorHostResolver->inspector HostFor(context);
165 if (!inspectorHost)
166 return 0;
167 return m_listenersMap.get(inspectorHost);
168 }
169
170 void PageScriptDebugServer::runMessageLoopOnPause(v8::Handle<v8::Context> contex t)
171 {
172 m_pausedHost = m_inspectorHostResolver->inspectorHostFor(context);
173 ASSERT(m_pausedHost);
174
175 // Wait for continue or step command.
176 m_clientMessageLoop->run(m_pausedHost);
177
178 // The listener may have been removed in the nested loop.
179 if (ScriptDebugListener* listener = m_listenersMap.get(m_pausedHost))
180 listener->didContinue();
181
182 m_pausedHost = 0;
183 }
184
185 void PageScriptDebugServer::quitMessageLoopOnPause()
186 {
187 m_clientMessageLoop->quitNow();
188 }
189
190 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/v8_inspector/PageScriptDebugServer.h ('k') | sky/engine/v8_inspector/PromiseTracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698