| 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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 v8::Local<v8::Object> resultTuple = v8result->ToObject(); | 285 v8::Local<v8::Object> resultTuple = v8result->ToObject(); |
| 286 int code = static_cast<int>(resultTuple->Get(0)->ToInteger()->Value()); | 286 int code = static_cast<int>(resultTuple->Get(0)->ToInteger()->Value()); |
| 287 switch (code) { | 287 switch (code) { |
| 288 case 0: | 288 case 0: |
| 289 { | 289 { |
| 290 v8::Local<v8::Value> normalResult = resultTuple->Get(1); | 290 v8::Local<v8::Value> normalResult = resultTuple->Get(1); |
| 291 if (normalResult->IsObject()) | 291 if (normalResult->IsObject()) |
| 292 *result = ScriptObject(ScriptState::current(), normalResult->ToO
bject()); | 292 *result = ScriptObject(ScriptState::current(), normalResult->ToO
bject()); |
| 293 // Call stack may have changed after if the edited function was on t
he stack. | 293 // Call stack may have changed after if the edited function was on t
he stack. |
| 294 if (!preview && isPaused()) | 294 if (!preview && isPaused()) |
| 295 *newCallFrames = currentCallFrame(); | 295 *newCallFrames = currentCallFrames(); |
| 296 return true; | 296 return true; |
| 297 } | 297 } |
| 298 // Compile error. | 298 // Compile error. |
| 299 case 1: | 299 case 1: |
| 300 { | 300 { |
| 301 RefPtr<TypeBuilder::Debugger::SetScriptSourceError::CompileError> co
mpileError = | 301 RefPtr<TypeBuilder::Debugger::SetScriptSourceError::CompileError> co
mpileError = |
| 302 TypeBuilder::Debugger::SetScriptSourceError::CompileError::creat
e() | 302 TypeBuilder::Debugger::SetScriptSourceError::CompileError::creat
e() |
| 303 .setMessage(toWebCoreStringWithUndefinedOrNullCheck(resultTu
ple->Get(2))) | 303 .setMessage(toWebCoreStringWithUndefinedOrNullCheck(resultTu
ple->Get(2))) |
| 304 .setLineNumber(resultTuple->Get(3)->ToInteger()->Value()) | 304 .setLineNumber(resultTuple->Get(3)->ToInteger()->Value()) |
| 305 .setColumnNumber(resultTuple->Get(4)->ToInteger()->Value()); | 305 .setColumnNumber(resultTuple->Get(4)->ToInteger()->Value()); |
| 306 | 306 |
| 307 *error = toWebCoreStringWithUndefinedOrNullCheck(resultTuple->Get(1)
); | 307 *error = toWebCoreStringWithUndefinedOrNullCheck(resultTuple->Get(1)
); |
| 308 errorData = TypeBuilder::Debugger::SetScriptSourceError::create(); | 308 errorData = TypeBuilder::Debugger::SetScriptSourceError::create(); |
| 309 errorData->setCompileError(compileError); | 309 errorData->setCompileError(compileError); |
| 310 return false; | 310 return false; |
| 311 } | 311 } |
| 312 } | 312 } |
| 313 *error = "Unknown error."; | 313 *error = "Unknown error."; |
| 314 return false; | 314 return false; |
| 315 } | 315 } |
| 316 | 316 |
| 317 | |
| 318 void ScriptDebugServer::updateCallStack(ScriptValue* callFrame) | |
| 319 { | |
| 320 if (isPaused()) | |
| 321 *callFrame = currentCallFrame(); | |
| 322 } | |
| 323 | |
| 324 PassRefPtr<JavaScriptCallFrame> ScriptDebugServer::wrapCallFrames(v8::Handle<v8:
:Object> executionState, int maximumLimit) | 317 PassRefPtr<JavaScriptCallFrame> ScriptDebugServer::wrapCallFrames(v8::Handle<v8:
:Object> executionState, int maximumLimit) |
| 325 { | 318 { |
| 326 v8::Handle<v8::Value> argv[] = { executionState, v8::Integer::New(maximumLim
it, m_isolate) }; | 319 v8::Handle<v8::Value> currentCallFrameV8; |
| 327 v8::Handle<v8::Value> currentCallFrameV8 = callDebuggerMethod("currentCallFr
ame", 2, argv); | 320 if (executionState.IsEmpty()) { |
| 328 | 321 v8::Handle<v8::Function> currentCallFrameFunction = v8::Local<v8::Functi
on>::Cast(m_debuggerScript.newLocal(m_isolate)->Get(v8AtomicString(m_isolate, "c
urrentCallFrame"))); |
| 322 currentCallFrameV8 = v8::Debug::Call(currentCallFrameFunction, v8::Integ
er::New(maximumLimit, m_isolate)); |
| 323 } else { |
| 324 v8::Handle<v8::Value> argv[] = { executionState, v8::Integer::New(maximu
mLimit, m_isolate) }; |
| 325 currentCallFrameV8 = callDebuggerMethod("currentCallFrame", 2, argv); |
| 326 } |
| 329 ASSERT(!currentCallFrameV8.IsEmpty()); | 327 ASSERT(!currentCallFrameV8.IsEmpty()); |
| 330 if (!currentCallFrameV8->IsObject()) | 328 if (!currentCallFrameV8->IsObject()) |
| 331 return PassRefPtr<JavaScriptCallFrame>(); | 329 return PassRefPtr<JavaScriptCallFrame>(); |
| 332 return JavaScriptCallFrame::create(v8::Debug::GetDebugContext(), v8::Handle<
v8::Object>::Cast(currentCallFrameV8)); | 330 return JavaScriptCallFrame::create(v8::Debug::GetDebugContext(), v8::Handle<
v8::Object>::Cast(currentCallFrameV8)); |
| 333 } | 331 } |
| 334 | 332 |
| 335 ScriptValue ScriptDebugServer::currentCallFrame() | 333 ScriptValue ScriptDebugServer::currentCallFrames() |
| 336 { | 334 { |
| 337 ASSERT(isPaused()); | |
| 338 v8::HandleScope handleScope(m_isolate); | 335 v8::HandleScope handleScope(m_isolate); |
| 339 RefPtr<JavaScriptCallFrame> currentCallFrame = wrapCallFrames(m_executionSta
te.newLocal(m_isolate), -1); | 336 RefPtr<JavaScriptCallFrame> currentCallFrame = wrapCallFrames(m_executionSta
te.newLocal(m_isolate), -1); |
| 340 if (!currentCallFrame) | 337 if (!currentCallFrame) |
| 341 return ScriptValue(v8::Null(m_isolate), m_isolate); | 338 return ScriptValue(v8::Null(m_isolate), m_isolate); |
| 342 v8::Context::Scope contextScope(m_pausedContext); | 339 |
| 343 return ScriptValue(toV8(currentCallFrame.release(), v8::Handle<v8::Object>()
, m_pausedContext->GetIsolate()), m_pausedContext->GetIsolate()); | 340 v8::HandleScope scope(m_isolate); |
| 341 v8::Handle<v8::Context> pausedContext = m_pausedContext.IsEmpty() ? m_isolat
e->GetCurrentContext() : m_pausedContext; |
| 342 if (pausedContext.IsEmpty()) |
| 343 return ScriptValue(v8::Null(m_isolate), m_isolate); |
| 344 |
| 345 v8::Context::Scope contextScope(pausedContext); |
| 346 return ScriptValue(toV8(currentCallFrame.release(), v8::Handle<v8::Object>()
, pausedContext->GetIsolate()), pausedContext->GetIsolate()); |
| 344 } | 347 } |
| 345 | 348 |
| 346 void ScriptDebugServer::interruptAndRun(PassOwnPtr<Task> task, v8::Isolate* isol
ate) | 349 void ScriptDebugServer::interruptAndRun(PassOwnPtr<Task> task, v8::Isolate* isol
ate) |
| 347 { | 350 { |
| 348 v8::Debug::DebugBreakForCommand(new ClientDataImpl(task), isolate); | 351 v8::Debug::DebugBreakForCommand(new ClientDataImpl(task), isolate); |
| 349 } | 352 } |
| 350 | 353 |
| 351 void ScriptDebugServer::runPendingTasks() | 354 void ScriptDebugServer::runPendingTasks() |
| 352 { | 355 { |
| 353 v8::Debug::ProcessDebugMessages(); | 356 v8::Debug::ProcessDebugMessages(); |
| 354 } | 357 } |
| 355 | 358 |
| 356 static ScriptDebugServer* toScriptDebugServer(v8::Handle<v8::Value> data) | 359 static ScriptDebugServer* toScriptDebugServer(v8::Handle<v8::Value> data) |
| 357 { | 360 { |
| 358 void* p = v8::Handle<v8::External>::Cast(data)->Value(); | 361 void* p = v8::Handle<v8::External>::Cast(data)->Value(); |
| 359 return static_cast<ScriptDebugServer*>(p); | 362 return static_cast<ScriptDebugServer*>(p); |
| 360 } | 363 } |
| 361 | 364 |
| 362 void ScriptDebugServer::breakProgramCallback(const v8::FunctionCallbackInfo<v8::
Value>& info) | 365 void ScriptDebugServer::breakProgramCallback(const v8::FunctionCallbackInfo<v8::
Value>& info) |
| 363 { | 366 { |
| 364 ASSERT(2 == info.Length()); | 367 ASSERT(2 == info.Length()); |
| 365 | |
| 366 ScriptDebugServer* thisPtr = toScriptDebugServer(info.Data()); | 368 ScriptDebugServer* thisPtr = toScriptDebugServer(info.Data()); |
| 367 v8::Handle<v8::Value> exception; | 369 v8::Handle<v8::Value> exception; |
| 368 v8::Handle<v8::Array> hitBreakpoints; | 370 v8::Handle<v8::Array> hitBreakpoints; |
| 369 thisPtr->handleProgramBreak(v8::Handle<v8::Object>::Cast(info[0]), exception
, hitBreakpoints); | 371 thisPtr->handleProgramBreak(v8::Handle<v8::Object>::Cast(info[0]), exception
, hitBreakpoints); |
| 370 } | 372 } |
| 371 | 373 |
| 372 void ScriptDebugServer::handleProgramBreak(v8::Handle<v8::Object> executionState
, v8::Handle<v8::Value> exception, v8::Handle<v8::Array> hitBreakpointNumbers) | 374 void ScriptDebugServer::handleProgramBreak(v8::Handle<v8::Object> executionState
, v8::Handle<v8::Value> exception, v8::Handle<v8::Array> hitBreakpointNumbers) |
| 373 { | 375 { |
| 374 // Don't allow nested breaks. | 376 // Don't allow nested breaks. |
| 375 if (isPaused()) | 377 if (isPaused()) |
| 376 return; | 378 return; |
| 377 | 379 |
| 378 ScriptDebugListener* listener = getDebugListenerForContext(m_pausedContext); | 380 ScriptDebugListener* listener = getDebugListenerForContext(m_pausedContext); |
| 379 if (!listener) | 381 if (!listener) |
| 380 return; | 382 return; |
| 381 | 383 |
| 382 Vector<String> breakpointIds; | 384 Vector<String> breakpointIds; |
| 383 if (!hitBreakpointNumbers.IsEmpty()) { | 385 if (!hitBreakpointNumbers.IsEmpty()) { |
| 384 breakpointIds.resize(hitBreakpointNumbers->Length()); | 386 breakpointIds.resize(hitBreakpointNumbers->Length()); |
| 385 for (size_t i = 0; i < hitBreakpointNumbers->Length(); i++) | 387 for (size_t i = 0; i < hitBreakpointNumbers->Length(); i++) |
| 386 breakpointIds[i] = toWebCoreStringWithUndefinedOrNullCheck(hitBreakp
ointNumbers->Get(i)); | 388 breakpointIds[i] = toWebCoreStringWithUndefinedOrNullCheck(hitBreakp
ointNumbers->Get(i)); |
| 387 } | 389 } |
| 388 | 390 |
| 389 m_executionState.set(m_isolate, executionState); | 391 m_executionState.set(m_isolate, executionState); |
| 390 ScriptState* currentCallFrameState = ScriptState::forContext(m_pausedContext
); | 392 ScriptState* currentCallFrameState = ScriptState::forContext(m_pausedContext
); |
| 391 listener->didPause(currentCallFrameState, currentCallFrame(), ScriptValue(ex
ception, currentCallFrameState->isolate()), breakpointIds); | 393 listener->didPause(currentCallFrameState, currentCallFrames(), ScriptValue(e
xception, currentCallFrameState->isolate()), breakpointIds); |
| 392 | 394 |
| 393 m_runningNestedMessageLoop = true; | 395 m_runningNestedMessageLoop = true; |
| 394 runMessageLoopOnPause(m_pausedContext); | 396 runMessageLoopOnPause(m_pausedContext); |
| 395 m_runningNestedMessageLoop = false; | 397 m_runningNestedMessageLoop = false; |
| 396 } | 398 } |
| 397 | 399 |
| 398 void ScriptDebugServer::handleProgramBreak(const v8::Debug::EventDetails& eventD
etails, v8::Handle<v8::Value> exception, v8::Handle<v8::Array> hitBreakpointNumb
ers) | 400 void ScriptDebugServer::handleProgramBreak(const v8::Debug::EventDetails& eventD
etails, v8::Handle<v8::Value> exception, v8::Handle<v8::Array> hitBreakpointNumb
ers) |
| 399 { | 401 { |
| 400 m_pausedContext = eventDetails.GetEventContext(); | 402 m_pausedContext = eventDetails.GetEventContext(); |
| 401 handleProgramBreak(eventDetails.GetExecutionState(), exception, hitBreakpoin
tNumbers); | 403 handleProgramBreak(eventDetails.GetExecutionState(), exception, hitBreakpoin
tNumbers); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 { | 618 { |
| 617 return PassOwnPtr<ScriptSourceCode>(); | 619 return PassOwnPtr<ScriptSourceCode>(); |
| 618 } | 620 } |
| 619 | 621 |
| 620 String ScriptDebugServer::preprocessEventListener(Frame*, const String& source,
const String& url, const String& functionName) | 622 String ScriptDebugServer::preprocessEventListener(Frame*, const String& source,
const String& url, const String& functionName) |
| 621 { | 623 { |
| 622 return source; | 624 return source; |
| 623 } | 625 } |
| 624 | 626 |
| 625 } // namespace WebCore | 627 } // namespace WebCore |
| OLD | NEW |