Skip to content

Commit 3c160e3

Browse files
committed
Allow unlock() to return a promise
1 parent de47b7c commit 3c160e3

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

index.html

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ <h2>
9191
updateLockButton(lockButton);
9292
}
9393

94+
async function unlock() {
95+
await screen.orientation.unlock();
96+
updateLockButton();
97+
}
98+
9499
screen.orientation.addEventListener("change", updateLockButton);
95100

96101
window.addEventListener("load", updateLockButton);
@@ -99,7 +104,7 @@ <h2>
99104
&lt;button onclick="rotate(this)" id="button"&gt;
100105
Lock to...
101106
&lt;/button&gt;
102-
&lt;button onclick="screen.orientation.unlock()"&gt;
107+
&lt;button onclick="unlock()"&gt;
103108
Unlock
104109
&lt;/button&gt;
105110
</pre>
@@ -392,7 +397,7 @@ <h2>
392397
[Exposed=Window]
393398
interface ScreenOrientation : EventTarget {
394399
Promise&lt;undefined&gt; lock(OrientationLockType orientation);
395-
undefined unlock();
400+
Promise&lt;undefined&gt; unlock();
396401
readonly attribute OrientationType type;
397402
readonly attribute unsigned short angle;
398403
attribute EventHandler onchange;
@@ -503,30 +508,29 @@ <h2>
503508
<li>Let |document:Document| be [=this=]'s [=relevant global
504509
object=]'s [=associated `Document`=].
505510
</li>
506-
<li>If |document| is not [=Document/fully active=],
507-
[=exception/throw=] an {{"InvalidStateError"}} {{DOMException}}.
511+
<li data-tests="non-fully-active.html">If |document| is not
512+
[=Document/fully active=], return [=a promise rejected with=] an
513+
{{"InvalidStateError"}} {{DOMException}}.
508514
</li>
509-
<li data-tests="lock-sandboxed-iframe.html">If |document| has the
510-
[=sandboxed orientation lock browsing context flag=] set, return
511-
`undefined`.
515+
<li>If |document| has the [=sandboxed orientation lock browsing
516+
context flag=] set, return [=a promise resolved with=] `undefined`.
512517
</li>
513518
<li>If screen's [=Screen/active orientation lock=] is `null`, return
514-
`undefined`.
519+
return [=a promise resolved with=] `undefined`.
520+
</li>
521+
<li data-tests="lock-basic.html">If |document|'s
522+
{{Document/[[orientationPendingPromise]]}} is not `null`, [=reject
523+
and nullify the current lock promise=] of |document| with an
524+
{{"AbortError"}}.
515525
</li>
516-
<li>If |document|'s {{Document/[[orientationPendingPromise]]}} is not
517-
`null`, [=reject and nullify the current lock promise=] of |document|
518-
with an {{"AbortError"}}.
526+
<li data-tests="lock-basic.html">Set |document|'s
527+
{{Document/[[orientationPendingPromise]]}} to [=a new promise=].
519528
</li>
520529
<li>[=Apply orientation lock=] `null` to |document|.
521530
</li>
531+
<li>Return |document|'s {{Document/[[orientationPendingPromise]]}}.
532+
</li>
522533
</ol>
523-
<p class='note' title="Why does unlock() not return a promise?">
524-
{{unlock()}} does not return a promise because it is equivalent to
525-
locking to the [=default screen orientation=] which might or might
526-
not be known by the [=user agent=]. Hence, the [=user agent=] can not
527-
predict what the new orientation is going to be and even if it is
528-
going to change at all.
529-
</p>
530534
</section>
531535
<section>
532536
<h2>

0 commit comments

Comments
 (0)