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

[inspector] set last evaluation result on Runtime.evaluate with awaitPromise

If objectGroup is console we should correctly save last evaluated result to expose for next console call in $_ variable.

R=dgozman@chromium.org

Bug: none
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ie0ba2d302606b1c9f096a9a3a107a51a80556c49
Reviewed-on: https://chromium-review.googlesource.com/598936Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47097}
parent 6aea7374
......@@ -313,6 +313,10 @@ v8::Local<v8::Value> InjectedScript::lastEvaluationResult() const {
return m_lastEvaluationResult.Get(m_context->isolate());
}
void InjectedScript::setLastEvaluationResult(v8::Local<v8::Value> result) {
m_lastEvaluationResult.Reset(m_context->isolate(), result);
}
Response InjectedScript::resolveCallArgument(
protocol::Runtime::CallArgument* callArgument,
v8::Local<v8::Value>* result) {
......
......@@ -102,6 +102,7 @@ class InjectedScript final {
std::unique_ptr<protocol::Runtime::RemoteObject>* result,
Maybe<protocol::Runtime::ExceptionDetails>*);
v8::Local<v8::Value> lastEvaluationResult() const;
void setLastEvaluationResult(v8::Local<v8::Value> result);
int bindObject(v8::Local<v8::Value>, const String16& groupName);
......
......@@ -115,7 +115,7 @@ class ProtocolPromiseHandler {
? info[0]
: v8::Local<v8::Value>::Cast(v8::Undefined(info.GetIsolate()));
std::unique_ptr<protocol::Runtime::RemoteObject> wrappedValue(
handler->wrapObject(value));
handler->wrapObject(value, true));
if (!wrappedValue) return;
handler->m_callback->sendSuccess(
std::move(wrappedValue), Maybe<protocol::Runtime::ExceptionDetails>());
......@@ -132,7 +132,7 @@ class ProtocolPromiseHandler {
: v8::Local<v8::Value>::Cast(v8::Undefined(info.GetIsolate()));
std::unique_ptr<protocol::Runtime::RemoteObject> wrappedValue(
handler->wrapObject(value));
handler->wrapObject(value, false));
if (!wrappedValue) return;
String16 message;
......@@ -200,7 +200,7 @@ class ProtocolPromiseHandler {
}
std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject(
v8::Local<v8::Value> value) {
v8::Local<v8::Value> value, bool success) {
V8InspectorSessionImpl* session =
m_inspector->sessionById(m_contextGroupId, m_sessionId);
if (!session) {
......@@ -213,6 +213,9 @@ class ProtocolPromiseHandler {
m_callback->sendFailure(response);
return nullptr;
}
if (success && m_objectGroup == "console") {
scope.injectedScript()->setLastEvaluationResult(value);
}
std::unique_ptr<protocol::Runtime::RemoteObject> wrappedValue;
response = scope.injectedScript()->wrapObject(
value, m_objectGroup, m_returnByValue, m_generatePreview,
......
......@@ -181,3 +181,25 @@ Running test: testExceptionInEvaluate
}
}
}
Running test: testLastEvaluatedResult
{
id : <messageId>
result : {
result : {
description : 42
type : number
value : 42
}
}
}
{
id : <messageId>
result : {
result : {
description : 42
type : number
value : 42
}
}
}
......@@ -89,5 +89,14 @@ InspectorTest.runTestSuite([
Protocol.Runtime.evaluate({ expression: "throw 239", awaitPromise: true })
.then(result => InspectorTest.logMessage(result))
.then(() => next());
}
},
function testLastEvaluatedResult(next)
{
Protocol.Runtime.evaluate({ expression: 'Promise.resolve(42)', awaitPromise: true, objectGroup: 'console' })
.then(result => InspectorTest.logMessage(result))
.then(() => Protocol.Runtime.evaluate({ expression: '$_', includeCommandLineAPI: true }))
.then(result => InspectorTest.logMessage(result))
.then(() => next());
},
]);
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