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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 return nullptr; | 345 return nullptr; |
346 return JavaScriptCallFrame::create(v8::Debug::GetDebugContext(), v8::Handle<
v8::Object>::Cast(currentCallFrameV8)); | 346 return JavaScriptCallFrame::create(v8::Debug::GetDebugContext(), v8::Handle<
v8::Object>::Cast(currentCallFrameV8)); |
347 } | 347 } |
348 | 348 |
349 ScriptValue ScriptDebugServer::currentCallFramesInner(ScopeInfoDetails scopeDeta
ils) | 349 ScriptValue ScriptDebugServer::currentCallFramesInner(ScopeInfoDetails scopeDeta
ils) |
350 { | 350 { |
351 if (!m_isolate->InContext()) | 351 if (!m_isolate->InContext()) |
352 return ScriptValue(); | 352 return ScriptValue(); |
353 v8::HandleScope handleScope(m_isolate); | 353 v8::HandleScope handleScope(m_isolate); |
354 | 354 |
| 355 // Filter out stack traces entirely consisting of V8's internal scripts. |
| 356 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(m_i
solate, 1); |
| 357 if (!stackTrace->GetFrameCount()) |
| 358 return ScriptValue(); |
| 359 |
355 RefPtrWillBeRawPtr<JavaScriptCallFrame> currentCallFrame = wrapCallFrames(0,
scopeDetails); | 360 RefPtrWillBeRawPtr<JavaScriptCallFrame> currentCallFrame = wrapCallFrames(0,
scopeDetails); |
356 if (!currentCallFrame) | 361 if (!currentCallFrame) |
357 return ScriptValue(); | 362 return ScriptValue(); |
358 | 363 |
359 ScriptState* scriptState = m_pausedScriptState ? m_pausedScriptState.get() :
ScriptState::current(m_isolate); | 364 ScriptState* scriptState = m_pausedScriptState ? m_pausedScriptState.get() :
ScriptState::current(m_isolate); |
360 ScriptState::Scope scope(scriptState); | 365 ScriptState::Scope scope(scriptState); |
361 return ScriptValue(scriptState, toV8(currentCallFrame.release(), scriptState
->context()->Global(), m_isolate)); | 366 return ScriptValue(scriptState, toV8(currentCallFrame.release(), scriptState
->context()->Global(), m_isolate)); |
362 } | 367 } |
363 | 368 |
364 ScriptValue ScriptDebugServer::currentCallFrames() | 369 ScriptValue ScriptDebugServer::currentCallFrames() |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 callDebuggerMethod(stepOutV8MethodName, 1, argv); | 446 callDebuggerMethod(stepOutV8MethodName, 1, argv); |
442 } | 447 } |
443 } | 448 } |
444 | 449 |
445 void ScriptDebugServer::v8DebugEventCallback(const v8::Debug::EventDetails& even
tDetails) | 450 void ScriptDebugServer::v8DebugEventCallback(const v8::Debug::EventDetails& even
tDetails) |
446 { | 451 { |
447 ScriptDebugServer* thisPtr = toScriptDebugServer(eventDetails.GetCallbackDat
a()); | 452 ScriptDebugServer* thisPtr = toScriptDebugServer(eventDetails.GetCallbackDat
a()); |
448 thisPtr->handleV8DebugEvent(eventDetails); | 453 thisPtr->handleV8DebugEvent(eventDetails); |
449 } | 454 } |
450 | 455 |
| 456 static v8::Handle<v8::Value> callInternalGetterFunction(v8::Handle<v8::Object> o
bject, const char* functionName, v8::Isolate* isolate) |
| 457 { |
| 458 v8::Handle<v8::Value> getterValue = object->Get(v8AtomicString(isolate, func
tionName)); |
| 459 ASSERT(!getterValue.IsEmpty() && getterValue->IsFunction()); |
| 460 return V8ScriptRunner::callInternalFunction(v8::Handle<v8::Function>::Cast(g
etterValue), object, 0, 0, isolate); |
| 461 } |
| 462 |
451 void ScriptDebugServer::handleV8DebugEvent(const v8::Debug::EventDetails& eventD
etails) | 463 void ScriptDebugServer::handleV8DebugEvent(const v8::Debug::EventDetails& eventD
etails) |
452 { | 464 { |
453 v8::DebugEvent event = eventDetails.GetEvent(); | 465 v8::DebugEvent event = eventDetails.GetEvent(); |
454 | 466 |
455 if (event == v8::BreakForCommand) { | 467 if (event == v8::BreakForCommand) { |
456 ClientDataImpl* data = static_cast<ClientDataImpl*>(eventDetails.GetClie
ntData()); | 468 ClientDataImpl* data = static_cast<ClientDataImpl*>(eventDetails.GetClie
ntData()); |
457 data->task()->run(); | 469 data->task()->run(); |
458 return; | 470 return; |
459 } | 471 } |
460 | 472 |
461 if (event != v8::Break && event != v8::Exception && event != v8::AfterCompil
e && event != v8::BeforeCompile) | 473 if (event != v8::AsyncTaskEvent && event != v8::Break && event != v8::Except
ion && event != v8::AfterCompile && event != v8::BeforeCompile) |
462 return; | 474 return; |
463 | 475 |
464 v8::Handle<v8::Context> eventContext = eventDetails.GetEventContext(); | 476 v8::Handle<v8::Context> eventContext = eventDetails.GetEventContext(); |
465 ASSERT(!eventContext.IsEmpty()); | 477 ASSERT(!eventContext.IsEmpty()); |
466 | 478 |
467 ScriptDebugListener* listener = getDebugListenerForContext(eventContext); | 479 ScriptDebugListener* listener = getDebugListenerForContext(eventContext); |
468 if (listener) { | 480 if (listener) { |
469 v8::HandleScope scope(m_isolate); | 481 v8::HandleScope scope(m_isolate); |
470 v8::Handle<v8::Object> debuggerScript = m_debuggerScript.newLocal(m_isol
ate); | 482 v8::Handle<v8::Object> debuggerScript = m_debuggerScript.newLocal(m_isol
ate); |
471 if (event == v8::BeforeCompile) { | 483 if (event == v8::BeforeCompile) { |
472 preprocessBeforeCompile(eventDetails); | 484 preprocessBeforeCompile(eventDetails); |
473 } else if (event == v8::AfterCompile) { | 485 } else if (event == v8::AfterCompile) { |
474 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); | 486 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); |
475 v8::Handle<v8::Function> getAfterCompileScript = v8::Local<v8::Funct
ion>::Cast(debuggerScript->Get(v8AtomicString(m_isolate, "getAfterCompileScript"
))); | 487 v8::Handle<v8::Function> getAfterCompileScript = v8::Local<v8::Funct
ion>::Cast(debuggerScript->Get(v8AtomicString(m_isolate, "getAfterCompileScript"
))); |
476 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() }; | 488 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() }; |
477 v8::Handle<v8::Value> value = V8ScriptRunner::callInternalFunction(g
etAfterCompileScript, debuggerScript, WTF_ARRAY_LENGTH(argv), argv, m_isolate); | 489 v8::Handle<v8::Value> value = V8ScriptRunner::callInternalFunction(g
etAfterCompileScript, debuggerScript, WTF_ARRAY_LENGTH(argv), argv, m_isolate); |
478 ASSERT(value->IsObject()); | 490 ASSERT(value->IsObject()); |
479 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value); | 491 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value); |
480 dispatchDidParseSource(listener, object); | 492 dispatchDidParseSource(listener, object); |
481 } else if (event == v8::Exception) { | 493 } else if (event == v8::Exception) { |
482 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackT
race(m_isolate, 1); | 494 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackT
race(m_isolate, 1); |
483 // Stack trace is empty in case of syntax error. Silently continue e
xecution in such cases. | 495 // Stack trace is empty in case of syntax error. Silently continue e
xecution in such cases. |
484 if (!stackTrace->GetFrameCount()) | 496 if (!stackTrace->GetFrameCount()) |
485 return; | 497 return; |
486 v8::Handle<v8::Object> eventData = eventDetails.GetEventData(); | 498 v8::Handle<v8::Object> eventData = eventDetails.GetEventData(); |
487 v8::Handle<v8::Value> exceptionGetterValue = eventData->Get(v8Atomic
String(m_isolate, "exception")); | 499 v8::Handle<v8::Value> exception = callInternalGetterFunction(eventDa
ta, "exception", m_isolate); |
488 ASSERT(!exceptionGetterValue.IsEmpty() && exceptionGetterValue->IsFu
nction()); | |
489 v8::Handle<v8::Value> exception = V8ScriptRunner::callInternalFuncti
on(v8::Handle<v8::Function>::Cast(exceptionGetterValue), eventData, 0, 0, m_isol
ate); | |
490 handleProgramBreak(ScriptState::from(eventContext), eventDetails.Get
ExecutionState(), exception, v8::Handle<v8::Array>()); | 500 handleProgramBreak(ScriptState::from(eventContext), eventDetails.Get
ExecutionState(), exception, v8::Handle<v8::Array>()); |
491 } else if (event == v8::Break) { | 501 } else if (event == v8::Break) { |
492 v8::Handle<v8::Function> getBreakpointNumbersFunction = v8::Local<v8
::Function>::Cast(debuggerScript->Get(v8AtomicString(m_isolate, "getBreakpointNu
mbers"))); | 502 v8::Handle<v8::Function> getBreakpointNumbersFunction = v8::Local<v8
::Function>::Cast(debuggerScript->Get(v8AtomicString(m_isolate, "getBreakpointNu
mbers"))); |
493 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() }; | 503 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() }; |
494 v8::Handle<v8::Value> hitBreakpoints = V8ScriptRunner::callInternalF
unction(getBreakpointNumbersFunction, debuggerScript, WTF_ARRAY_LENGTH(argv), ar
gv, m_isolate); | 504 v8::Handle<v8::Value> hitBreakpoints = V8ScriptRunner::callInternalF
unction(getBreakpointNumbersFunction, debuggerScript, WTF_ARRAY_LENGTH(argv), ar
gv, m_isolate); |
495 ASSERT(hitBreakpoints->IsArray()); | 505 ASSERT(hitBreakpoints->IsArray()); |
496 handleProgramBreak(ScriptState::from(eventContext), eventDetails.Get
ExecutionState(), v8::Handle<v8::Value>(), hitBreakpoints.As<v8::Array>()); | 506 handleProgramBreak(ScriptState::from(eventContext), eventDetails.Get
ExecutionState(), v8::Handle<v8::Value>(), hitBreakpoints.As<v8::Array>()); |
| 507 } else if (event == v8::AsyncTaskEvent) { |
| 508 handleV8AsyncTaskEvent(listener, ScriptState::from(eventContext), ev
entDetails.GetExecutionState(), eventDetails.GetEventData()); |
497 } | 509 } |
498 } | 510 } |
499 } | 511 } |
500 | 512 |
| 513 void ScriptDebugServer::handleV8AsyncTaskEvent(ScriptDebugListener* listener, Sc
riptState* pausedScriptState, v8::Handle<v8::Object> executionState, v8::Handle<
v8::Object> eventData) |
| 514 { |
| 515 String type = toCoreStringWithUndefinedOrNullCheck(callInternalGetterFunctio
n(eventData, "type", m_isolate)); |
| 516 String name = toCoreStringWithUndefinedOrNullCheck(callInternalGetterFunctio
n(eventData, "name", m_isolate)); |
| 517 int id = callInternalGetterFunction(eventData, "id", m_isolate)->ToInteger()
->Value(); |
| 518 |
| 519 // FIXME: Remove when not needed. |
| 520 if (name == "Promise.Resolved") |
| 521 name = "Promise.resolve"; |
| 522 else if (name == "Promise.Rejected") |
| 523 name = "Promise.reject"; |
| 524 |
| 525 m_pausedScriptState = pausedScriptState; |
| 526 m_executionState = executionState; |
| 527 listener->didReceiveV8AsyncTaskEvent(pausedScriptState->executionContext(),
type, name, id); |
| 528 m_pausedScriptState.clear(); |
| 529 m_executionState.Clear(); |
| 530 } |
| 531 |
501 void ScriptDebugServer::dispatchDidParseSource(ScriptDebugListener* listener, v8
::Handle<v8::Object> object) | 532 void ScriptDebugServer::dispatchDidParseSource(ScriptDebugListener* listener, v8
::Handle<v8::Object> object) |
502 { | 533 { |
503 v8::Handle<v8::Value> id = object->Get(v8AtomicString(m_isolate, "id")); | 534 v8::Handle<v8::Value> id = object->Get(v8AtomicString(m_isolate, "id")); |
504 ASSERT(!id.IsEmpty() && id->IsInt32()); | 535 ASSERT(!id.IsEmpty() && id->IsInt32()); |
505 String sourceID = String::number(id->Int32Value()); | 536 String sourceID = String::number(id->Int32Value()); |
506 | 537 |
507 ScriptDebugListener::Script script; | 538 ScriptDebugListener::Script script; |
508 script.url = toCoreStringWithUndefinedOrNullCheck(object->Get(v8AtomicString
(m_isolate, "name"))); | 539 script.url = toCoreStringWithUndefinedOrNullCheck(object->Get(v8AtomicString
(m_isolate, "name"))); |
509 script.source = toCoreStringWithUndefinedOrNullCheck(object->Get(v8AtomicStr
ing(m_isolate, "source"))); | 540 script.source = toCoreStringWithUndefinedOrNullCheck(object->Get(v8AtomicStr
ing(m_isolate, "source"))); |
510 script.sourceMappingURL = toCoreStringWithUndefinedOrNullCheck(object->Get(v
8AtomicString(m_isolate, "sourceMappingURL"))); | 541 script.sourceMappingURL = toCoreStringWithUndefinedOrNullCheck(object->Get(v
8AtomicString(m_isolate, "sourceMappingURL"))); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 { | 673 { |
643 return PassOwnPtr<ScriptSourceCode>(); | 674 return PassOwnPtr<ScriptSourceCode>(); |
644 } | 675 } |
645 | 676 |
646 String ScriptDebugServer::preprocessEventListener(LocalFrame*, const String& sou
rce, const String& url, const String& functionName) | 677 String ScriptDebugServer::preprocessEventListener(LocalFrame*, const String& sou
rce, const String& url, const String& functionName) |
647 { | 678 { |
648 return source; | 679 return source; |
649 } | 680 } |
650 | 681 |
651 } // namespace WebCore | 682 } // namespace WebCore |
OLD | NEW |