[inspector] check callback before calling on promise collected

R=dgozman@chromium.org

Bug: chromium:754560
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I3c0d5c4eebc3e8dbfa6663210046d6a86b1226b5
Reviewed-on: https://chromium-review.googlesource.com/612452
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47321}
This commit is contained in:
Alexey Kozyatinskiy 2017-08-11 10:36:26 -07:00 committed by Commit Bot
parent c820b89bc5
commit 438a845c52
3 changed files with 18 additions and 3 deletions

View File

@ -137,8 +137,7 @@ class InjectedScript::ProtocolPromiseHandler {
data.GetParameter()->m_wrapper.Reset();
data.SetSecondPassCallback(cleanup);
} else {
data.GetParameter()->m_callback->sendFailure(
Response::Error("Promise was collected"));
data.GetParameter()->sendPromiseCollected();
delete data.GetParameter();
}
}
@ -219,6 +218,19 @@ class InjectedScript::ProtocolPromiseHandler {
callback->sendSuccess(std::move(wrappedValue), std::move(exceptionDetails));
}
void sendPromiseCollected() {
V8InspectorSessionImpl* session =
m_inspector->sessionById(m_contextGroupId, m_sessionId);
if (!session) return;
InjectedScript::ContextScope scope(session, m_executionContextId);
Response response = scope.initialize();
if (!response.isSuccess()) return;
std::unique_ptr<EvaluateCallback> callback =
scope.injectedScript()->takeEvaluateCallback(m_callback);
if (!callback) return;
callback->sendFailure(Response::Error("Promise was collected"));
}
V8InspectorImpl* m_inspector;
int m_sessionId;
int m_contextGroupId;

View File

@ -229,3 +229,4 @@ Destroying context..
id : <messageId>
}
Context destroyed
Triggering weak callback..

View File

@ -129,10 +129,12 @@ InspectorTest.runAsyncTestSuite([
async function testImmediatelyResolvedAfterAfterContextDestroyed()
{
Protocol.Runtime.evaluate({
expression: 'a = new Promise(() => 42)',
expression: 'new Promise(() => 42)',
awaitPromise: true }).then(InspectorTest.logMessage);
InspectorTest.log('Destroying context..');
await Protocol.Runtime.evaluate({expression: 'inspector.fireContextDestroyed()'});
InspectorTest.log('Context destroyed');
InspectorTest.log('Triggering weak callback..');
await Protocol.HeapProfiler.collectGarbage();
}
]);