-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib,crypto: add optional cause to DOMException
#44224
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -49,14 +49,23 @@ const disusedNamesSet = new SafeSet() | |||||||||||||||||||||||||
.add('ValidationError'); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
class DOMException { | ||||||||||||||||||||||||||
constructor(message = '', name = 'Error') { | ||||||||||||||||||||||||||
constructor(message = '', name = 'Error', cause = undefined) { | ||||||||||||||||||||||||||
ErrorCaptureStackTrace(this); | ||||||||||||||||||||||||||
internalsMap.set(this, { | ||||||||||||||||||||||||||
message: `${message}`, | ||||||||||||||||||||||||||
name: `${name}` | ||||||||||||||||||||||||||
name: `${name}`, | ||||||||||||||||||||||||||
cause | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
Comment on lines
+57
to
58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't that be more correct? (at least that's the
Suggested change
|
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
get cause() { | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per the debate (whatwg/webidl#1179) that is happening in the PR that is updating const err1 = new Error('no cause');
console.log('cause' in err1); // false
console.log(err1.cause); // undefined
const err2 = new Error('undefined cause', { cause: undefined });
console.log('cause' in err2); // true
console.log(err2.cause); // undefined From all appearances, it seems a decision is going to be made that const err1 = new DOMException('no cause', 'ABORT_ERR');
console.log('cause' in err1); // true
console.log(err1.cause); // undefined
const err2 = new DOMException('undefined cause', { name: 'ABORT_ERR', cause: undefined });
console.log('cause' in err2); // true
console.log(err2.cause); // undefined The reasons for diverging do not seem that well defined beyond consistency with the way For our implementation, I'd rather we choose to align with TC-39's definition and intentionally diverge from the official definition that is likely to land in the WebIDL spec. tl;dr ... let's not use an accessor for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||
const internals = internalsMap.get(this); | ||||||||||||||||||||||||||
if (internals === undefined) { | ||||||||||||||||||||||||||
throwInvalidThisError(TypeError, 'DOMException'); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
return internals.cause; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
get name() { | ||||||||||||||||||||||||||
const internals = internalsMap.get(this); | ||||||||||||||||||||||||||
if (internals === undefined) { | ||||||||||||||||||||||||||
|
@@ -93,6 +102,7 @@ ObjectDefineProperties(DOMException.prototype, { | |||||||||||||||||||||||||
[SymbolToStringTag]: { __proto__: null, configurable: true, value: 'DOMException' }, | ||||||||||||||||||||||||||
name: { __proto__: null, enumerable: true, configurable: true }, | ||||||||||||||||||||||||||
message: { __proto__: null, enumerable: true, configurable: true }, | ||||||||||||||||||||||||||
cause: { __proto__: null, enumerable: true, configurable: true }, | ||||||||||||||||||||||||||
code: { __proto__: null, enumerable: true, configurable: true } | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this signature preferable over any of these?
or