| OLD | NEW |
| (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 "config.h" | |
| 32 #include "bindings/v8/WorkerScriptDebugServer.h" | |
| 33 | |
| 34 #include "bindings/v8/V8ScriptRunner.h" | |
| 35 #include "core/inspector/ScriptDebugListener.h" | |
| 36 #include "core/inspector/WorkerDebuggerAgent.h" | |
| 37 #include "core/workers/WorkerGlobalScope.h" | |
| 38 #include "core/workers/WorkerThread.h" | |
| 39 #include <v8.h> | |
| 40 #include "wtf/MessageQueue.h" | |
| 41 | |
| 42 | |
| 43 namespace WebCore { | |
| 44 | |
| 45 WorkerScriptDebugServer::WorkerScriptDebugServer(WorkerGlobalScope* workerGlobal
Scope) | |
| 46 : ScriptDebugServer(v8::Isolate::GetCurrent()) | |
| 47 , m_listener(0) | |
| 48 , m_workerGlobalScope(workerGlobalScope) | |
| 49 { | |
| 50 ASSERT(m_isolate); | |
| 51 } | |
| 52 | |
| 53 void WorkerScriptDebugServer::addListener(ScriptDebugListener* listener) | |
| 54 { | |
| 55 v8::HandleScope scope(m_isolate); | |
| 56 ASSERT(!m_listener); | |
| 57 | |
| 58 v8::Debug::SetDebugEventListener(&WorkerScriptDebugServer::v8DebugEventCallb
ack, v8::External::New(m_isolate, this)); | |
| 59 ensureDebuggerScriptCompiled(); | |
| 60 m_listener = listener; | |
| 61 | |
| 62 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext(); | |
| 63 v8::Context::Scope contextScope(debuggerContext); | |
| 64 | |
| 65 v8::Local<v8::Object> debuggerScript = m_debuggerScript.newLocal(m_isolate); | |
| 66 ASSERT(!debuggerScript->IsUndefined()); | |
| 67 | |
| 68 v8::Handle<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast(
debuggerScript->Get(v8AtomicString(m_isolate, "getWorkerScripts"))); | |
| 69 v8::Handle<v8::Value> value = V8ScriptRunner::callInternalFunction(getScript
sFunction, debuggerScript, 0, 0, m_isolate); | |
| 70 if (value.IsEmpty()) | |
| 71 return; | |
| 72 ASSERT(!value->IsUndefined() && value->IsArray()); | |
| 73 v8::Handle<v8::Array> scriptsArray = v8::Handle<v8::Array>::Cast(value); | |
| 74 for (unsigned i = 0; i < scriptsArray->Length(); ++i) | |
| 75 dispatchDidParseSource(listener, v8::Handle<v8::Object>::Cast(scriptsArr
ay->Get(v8::Integer::New(m_isolate, i)))); | |
| 76 } | |
| 77 | |
| 78 void WorkerScriptDebugServer::removeListener(ScriptDebugListener* listener) | |
| 79 { | |
| 80 ASSERT(m_listener == listener); | |
| 81 continueProgram(); | |
| 82 discardDebuggerScript(); | |
| 83 m_listener = 0; | |
| 84 v8::Debug::SetDebugEventListener(0); | |
| 85 } | |
| 86 | |
| 87 void WorkerScriptDebugServer::interruptAndRunTask(PassOwnPtr<Task> task) | |
| 88 { | |
| 89 interruptAndRun(task, m_isolate); | |
| 90 } | |
| 91 | |
| 92 ScriptDebugListener* WorkerScriptDebugServer::getDebugListenerForContext(v8::Han
dle<v8::Context>) | |
| 93 { | |
| 94 // There is only one worker context in isolate. | |
| 95 return m_listener; | |
| 96 } | |
| 97 | |
| 98 void WorkerScriptDebugServer::runMessageLoopOnPause(v8::Handle<v8::Context>) | |
| 99 { | |
| 100 MessageQueueWaitResult result; | |
| 101 do { | |
| 102 result = m_workerGlobalScope->thread()->runLoop().runDebuggerTask(); | |
| 103 // Keep waiting until execution is resumed. | |
| 104 } while (result == MessageQueueMessageReceived && isPaused()); | |
| 105 | |
| 106 // The listener may have been removed in the nested loop. | |
| 107 if (m_listener) | |
| 108 m_listener->didContinue(); | |
| 109 } | |
| 110 | |
| 111 void WorkerScriptDebugServer::quitMessageLoopOnPause() | |
| 112 { | |
| 113 // Nothing to do here in case of workers since runMessageLoopOnPause will ch
eck for paused state after each debugger command. | |
| 114 } | |
| 115 | |
| 116 } // namespace WebCore | |
| OLD | NEW |