w3c / web-locks

Cross-tab resource coordination API
https://w3c.github.io/web-locks/
Other
124 stars 16 forks source link

Spec out how to handle synchronous exceptions #32

Closed ralphch0 closed 6 years ago

ralphch0 commented 6 years ago

The spec mentions that if the promise from the callback rejects, the lock is released. I don't think it mentions what happens if there is a synchronous error thrown. eg:

var myvar = null; [...] navigator.locks.acquire('mylock', (lock) => { myvar.mymethod(); // Null pointer!! });

The example above should also release the lock. The risk is that a bug could cause the lock to be held for the lifetime of the tab, when it's not intended.

inexorabletash commented 6 years ago

Already handled - this is the "abrupt completion" of the callback, which turns into a rejected promise in the steps:

  • Let r be the result of invoking callback with a new Lock object associated with lock as the only argument. (Note that r may be a regular completion, an abrupt completion, or an unresolved Promise.)
  • Resolve waiting with r.