Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 67eaa30

Browse filesBrowse files
flakey5danielleadams
authored andcommitted
lib: add cause to DOMException
PR-URL: #44703 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 780144c commit 67eaa30
Copy full SHA for 67eaa30

File tree

Expand file treeCollapse file tree

2 files changed

+57
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+57
-5
lines changed
Open diff view settings
Collapse file

‎lib/internal/per_context/domexception.js‎

Copy file name to clipboardExpand all lines: lib/internal/per_context/domexception.js
+24-5Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,31 @@ const disusedNamesSet = new SafeSet()
4949
.add('ValidationError');
5050

5151
class DOMException {
52-
constructor(message = '', name = 'Error') {
52+
constructor(message = '', options = 'Error') {
5353
ErrorCaptureStackTrace(this);
54-
internalsMap.set(this, {
55-
message: `${message}`,
56-
name: `${name}`
57-
});
54+
55+
if (options && typeof options === 'object') {
56+
const { name } = options;
57+
internalsMap.set(this, {
58+
message: `${message}`,
59+
name: `${name}`
60+
});
61+
62+
if ('cause' in options) {
63+
ObjectDefineProperty(this, 'cause', {
64+
__proto__: null,
65+
value: options.cause,
66+
configurable: true,
67+
writable: true,
68+
enumerable: false,
69+
});
70+
}
71+
} else {
72+
internalsMap.set(this, {
73+
message: `${message}`,
74+
name: `${options}`
75+
});
76+
}
5877
}
5978

6079
get name() {
Collapse file
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
require('../common');
4+
const { strictEqual, deepStrictEqual } = require('assert');
5+
6+
{
7+
const domException = new DOMException('no cause', 'abc');
8+
strictEqual(domException.name, 'abc');
9+
strictEqual('cause' in domException, false);
10+
strictEqual(domException.cause, undefined);
11+
}
12+
13+
{
14+
const domException = new DOMException('with undefined cause', { name: 'abc', cause: undefined });
15+
strictEqual(domException.name, 'abc');
16+
strictEqual('cause' in domException, true);
17+
strictEqual(domException.cause, undefined);
18+
}
19+
20+
{
21+
const domException = new DOMException('with string cause', { name: 'abc', cause: 'foo' });
22+
strictEqual(domException.name, 'abc');
23+
strictEqual('cause' in domException, true);
24+
strictEqual(domException.cause, 'foo');
25+
}
26+
27+
{
28+
const object = { reason: 'foo' };
29+
const domException = new DOMException('with object cause', { name: 'abc', cause: object });
30+
strictEqual(domException.name, 'abc');
31+
strictEqual('cause' in domException, true);
32+
deepStrictEqual(domException.cause, object);
33+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.