| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010-2011 Google Inc. All rights reserved. | 2 * Copyright (c) 2010-2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "bindings/core/v8/ScriptCallStackFactory.h" | 34 #include "bindings/core/v8/ScriptCallStackFactory.h" |
| 35 #include "bindings/core/v8/ScriptSourceCode.h" | 35 #include "bindings/core/v8/ScriptSourceCode.h" |
| 36 #include "bindings/core/v8/ScriptValue.h" | 36 #include "bindings/core/v8/ScriptValue.h" |
| 37 #include "bindings/core/v8/V8JavaScriptCallFrame.h" | 37 #include "bindings/core/v8/V8JavaScriptCallFrame.h" |
| 38 #include "bindings/core/v8/V8ScriptRunner.h" | 38 #include "bindings/core/v8/V8ScriptRunner.h" |
| 39 #include "core/inspector/JavaScriptCallFrame.h" | 39 #include "core/inspector/JavaScriptCallFrame.h" |
| 40 #include "core/inspector/ScriptDebugListener.h" | 40 #include "core/inspector/ScriptDebugListener.h" |
| 41 #include "platform/JSONValues.h" | 41 #include "platform/JSONValues.h" |
| 42 #include "public/platform/Platform.h" | 42 #include "public/platform/Platform.h" |
| 43 #include "public/platform/WebData.h" | 43 #include "public/platform/WebData.h" |
| 44 #include "wtf/Deque.h" |
| 44 #include "wtf/StdLibExtras.h" | 45 #include "wtf/StdLibExtras.h" |
| 46 #include "wtf/ThreadingPrimitives.h" |
| 45 #include "wtf/Vector.h" | 47 #include "wtf/Vector.h" |
| 46 #include "wtf/dtoa/utils.h" | 48 #include "wtf/dtoa/utils.h" |
| 47 #include "wtf/text/CString.h" | 49 #include "wtf/text/CString.h" |
| 48 | 50 |
| 49 namespace blink { | 51 namespace blink { |
| 50 | 52 |
| 51 namespace { | 53 namespace { |
| 52 | |
| 53 class ClientDataImpl : public v8::Debug::ClientData { | |
| 54 public: | |
| 55 ClientDataImpl(PassOwnPtr<ScriptDebugServer::Task> task) : m_task(task) { } | |
| 56 virtual ~ClientDataImpl() { } | |
| 57 ScriptDebugServer::Task* task() const { return m_task.get(); } | |
| 58 private: | |
| 59 OwnPtr<ScriptDebugServer::Task> m_task; | |
| 60 }; | |
| 61 | |
| 62 const char stepIntoV8MethodName[] = "stepIntoStatement"; | 54 const char stepIntoV8MethodName[] = "stepIntoStatement"; |
| 63 const char stepOutV8MethodName[] = "stepOutOfFunction"; | 55 const char stepOutV8MethodName[] = "stepOutOfFunction"; |
| 64 } | 56 } |
| 65 | 57 |
| 58 class ScriptDebugServer::ThreadSafeTaskQueue { |
| 59 WTF_MAKE_NONCOPYABLE(ThreadSafeTaskQueue); |
| 60 public: |
| 61 ThreadSafeTaskQueue() { } |
| 62 PassOwnPtr<Task> tryTake() |
| 63 { |
| 64 MutexLocker lock(m_mutex); |
| 65 if (m_queue.isEmpty()) |
| 66 return nullptr; |
| 67 return m_queue.takeFirst(); |
| 68 } |
| 69 void append(PassOwnPtr<Task> task) |
| 70 { |
| 71 MutexLocker lock(m_mutex); |
| 72 m_queue.append(task); |
| 73 } |
| 74 private: |
| 75 Mutex m_mutex; |
| 76 Deque<OwnPtr<Task>> m_queue; |
| 77 }; |
| 78 |
| 66 v8::Local<v8::Value> ScriptDebugServer::callDebuggerMethod(const char* functionN
ame, int argc, v8::Local<v8::Value> argv[]) | 79 v8::Local<v8::Value> ScriptDebugServer::callDebuggerMethod(const char* functionN
ame, int argc, v8::Local<v8::Value> argv[]) |
| 67 { | 80 { |
| 68 v8::Local<v8::Object> debuggerScript = debuggerScriptLocal(); | 81 v8::Local<v8::Object> debuggerScript = debuggerScriptLocal(); |
| 69 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(debuggerScr
ipt->Get(v8InternalizedString(functionName))); | 82 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(debuggerScr
ipt->Get(v8InternalizedString(functionName))); |
| 70 ASSERT(m_isolate->InContext()); | 83 ASSERT(m_isolate->InContext()); |
| 71 return V8ScriptRunner::callInternalFunction(function, debuggerScript, argc,
argv, m_isolate); | 84 return V8ScriptRunner::callInternalFunction(function, debuggerScript, argc,
argv, m_isolate); |
| 72 } | 85 } |
| 73 | 86 |
| 74 ScriptDebugServer::ScriptDebugServer(v8::Isolate* isolate) | 87 ScriptDebugServer::ScriptDebugServer(v8::Isolate* isolate) |
| 75 : m_isolate(isolate) | 88 : m_isolate(isolate) |
| 76 , m_breakpointsActivated(true) | 89 , m_breakpointsActivated(true) |
| 77 , m_compiledScripts(isolate) | 90 , m_compiledScripts(isolate) |
| 78 , m_runningNestedMessageLoop(false) | 91 , m_runningNestedMessageLoop(false) |
| 92 , m_taskQueue(adoptPtr(new ThreadSafeTaskQueue)) |
| 79 { | 93 { |
| 80 } | 94 } |
| 81 | 95 |
| 82 ScriptDebugServer::~ScriptDebugServer() | 96 ScriptDebugServer::~ScriptDebugServer() |
| 83 { | 97 { |
| 84 } | 98 } |
| 85 | 99 |
| 86 DEFINE_TRACE(ScriptDebugServer) | 100 DEFINE_TRACE(ScriptDebugServer) |
| 87 { | 101 { |
| 88 } | 102 } |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 currentCallFrameV8 = callDebuggerMethod("currentCallFrameByIndex", WTF_A
RRAY_LENGTH(argv), argv); | 475 currentCallFrameV8 = callDebuggerMethod("currentCallFrameByIndex", WTF_A
RRAY_LENGTH(argv), argv); |
| 462 } | 476 } |
| 463 ASSERT(!currentCallFrameV8.IsEmpty()); | 477 ASSERT(!currentCallFrameV8.IsEmpty()); |
| 464 if (!currentCallFrameV8->IsObject()) | 478 if (!currentCallFrameV8->IsObject()) |
| 465 return nullptr; | 479 return nullptr; |
| 466 return JavaScriptCallFrame::create(v8::Debug::GetDebugContext(), v8::Local<v
8::Object>::Cast(currentCallFrameV8)); | 480 return JavaScriptCallFrame::create(v8::Debug::GetDebugContext(), v8::Local<v
8::Object>::Cast(currentCallFrameV8)); |
| 467 } | 481 } |
| 468 | 482 |
| 469 void ScriptDebugServer::interruptAndRun(PassOwnPtr<Task> task) | 483 void ScriptDebugServer::interruptAndRun(PassOwnPtr<Task> task) |
| 470 { | 484 { |
| 471 v8::Debug::DebugBreakForCommand(m_isolate, new ClientDataImpl(task)); | 485 m_taskQueue->append(task); |
| 486 m_isolate->RequestInterrupt(&v8InterruptCallback, this); |
| 472 } | 487 } |
| 473 | 488 |
| 474 void ScriptDebugServer::runPendingTasks() | 489 void ScriptDebugServer::runPendingTasks() |
| 475 { | 490 { |
| 476 v8::Debug::ProcessDebugMessages(); | 491 while (true) { |
| 492 OwnPtr<Task> task = m_taskQueue->tryTake(); |
| 493 if (!task) |
| 494 return; |
| 495 task->run(); |
| 496 } |
| 477 } | 497 } |
| 478 | 498 |
| 479 static ScriptDebugServer* toScriptDebugServer(v8::Local<v8::Value> data) | 499 static ScriptDebugServer* toScriptDebugServer(v8::Local<v8::Value> data) |
| 480 { | 500 { |
| 481 void* p = v8::Local<v8::External>::Cast(data)->Value(); | 501 void* p = v8::Local<v8::External>::Cast(data)->Value(); |
| 482 return static_cast<ScriptDebugServer*>(p); | 502 return static_cast<ScriptDebugServer*>(p); |
| 483 } | 503 } |
| 484 | 504 |
| 485 void ScriptDebugServer::breakProgramCallback(const v8::FunctionCallbackInfo<v8::
Value>& info) | 505 void ScriptDebugServer::breakProgramCallback(const v8::FunctionCallbackInfo<v8::
Value>& info) |
| 486 { | 506 { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 callDebuggerMethod("stepFrameStatement", 1, argv); | 548 callDebuggerMethod("stepFrameStatement", 1, argv); |
| 529 } else if (result == ScriptDebugListener::StepInto) { | 549 } else if (result == ScriptDebugListener::StepInto) { |
| 530 v8::Local<v8::Value> argv[] = { executionState }; | 550 v8::Local<v8::Value> argv[] = { executionState }; |
| 531 callDebuggerMethod(stepIntoV8MethodName, 1, argv); | 551 callDebuggerMethod(stepIntoV8MethodName, 1, argv); |
| 532 } else if (result == ScriptDebugListener::StepOut) { | 552 } else if (result == ScriptDebugListener::StepOut) { |
| 533 v8::Local<v8::Value> argv[] = { executionState }; | 553 v8::Local<v8::Value> argv[] = { executionState }; |
| 534 callDebuggerMethod(stepOutV8MethodName, 1, argv); | 554 callDebuggerMethod(stepOutV8MethodName, 1, argv); |
| 535 } | 555 } |
| 536 } | 556 } |
| 537 | 557 |
| 558 void ScriptDebugServer::v8InterruptCallback(v8::Isolate*, void* data) |
| 559 { |
| 560 ScriptDebugServer* server = static_cast<ScriptDebugServer*>(data); |
| 561 server->runPendingTasks(); |
| 562 } |
| 563 |
| 538 void ScriptDebugServer::v8DebugEventCallback(const v8::Debug::EventDetails& even
tDetails) | 564 void ScriptDebugServer::v8DebugEventCallback(const v8::Debug::EventDetails& even
tDetails) |
| 539 { | 565 { |
| 540 ScriptDebugServer* thisPtr = toScriptDebugServer(eventDetails.GetCallbackDat
a()); | 566 ScriptDebugServer* thisPtr = toScriptDebugServer(eventDetails.GetCallbackDat
a()); |
| 541 thisPtr->handleV8DebugEvent(eventDetails); | 567 thisPtr->handleV8DebugEvent(eventDetails); |
| 542 } | 568 } |
| 543 | 569 |
| 544 static v8::Local<v8::Value> callInternalGetterFunction(v8::Local<v8::Object> obj
ect, const char* functionName, v8::Isolate* isolate) | 570 static v8::Local<v8::Value> callInternalGetterFunction(v8::Local<v8::Object> obj
ect, const char* functionName, v8::Isolate* isolate) |
| 545 { | 571 { |
| 546 v8::Local<v8::Value> getterValue = object->Get(v8AtomicString(isolate, funct
ionName)); | 572 v8::Local<v8::Value> getterValue = object->Get(v8AtomicString(isolate, funct
ionName)); |
| 547 ASSERT(!getterValue.IsEmpty() && getterValue->IsFunction()); | 573 ASSERT(!getterValue.IsEmpty() && getterValue->IsFunction()); |
| 548 return V8ScriptRunner::callInternalFunction(v8::Local<v8::Function>::Cast(ge
tterValue), object, 0, 0, isolate); | 574 return V8ScriptRunner::callInternalFunction(v8::Local<v8::Function>::Cast(ge
tterValue), object, 0, 0, isolate); |
| 549 } | 575 } |
| 550 | 576 |
| 551 void ScriptDebugServer::handleV8DebugEvent(const v8::Debug::EventDetails& eventD
etails) | 577 void ScriptDebugServer::handleV8DebugEvent(const v8::Debug::EventDetails& eventD
etails) |
| 552 { | 578 { |
| 553 v8::DebugEvent event = eventDetails.GetEvent(); | 579 v8::DebugEvent event = eventDetails.GetEvent(); |
| 554 | |
| 555 if (event == v8::BreakForCommand) { | |
| 556 ClientDataImpl* data = static_cast<ClientDataImpl*>(eventDetails.GetClie
ntData()); | |
| 557 data->task()->run(); | |
| 558 return; | |
| 559 } | |
| 560 | |
| 561 if (event != v8::AsyncTaskEvent && event != v8::Break && event != v8::Except
ion && event != v8::AfterCompile && event != v8::BeforeCompile && event != v8::C
ompileError && event != v8::PromiseEvent) | 580 if (event != v8::AsyncTaskEvent && event != v8::Break && event != v8::Except
ion && event != v8::AfterCompile && event != v8::BeforeCompile && event != v8::C
ompileError && event != v8::PromiseEvent) |
| 562 return; | 581 return; |
| 563 | 582 |
| 564 v8::Local<v8::Context> eventContext = eventDetails.GetEventContext(); | 583 v8::Local<v8::Context> eventContext = eventDetails.GetEventContext(); |
| 565 ASSERT(!eventContext.IsEmpty()); | 584 ASSERT(!eventContext.IsEmpty()); |
| 566 | 585 |
| 567 ScriptDebugListener* listener = getDebugListenerForContext(eventContext); | 586 ScriptDebugListener* listener = getDebugListenerForContext(eventContext); |
| 568 if (listener) { | 587 if (listener) { |
| 569 v8::HandleScope scope(m_isolate); | 588 v8::HandleScope scope(m_isolate); |
| 570 if (event == v8::AfterCompile || event == v8::CompileError) { | 589 if (event == v8::AfterCompile || event == v8::CompileError) { |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 *lineNumber = message->GetLineNumber(); | 809 *lineNumber = message->GetLineNumber(); |
| 791 *columnNumber = message->GetStartColumn(); | 810 *columnNumber = message->GetStartColumn(); |
| 792 v8::Local<v8::StackTrace> messageStackTrace = message->GetStackTrace
(); | 811 v8::Local<v8::StackTrace> messageStackTrace = message->GetStackTrace
(); |
| 793 if (!messageStackTrace.IsEmpty() && messageStackTrace->GetFrameCount
() > 0) | 812 if (!messageStackTrace.IsEmpty() && messageStackTrace->GetFrameCount
() > 0) |
| 794 *stackTrace = createScriptCallStack(m_isolate, messageStackTrace
, messageStackTrace->GetFrameCount()); | 813 *stackTrace = createScriptCallStack(m_isolate, messageStackTrace
, messageStackTrace->GetFrameCount()); |
| 795 } | 814 } |
| 796 } | 815 } |
| 797 } | 816 } |
| 798 | 817 |
| 799 } // namespace blink | 818 } // namespace blink |
| OLD | NEW |