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 { ...@@ -313,6 +313,10 @@ v8::Local<v8::Value> InjectedScript::lastEvaluationResult() const {
return m_lastEvaluationResult.Get(m_context->isolate()); 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( Response InjectedScript::resolveCallArgument(
protocol::Runtime::CallArgument* callArgument, protocol::Runtime::CallArgument* callArgument,
v8::Local<v8::Value>* result) { v8::Local<v8::Value>* result) {
......
...@@ -102,6 +102,7 @@ class InjectedScript final { ...@@ -102,6 +102,7 @@ class InjectedScript final {
std::unique_ptr<protocol::Runtime::RemoteObject>* result, std::unique_ptr<protocol::Runtime::RemoteObject>* result,
Maybe<protocol::Runtime::ExceptionDetails>*); Maybe<protocol::Runtime::ExceptionDetails>*);
v8::Local<v8::Value> lastEvaluationResult() const; v8::Local<v8::Value> lastEvaluationResult() const;
void setLastEvaluationResult(v8::Local<v8::Value> result);
int bindObject(v8::Local<v8::Value>, const String16& groupName); int bindObject(v8::Local<v8::Value>, const String16& groupName);
......
...@@ -115,7 +115,7 @@ class ProtocolPromiseHandler { ...@@ -115,7 +115,7 @@ class ProtocolPromiseHandler {
? info[0] ? info[0]
: v8::Local<v8::Value>::Cast(v8::Undefined(info.GetIsolate())); : v8::Local<v8::Value>::Cast(v8::Undefined(info.GetIsolate()));
std::unique_ptr<protocol::Runtime::RemoteObject> wrappedValue( std::unique_ptr<protocol::Runtime::RemoteObject> wrappedValue(
handler->wrapObject(value)); handler->wrapObject(value, true));
if (!wrappedValue) return; if (!wrappedValue) return;
handler->m_callback->sendSuccess( handler->m_callback->sendSuccess(
std::move(wrappedValue), Maybe<protocol::Runtime::ExceptionDetails>()); std::move(wrappedValue), Maybe<protocol::Runtime::ExceptionDetails>());
...@@ -132,7 +132,7 @@ class ProtocolPromiseHandler { ...@@ -132,7 +132,7 @@ class ProtocolPromiseHandler {
: v8::Local<v8::Value>::Cast(v8::Undefined(info.GetIsolate())); : v8::Local<v8::Value>::Cast(v8::Undefined(info.GetIsolate()));
std::unique_ptr<protocol::Runtime::RemoteObject> wrappedValue( std::unique_ptr<protocol::Runtime::RemoteObject> wrappedValue(
handler->wrapObject(value)); handler->wrapObject(value, false));
if (!wrappedValue) return; if (!wrappedValue) return;
String16 message; String16 message;
...@@ -200,7 +200,7 @@ class ProtocolPromiseHandler { ...@@ -200,7 +200,7 @@ class ProtocolPromiseHandler {
} }
std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject( std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject(
v8::Local<v8::Value> value) { v8::Local<v8::Value> value, bool success) {
V8InspectorSessionImpl* session = V8InspectorSessionImpl* session =
m_inspector->sessionById(m_contextGroupId, m_sessionId); m_inspector->sessionById(m_contextGroupId, m_sessionId);
if (!session) { if (!session) {
...@@ -213,6 +213,9 @@ class ProtocolPromiseHandler { ...@@ -213,6 +213,9 @@ class ProtocolPromiseHandler {
m_callback->sendFailure(response); m_callback->sendFailure(response);
return nullptr; return nullptr;
} }
if (success && m_objectGroup == "console") {
scope.injectedScript()->setLastEvaluationResult(value);
}
std::unique_ptr<protocol::Runtime::RemoteObject> wrappedValue; std::unique_ptr<protocol::Runtime::RemoteObject> wrappedValue;
response = scope.injectedScript()->wrapObject( response = scope.injectedScript()->wrapObject(
value, m_objectGroup, m_returnByValue, m_generatePreview, value, m_objectGroup, m_returnByValue, m_generatePreview,
......
...@@ -181,3 +181,25 @@ Running test: testExceptionInEvaluate ...@@ -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([ ...@@ -89,5 +89,14 @@ InspectorTest.runTestSuite([
Protocol.Runtime.evaluate({ expression: "throw 239", awaitPromise: true }) Protocol.Runtime.evaluate({ expression: "throw 239", awaitPromise: true })
.then(result => InspectorTest.logMessage(result)) .then(result => InspectorTest.logMessage(result))
.then(() => next()); .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