[inspector] introduce debug-interface.h
debug-interface.h contains part of v8-debug.h that is used by src/inspector. BUG=v8:5510 R=dgozman@chromium.org, yangguo@chromium.org Review-Url: https://codereview.chromium.org/2423713003 Cr-Commit-Position: refs/heads/master@{#40404}
This commit is contained in:
parent
7bbfe5c81a
commit
8bb2cef9c3
1
BUILD.gn
1
BUILD.gn
@ -1287,6 +1287,7 @@ v8_source_set("v8_base") {
|
||||
"src/debug/debug-evaluate.h",
|
||||
"src/debug/debug-frames.cc",
|
||||
"src/debug/debug-frames.h",
|
||||
"src/debug/debug-interface.h",
|
||||
"src/debug/debug-scopes.cc",
|
||||
"src/debug/debug-scopes.h",
|
||||
"src/debug/debug.cc",
|
||||
|
40
src/api.cc
40
src/api.cc
@ -8764,6 +8764,46 @@ MaybeLocal<Array> Debug::GetInternalProperties(Isolate* v8_isolate,
|
||||
return Utils::ToLocal(result);
|
||||
}
|
||||
|
||||
bool DebugInterface::SetDebugEventListener(Isolate* isolate,
|
||||
DebugInterface::EventCallback that,
|
||||
Local<Value> data) {
|
||||
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
||||
ENTER_V8(i_isolate);
|
||||
i::HandleScope scope(i_isolate);
|
||||
i::Handle<i::Object> foreign = i_isolate->factory()->undefined_value();
|
||||
if (that != NULL) {
|
||||
foreign = i_isolate->factory()->NewForeign(FUNCTION_ADDR(that));
|
||||
}
|
||||
i_isolate->debug()->SetEventListener(foreign, Utils::OpenHandle(*data, true));
|
||||
return true;
|
||||
}
|
||||
|
||||
Local<Context> DebugInterface::GetDebugContext(Isolate* isolate) {
|
||||
return Debug::GetDebugContext(isolate);
|
||||
}
|
||||
|
||||
MaybeLocal<Value> DebugInterface::Call(Local<Context> context,
|
||||
v8::Local<v8::Function> fun,
|
||||
v8::Local<v8::Value> data) {
|
||||
return Debug::Call(context, fun, data);
|
||||
}
|
||||
|
||||
void DebugInterface::SetLiveEditEnabled(Isolate* isolate, bool enable) {
|
||||
Debug::SetLiveEditEnabled(isolate, enable);
|
||||
}
|
||||
|
||||
void DebugInterface::DebugBreak(Isolate* isolate) {
|
||||
Debug::DebugBreak(isolate);
|
||||
}
|
||||
|
||||
void DebugInterface::CancelDebugBreak(Isolate* isolate) {
|
||||
Debug::CancelDebugBreak(isolate);
|
||||
}
|
||||
|
||||
MaybeLocal<Array> DebugInterface::GetInternalProperties(Isolate* isolate,
|
||||
Local<Value> value) {
|
||||
return Debug::GetInternalProperties(isolate, value);
|
||||
}
|
||||
|
||||
Local<String> CpuProfileNode::GetFunctionName() const {
|
||||
const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
|
||||
|
119
src/debug/debug-interface.h
Normal file
119
src/debug/debug-interface.h
Normal file
@ -0,0 +1,119 @@
|
||||
// Copyright 2016 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef V8_DEBUG_DEBUG_INTERFACE_H_
|
||||
#define V8_DEBUG_DEBUG_INTERFACE_H_
|
||||
|
||||
#include "include/v8-debug.h"
|
||||
#include "include/v8.h"
|
||||
|
||||
namespace v8 {
|
||||
|
||||
class DebugInterface {
|
||||
public:
|
||||
/**
|
||||
* An event details object passed to the debug event listener.
|
||||
*/
|
||||
class EventDetails : public v8::Debug::EventDetails {
|
||||
public:
|
||||
/**
|
||||
* Event type.
|
||||
*/
|
||||
virtual v8::DebugEvent GetEvent() const = 0;
|
||||
|
||||
/**
|
||||
* Access to execution state and event data of the debug event. Don't store
|
||||
* these cross callbacks as their content becomes invalid.
|
||||
*/
|
||||
virtual Local<Object> GetExecutionState() const = 0;
|
||||
virtual Local<Object> GetEventData() const = 0;
|
||||
|
||||
/**
|
||||
* Get the context active when the debug event happened. Note this is not
|
||||
* the current active context as the JavaScript part of the debugger is
|
||||
* running in its own context which is entered at this point.
|
||||
*/
|
||||
virtual Local<Context> GetEventContext() const = 0;
|
||||
|
||||
/**
|
||||
* Client data passed with the corresponding callback when it was
|
||||
* registered.
|
||||
*/
|
||||
virtual Local<Value> GetCallbackData() const = 0;
|
||||
|
||||
virtual ~EventDetails() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Debug event callback function.
|
||||
*
|
||||
* \param event_details object providing information about the debug event
|
||||
*
|
||||
* A EventCallback does not take possession of the event data,
|
||||
* and must not rely on the data persisting after the handler returns.
|
||||
*/
|
||||
typedef void (*EventCallback)(const EventDetails& event_details);
|
||||
|
||||
static bool SetDebugEventListener(Isolate* isolate, EventCallback that,
|
||||
Local<Value> data = Local<Value>());
|
||||
|
||||
/**
|
||||
* Debugger is running in its own context which is entered while debugger
|
||||
* messages are being dispatched. This is an explicit getter for this
|
||||
* debugger context. Note that the content of the debugger context is subject
|
||||
* to change. The Context exists only when the debugger is active, i.e. at
|
||||
* least one DebugEventListener or MessageHandler is set.
|
||||
*/
|
||||
static Local<Context> GetDebugContext(Isolate* isolate);
|
||||
|
||||
/**
|
||||
* Run a JavaScript function in the debugger.
|
||||
* \param fun the function to call
|
||||
* \param data passed as second argument to the function
|
||||
* With this call the debugger is entered and the function specified is called
|
||||
* with the execution state as the first argument. This makes it possible to
|
||||
* get access to information otherwise not available during normal JavaScript
|
||||
* execution e.g. details on stack frames. Receiver of the function call will
|
||||
* be the debugger context global object, however this is a subject to change.
|
||||
* The following example shows a JavaScript function which when passed to
|
||||
* v8::Debug::Call will return the current line of JavaScript execution.
|
||||
*
|
||||
* \code
|
||||
* function frame_source_line(exec_state) {
|
||||
* return exec_state.frame(0).sourceLine();
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
// TODO(dcarney): data arg should be a MaybeLocal
|
||||
static MaybeLocal<Value> Call(Local<Context> context,
|
||||
v8::Local<v8::Function> fun,
|
||||
Local<Value> data = Local<Value>());
|
||||
|
||||
/**
|
||||
* Enable/disable LiveEdit functionality for the given Isolate
|
||||
* (default Isolate if not provided). V8 will abort if LiveEdit is
|
||||
* unexpectedly used. LiveEdit is enabled by default.
|
||||
*/
|
||||
static void SetLiveEditEnabled(Isolate* isolate, bool enable);
|
||||
|
||||
// Schedule a debugger break to happen when JavaScript code is run
|
||||
// in the given isolate.
|
||||
static void DebugBreak(Isolate* isolate);
|
||||
|
||||
// Remove scheduled debugger break in given isolate if it has not
|
||||
// happened yet.
|
||||
static void CancelDebugBreak(Isolate* isolate);
|
||||
|
||||
/**
|
||||
* Returns array of internal properties specific to the value type. Result has
|
||||
* the following format: [<name>, <value>,...,<name>, <value>]. Result array
|
||||
* will be allocated in the current context.
|
||||
*/
|
||||
static MaybeLocal<Array> GetInternalProperties(Isolate* isolate,
|
||||
Local<Value> value);
|
||||
};
|
||||
|
||||
} // namespace v8
|
||||
|
||||
#endif // V8_DEBUG_DEBUG_INTERFACE_H_
|
@ -1841,8 +1841,8 @@ void Debug::CallEventCallback(v8::DebugEvent event,
|
||||
in_debug_event_listener_ = true;
|
||||
if (event_listener_->IsForeign()) {
|
||||
// Invoke the C debug event listener.
|
||||
v8::Debug::EventCallback callback =
|
||||
FUNCTION_CAST<v8::Debug::EventCallback>(
|
||||
v8::DebugInterface::EventCallback callback =
|
||||
FUNCTION_CAST<v8::DebugInterface::EventCallback>(
|
||||
Handle<Foreign>::cast(event_listener_)->foreign_address());
|
||||
EventDetailsImpl event_details(event,
|
||||
Handle<JSObject>::cast(exec_state),
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "src/base/atomicops.h"
|
||||
#include "src/base/hashmap.h"
|
||||
#include "src/base/platform/platform.h"
|
||||
#include "src/debug/debug-interface.h"
|
||||
#include "src/execution.h"
|
||||
#include "src/factory.h"
|
||||
#include "src/flags.h"
|
||||
@ -290,7 +291,7 @@ class MessageImpl: public v8::Debug::Message {
|
||||
|
||||
|
||||
// Details of the debug event delivered to the debug event listener.
|
||||
class EventDetailsImpl : public v8::Debug::EventDetails {
|
||||
class EventDetailsImpl : public v8::DebugInterface::EventDetails {
|
||||
public:
|
||||
EventDetailsImpl(DebugEvent event,
|
||||
Handle<JSObject> exec_state,
|
||||
|
@ -6,4 +6,6 @@ include_rules = [
|
||||
"+src/base/platform/platform.h",
|
||||
"+src/inspector",
|
||||
"+src/tracing",
|
||||
"-include/v8-debug.h",
|
||||
"+src/debug/debug-interface.h",
|
||||
]
|
||||
|
@ -30,10 +30,9 @@
|
||||
|
||||
#include "src/inspector/java-script-call-frame.h"
|
||||
|
||||
#include "src/debug/debug-interface.h"
|
||||
#include "src/inspector/string-util.h"
|
||||
|
||||
#include "include/v8-debug.h"
|
||||
|
||||
namespace v8_inspector {
|
||||
|
||||
JavaScriptCallFrame::JavaScriptCallFrame(v8::Local<v8::Context> debuggerContext,
|
||||
@ -130,10 +129,10 @@ v8::MaybeLocal<v8::Value> JavaScriptCallFrame::restart() {
|
||||
v8::Local<v8::Function> restartFunction = v8::Local<v8::Function>::Cast(
|
||||
callFrame->Get(context, toV8StringInternalized(m_isolate, "restart"))
|
||||
.ToLocalChecked());
|
||||
v8::Debug::SetLiveEditEnabled(m_isolate, true);
|
||||
v8::DebugInterface::SetLiveEditEnabled(m_isolate, true);
|
||||
v8::MaybeLocal<v8::Value> result = restartFunction->Call(
|
||||
m_debuggerContext.Get(m_isolate), callFrame, 0, nullptr);
|
||||
v8::Debug::SetLiveEditEnabled(m_isolate, false);
|
||||
v8::DebugInterface::SetLiveEditEnabled(m_isolate, false);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "src/debug/debug-interface.h"
|
||||
#include "src/inspector/injected-script.h"
|
||||
#include "src/inspector/inspected-context.h"
|
||||
#include "src/inspector/java-script-call-frame.h"
|
||||
@ -914,7 +915,7 @@ std::unique_ptr<Array<CallFrame>> V8DebuggerAgentImpl::currentCallFrames(
|
||||
ErrorString ignored;
|
||||
v8::HandleScope handles(m_isolate);
|
||||
v8::Local<v8::Context> debuggerContext =
|
||||
v8::Debug::GetDebugContext(m_isolate);
|
||||
v8::DebugInterface::GetDebugContext(m_isolate);
|
||||
v8::Context::Scope contextScope(debuggerContext);
|
||||
|
||||
v8::Local<v8::Array> objects = v8::Array::New(m_isolate);
|
||||
|
@ -63,9 +63,11 @@ void V8Debugger::enable() {
|
||||
if (m_enableCount++) return;
|
||||
DCHECK(!enabled());
|
||||
v8::HandleScope scope(m_isolate);
|
||||
v8::Debug::SetDebugEventListener(m_isolate, &V8Debugger::v8DebugEventCallback,
|
||||
v8::DebugInterface::SetDebugEventListener(m_isolate,
|
||||
&V8Debugger::v8DebugEventCallback,
|
||||
v8::External::New(m_isolate, this));
|
||||
m_debuggerContext.Reset(m_isolate, v8::Debug::GetDebugContext(m_isolate));
|
||||
m_debuggerContext.Reset(m_isolate,
|
||||
v8::DebugInterface::GetDebugContext(m_isolate));
|
||||
compileDebuggerScript();
|
||||
}
|
||||
|
||||
@ -76,7 +78,7 @@ void V8Debugger::disable() {
|
||||
m_debuggerScript.Reset();
|
||||
m_debuggerContext.Reset();
|
||||
allAsyncTasksCanceled();
|
||||
v8::Debug::SetDebugEventListener(m_isolate, nullptr);
|
||||
v8::DebugInterface::SetDebugEventListener(m_isolate, nullptr);
|
||||
}
|
||||
|
||||
bool V8Debugger::enabled() const { return !m_debuggerScript.IsEmpty(); }
|
||||
@ -171,7 +173,7 @@ String16 V8Debugger::setBreakpoint(const String16& sourceID,
|
||||
->Get(context, toV8StringInternalized(m_isolate, "setBreakpoint"))
|
||||
.ToLocalChecked());
|
||||
v8::Local<v8::Value> breakpointId =
|
||||
v8::Debug::Call(debuggerContext(), setBreakpointFunction, info)
|
||||
v8::DebugInterface::Call(debuggerContext(), setBreakpointFunction, info)
|
||||
.ToLocalChecked();
|
||||
if (!breakpointId->IsString()) return "";
|
||||
*actualLineNumber =
|
||||
@ -206,7 +208,7 @@ void V8Debugger::removeBreakpoint(const String16& breakpointId) {
|
||||
->Get(context,
|
||||
toV8StringInternalized(m_isolate, "removeBreakpoint"))
|
||||
.ToLocalChecked());
|
||||
v8::Debug::Call(debuggerContext(), removeBreakpointFunction, info)
|
||||
v8::DebugInterface::Call(debuggerContext(), removeBreakpointFunction, info)
|
||||
.ToLocalChecked();
|
||||
}
|
||||
|
||||
@ -219,7 +221,8 @@ void V8Debugger::clearBreakpoints() {
|
||||
m_debuggerScript.Get(m_isolate)
|
||||
->Get(context, toV8StringInternalized(m_isolate, "clearBreakpoints"))
|
||||
.ToLocalChecked());
|
||||
v8::Debug::Call(debuggerContext(), clearBreakpoints).ToLocalChecked();
|
||||
v8::DebugInterface::Call(debuggerContext(), clearBreakpoints)
|
||||
.ToLocalChecked();
|
||||
}
|
||||
|
||||
void V8Debugger::setBreakpointsActivated(bool activated) {
|
||||
@ -243,7 +246,7 @@ void V8Debugger::setBreakpointsActivated(bool activated) {
|
||||
->Get(context, toV8StringInternalized(m_isolate,
|
||||
"setBreakpointsActivated"))
|
||||
.ToLocalChecked());
|
||||
v8::Debug::Call(debuggerContext(), setBreakpointsActivated, info)
|
||||
v8::DebugInterface::Call(debuggerContext(), setBreakpointsActivated, info)
|
||||
.ToLocalChecked();
|
||||
|
||||
m_breakpointsActivated = activated;
|
||||
@ -276,9 +279,9 @@ void V8Debugger::setPauseOnExceptionsState(
|
||||
void V8Debugger::setPauseOnNextStatement(bool pause) {
|
||||
if (m_runningNestedMessageLoop) return;
|
||||
if (pause)
|
||||
v8::Debug::DebugBreak(m_isolate);
|
||||
v8::DebugInterface::DebugBreak(m_isolate);
|
||||
else
|
||||
v8::Debug::CancelDebugBreak(m_isolate);
|
||||
v8::DebugInterface::CancelDebugBreak(m_isolate);
|
||||
}
|
||||
|
||||
bool V8Debugger::canBreakProgram() {
|
||||
@ -306,7 +309,7 @@ void V8Debugger::breakProgram() {
|
||||
v8::ConstructorBehavior::kThrow)
|
||||
.ToLocal(&breakFunction))
|
||||
return;
|
||||
v8::Debug::Call(debuggerContext(), breakFunction).ToLocalChecked();
|
||||
v8::DebugInterface::Call(debuggerContext(), breakFunction).ToLocalChecked();
|
||||
}
|
||||
|
||||
void V8Debugger::continueProgram() {
|
||||
@ -359,11 +362,11 @@ bool V8Debugger::setScriptSource(
|
||||
class EnableLiveEditScope {
|
||||
public:
|
||||
explicit EnableLiveEditScope(v8::Isolate* isolate) : m_isolate(isolate) {
|
||||
v8::Debug::SetLiveEditEnabled(m_isolate, true);
|
||||
v8::DebugInterface::SetLiveEditEnabled(m_isolate, true);
|
||||
inLiveEditScope = true;
|
||||
}
|
||||
~EnableLiveEditScope() {
|
||||
v8::Debug::SetLiveEditEnabled(m_isolate, false);
|
||||
v8::DebugInterface::SetLiveEditEnabled(m_isolate, false);
|
||||
inLiveEditScope = false;
|
||||
}
|
||||
|
||||
@ -459,7 +462,7 @@ JavaScriptCallFrames V8Debugger::currentCallFrames(int limit) {
|
||||
toV8StringInternalized(m_isolate, "currentCallFrames"))
|
||||
.ToLocalChecked());
|
||||
currentCallFramesV8 =
|
||||
v8::Debug::Call(debuggerContext(), currentCallFramesFunction,
|
||||
v8::DebugInterface::Call(debuggerContext(), currentCallFramesFunction,
|
||||
v8::Integer::New(m_isolate, limit))
|
||||
.ToLocalChecked();
|
||||
} else {
|
||||
@ -559,7 +562,7 @@ void V8Debugger::handleProgramBreak(v8::Local<v8::Context> pausedContext,
|
||||
}
|
||||
|
||||
void V8Debugger::v8DebugEventCallback(
|
||||
const v8::Debug::EventDetails& eventDetails) {
|
||||
const v8::DebugInterface::EventDetails& eventDetails) {
|
||||
V8Debugger* thisPtr = toV8Debugger(eventDetails.GetCallbackData());
|
||||
thisPtr->handleV8DebugEvent(eventDetails);
|
||||
}
|
||||
@ -580,7 +583,7 @@ v8::Local<v8::Value> V8Debugger::callInternalGetterFunction(
|
||||
}
|
||||
|
||||
void V8Debugger::handleV8DebugEvent(
|
||||
const v8::Debug::EventDetails& eventDetails) {
|
||||
const v8::DebugInterface::EventDetails& eventDetails) {
|
||||
if (!enabled()) return;
|
||||
v8::DebugEvent event = eventDetails.GetEvent();
|
||||
if (event != v8::AsyncTaskEvent && event != v8::Break &&
|
||||
@ -729,7 +732,8 @@ v8::MaybeLocal<v8::Value> V8Debugger::functionScopes(
|
||||
v8::MaybeLocal<v8::Array> V8Debugger::internalProperties(
|
||||
v8::Local<v8::Context> context, v8::Local<v8::Value> value) {
|
||||
v8::Local<v8::Array> properties;
|
||||
if (!v8::Debug::GetInternalProperties(m_isolate, value).ToLocal(&properties))
|
||||
if (!v8::DebugInterface::GetInternalProperties(m_isolate, value)
|
||||
.ToLocal(&properties))
|
||||
return v8::MaybeLocal<v8::Array>();
|
||||
if (value->IsFunction()) {
|
||||
v8::Local<v8::Function> function = value.As<v8::Function>();
|
||||
|
@ -8,12 +8,12 @@
|
||||
#include <vector>
|
||||
|
||||
#include "src/base/macros.h"
|
||||
#include "src/debug/debug-interface.h"
|
||||
#include "src/inspector/java-script-call-frame.h"
|
||||
#include "src/inspector/protocol/Forward.h"
|
||||
#include "src/inspector/protocol/Runtime.h"
|
||||
#include "src/inspector/v8-debugger-script.h"
|
||||
|
||||
#include "include/v8-debug.h"
|
||||
#include "include/v8-inspector.h"
|
||||
|
||||
namespace v8_inspector {
|
||||
@ -114,10 +114,10 @@ class V8Debugger {
|
||||
v8::Local<v8::Value> exception,
|
||||
v8::Local<v8::Array> hitBreakpoints,
|
||||
bool isPromiseRejection = false);
|
||||
static void v8DebugEventCallback(const v8::Debug::EventDetails&);
|
||||
static void v8DebugEventCallback(const v8::DebugInterface::EventDetails&);
|
||||
v8::Local<v8::Value> callInternalGetterFunction(v8::Local<v8::Object>,
|
||||
const char* functionName);
|
||||
void handleV8DebugEvent(const v8::Debug::EventDetails&);
|
||||
void handleV8DebugEvent(const v8::DebugInterface::EventDetails&);
|
||||
void handleV8AsyncTaskEvent(v8::Local<v8::Context>,
|
||||
v8::Local<v8::Object> executionState,
|
||||
v8::Local<v8::Object> eventData);
|
||||
|
@ -824,6 +824,7 @@
|
||||
'dateparser.h',
|
||||
'debug/debug-evaluate.cc',
|
||||
'debug/debug-evaluate.h',
|
||||
'debug/debug-interface.h',
|
||||
'debug/debug-frames.cc',
|
||||
'debug/debug-frames.h',
|
||||
'debug/debug-scopes.cc',
|
||||
|
Loading…
Reference in New Issue
Block a user