Commit 82bcbd9e authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Use [RaisesException] for immediate promise rejections in background_sync

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

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

Bug: 1001114
Change-Id: I6146006633aa4147f8682b73e2e268ee5b11b63c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1958555Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#724083}
parent 06e1a907
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/modules/background_sync/background_sync_options.h" #include "third_party/blink/renderer/modules/background_sync/background_sync_options.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_registration.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_registration.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
namespace blink { namespace blink {
...@@ -25,12 +26,13 @@ PeriodicSyncManager::PeriodicSyncManager( ...@@ -25,12 +26,13 @@ PeriodicSyncManager::PeriodicSyncManager(
ScriptPromise PeriodicSyncManager::registerPeriodicSync( ScriptPromise PeriodicSyncManager::registerPeriodicSync(
ScriptState* script_state, ScriptState* script_state,
const String& tag, const String& tag,
const BackgroundSyncOptions* options) { const BackgroundSyncOptions* options,
ExceptionState& exception_state) {
if (!registration_->active()) { if (!registration_->active()) {
return ScriptPromise::RejectWithDOMException( exception_state.ThrowDOMException(
script_state, MakeGarbageCollected<DOMException>( DOMExceptionCode::kInvalidStateError,
DOMExceptionCode::kInvalidStateError, "Registration failed - no active Service Worker");
"Registration failed - no active Service Worker")); return ScriptPromise();
} }
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
namespace blink { namespace blink {
class BackgroundSyncOptions; class BackgroundSyncOptions;
class ExceptionState;
class ScriptPromise; class ScriptPromise;
class ScriptPromiseResolver; class ScriptPromiseResolver;
class ScriptState; class ScriptState;
...@@ -37,7 +38,8 @@ class PeriodicSyncManager final : public ScriptWrappable { ...@@ -37,7 +38,8 @@ class PeriodicSyncManager final : public ScriptWrappable {
// IDL exposed interface // IDL exposed interface
ScriptPromise registerPeriodicSync(ScriptState* script_state, ScriptPromise registerPeriodicSync(ScriptState* script_state,
const String& tag, const String& tag,
const BackgroundSyncOptions* options); const BackgroundSyncOptions* options,
ExceptionState& exception_state);
ScriptPromise getTags(ScriptState* script_state); ScriptPromise getTags(ScriptState* script_state);
ScriptPromise unregister(ScriptState* script_state, const String& tag); ScriptPromise unregister(ScriptState* script_state, const String& tag);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
Exposed=(Window,Worker), Exposed=(Window,Worker),
RuntimeEnabled=PeriodicBackgroundSync RuntimeEnabled=PeriodicBackgroundSync
] interface PeriodicSyncManager { ] interface PeriodicSyncManager {
[MeasureAs=PeriodicBackgroundSyncRegister,CallWith=ScriptState,ImplementedAs=registerPeriodicSync] Promise<void> register(DOMString tag, optional BackgroundSyncOptions options); [MeasureAs=PeriodicBackgroundSyncRegister,CallWith=ScriptState,RaisesException,ImplementedAs=registerPeriodicSync] Promise<void> register(DOMString tag, optional BackgroundSyncOptions options);
[MeasureAs=PeriodicBackgroundSyncGetTags, CallWith=ScriptState] Promise<sequence<DOMString>> getTags(); [MeasureAs=PeriodicBackgroundSyncGetTags, CallWith=ScriptState] Promise<sequence<DOMString>> getTags();
[MeasureAs=PeriodicBackgroundSyncUnregister,CallWith=ScriptState] Promise<void> unregister(DOMString tag); [MeasureAs=PeriodicBackgroundSyncUnregister,CallWith=ScriptState] Promise<void> unregister(DOMString tag);
}; };
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#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/execution_context/execution_context.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_registration.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_registration.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/heap/persistent.h" #include "third_party/blink/renderer/platform/heap/persistent.h"
...@@ -26,12 +27,13 @@ SyncManager::SyncManager(ServiceWorkerRegistration* registration, ...@@ -26,12 +27,13 @@ SyncManager::SyncManager(ServiceWorkerRegistration* registration,
} }
ScriptPromise SyncManager::registerFunction(ScriptState* script_state, ScriptPromise SyncManager::registerFunction(ScriptState* script_state,
const String& tag) { const String& tag,
ExceptionState& exception_state) {
if (!registration_->active()) { if (!registration_->active()) {
return ScriptPromise::RejectWithDOMException( exception_state.ThrowDOMException(
script_state, MakeGarbageCollected<DOMException>( DOMExceptionCode::kInvalidStateError,
DOMExceptionCode::kInvalidStateError, "Registration failed - no active Service Worker");
"Registration failed - no active Service Worker")); return ScriptPromise();
} }
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
namespace blink { namespace blink {
class ExceptionState;
class ScriptPromise; class ScriptPromise;
class ScriptPromiseResolver; class ScriptPromiseResolver;
class ScriptState; class ScriptState;
...@@ -32,7 +33,9 @@ class SyncManager final : public ScriptWrappable { ...@@ -32,7 +33,9 @@ class SyncManager final : public ScriptWrappable {
SyncManager(ServiceWorkerRegistration*, SyncManager(ServiceWorkerRegistration*,
scoped_refptr<base::SequencedTaskRunner>); scoped_refptr<base::SequencedTaskRunner>);
ScriptPromise registerFunction(ScriptState*, const String& tag); ScriptPromise registerFunction(ScriptState*,
const String& tag,
ExceptionState& exception_state);
ScriptPromise getTags(ScriptState*); ScriptPromise getTags(ScriptState*);
void Trace(blink::Visitor*) override; void Trace(blink::Visitor*) override;
......
...@@ -7,6 +7,6 @@ ...@@ -7,6 +7,6 @@
[ [
Exposed=(Window,Worker) Exposed=(Window,Worker)
] interface SyncManager { ] interface SyncManager {
[MeasureAs=BackgroundSyncRegister,CallWith=ScriptState,ImplementedAs=registerFunction] Promise<void> register(DOMString tag); [MeasureAs=BackgroundSyncRegister,CallWith=ScriptState,RaisesException,ImplementedAs=registerFunction] Promise<void> register(DOMString tag);
[CallWith=ScriptState] Promise<sequence<DOMString>> getTags(); [CallWith=ScriptState] Promise<sequence<DOMString>> getTags();
}; };
...@@ -27,7 +27,7 @@ async_test(function(test) { ...@@ -27,7 +27,7 @@ async_test(function(test) {
assert_unreached('sync.register() must not succeed without an active service worker'); assert_unreached('sync.register() must not succeed without an active service worker');
}, function(e) { }, function(e) {
assert_equals(e.name, 'InvalidStateError'); assert_equals(e.name, 'InvalidStateError');
assert_equals(e.message, 'Registration failed - no active Service Worker'); assert_equals(e.message, 'Failed to execute \'register\' on \'SyncManager\': Registration failed - no active Service Worker');
return service_worker_unregister_and_done(test, workerScope); return service_worker_unregister_and_done(test, workerScope);
}) })
.catch(unreached_rejection(test)); .catch(unreached_rejection(test));
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
}, error => { }, error => {
assert_equals(error.name, 'InvalidStateError'); assert_equals(error.name, 'InvalidStateError');
assert_equals( assert_equals(
error.message, 'Registration failed - no active Service Worker'); error.message, 'Failed to execute \'register\' on \'PeriodicSyncManager\': Registration failed - no active Service Worker');
return service_worker_unregister_and_done(test, workerScope); return service_worker_unregister_and_done(test, workerScope);
}) })
.catch(unreached_rejection(test)); .catch(unreached_rejection(test));
......
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