Skip to content

Commit

Permalink
Web Locks: Reject promise for non-fully-active documents
Browse files Browse the repository at this point in the history
The script-facing request() and query() methods in our Web Locks
implementation had an early exit for the non-fully-active a.k.a.
detached document case, but simply returned a dummy promise. Since
this was implemented, the web platform generally and the Web Locks API
specifically have better defined the behavior for this case, where a
rejected promise should be returned.

There was already a WPT for this which we were failing. Make it pass!

BUG: 1234679

Change-Id: I6ad937292c2d768fba783b890f3bb4332cb228cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4112406
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Commit-Queue: Joshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1084539}
  • Loading branch information
inexorabletash authored and Chromium LUCI CQ committed Dec 16, 2022
1 parent f5ec486 commit 49083fd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 7 additions & 1 deletion third_party/blink/renderer/modules/locks/lock_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace {

constexpr char kRequestAbortedMessage[] = "The request was aborted.";
constexpr char kSecurityErrorMessage[] = "The request was denied.";
constexpr char kInvalidStateErrorMessage[] = "The document is not active.";

LockInfo* ToLockInfo(const mojom::blink::LockInfoPtr& record) {
LockInfo* info = LockInfo::Create();
Expand Down Expand Up @@ -270,8 +271,11 @@ ScriptPromise LockManager::request(ScriptState* script_state,
V8LockGrantedCallback* callback,
ExceptionState& exception_state) {
// Observed context may be gone if frame is detached.
if (!GetExecutionContext())
if (!GetExecutionContext()) {
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
kInvalidStateErrorMessage);
return ScriptPromise();
}

ExecutionContext* context = ExecutionContext::From(script_state);
DCHECK(context->IsContextThread());
Expand Down Expand Up @@ -423,6 +427,8 @@ ScriptPromise LockManager::query(ScriptState* script_state,
ExceptionState& exception_state) {
// Observed context may be gone if frame is detached.
if (!GetExecutionContext()) {
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
kInvalidStateErrorMessage);
return ScriptPromise();
}
ExecutionContext* context = ExecutionContext::From(script_state);
Expand Down

This file was deleted.

0 comments on commit 49083fd

Please sign in to comment.