Commit 6c24f838 authored by Scott Haseley's avatar Scott Haseley Committed by Commit Bot

[Scheduling APIs] Add support for async callstacks to postTask

This CL adds the necessary wiring to make devtools aware of postTask to
show async callstacks, similar to setTimeout and requestIdleCallback.

Bug: 979017
Change-Id: I960b13d1c13f171dbc033b8e79bff3768e65c347
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2025870Reviewed-by: default avatarNate Chapin <japhet@chromium.org>
Commit-Queue: Scott Haseley <shaseley@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736504}
parent 3e515212
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_function.h" #include "third_party/blink/renderer/bindings/core/v8/v8_function.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/modules/scheduler/dom_scheduler.h" #include "third_party/blink/renderer/modules/scheduler/dom_scheduler.h"
#include "third_party/blink/renderer/modules/scheduler/dom_task_signal.h" #include "third_party/blink/renderer/modules/scheduler/dom_task_signal.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h"
...@@ -41,6 +42,12 @@ DOMTask::DOMTask(DOMScheduler* scheduler, ...@@ -41,6 +42,12 @@ DOMTask::DOMTask(DOMScheduler* scheduler,
task_handle_ = PostDelayedCancellableTask( task_handle_ = PostDelayedCancellableTask(
*task_runner, FROM_HERE, *task_runner, FROM_HERE,
WTF::Bind(&DOMTask::Invoke, WrapPersistent(this)), delay); WTF::Bind(&DOMTask::Invoke, WrapPersistent(this)), delay);
ScriptState* script_state =
callback_->CallbackRelevantScriptStateOrReportError("DOMTask", "Create");
DCHECK(script_state && script_state->ContextIsValid());
probe::AsyncTaskScheduled(ExecutionContext::From(script_state), "postTask",
&async_task_id_);
} }
void DOMTask::Trace(Visitor* visitor) { void DOMTask::Trace(Visitor* visitor) {
...@@ -69,6 +76,11 @@ void DOMTask::InvokeInternal(ScriptState* script_state) { ...@@ -69,6 +76,11 @@ void DOMTask::InvokeInternal(ScriptState* script_state) {
v8::TryCatch try_catch(script_state->GetIsolate()); v8::TryCatch try_catch(script_state->GetIsolate());
try_catch.SetVerbose(true); try_catch.SetVerbose(true);
ExecutionContext* context = ExecutionContext::From(script_state);
DCHECK(context);
probe::AsyncTask async_task(context, &async_task_id_);
probe::UserCallback probe(context, "postTask", AtomicString(), true);
ScriptValue result; ScriptValue result;
if (callback_->Invoke(nullptr, arguments_).To(&result)) if (callback_->Invoke(nullptr, arguments_).To(&result))
resolver_->Resolve(result.V8Value()); resolver_->Resolve(result.V8Value());
...@@ -77,9 +89,20 @@ void DOMTask::InvokeInternal(ScriptState* script_state) { ...@@ -77,9 +89,20 @@ void DOMTask::InvokeInternal(ScriptState* script_state) {
} }
void DOMTask::Abort() { void DOMTask::Abort() {
// If the task has already finished running, the promise is either resolved or
// rejected, in which case abort will no longer have any effect.
if (!callback_)
return;
task_handle_.Cancel(); task_handle_.Cancel();
resolver_->Reject( resolver_->Reject(
MakeGarbageCollected<DOMException>(DOMExceptionCode::kAbortError)); MakeGarbageCollected<DOMException>(DOMExceptionCode::kAbortError));
ScriptState* script_state =
callback_->CallbackRelevantScriptStateOrReportError("DOMTask", "Abort");
DCHECK(script_state && script_state->ContextIsValid());
probe::AsyncTaskCanceled(ExecutionContext::From(script_state),
&async_task_id_);
} }
} // namespace blink } // namespace blink
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/core/probe/async_task_id.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cancellable_task.h" #include "third_party/blink/renderer/platform/scheduler/public/post_cancellable_task.h"
...@@ -45,6 +46,7 @@ class DOMTask final : public GarbageCollected<DOMTask> { ...@@ -45,6 +46,7 @@ class DOMTask final : public GarbageCollected<DOMTask> {
Member<V8Function> callback_; Member<V8Function> callback_;
HeapVector<ScriptValue> arguments_; HeapVector<ScriptValue> arguments_;
Member<ScriptPromiseResolver> resolver_; Member<ScriptPromiseResolver> resolver_;
probe::AsyncTaskId async_task_id_;
}; };
} // namespace blink } // namespace blink
......
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