Commit 51740cc1 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[inspector] expose V8InspectorSession::breakProgram in test harness.

V8InspectorSession::schedulePauseOnNextStatement and V8InspectorSession::cancelPauseOnNextStatement are now exposed in inspector tests. These methods are required at least for better blackboxing tests.

BUG=v8:5842
R=dgozman@chromium.org

Review-Url: https://codereview.chromium.org/2636613002
Cr-Commit-Position: refs/heads/master@{#42469}
parent d794ef7d
Checks breakProgram,(schedule|cancel)PauseOnNextStatement test API
Running test: testBreakProgram
Stack:
callBreakProgram (:9:2)
(anonymous) (:0:0)
Other data:
{
method : Debugger.paused
params : {
data : {
a : 42
}
hitBreakpoints : [
]
reason : reason
}
}
Running test: testSchedulePauseOnNextStatement
Stack:
(anonymous) (expr1.js:0:0)
Other data:
{
method : Debugger.paused
params : {
data : {
a : 42
}
hitBreakpoints : [
]
reason : reason
}
}
Running test: testCancelPauseOnNextStatement
// Copyright 2017 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.
print("Checks breakProgram,(schedule|cancel)PauseOnNextStatement test API");
InspectorTest.addScript(`
function callBreakProgram() {
breakProgram('reason', JSON.stringify({a: 42}));
}
function foo() {
return 42;
}`, 7, 26);
InspectorTest.setupScriptMap();
Protocol.Debugger.onPaused(message => {
InspectorTest.log('Stack:');
InspectorTest.logCallFrames(message.params.callFrames);
delete message.params.callFrames;
InspectorTest.log('Other data:');
InspectorTest.logMessage(message);
InspectorTest.log('');
Protocol.Debugger.resume();
});
Protocol.Debugger.enable();
InspectorTest.runTestSuite([
function testBreakProgram(next) {
Protocol.Runtime.evaluate({ expression: 'callBreakProgram()'})
.then(next);
},
function testSchedulePauseOnNextStatement(next) {
schedulePauseOnNextStatement('reason', JSON.stringify({a: 42}));
Protocol.Runtime.evaluate({ expression: 'foo()//# sourceURL=expr1.js'})
.then(() => Protocol.Runtime.evaluate({
expression: 'foo()//# sourceURL=expr2.js'}))
.then(next);
},
function testCancelPauseOnNextStatement(next) {
schedulePauseOnNextStatement('reason', JSON.stringify({a: 42}));
cancelPauseOnNextStatement();
Protocol.Runtime.evaluate({ expression: 'foo()'})
.then(next);
}
]);
...@@ -27,9 +27,13 @@ class InspectorClientImpl : public v8_inspector::V8InspectorClient { ...@@ -27,9 +27,13 @@ class InspectorClientImpl : public v8_inspector::V8InspectorClient {
static v8_inspector::V8Inspector* InspectorFromContext( static v8_inspector::V8Inspector* InspectorFromContext(
v8::Local<v8::Context> context); v8::Local<v8::Context> context);
static v8_inspector::V8InspectorSession* SessionFromContext(
v8::Local<v8::Context> context);
void setCurrentTimeMSForTest(double time); void setCurrentTimeMSForTest(double time);
v8_inspector::V8InspectorSession* session() const { return session_.get(); }
private: private:
// V8InspectorClient implementation. // V8InspectorClient implementation.
v8::Local<v8::Context> ensureDefaultContextInGroup( v8::Local<v8::Context> ensureDefaultContextInGroup(
...@@ -38,9 +42,6 @@ class InspectorClientImpl : public v8_inspector::V8InspectorClient { ...@@ -38,9 +42,6 @@ class InspectorClientImpl : public v8_inspector::V8InspectorClient {
void runMessageLoopOnPause(int context_group_id) override; void runMessageLoopOnPause(int context_group_id) override;
void quitMessageLoopOnPause() override; void quitMessageLoopOnPause() override;
static v8_inspector::V8InspectorSession* SessionFromContext(
v8::Local<v8::Context> context);
friend class SendMessageToBackendTask; friend class SendMessageToBackendTask;
friend class ConnectTask; friend class ConnectTask;
......
...@@ -55,7 +55,9 @@ class UtilsExtension : public v8::Extension { ...@@ -55,7 +55,9 @@ class UtilsExtension : public v8::Extension {
"native function setlocale();" "native function setlocale();"
"native function load();" "native function load();"
"native function compileAndRunWithOrigin();" "native function compileAndRunWithOrigin();"
"native function setCurrentTimeMSForTest();") {} "native function setCurrentTimeMSForTest();"
"native function schedulePauseOnNextStatement();"
"native function cancelPauseOnNextStatement();") {}
virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
v8::Isolate* isolate, v8::Local<v8::String> name) { v8::Isolate* isolate, v8::Local<v8::String> name) {
v8::Local<v8::Context> context = isolate->GetCurrentContext(); v8::Local<v8::Context> context = isolate->GetCurrentContext();
...@@ -96,6 +98,21 @@ class UtilsExtension : public v8::Extension { ...@@ -96,6 +98,21 @@ class UtilsExtension : public v8::Extension {
.FromJust()) { .FromJust()) {
return v8::FunctionTemplate::New(isolate, return v8::FunctionTemplate::New(isolate,
UtilsExtension::SetCurrentTimeMSForTest); UtilsExtension::SetCurrentTimeMSForTest);
} else if (name->Equals(context,
v8::String::NewFromUtf8(
isolate, "schedulePauseOnNextStatement",
v8::NewStringType::kNormal)
.ToLocalChecked())
.FromJust()) {
return v8::FunctionTemplate::New(
isolate, UtilsExtension::SchedulePauseOnNextStatement);
} else if (name->Equals(context, v8::String::NewFromUtf8(
isolate, "cancelPauseOnNextStatement",
v8::NewStringType::kNormal)
.ToLocalChecked())
.FromJust()) {
return v8::FunctionTemplate::New(
isolate, UtilsExtension::CancelPauseOnNextStatement);
} }
return v8::Local<v8::FunctionTemplate>(); return v8::Local<v8::FunctionTemplate>();
} }
...@@ -203,6 +220,31 @@ class UtilsExtension : public v8::Extension { ...@@ -203,6 +220,31 @@ class UtilsExtension : public v8::Extension {
inspector_client_->setCurrentTimeMSForTest( inspector_client_->setCurrentTimeMSForTest(
args[0].As<v8::Number>()->Value()); args[0].As<v8::Number>()->Value());
} }
static void SchedulePauseOnNextStatement(
const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsString()) {
fprintf(
stderr,
"Internal error: schedulePauseOnNextStatement('reason', 'details').");
Exit();
}
v8::internal::Vector<uint16_t> reason = ToVector(args[0].As<v8::String>());
v8_inspector::StringView reason_view(reason.start(), reason.length());
v8::internal::Vector<uint16_t> details = ToVector(args[1].As<v8::String>());
v8_inspector::StringView details_view(details.start(), details.length());
inspector_client_->session()->schedulePauseOnNextStatement(reason_view,
details_view);
}
static void CancelPauseOnNextStatement(
const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 0) {
fprintf(stderr, "Internal error: cancelPauseOnNextStatement().");
Exit();
}
inspector_client_->session()->cancelPauseOnNextStatement();
}
}; };
TaskRunner* UtilsExtension::backend_runner_ = nullptr; TaskRunner* UtilsExtension::backend_runner_ = nullptr;
...@@ -283,7 +325,8 @@ class InspectorExtension : public v8::Extension { ...@@ -283,7 +325,8 @@ class InspectorExtension : public v8::Extension {
: v8::Extension("v8_inspector/inspector", : v8::Extension("v8_inspector/inspector",
"native function attachInspector();" "native function attachInspector();"
"native function detachInspector();" "native function detachInspector();"
"native function setMaxAsyncTaskStacks();") {} "native function setMaxAsyncTaskStacks();"
"native function breakProgram();") {}
virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
v8::Isolate* isolate, v8::Local<v8::String> name) { v8::Isolate* isolate, v8::Local<v8::String> name) {
...@@ -307,6 +350,13 @@ class InspectorExtension : public v8::Extension { ...@@ -307,6 +350,13 @@ class InspectorExtension : public v8::Extension {
.FromJust()) { .FromJust()) {
return v8::FunctionTemplate::New( return v8::FunctionTemplate::New(
isolate, InspectorExtension::SetMaxAsyncTaskStacks); isolate, InspectorExtension::SetMaxAsyncTaskStacks);
} else if (name->Equals(context,
v8::String::NewFromUtf8(isolate, "breakProgram",
v8::NewStringType::kNormal)
.ToLocalChecked())
.FromJust()) {
return v8::FunctionTemplate::New(isolate,
InspectorExtension::BreakProgram);
} }
return v8::Local<v8::FunctionTemplate>(); return v8::Local<v8::FunctionTemplate>();
} }
...@@ -350,6 +400,23 @@ class InspectorExtension : public v8::Extension { ...@@ -350,6 +400,23 @@ class InspectorExtension : public v8::Extension {
v8_inspector::SetMaxAsyncTaskStacksForTest( v8_inspector::SetMaxAsyncTaskStacksForTest(
inspector, args[0].As<v8::Int32>()->Value()); inspector, args[0].As<v8::Int32>()->Value());
} }
static void BreakProgram(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsString()) {
fprintf(stderr, "Internal error: breakProgram('reason', 'details').");
Exit();
}
v8_inspector::V8InspectorSession* session =
InspectorClientImpl::SessionFromContext(
args.GetIsolate()->GetCurrentContext());
CHECK(session);
v8::internal::Vector<uint16_t> reason = ToVector(args[0].As<v8::String>());
v8_inspector::StringView reason_view(reason.start(), reason.length());
v8::internal::Vector<uint16_t> details = ToVector(args[1].As<v8::String>());
v8_inspector::StringView details_view(details.start(), details.length());
session->breakProgram(reason_view, details_view);
}
}; };
v8::Local<v8::String> ToString(v8::Isolate* isolate, v8::Local<v8::String> ToString(v8::Isolate* isolate,
......
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