Commit d920bf37 authored by Alexey Kozyatinskiy's avatar Alexey Kozyatinskiy Committed by Commit Bot

[inspector] removed last usage of debugger context on inspector side

This is another step to remove a huge amount of legacy code from v8.

R=dgozman@chromium.org

Bug: v8:5530
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I634bda41c53a49dc4912291eb52f02847f56f4f3
Reviewed-on: https://chromium-review.googlesource.com/1080398Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53459}
parent 6636f7cc
......@@ -9100,29 +9100,6 @@ v8_inspector::V8Inspector* debug::GetInspector(Isolate* isolate) {
return reinterpret_cast<i::Isolate*>(isolate)->inspector();
}
Local<Context> debug::GetDebugContext(Isolate* isolate) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
return Utils::ToLocal(i_isolate->debug()->GetDebugContext());
}
MaybeLocal<Value> debug::Call(Local<Context> context,
v8::Local<v8::Function> fun,
v8::Local<v8::Value> data) {
PREPARE_FOR_EXECUTION(context, Debug, Call, Value);
i::Handle<i::Object> data_obj;
if (data.IsEmpty()) {
data_obj = isolate->factory()->undefined_value();
} else {
data_obj = Utils::OpenHandle(*data);
}
Local<Value> result;
has_pending_exception = !ToLocal<Value>(
isolate->debug()->Call(Utils::OpenHandle(*fun), data_obj), &result);
RETURN_ON_FAILED_EXECUTION(Value);
RETURN_ESCAPED(result);
}
void debug::SetLiveEditEnabled(Isolate* isolate, bool enable) {
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
internal_isolate->debug()->set_live_edit_enabled(enable);
......
......@@ -33,37 +33,6 @@ int GetContextId(Local<Context> context);
void SetInspector(Isolate* isolate, v8_inspector::V8Inspector*);
v8_inspector::V8Inspector* GetInspector(Isolate* isolate);
/**
* 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.
*/
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
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
......
......@@ -717,9 +717,12 @@ Response V8DebuggerAgentImpl::getPossibleBreakpoints(
std::vector<v8::debug::BreakLocation> v8Locations;
{
v8::HandleScope handleScope(m_isolate);
v8::Local<v8::Context> debuggerContext =
v8::debug::GetDebugContext(m_isolate);
v8::Context::Scope contextScope(debuggerContext);
int contextId = it->second->executionContextId();
InspectedContext* inspected = m_inspector->getContext(contextId);
if (!inspected) {
return Response::Error("Cannot retrive script context");
}
v8::Context::Scope contextScope(inspected->context());
v8::MicrotasksScope microtasks(m_isolate,
v8::MicrotasksScope::kDoNotRunMicrotasks);
v8::TryCatch tryCatch(m_isolate);
......
......@@ -533,9 +533,6 @@ void V8Debugger::handleProgramBreak(
});
{
v8::Context::Scope scope(pausedContext);
v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
CHECK(!context.IsEmpty() &&
context != v8::debug::GetDebugContext(m_isolate));
m_inspector->client()->runMessageLoopOnPause(contextGroupId);
m_pausedContextGroupId = 0;
}
......
......@@ -4646,214 +4646,6 @@ TEST(SetDebugEventListenerOnUninitializedVM) {
EnableDebugger(CcTest::isolate());
}
// Source for a JavaScript function which returns the data parameter of a
// function called in the context of the debugger. If no data parameter is
// passed it throws an exception.
static const char* debugger_call_with_data_source =
"function debugger_call_with_data(exec_state, data) {"
" if (data) return data;"
" throw 'No data!'"
"}";
v8::Local<v8::Function> debugger_call_with_data;
// Source for a JavaScript function which returns the data parameter of a
// function called in the context of the debugger. If no data parameter is
// passed it throws an exception.
static const char* debugger_call_with_closure_source =
"var x = 3;"
"(function (exec_state) {"
" if (exec_state.y) return x - 1;"
" exec_state.y = x;"
" return exec_state.y"
"})";
v8::Local<v8::Function> debugger_call_with_closure;
// Function to retrieve the number of JavaScript frames by calling a JavaScript
// in the debugger.
static void CheckFrameCount(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext();
CHECK(v8::debug::Call(context, frame_count).ToLocalChecked()->IsNumber());
CHECK_EQ(args[0]->Int32Value(context).FromJust(),
v8::debug::Call(context, frame_count)
.ToLocalChecked()
->Int32Value(context)
.FromJust());
}
// Function to retrieve the source line of the top JavaScript frame by calling a
// JavaScript function in the debugger.
static void CheckSourceLine(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext();
CHECK(
v8::debug::Call(context, frame_source_line).ToLocalChecked()->IsNumber());
CHECK_EQ(args[0]->Int32Value(context).FromJust(),
v8::debug::Call(context, frame_source_line)
.ToLocalChecked()
->Int32Value(context)
.FromJust());
}
// Function to test passing an additional parameter to a JavaScript function
// called in the debugger. It also tests that functions called in the debugger
// can throw exceptions.
static void CheckDataParameter(
const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Local<v8::String> data = v8_str(args.GetIsolate(), "Test");
v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext();
CHECK(v8::debug::Call(context, debugger_call_with_data, data)
.ToLocalChecked()
->IsString());
for (int i = 0; i < 3; i++) {
v8::TryCatch catcher(args.GetIsolate());
CHECK(v8::debug::Call(context, debugger_call_with_data).IsEmpty());
CHECK(catcher.HasCaught());
CHECK(catcher.Exception()->IsString());
}
}
// Function to test using a JavaScript with closure in the debugger.
static void CheckClosure(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext();
CHECK(v8::debug::Call(context, debugger_call_with_closure)
.ToLocalChecked()
->IsNumber());
CHECK_EQ(3, v8::debug::Call(context, debugger_call_with_closure)
.ToLocalChecked()
->Int32Value(context)
.FromJust());
}
// Test functions called through the debugger.
TEST(CallFunctionInDebugger) {
// Create and enter a context with the functions CheckFrameCount,
// CheckSourceLine and CheckDataParameter installed.
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
v8::Local<v8::ObjectTemplate> global_template =
v8::ObjectTemplate::New(isolate);
global_template->Set(v8_str(isolate, "CheckFrameCount"),
v8::FunctionTemplate::New(isolate, CheckFrameCount));
global_template->Set(v8_str(isolate, "CheckSourceLine"),
v8::FunctionTemplate::New(isolate, CheckSourceLine));
global_template->Set(v8_str(isolate, "CheckDataParameter"),
v8::FunctionTemplate::New(isolate, CheckDataParameter));
global_template->Set(v8_str(isolate, "CheckClosure"),
v8::FunctionTemplate::New(isolate, CheckClosure));
v8::Local<v8::Context> context =
v8::Context::New(isolate, nullptr, global_template);
v8::Context::Scope context_scope(context);
// Compile a function for checking the number of JavaScript frames.
v8::Script::Compile(context, v8_str(isolate, frame_count_source))
.ToLocalChecked()
->Run(context)
.ToLocalChecked();
frame_count = v8::Local<v8::Function>::Cast(
context->Global()
->Get(context, v8_str(isolate, "frame_count"))
.ToLocalChecked());
// Compile a function for returning the source line for the top frame.
v8::Script::Compile(context, v8_str(isolate, frame_source_line_source))
.ToLocalChecked()
->Run(context)
.ToLocalChecked();
frame_source_line = v8::Local<v8::Function>::Cast(
context->Global()
->Get(context, v8_str(isolate, "frame_source_line"))
.ToLocalChecked());
// Compile a function returning the data parameter.
v8::Script::Compile(context, v8_str(isolate, debugger_call_with_data_source))
.ToLocalChecked()
->Run(context)
.ToLocalChecked();
debugger_call_with_data = v8::Local<v8::Function>::Cast(
context->Global()
->Get(context, v8_str(isolate, "debugger_call_with_data"))
.ToLocalChecked());
// Compile a function capturing closure.
debugger_call_with_closure = v8::Local<v8::Function>::Cast(
v8::Script::Compile(context,
v8_str(isolate, debugger_call_with_closure_source))
.ToLocalChecked()
->Run(context)
.ToLocalChecked());
// Calling a function through the debugger returns 0 frames if there are
// no JavaScript frames.
CHECK(v8::Integer::New(isolate, 0)
->Equals(context,
v8::debug::Call(context, frame_count).ToLocalChecked())
.FromJust());
// Test that the number of frames can be retrieved.
v8::Script::Compile(context, v8_str(isolate, "CheckFrameCount(1)"))
.ToLocalChecked()
->Run(context)
.ToLocalChecked();
v8::Script::Compile(context, v8_str(isolate,
"function f() {"
" CheckFrameCount(2);"
"}; f()"))
.ToLocalChecked()
->Run(context)
.ToLocalChecked();
// Test that the source line can be retrieved.
v8::Script::Compile(context, v8_str(isolate, "CheckSourceLine(0)"))
.ToLocalChecked()
->Run(context)
.ToLocalChecked();
v8::Script::Compile(context, v8_str(isolate,
"function f() {\n"
" CheckSourceLine(1)\n"
" CheckSourceLine(2)\n"
" CheckSourceLine(3)\n"
"}; f()"))
.ToLocalChecked()
->Run(context)
.ToLocalChecked();
// Test that a parameter can be passed to a function called in the debugger.
v8::Script::Compile(context, v8_str(isolate, "CheckDataParameter()"))
.ToLocalChecked()
->Run(context)
.ToLocalChecked();
// Test that a function with closure can be run in the debugger.
v8::Script::Compile(context, v8_str(isolate, "CheckClosure()"))
.ToLocalChecked()
->Run(context)
.ToLocalChecked();
// Test that the source line is correct when there is a line offset.
v8::ScriptOrigin origin(v8_str(isolate, "test"),
v8::Integer::New(isolate, 7));
v8::Script::Compile(context, v8_str(isolate, "CheckSourceLine(7)"), &origin)
.ToLocalChecked()
->Run(context)
.ToLocalChecked();
v8::Script::Compile(context, v8_str(isolate,
"function f() {\n"
" CheckSourceLine(8)\n"
" CheckSourceLine(9)\n"
" CheckSourceLine(10)\n"
"}; f()"),
&origin)
.ToLocalChecked()
->Run(context)
.ToLocalChecked();
}
// Test that clearing the debug event listener actually clears all break points
// and related information.
TEST(DebuggerUnload) {
......
......@@ -17,6 +17,24 @@ getPossibleBreakpoints should not crash during lazy compilation (crbug.com/71533
url : test.js
}
}
{
method : Debugger.scriptFailedToParse
params : {
endColumn : 21
endLine : 2
executionContextId : <executionContextId>
hasSourceURL : true
hash : 124cb0278e3aa9f250651d433cdefeb5618c7202
isModule : false
length : 52
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
startLine : 0
url : test.js
}
}
One script is reported twice
{
id : <messageId>
result : {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment