Index: src/inspector/v8-debugger.cc |
diff --git a/src/inspector/v8-debugger.cc b/src/inspector/v8-debugger.cc |
index 51346ed787e6ae509ae42fb11689077a8e0b867a..7c198d7b93550c1c7e2816007d72f0afeda70cff 100644 |
--- a/src/inspector/v8-debugger.cc |
+++ b/src/inspector/v8-debugger.cc |
@@ -68,12 +68,14 @@ void V8Debugger::enable() { |
if (m_enableCount++) return; |
DCHECK(!enabled()); |
v8::HandleScope scope(m_isolate); |
- v8::debug::SetDebugEventListener(m_isolate, &V8Debugger::v8DebugEventCallback, |
- v8::External::New(m_isolate, this)); |
v8::debug::SetAsyncTaskListener(m_isolate, &V8Debugger::v8AsyncTaskListener, |
this); |
v8::debug::SetCompileEventListener(m_isolate, |
&V8Debugger::v8CompileEventListener, this); |
+ v8::debug::SetBreakEventListener(m_isolate, &V8Debugger::v8BreakEventListener, |
+ this); |
+ v8::debug::SetExceptionEventListener( |
+ m_isolate, &V8Debugger::v8ExceptionEventListener, this); |
m_debuggerContext.Reset(m_isolate, v8::debug::GetDebugContext(m_isolate)); |
v8::debug::ChangeBreakOnException(m_isolate, v8::debug::NoBreakOnException); |
m_pauseOnExceptionsState = v8::debug::NoBreakOnException; |
@@ -88,9 +90,12 @@ void V8Debugger::disable() { |
m_debuggerContext.Reset(); |
allAsyncTasksCanceled(); |
m_wasmTranslation.Clear(); |
- v8::debug::SetDebugEventListener(m_isolate, nullptr); |
v8::debug::SetAsyncTaskListener(m_isolate, nullptr, nullptr); |
v8::debug::SetCompileEventListener(m_isolate, nullptr, nullptr); |
+ v8::debug::SetBreakEventListener(m_isolate, nullptr, nullptr); |
+ v8::debug::SetExceptionEventListener(m_isolate, nullptr, nullptr); |
+ v8::debug::SetBreakEventListener(m_isolate, nullptr, nullptr); |
jgruber
2017/01/17 08:55:11
Double copy-and-paste
|
+ v8::debug::SetExceptionEventListener(m_isolate, nullptr, nullptr); |
} |
bool V8Debugger::enabled() const { return !m_debuggerScript.IsEmpty(); } |
@@ -512,67 +517,6 @@ void V8Debugger::handleProgramBreak(v8::Local<v8::Context> pausedContext, |
} |
} |
-void V8Debugger::v8DebugEventCallback( |
- const v8::debug::EventDetails& eventDetails) { |
- V8Debugger* thisPtr = toV8Debugger(eventDetails.GetCallbackData()); |
- thisPtr->handleV8DebugEvent(eventDetails); |
-} |
- |
-v8::Local<v8::Value> V8Debugger::callInternalGetterFunction( |
- v8::Local<v8::Object> object, const char* functionName) { |
- v8::MicrotasksScope microtasks(m_isolate, |
- v8::MicrotasksScope::kDoNotRunMicrotasks); |
- v8::Local<v8::Value> getterValue = |
- object |
- ->Get(m_isolate->GetCurrentContext(), |
- toV8StringInternalized(m_isolate, functionName)) |
- .ToLocalChecked(); |
- DCHECK(!getterValue.IsEmpty() && getterValue->IsFunction()); |
- return v8::Local<v8::Function>::Cast(getterValue) |
- ->Call(m_isolate->GetCurrentContext(), object, 0, nullptr) |
- .ToLocalChecked(); |
-} |
- |
-void V8Debugger::handleV8DebugEvent( |
- const v8::debug::EventDetails& eventDetails) { |
- if (!enabled()) return; |
- v8::HandleScope scope(m_isolate); |
- |
- v8::DebugEvent event = eventDetails.GetEvent(); |
- if (event != v8::Break && event != v8::Exception) return; |
- |
- v8::Local<v8::Context> eventContext = eventDetails.GetEventContext(); |
- DCHECK(!eventContext.IsEmpty()); |
- V8DebuggerAgentImpl* agent = m_inspector->enabledDebuggerAgentForGroup( |
- m_inspector->contextGroupId(eventContext)); |
- if (!agent) return; |
- |
- if (event == v8::Exception) { |
- v8::Local<v8::Context> context = debuggerContext(); |
- v8::Local<v8::Object> eventData = eventDetails.GetEventData(); |
- v8::Local<v8::Value> exception = |
- callInternalGetterFunction(eventData, "exception"); |
- v8::Local<v8::Value> promise = |
- callInternalGetterFunction(eventData, "promise"); |
- bool isPromiseRejection = !promise.IsEmpty() && promise->IsObject(); |
- v8::Local<v8::Value> uncaught = |
- callInternalGetterFunction(eventData, "uncaught"); |
- bool isUncaught = uncaught->BooleanValue(context).FromJust(); |
- handleProgramBreak(eventContext, eventDetails.GetExecutionState(), |
- exception, v8::Local<v8::Array>(), isPromiseRejection, |
- isUncaught); |
- } else if (event == v8::Break) { |
- v8::Local<v8::Value> argv[] = {eventDetails.GetEventData()}; |
- v8::Local<v8::Value> hitBreakpoints; |
- if (!callDebuggerMethod("getBreakpointNumbers", 1, argv) |
- .ToLocal(&hitBreakpoints)) |
- return; |
- DCHECK(hitBreakpoints->IsArray()); |
- handleProgramBreak(eventContext, eventDetails.GetExecutionState(), |
- v8::Local<v8::Value>(), hitBreakpoints.As<v8::Array>()); |
- } |
-} |
- |
void V8Debugger::v8CompileEventListener(v8::Local<v8::debug::Script> script, |
bool has_compile_error, void* data) { |
V8Debugger* debugger = static_cast<V8Debugger*>(data); |
@@ -594,6 +538,33 @@ void V8Debugger::v8CompileEventListener(v8::Local<v8::debug::Script> script, |
} |
} |
+void V8Debugger::v8BreakEventListener(v8::Local<v8::Context> pausedContext, |
+ v8::Local<v8::Object> execState, |
+ v8::Local<v8::Value> breakPointsHit, |
+ void* data) { |
+ V8Debugger* debugger = static_cast<V8Debugger*>(data); |
+ v8::Local<v8::Value> argv[] = {breakPointsHit}; |
+ v8::Local<v8::Value> hitBreakpoints; |
+ if (!debugger->callDebuggerMethod("getBreakpointNumbers", 1, argv) |
+ .ToLocal(&hitBreakpoints)) { |
+ return; |
+ } |
+ DCHECK(hitBreakpoints->IsArray()); |
+ debugger->handleProgramBreak(pausedContext, execState, v8::Local<v8::Value>(), |
+ hitBreakpoints.As<v8::Array>()); |
+} |
+ |
+void V8Debugger::v8ExceptionEventListener(v8::Local<v8::Context> pausedContext, |
+ v8::Local<v8::Object> execState, |
+ v8::Local<v8::Value> exception, |
+ bool isPromiseRejection, |
+ bool isUncaught, void* data) { |
+ V8Debugger* debugger = static_cast<V8Debugger*>(data); |
+ debugger->handleProgramBreak(pausedContext, execState, exception, |
+ v8::Local<v8::Array>(), isPromiseRejection, |
+ isUncaught); |
+} |
+ |
void V8Debugger::v8AsyncTaskListener(v8::debug::PromiseDebugActionType type, |
int id, void* data) { |
V8Debugger* debugger = static_cast<V8Debugger*>(data); |