Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! worker: implement Web Locks API
  • Loading branch information
addaleax committed Dec 14, 2020
commit a4f7cf009f51222ab8bcefd7adacde14b05ab91e
26 changes: 18 additions & 8 deletions lib/internal/worker/locks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const {
onclose_message_symbol,
} = internalBinding('symbols');
const assert = require('internal/assert');
const {
ERR_INVALID_ARG_VALUE
Comment thread
aduh95 marked this conversation as resolved.
Outdated
} = require('internal/errors');
const {
SafeMap,
SymbolToStringTag,
Expand Down Expand Up @@ -415,24 +418,31 @@ class LockManager {
if (name.startsWith('-')) {
// If name starts with U+002D HYPHEN-MINUS (-), then reject promise with a
// "NotSupportedError" DOMException.
throw new DOMException('NotSupportedError');
throw new DOMException('Lock name may not start with hyphen',
'NotSupportedError');
} else if (options.ifAvailable === true && options.steal === true) {
// Otherwise, if both options' steal dictionary member and option's
// ifAvailable dictionary member are true, then reject promise with a
// "NotSupportedError" DOMException.
throw new DOMException('NotSupportedError');
} else if (options.steal === true && options.mode !== 'exclusive') {
// Otherwise, if options' steal dictionary member is true and option's
// mode dictionary member is not "exclusive", then reject promise with a
// "NotSupportedError" DOMException.
throw new DOMException('NotSupportedError');
throw new DOMException('ifAvailable and steal are mutually exclusive',
'NotSupportedError');
} else if (options.mode !== 'shared' && options.mode !== 'exclusive') {
throw new ERR_INVALID_ARG_VALUE.TypeError(
'mode must be "shared" or "exclusive"');
} else if (options.mode !== 'exclusive' && options.steal === true) {
// If options' steal dictionary member is true and options' mode
// dictionary member is not "exclusive", then return a promise rejected
// with a "NotSupportedError" DOMException.
throw new DOMException('mode: "shared" and steal are mutually exclusive',
'NotSupportedError');
} else if (options.signal &&
(options.steal === true || options.ifAvailable === true)) {
// If options' signal dictionary member is present, and either of
// options' steal dictionary member or options' ifAvailable dictionary
// member is true, then return a promise rejected with a
// "NotSupportedError" DOMException.
throw new DOMException('NotSupportedError');
throw new DOMException('signal cannot be used with steal or ifAvailable',
'NotSupportedError');
} else if (options.signal && options.signal.aborted) {
throw new DOMException('The operation was aborted', 'AbortError');
}
Expand Down