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

Side by Side Diff: Source/bindings/v8/ScriptDebugServer.cpp

Issue 300393002: Merge DevTools Refactor CL to Blink36 (Closed) Base URL: svn://svn.chromium.org/blink/branches/dart/1985
Patch Set: PTAL Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
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 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "bindings/v8/ScriptDebugServer.h" 32 #include "bindings/v8/ScriptDebugServer.h"
33
34 #include "DebuggerScriptSource.h" 33 #include "DebuggerScriptSource.h"
35 #include "V8JavaScriptCallFrame.h" 34 #include "V8JavaScriptCallFrame.h"
36 #include "bindings/dart/DartDebugServer.h" 35 #include "bindings/common/StackTrace.h"
36 #include "bindings/dart/DartScriptDebugServer.h"
37 #include "bindings/v8/ScopedPersistent.h" 37 #include "bindings/v8/ScopedPersistent.h"
38 #include "bindings/v8/ScriptCallStackFactory.h"
38 #include "bindings/v8/ScriptController.h" 39 #include "bindings/v8/ScriptController.h"
39 #include "bindings/v8/ScriptObject.h" 40 #include "bindings/v8/ScriptObject.h"
40 #include "bindings/v8/ScriptSourceCode.h" 41 #include "bindings/v8/ScriptSourceCode.h"
41 #include "bindings/v8/V8Binding.h" 42 #include "bindings/v8/V8Binding.h"
42 #include "bindings/v8/V8ScriptRunner.h" 43 #include "bindings/v8/V8ScriptRunner.h"
43 #include "core/inspector/JavaScriptCallFrame.h" 44 #include "core/inspector/JavaScriptCallFrame.h"
45 #include "core/inspector/ScriptCallFrame.h"
44 #include "core/inspector/ScriptDebugListener.h" 46 #include "core/inspector/ScriptDebugListener.h"
45 #include "platform/JSONValues.h" 47 #include "platform/JSONValues.h"
46 #include "wtf/StdLibExtras.h" 48 #include "wtf/StdLibExtras.h"
47 #include "wtf/Vector.h" 49 #include "wtf/Vector.h"
48 #include "wtf/dtoa/utils.h" 50 #include "wtf/dtoa/utils.h"
49 #include "wtf/text/CString.h" 51 #include "wtf/text/CString.h"
50 52
51 namespace WebCore { 53 namespace WebCore {
52 54
53 namespace { 55 namespace {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 167
166 v8::Handle<v8::Value> argv[] = { v8::Int32::New(m_isolate, pauseOnExceptions State) }; 168 v8::Handle<v8::Value> argv[] = { v8::Int32::New(m_isolate, pauseOnExceptions State) };
167 callDebuggerMethod("setPauseOnExceptionsState", 1, argv); 169 callDebuggerMethod("setPauseOnExceptionsState", 1, argv);
168 } 170 }
169 171
170 void ScriptDebugServer::setPauseOnNextStatement(bool pause) 172 void ScriptDebugServer::setPauseOnNextStatement(bool pause)
171 { 173 {
172 if (isPaused()) 174 if (isPaused())
173 return; 175 return;
174 if (pause) { 176 if (pause) {
175 DartDebugServer::shared().debugBreak();
176 v8::Debug::DebugBreak(m_isolate); 177 v8::Debug::DebugBreak(m_isolate);
177 } else { 178 } else {
178 DartDebugServer::shared().cancelDebugBreak();
179 v8::Debug::CancelDebugBreak(m_isolate); 179 v8::Debug::CancelDebugBreak(m_isolate);
180 } 180 }
181 } 181 }
182 182
183 bool ScriptDebugServer::canBreakProgram() 183 bool ScriptDebugServer::canBreakProgram()
184 { 184 {
185 if (!m_breakpointsActivated) 185 if (!m_breakpointsActivated)
186 return false; 186 return false;
187 v8::HandleScope scope(m_isolate); 187 v8::HandleScope scope(m_isolate);
188 return !m_isolate->GetCurrentContext().IsEmpty(); 188 return !m_isolate->GetCurrentContext().IsEmpty();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 236
237 v8::Handle<v8::Value> argv[] = { 237 v8::Handle<v8::Value> argv[] = {
238 m_executionState.newLocal(m_isolate), 238 m_executionState.newLocal(m_isolate),
239 callFrame 239 callFrame
240 }; 240 };
241 241
242 callDebuggerMethod(functionName, 2, argv); 242 callDebuggerMethod(functionName, 2, argv);
243 continueProgram(); 243 continueProgram();
244 } 244 }
245 245
246 void ScriptDebugServer::stepOverStatement(const ScriptValue& frame) 246 void ScriptDebugServer::stepOverStatement(const ActivationFrame& frame)
247 { 247 {
248 stepCommandWithFrame("stepOverStatement", frame); 248 ASSERT(frame.isJavaScript());
249 stepCommandWithFrame("stepOverStatement", frame.asJavaScript());
249 } 250 }
250 251
251 void ScriptDebugServer::stepOutOfFunction(const ScriptValue& frame) 252 void ScriptDebugServer::stepOutOfFunction(const ActivationFrame& frame)
252 { 253 {
253 stepCommandWithFrame(stepOutV8MethodName, frame); 254 ASSERT(frame.isJavaScript());
255 stepCommandWithFrame(stepOutV8MethodName, frame.asJavaScript());
254 } 256 }
255 257
256 bool ScriptDebugServer::setScriptSource(const String& sourceID, const String& ne wContent, bool preview, String* error, RefPtr<TypeBuilder::Debugger::SetScriptSo urceError>& errorData, ScriptValue* newCallFrames, RefPtr<JSONObject>* result) 258 bool ScriptDebugServer::setScriptSource(const String& sourceID, const String& ne wContent, bool preview, String* error, RefPtr<TypeBuilder::Debugger::SetScriptSo urceError>& errorData, StackTrace* newCallFrames, RefPtr<JSONObject>& result)
257 { 259 {
258 class EnableLiveEditScope { 260 class EnableLiveEditScope {
259 public: 261 public:
260 explicit EnableLiveEditScope(v8::Isolate* isolate) : m_isolate(isolate) { v8::Debug::SetLiveEditEnabled(m_isolate, true); } 262 explicit EnableLiveEditScope(v8::Isolate* isolate) : m_isolate(isolate) { v8::Debug::SetLiveEditEnabled(m_isolate, true); }
261 ~EnableLiveEditScope() { v8::Debug::SetLiveEditEnabled(m_isolate, false) ; } 263 ~EnableLiveEditScope() { v8::Debug::SetLiveEditEnabled(m_isolate, false) ; }
262 private: 264 private:
263 v8::Isolate* m_isolate; 265 v8::Isolate* m_isolate;
264 }; 266 };
265 267
266 ensureDebuggerScriptCompiled(); 268 ensureDebuggerScriptCompiled();
(...skipping 23 matching lines...) Expand all
290 } 292 }
291 ASSERT(!v8result.IsEmpty()); 293 ASSERT(!v8result.IsEmpty());
292 v8::Local<v8::Object> resultTuple = v8result->ToObject(); 294 v8::Local<v8::Object> resultTuple = v8result->ToObject();
293 int code = static_cast<int>(resultTuple->Get(0)->ToInteger()->Value()); 295 int code = static_cast<int>(resultTuple->Get(0)->ToInteger()->Value());
294 switch (code) { 296 switch (code) {
295 case 0: 297 case 0:
296 { 298 {
297 v8::Local<v8::Value> normalResult = resultTuple->Get(1); 299 v8::Local<v8::Value> normalResult = resultTuple->Get(1);
298 RefPtr<JSONValue> jsonResult = v8ToJSONValue(m_isolate, normalResult , JSONValue::maxDepth); 300 RefPtr<JSONValue> jsonResult = v8ToJSONValue(m_isolate, normalResult , JSONValue::maxDepth);
299 if (jsonResult) 301 if (jsonResult)
300 *result = jsonResult->asObject(); 302 result = jsonResult->asObject();
301 // Call stack may have changed after if the edited function was on t he stack. 303 // Call stack may have changed after if the edited function was on t he stack.
302 if (!preview && isPaused()) 304 if (!preview && isPaused())
303 *newCallFrames = currentCallFrames(); 305 *newCallFrames = currentCallFrames();
304 return true; 306 return true;
305 } 307 }
306 // Compile error. 308 // Compile error.
307 case 1: 309 case 1:
308 { 310 {
309 RefPtr<TypeBuilder::Debugger::SetScriptSourceError::CompileError> co mpileError = 311 RefPtr<TypeBuilder::Debugger::SetScriptSourceError::CompileError> co mpileError =
310 TypeBuilder::Debugger::SetScriptSourceError::CompileError::creat e() 312 TypeBuilder::Debugger::SetScriptSourceError::CompileError::creat e()
(...skipping 24 matching lines...) Expand all
335 } else { 337 } else {
336 v8::Handle<v8::Value> argv[] = { executionState, v8::Integer::New(m_isol ate, data) }; 338 v8::Handle<v8::Value> argv[] = { executionState, v8::Integer::New(m_isol ate, data) };
337 currentCallFrameV8 = callDebuggerMethod("currentCallFrame", WTF_ARRAY_LE NGTH(argv), argv); 339 currentCallFrameV8 = callDebuggerMethod("currentCallFrame", WTF_ARRAY_LE NGTH(argv), argv);
338 } 340 }
339 ASSERT(!currentCallFrameV8.IsEmpty()); 341 ASSERT(!currentCallFrameV8.IsEmpty());
340 if (!currentCallFrameV8->IsObject()) 342 if (!currentCallFrameV8->IsObject())
341 return PassRefPtr<JavaScriptCallFrame>(); 343 return PassRefPtr<JavaScriptCallFrame>();
342 return JavaScriptCallFrame::create(v8::Debug::GetDebugContext(), v8::Handle< v8::Object>::Cast(currentCallFrameV8)); 344 return JavaScriptCallFrame::create(v8::Debug::GetDebugContext(), v8::Handle< v8::Object>::Cast(currentCallFrameV8));
343 } 345 }
344 346
345 ScriptValue ScriptDebugServer::currentCallFramesInner(ScopeInfoDetails scopeDeta ils) 347 StackTrace ScriptDebugServer::currentCallFramesInner(ScopeInfoDetails scopeDetai ls)
346 { 348 {
347 v8::HandleScope scope(m_isolate); 349 v8::HandleScope scope(m_isolate);
348 v8::Handle<v8::Context> pausedContext = m_pausedContext.IsEmpty() ? m_isolat e->GetCurrentContext() : m_pausedContext; 350 v8::Handle<v8::Context> pausedContext = m_pausedContext.IsEmpty() ? m_isolat e->GetCurrentContext() : m_pausedContext;
349 if (pausedContext.IsEmpty()) 351 if (pausedContext.IsEmpty())
350 return ScriptValue(); 352 return StackTrace(ScriptValue());
351 353
352 RefPtr<JavaScriptCallFrame> currentCallFrame = wrapCallFrames(m_executionSta te.newLocal(m_isolate), 0, scopeDetails); 354 RefPtr<JavaScriptCallFrame> currentCallFrame = wrapCallFrames(m_executionSta te.newLocal(m_isolate), 0, scopeDetails);
353 if (!currentCallFrame) 355 if (!currentCallFrame)
354 return ScriptValue(); 356 return StackTrace(ScriptValue());
355 357
356 v8::Context::Scope contextScope(pausedContext); 358 v8::Context::Scope contextScope(pausedContext);
357 return ScriptValue(V8ScriptState::from(pausedContext), toV8(currentCallFrame .release(), v8::Handle<v8::Object>(), pausedContext->GetIsolate())); 359 return StackTrace(ScriptValue(V8ScriptState::from(pausedContext), toV8(curre ntCallFrame.release(), v8::Handle<v8::Object>(), pausedContext->GetIsolate())));
358 } 360 }
359 361
360 ScriptValue ScriptDebugServer::currentCallFrames() 362 StackTrace ScriptDebugServer::currentCallFrames()
361 { 363 {
362 return currentCallFramesInner(AllScopes); 364 return currentCallFramesInner(AllScopes);
363 } 365 }
364 366
365 ScriptValue ScriptDebugServer::currentCallFramesForAsyncStack() 367 StackTrace ScriptDebugServer::currentCallFramesForAsyncStack()
366 { 368 {
367 return currentCallFramesInner(FastAsyncScopes); 369 return currentCallFramesInner(FastAsyncScopes);
368 } 370 }
369 371
370 void ScriptDebugServer::interruptAndRun(PassOwnPtr<Task> task, v8::Isolate* isol ate) 372 void ScriptDebugServer::interruptAndRun(PassOwnPtr<Task> task, v8::Isolate* isol ate)
371 { 373 {
372 v8::Debug::DebugBreakForCommand(isolate, new ClientDataImpl(task)); 374 v8::Debug::DebugBreakForCommand(isolate, new ClientDataImpl(task));
373 } 375 }
374 376
375 void ScriptDebugServer::runPendingTasks() 377 void ScriptDebugServer::runPendingTasks()
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 if (!stackTrace->GetFrameCount()) { 489 if (!stackTrace->GetFrameCount()) {
488 // FIXME: we would prefer to remove the outer check for whether 490 // FIXME: we would prefer to remove the outer check for whether
489 // the V8 stack trace is empty and instead just perform the 491 // the V8 stack trace is empty and instead just perform the
490 // following check which works correctly for both V8 and Dart. 492 // following check which works correctly for both V8 and Dart.
491 v8::Handle<v8::Value> argv[] = { eventDetails.GetExecutionState( ) }; 493 v8::Handle<v8::Value> argv[] = { eventDetails.GetExecutionState( ) };
492 v8::Handle<v8::Value> currentCallFrame = callDebuggerMethod("cur rentCallFrame", 1, argv); 494 v8::Handle<v8::Value> currentCallFrame = callDebuggerMethod("cur rentCallFrame", 1, argv);
493 ASSERT(!currentCallFrame.IsEmpty()); 495 ASSERT(!currentCallFrame.IsEmpty());
494 if (!currentCallFrame->IsObject()) 496 if (!currentCallFrame->IsObject())
495 return; 497 return;
496 } 498 }
497 RefPtr<JavaScriptCallFrame> topFrame = wrapCallFrames(eventDetails.G etExecutionState(), 1, NoScopes); 499
498 if (executeSkipPauseRequest(listener->shouldSkipExceptionPause(topFr ame), eventDetails.GetExecutionState())) 500 if (stackTrace->GetFrameCount() && executeSkipPauseRequest(listener- >shouldSkipExceptionPause(toScriptCallFrame(stackTrace->GetFrame(0))), eventDeta ils.GetExecutionState()))
499 return; 501 return;
500 v8::Handle<v8::Object> eventData = eventDetails.GetEventData(); 502 v8::Handle<v8::Object> eventData = eventDetails.GetEventData();
501 v8::Handle<v8::Value> exceptionGetterValue = eventData->Get(v8Atomic String(m_isolate, "exception")); 503 v8::Handle<v8::Value> exceptionGetterValue = eventData->Get(v8Atomic String(m_isolate, "exception"));
502 ASSERT(!exceptionGetterValue.IsEmpty() && exceptionGetterValue->IsFu nction()); 504 ASSERT(!exceptionGetterValue.IsEmpty() && exceptionGetterValue->IsFu nction());
503 v8::Handle<v8::Value> exception = V8ScriptRunner::callInternalFuncti on(v8::Handle<v8::Function>::Cast(exceptionGetterValue), eventData, 0, 0, m_isol ate); 505 v8::Handle<v8::Value> exception = V8ScriptRunner::callInternalFuncti on(v8::Handle<v8::Function>::Cast(exceptionGetterValue), eventData, 0, 0, m_isol ate);
504 handleProgramBreak(eventDetails, exception, v8::Handle<v8::Array>()) ; 506 handleProgramBreak(eventDetails, exception, v8::Handle<v8::Array>()) ;
505 } else if (event == v8::Break) { 507 } else if (event == v8::Break) {
506 v8::Handle<v8::Function> getBreakpointNumbersFunction = v8::Local<v8 ::Function>::Cast(debuggerScript->Get(v8AtomicString(m_isolate, "getBreakpointNu mbers"))); 508 v8::Handle<v8::Function> getBreakpointNumbersFunction = v8::Local<v8 ::Function>::Cast(debuggerScript->Get(v8AtomicString(m_isolate, "getBreakpointNu mbers")));
507 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() }; 509 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() };
508 v8::Handle<v8::Value> hitBreakpoints = V8ScriptRunner::callInternalF unction(getBreakpointNumbersFunction, debuggerScript, WTF_ARRAY_LENGTH(argv), ar gv, m_isolate); 510 v8::Handle<v8::Value> hitBreakpoints = V8ScriptRunner::callInternalF unction(getBreakpointNumbersFunction, debuggerScript, WTF_ARRAY_LENGTH(argv), ar gv, m_isolate);
509 ASSERT(hitBreakpoints->IsArray()); 511 ASSERT(hitBreakpoints->IsArray());
510 RefPtr<JavaScriptCallFrame> topFrame = wrapCallFrames(eventDetails.G etExecutionState(), 1, NoScopes); 512 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackT race(m_isolate, 1);
513 ScriptCallFrame topCallFrame = toScriptCallFrame(stackTrace->GetFram e(0));
514
511 ScriptDebugListener::SkipPauseRequest skipRequest; 515 ScriptDebugListener::SkipPauseRequest skipRequest;
512 if (v8::Handle<v8::Array>::Cast(hitBreakpoints)->Length()) 516 if (v8::Handle<v8::Array>::Cast(hitBreakpoints)->Length())
513 skipRequest = listener->shouldSkipBreakpointPause(topFrame); 517 skipRequest = listener->shouldSkipBreakpointPause(topCallFrame);
514 else 518 else
515 skipRequest = listener->shouldSkipStepPause(topFrame); 519 skipRequest = listener->shouldSkipStepPause(topCallFrame);
516 if (executeSkipPauseRequest(skipRequest, eventDetails.GetExecutionSt ate())) 520 if (executeSkipPauseRequest(skipRequest, eventDetails.GetExecutionSt ate()))
517 return; 521 return;
518 handleProgramBreak(eventDetails, v8::Handle<v8::Value>(), hitBreakpo ints.As<v8::Array>()); 522 handleProgramBreak(eventDetails, v8::Handle<v8::Value>(), hitBreakpo ints.As<v8::Array>());
519 } 523 }
520 } 524 }
521 } 525 }
522 526
523 void ScriptDebugServer::dispatchDidParseSource(ScriptDebugListener* listener, v8 ::Handle<v8::Object> object) 527 void ScriptDebugServer::dispatchDidParseSource(ScriptDebugListener* listener, v8 ::Handle<v8::Object> object)
524 { 528 {
525 v8::Handle<v8::Value> id = object->Get(v8AtomicString(m_isolate, "id")); 529 v8::Handle<v8::Value> id = object->Get(v8AtomicString(m_isolate, "id"));
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 { 660 {
657 return PassOwnPtr<ScriptSourceCode>(); 661 return PassOwnPtr<ScriptSourceCode>();
658 } 662 }
659 663
660 String ScriptDebugServer::preprocessEventListener(LocalFrame*, const String& sou rce, const String& url, const String& functionName) 664 String ScriptDebugServer::preprocessEventListener(LocalFrame*, const String& sou rce, const String& url, const String& functionName)
661 { 665 {
662 return source; 666 return source;
663 } 667 }
664 668
665 } // namespace WebCore 669 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/ScriptDebugServer.h ('k') | Source/bindings/v8/custom/V8InjectedScriptHostCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698