Commit 1d8aa4c1 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Use [RaisesException] for immediate promise rejections in scheduler

This is a part of effort for using [RaisesException] when synchronously
rejecting a promise.

It uses [RaisesException] for
//third_party/blink/renderer/modules/scheduler.

Bug: 1001114
Change-Id: Ic51051ce7b109e30a8995f8c5185abb6eef9d25f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1980262Reviewed-by: default avatarNate Chapin <japhet@chromium.org>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#728759}
parent a3287e45
......@@ -18,11 +18,12 @@ namespace blink {
namespace {
static ScriptPromise RejectPromiseImmediately(ScriptState* script_state) {
return ScriptPromise::RejectWithDOMException(
script_state,
MakeGarbageCollected<DOMException>(DOMExceptionCode::kNotSupportedError,
"Current document is detached"));
static ScriptPromise RejectPromiseImmediately(ExceptionState& exception_state) {
// The bindings layer implicitly converts thrown exceptions in
// promise-returning functions to promise rejections.
exception_state.ThrowDOMException(DOMExceptionCode::kNotSupportedError,
"Current document is detached");
return ScriptPromise();
}
} // namespace
......@@ -65,9 +66,10 @@ void DOMScheduler::OnTaskCompleted(DOMTask*) {}
ScriptPromise DOMScheduler::postTask(ScriptState* script_state,
V8Function* callback_function,
SchedulerPostTaskOptions* options,
const HeapVector<ScriptValue>& args) {
const HeapVector<ScriptValue>& args,
ExceptionState& exception_state) {
if (!GetExecutionContext() || GetExecutionContext()->IsContextDestroyed())
return RejectPromiseImmediately(script_state);
return RejectPromiseImmediately(exception_state);
// Always honor the priority and the task signal if given. Therefore:
// * If both priority and signal are set, use the signal but choose the
......@@ -89,7 +91,7 @@ ScriptPromise DOMScheduler::postTask(ScriptState* script_state,
} else if (auto* task_signal = DynamicTo<DOMTaskSignal>(options->signal())) {
task_runner = task_signal->GetTaskRunner();
if (!task_runner)
return RejectPromiseImmediately(script_state);
return RejectPromiseImmediately(exception_state);
} else {
task_runner = GetTaskRunnerFor(WebSchedulingPriority::kDefaultPriority);
}
......
......@@ -18,6 +18,7 @@
namespace blink {
class DOMTask;
class ExceptionState;
class ExecutionContext;
class SchedulerPostTaskOptions;
class ScriptValue;
......@@ -46,7 +47,8 @@ class MODULES_EXPORT DOMScheduler : public ScriptWrappable,
ScriptPromise postTask(ScriptState*,
V8Function*,
SchedulerPostTaskOptions*,
const HeapVector<ScriptValue>& args);
const HeapVector<ScriptValue>& args,
ExceptionState&);
// Callbacks invoked by DOMTasks when they run.
void OnTaskStarted(DOMTask*);
......
......@@ -8,5 +8,5 @@
ImplementedAs=DOMScheduler,
RuntimeEnabled=WebScheduler
] interface Scheduler {
[CallWith=ScriptState] Promise<any> postTask(Function callback, optional SchedulerPostTaskOptions options, any... arguments);
[CallWith=ScriptState, RaisesException] Promise<any> postTask(Function callback, optional SchedulerPostTaskOptions options, any... arguments);
};
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