| 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 196 } |
| 197 | 197 |
| 198 v8::Handle<v8::Function> breakProgramFunction = m_breakProgramCallbackTempla
te.newLocal(m_isolate)->GetFunction(); | 198 v8::Handle<v8::Function> breakProgramFunction = m_breakProgramCallbackTempla
te.newLocal(m_isolate)->GetFunction(); |
| 199 v8::Debug::Call(breakProgramFunction); | 199 v8::Debug::Call(breakProgramFunction); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void ScriptDebugServer::continueProgram() | 202 void ScriptDebugServer::continueProgram() |
| 203 { | 203 { |
| 204 if (isPaused()) | 204 if (isPaused()) |
| 205 quitMessageLoopOnPause(); | 205 quitMessageLoopOnPause(); |
| 206 m_pausedContext.Clear(); | 206 m_pausedScriptState.clear(); |
| 207 m_executionState.Clear(); | 207 m_executionState.Clear(); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void ScriptDebugServer::stepIntoStatement() | 210 void ScriptDebugServer::stepIntoStatement() |
| 211 { | 211 { |
| 212 ASSERT(isPaused()); | 212 ASSERT(isPaused()); |
| 213 ASSERT(!m_executionState.IsEmpty()); | 213 ASSERT(!m_executionState.IsEmpty()); |
| 214 v8::HandleScope handleScope(m_isolate); | 214 v8::HandleScope handleScope(m_isolate); |
| 215 v8::Handle<v8::Value> argv[] = { m_executionState }; | 215 v8::Handle<v8::Value> argv[] = { m_executionState }; |
| 216 callDebuggerMethod(stepIntoV8MethodName, 1, argv); | 216 callDebuggerMethod(stepIntoV8MethodName, 1, argv); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 currentCallFrameV8 = callDebuggerMethod("currentCallFrame", WTF_ARRAY_LE
NGTH(argv), argv); | 330 currentCallFrameV8 = callDebuggerMethod("currentCallFrame", WTF_ARRAY_LE
NGTH(argv), argv); |
| 331 } | 331 } |
| 332 ASSERT(!currentCallFrameV8.IsEmpty()); | 332 ASSERT(!currentCallFrameV8.IsEmpty()); |
| 333 if (!currentCallFrameV8->IsObject()) | 333 if (!currentCallFrameV8->IsObject()) |
| 334 return PassRefPtr<JavaScriptCallFrame>(); | 334 return PassRefPtr<JavaScriptCallFrame>(); |
| 335 return JavaScriptCallFrame::create(v8::Debug::GetDebugContext(), v8::Handle<
v8::Object>::Cast(currentCallFrameV8)); | 335 return JavaScriptCallFrame::create(v8::Debug::GetDebugContext(), v8::Handle<
v8::Object>::Cast(currentCallFrameV8)); |
| 336 } | 336 } |
| 337 | 337 |
| 338 ScriptValue ScriptDebugServer::currentCallFramesInner(ScopeInfoDetails scopeDeta
ils) | 338 ScriptValue ScriptDebugServer::currentCallFramesInner(ScopeInfoDetails scopeDeta
ils) |
| 339 { | 339 { |
| 340 v8::HandleScope scope(m_isolate); | 340 if (!m_isolate->InContext()) |
| 341 v8::Handle<v8::Context> pausedContext = m_pausedContext.IsEmpty() ? m_isolat
e->GetCurrentContext() : m_pausedContext; | |
| 342 if (pausedContext.IsEmpty()) | |
| 343 return ScriptValue(); | 341 return ScriptValue(); |
| 342 v8::HandleScope handleScope(m_isolate); |
| 344 | 343 |
| 345 RefPtr<JavaScriptCallFrame> currentCallFrame = wrapCallFrames(0, scopeDetail
s); | 344 RefPtr<JavaScriptCallFrame> currentCallFrame = wrapCallFrames(0, scopeDetail
s); |
| 346 if (!currentCallFrame) | 345 if (!currentCallFrame) |
| 347 return ScriptValue(); | 346 return ScriptValue(); |
| 348 | 347 |
| 349 v8::Context::Scope contextScope(pausedContext); | 348 ScriptState* scriptState = m_pausedScriptState ? m_pausedScriptState.get() :
ScriptState::current(m_isolate); |
| 350 return ScriptValue(ScriptState::from(pausedContext), toV8(currentCallFrame.r
elease(), pausedContext->Global(), pausedContext->GetIsolate())); | 349 ScriptState::Scope scope(scriptState); |
| 350 return ScriptValue(scriptState, toV8(currentCallFrame.release(), scriptState
->context()->Global(), m_isolate)); |
| 351 } | 351 } |
| 352 | 352 |
| 353 ScriptValue ScriptDebugServer::currentCallFrames() | 353 ScriptValue ScriptDebugServer::currentCallFrames() |
| 354 { | 354 { |
| 355 return currentCallFramesInner(AllScopes); | 355 return currentCallFramesInner(AllScopes); |
| 356 } | 356 } |
| 357 | 357 |
| 358 ScriptValue ScriptDebugServer::currentCallFramesForAsyncStack() | 358 ScriptValue ScriptDebugServer::currentCallFramesForAsyncStack() |
| 359 { | 359 { |
| 360 return currentCallFramesInner(FastAsyncScopes); | 360 return currentCallFramesInner(FastAsyncScopes); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 378 static ScriptDebugServer* toScriptDebugServer(v8::Handle<v8::Value> data) | 378 static ScriptDebugServer* toScriptDebugServer(v8::Handle<v8::Value> data) |
| 379 { | 379 { |
| 380 void* p = v8::Handle<v8::External>::Cast(data)->Value(); | 380 void* p = v8::Handle<v8::External>::Cast(data)->Value(); |
| 381 return static_cast<ScriptDebugServer*>(p); | 381 return static_cast<ScriptDebugServer*>(p); |
| 382 } | 382 } |
| 383 | 383 |
| 384 void ScriptDebugServer::breakProgramCallback(const v8::FunctionCallbackInfo<v8::
Value>& info) | 384 void ScriptDebugServer::breakProgramCallback(const v8::FunctionCallbackInfo<v8::
Value>& info) |
| 385 { | 385 { |
| 386 ASSERT(2 == info.Length()); | 386 ASSERT(2 == info.Length()); |
| 387 ScriptDebugServer* thisPtr = toScriptDebugServer(info.Data()); | 387 ScriptDebugServer* thisPtr = toScriptDebugServer(info.Data()); |
| 388 v8::Handle<v8::Context> pausedContext = thisPtr->m_isolate->GetCurrentContex
t(); | 388 ScriptState* pausedScriptState = ScriptState::current(thisPtr->m_isolate); |
| 389 v8::Handle<v8::Value> exception; | 389 v8::Handle<v8::Value> exception; |
| 390 v8::Handle<v8::Array> hitBreakpoints; | 390 v8::Handle<v8::Array> hitBreakpoints; |
| 391 thisPtr->handleProgramBreak(pausedContext, v8::Handle<v8::Object>::Cast(info
[0]), exception, hitBreakpoints); | 391 thisPtr->handleProgramBreak(pausedScriptState, v8::Handle<v8::Object>::Cast(
info[0]), exception, hitBreakpoints); |
| 392 } | 392 } |
| 393 | 393 |
| 394 void ScriptDebugServer::handleProgramBreak(v8::Handle<v8::Context> pausedContext
, v8::Handle<v8::Object> executionState, v8::Handle<v8::Value> exception, v8::Ha
ndle<v8::Array> hitBreakpointNumbers) | 394 void ScriptDebugServer::handleProgramBreak(ScriptState* pausedScriptState, v8::H
andle<v8::Object> executionState, v8::Handle<v8::Value> exception, v8::Handle<v8
::Array> hitBreakpointNumbers) |
| 395 { | 395 { |
| 396 // Don't allow nested breaks. | 396 // Don't allow nested breaks. |
| 397 if (isPaused()) | 397 if (isPaused()) |
| 398 return; | 398 return; |
| 399 | 399 |
| 400 ScriptDebugListener* listener = getDebugListenerForContext(pausedContext); | 400 ScriptDebugListener* listener = getDebugListenerForContext(pausedScriptState
->context()); |
| 401 if (!listener) | 401 if (!listener) |
| 402 return; | 402 return; |
| 403 | 403 |
| 404 Vector<String> breakpointIds; | 404 Vector<String> breakpointIds; |
| 405 if (!hitBreakpointNumbers.IsEmpty()) { | 405 if (!hitBreakpointNumbers.IsEmpty()) { |
| 406 breakpointIds.resize(hitBreakpointNumbers->Length()); | 406 breakpointIds.resize(hitBreakpointNumbers->Length()); |
| 407 for (size_t i = 0; i < hitBreakpointNumbers->Length(); i++) { | 407 for (size_t i = 0; i < hitBreakpointNumbers->Length(); i++) { |
| 408 v8::Handle<v8::Value> hitBreakpointNumber = hitBreakpointNumbers->Ge
t(i); | 408 v8::Handle<v8::Value> hitBreakpointNumber = hitBreakpointNumbers->Ge
t(i); |
| 409 ASSERT(!hitBreakpointNumber.IsEmpty() && hitBreakpointNumber->IsInt3
2()); | 409 ASSERT(!hitBreakpointNumber.IsEmpty() && hitBreakpointNumber->IsInt3
2()); |
| 410 breakpointIds[i] = String::number(hitBreakpointNumber->Int32Value())
; | 410 breakpointIds[i] = String::number(hitBreakpointNumber->Int32Value())
; |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 | 413 |
| 414 m_pausedContext = pausedContext; | 414 m_pausedScriptState = pausedScriptState; |
| 415 m_executionState = executionState; | 415 m_executionState = executionState; |
| 416 ScriptState* scriptState = ScriptState::from(pausedContext); | 416 ScriptDebugListener::SkipPauseRequest result = listener->didPause(pausedScri
ptState, currentCallFrames(), ScriptValue(pausedScriptState, exception), breakpo
intIds); |
| 417 ScriptDebugListener::SkipPauseRequest result = listener->didPause(scriptStat
e, currentCallFrames(), ScriptValue(scriptState, exception), breakpointIds); | |
| 418 if (result == ScriptDebugListener::NoSkip) { | 417 if (result == ScriptDebugListener::NoSkip) { |
| 419 m_runningNestedMessageLoop = true; | 418 m_runningNestedMessageLoop = true; |
| 420 runMessageLoopOnPause(pausedContext); | 419 runMessageLoopOnPause(pausedScriptState->context()); |
| 421 m_runningNestedMessageLoop = false; | 420 m_runningNestedMessageLoop = false; |
| 422 } | 421 } |
| 423 m_pausedContext.Clear(); | 422 m_pausedScriptState.clear(); |
| 424 m_executionState.Clear(); | 423 m_executionState.Clear(); |
| 425 | 424 |
| 426 if (result == ScriptDebugListener::StepInto) { | 425 if (result == ScriptDebugListener::StepInto) { |
| 427 v8::Handle<v8::Value> argv[] = { executionState }; | 426 v8::Handle<v8::Value> argv[] = { executionState }; |
| 428 callDebuggerMethod(stepIntoV8MethodName, 1, argv); | 427 callDebuggerMethod(stepIntoV8MethodName, 1, argv); |
| 429 } else if (result == ScriptDebugListener::StepOut) { | 428 } else if (result == ScriptDebugListener::StepOut) { |
| 430 v8::Handle<v8::Value> argv[] = { executionState }; | 429 v8::Handle<v8::Value> argv[] = { executionState }; |
| 431 callDebuggerMethod(stepOutV8MethodName, 1, argv); | 430 callDebuggerMethod(stepOutV8MethodName, 1, argv); |
| 432 } | 431 } |
| 433 } | 432 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 dispatchDidParseSource(listener, object); | 469 dispatchDidParseSource(listener, object); |
| 471 } else if (event == v8::Exception) { | 470 } else if (event == v8::Exception) { |
| 472 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackT
race(m_isolate, 1); | 471 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackT
race(m_isolate, 1); |
| 473 // Stack trace is empty in case of syntax error. Silently continue e
xecution in such cases. | 472 // Stack trace is empty in case of syntax error. Silently continue e
xecution in such cases. |
| 474 if (!stackTrace->GetFrameCount()) | 473 if (!stackTrace->GetFrameCount()) |
| 475 return; | 474 return; |
| 476 v8::Handle<v8::Object> eventData = eventDetails.GetEventData(); | 475 v8::Handle<v8::Object> eventData = eventDetails.GetEventData(); |
| 477 v8::Handle<v8::Value> exceptionGetterValue = eventData->Get(v8Atomic
String(m_isolate, "exception")); | 476 v8::Handle<v8::Value> exceptionGetterValue = eventData->Get(v8Atomic
String(m_isolate, "exception")); |
| 478 ASSERT(!exceptionGetterValue.IsEmpty() && exceptionGetterValue->IsFu
nction()); | 477 ASSERT(!exceptionGetterValue.IsEmpty() && exceptionGetterValue->IsFu
nction()); |
| 479 v8::Handle<v8::Value> exception = V8ScriptRunner::callInternalFuncti
on(v8::Handle<v8::Function>::Cast(exceptionGetterValue), eventData, 0, 0, m_isol
ate); | 478 v8::Handle<v8::Value> exception = V8ScriptRunner::callInternalFuncti
on(v8::Handle<v8::Function>::Cast(exceptionGetterValue), eventData, 0, 0, m_isol
ate); |
| 480 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), e
xception, v8::Handle<v8::Array>()); | 479 handleProgramBreak(ScriptState::from(eventContext), eventDetails.Get
ExecutionState(), exception, v8::Handle<v8::Array>()); |
| 481 } else if (event == v8::Break) { | 480 } else if (event == v8::Break) { |
| 482 v8::Handle<v8::Function> getBreakpointNumbersFunction = v8::Local<v8
::Function>::Cast(debuggerScript->Get(v8AtomicString(m_isolate, "getBreakpointNu
mbers"))); | 481 v8::Handle<v8::Function> getBreakpointNumbersFunction = v8::Local<v8
::Function>::Cast(debuggerScript->Get(v8AtomicString(m_isolate, "getBreakpointNu
mbers"))); |
| 483 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() }; | 482 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() }; |
| 484 v8::Handle<v8::Value> hitBreakpoints = V8ScriptRunner::callInternalF
unction(getBreakpointNumbersFunction, debuggerScript, WTF_ARRAY_LENGTH(argv), ar
gv, m_isolate); | 483 v8::Handle<v8::Value> hitBreakpoints = V8ScriptRunner::callInternalF
unction(getBreakpointNumbersFunction, debuggerScript, WTF_ARRAY_LENGTH(argv), ar
gv, m_isolate); |
| 485 ASSERT(hitBreakpoints->IsArray()); | 484 ASSERT(hitBreakpoints->IsArray()); |
| 486 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), v
8::Handle<v8::Value>(), hitBreakpoints.As<v8::Array>()); | 485 handleProgramBreak(ScriptState::from(eventContext), eventDetails.Get
ExecutionState(), v8::Handle<v8::Value>(), hitBreakpoints.As<v8::Array>()); |
| 487 } | 486 } |
| 488 } | 487 } |
| 489 } | 488 } |
| 490 | 489 |
| 491 void ScriptDebugServer::dispatchDidParseSource(ScriptDebugListener* listener, v8
::Handle<v8::Object> object) | 490 void ScriptDebugServer::dispatchDidParseSource(ScriptDebugListener* listener, v8
::Handle<v8::Object> object) |
| 492 { | 491 { |
| 493 v8::Handle<v8::Value> id = object->Get(v8AtomicString(m_isolate, "id")); | 492 v8::Handle<v8::Value> id = object->Get(v8AtomicString(m_isolate, "id")); |
| 494 ASSERT(!id.IsEmpty() && id->IsInt32()); | 493 ASSERT(!id.IsEmpty() && id->IsInt32()); |
| 495 String sourceID = String::number(id->Int32Value()); | 494 String sourceID = String::number(id->Int32Value()); |
| 496 | 495 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 v8::Handle<v8::Value>(v8::Integer::New(debuggerContext->GetIsolate(), sc
opeNumber)), | 548 v8::Handle<v8::Value>(v8::Integer::New(debuggerContext->GetIsolate(), sc
opeNumber)), |
| 550 v8String(debuggerContext->GetIsolate(), variableName), | 549 v8String(debuggerContext->GetIsolate(), variableName), |
| 551 newValue | 550 newValue |
| 552 }; | 551 }; |
| 553 return callDebuggerMethod("setFunctionVariableValue", 4, argv); | 552 return callDebuggerMethod("setFunctionVariableValue", 4, argv); |
| 554 } | 553 } |
| 555 | 554 |
| 556 | 555 |
| 557 bool ScriptDebugServer::isPaused() | 556 bool ScriptDebugServer::isPaused() |
| 558 { | 557 { |
| 559 return !m_pausedContext.IsEmpty(); | 558 return m_pausedScriptState; |
| 560 } | 559 } |
| 561 | 560 |
| 562 void ScriptDebugServer::compileScript(ScriptState* scriptState, const String& ex
pression, const String& sourceURL, String* scriptId, String* exceptionMessage) | 561 void ScriptDebugServer::compileScript(ScriptState* scriptState, const String& ex
pression, const String& sourceURL, String* scriptId, String* exceptionMessage) |
| 563 { | 562 { |
| 564 if (scriptState->contextIsEmpty()) | 563 if (scriptState->contextIsEmpty()) |
| 565 return; | 564 return; |
| 566 ScriptState::Scope scope(scriptState); | 565 ScriptState::Scope scope(scriptState); |
| 567 | 566 |
| 568 v8::Handle<v8::String> source = v8String(m_isolate, expression); | 567 v8::Handle<v8::String> source = v8String(m_isolate, expression); |
| 569 v8::TryCatch tryCatch; | 568 v8::TryCatch tryCatch; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 { | 617 { |
| 619 return PassOwnPtr<ScriptSourceCode>(); | 618 return PassOwnPtr<ScriptSourceCode>(); |
| 620 } | 619 } |
| 621 | 620 |
| 622 String ScriptDebugServer::preprocessEventListener(LocalFrame*, const String& sou
rce, const String& url, const String& functionName) | 621 String ScriptDebugServer::preprocessEventListener(LocalFrame*, const String& sou
rce, const String& url, const String& functionName) |
| 623 { | 622 { |
| 624 return source; | 623 return source; |
| 625 } | 624 } |
| 626 | 625 |
| 627 } // namespace WebCore | 626 } // namespace WebCore |
| OLD | NEW |