Skip to content

Commit 75b30c2

Browse files
committed
fix errors: add a [[ErrorData]] internal slot to DOMException
1 parent abfb7cc commit 75b30c2

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/internal/per_context/domexception.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
'use strict';
22

33
const {
4-
ErrorCaptureStackTrace,
4+
Error,
55
ErrorPrototype,
66
ObjectDefineProperties,
77
ObjectDefineProperty,
88
ObjectSetPrototypeOf,
9+
ReflectConstruct,
910
SafeMap,
1011
SafeSet,
1112
SafeWeakMap,
@@ -50,17 +51,17 @@ const disusedNamesSet = new SafeSet()
5051

5152
class DOMException {
5253
constructor(message = '', options = 'Error') {
53-
ErrorCaptureStackTrace(this);
54+
const error = ReflectConstruct(Error, [], new.target);
5455

5556
if (options && typeof options === 'object') {
5657
const { name } = options;
57-
internalsMap.set(this, {
58+
internalsMap.set(error, {
5859
message: `${message}`,
5960
name: `${name}`,
6061
});
6162

6263
if ('cause' in options) {
63-
ObjectDefineProperty(this, 'cause', {
64+
ObjectDefineProperty(error, 'cause', {
6465
__proto__: null,
6566
value: options.cause,
6667
configurable: true,
@@ -69,11 +70,13 @@ class DOMException {
6970
});
7071
}
7172
} else {
72-
internalsMap.set(this, {
73+
internalsMap.set(error, {
7374
message: `${message}`,
7475
name: `${options}`,
7576
});
7677
}
78+
79+
return error;
7780
}
7881

7982
get name() {

test/parallel/test-util.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ assert.strictEqual(util.toUSVString('string\ud801'), 'string\ufffd');
5555
assert.strictEqual(util.types.isNativeError(new Error()), true);
5656
assert.strictEqual(util.types.isNativeError(new TypeError()), true);
5757
assert.strictEqual(util.types.isNativeError(new SyntaxError()), true);
58+
assert.strictEqual(util.types.isNativeError(new DOMException()), true);
5859
assert.strictEqual(util.types.isNativeError(new (context('Error'))()), true);
5960
assert.strictEqual(
6061
util.types.isNativeError(new (context('TypeError'))()),

0 commit comments

Comments
 (0)