Skip to content

Commit e2b32fc

Browse files
committed
stream: remove custom CloneableDOMException implementation
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: #64469 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 4a158cf commit e2b32fc

1 file changed

Lines changed: 2 additions & 85 deletions

File tree

lib/internal/webstreams/transfer.js

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

33
const {
4-
ObjectDefineProperties,
54
PromiseResolve,
65
PromiseWithResolvers,
7-
ReflectConstruct,
86
} = primordials;
97

108
const {
@@ -31,73 +29,6 @@ const {
3129

3230
const assert = require('internal/assert');
3331

34-
const {
35-
markTransferMode,
36-
kClone,
37-
kDeserialize,
38-
} = require('internal/worker/js_transferable');
39-
40-
// This class is a bit of a hack. The Node.js implementation of
41-
// DOMException is not transferable/cloneable. This provides us
42-
// with a variant that is. Unfortunately, it means playing around
43-
// a bit with the message, name, and code properties and the
44-
// prototype. We can revisit this if DOMException is ever made
45-
// properly cloneable.
46-
class CloneableDOMException extends DOMException {
47-
constructor(message, name) {
48-
super(message, name);
49-
markTransferMode(this, true, false);
50-
this[kDeserialize]({
51-
message: this.message,
52-
name: this.name,
53-
code: this.code,
54-
});
55-
}
56-
57-
[kClone]() {
58-
return {
59-
data: {
60-
message: this.message,
61-
name: this.name,
62-
code: this.code,
63-
},
64-
deserializeInfo:
65-
'internal/webstreams/transfer:InternalCloneableDOMException',
66-
};
67-
}
68-
69-
[kDeserialize]({ message, name, code }) {
70-
ObjectDefineProperties(this, {
71-
message: {
72-
__proto__: null,
73-
configurable: true,
74-
enumerable: true,
75-
get() { return message; },
76-
},
77-
name: {
78-
__proto__: null,
79-
configurable: true,
80-
enumerable: true,
81-
get() { return name; },
82-
},
83-
code: {
84-
__proto__: null,
85-
configurable: true,
86-
enumerable: true,
87-
get() { return code; },
88-
},
89-
});
90-
}
91-
}
92-
93-
function InternalCloneableDOMException() {
94-
return ReflectConstruct(
95-
CloneableDOMException,
96-
[],
97-
DOMException);
98-
}
99-
InternalCloneableDOMException[kDeserialize] = () => {};
100-
10132
class CrossRealmTransformReadableSource {
10233
constructor(port, unref) {
10334
this[kState] = {
@@ -132,7 +63,7 @@ class CrossRealmTransformReadableSource {
13263
};
13364

13465
port.onmessageerror = () => {
135-
const error = new CloneableDOMException(
66+
const error = new DOMException(
13667
'Internal transferred ReadableStream error',
13768
'DataCloneError');
13869
port.postMessage({ type: 'error', value: error });
@@ -161,10 +92,6 @@ class CrossRealmTransformReadableSource {
16192
try {
16293
this[kState].port.postMessage({ type: 'error', value: reason });
16394
} catch (error) {
164-
if (error instanceof DOMException) {
165-
// eslint-disable-next-line no-ex-assign
166-
error = new CloneableDOMException(error.message, error.name);
167-
}
16895
this[kState].port.postMessage({ type: 'error', value: error });
16996
throw error;
17097
} finally {
@@ -206,7 +133,7 @@ class CrossRealmTransformWritableSink {
206133
}
207134
};
208135
port.onmessageerror = () => {
209-
const error = new CloneableDOMException(
136+
const error = new DOMException(
210137
'Internal transferred ReadableStream error',
211138
'DataCloneError');
212139
port.postMessage({ type: 'error', value: error });
@@ -240,10 +167,6 @@ class CrossRealmTransformWritableSink {
240167
try {
241168
this[kState].port.postMessage({ type: 'chunk', value: chunk });
242169
} catch (error) {
243-
if (error instanceof DOMException) {
244-
// eslint-disable-next-line no-ex-assign
245-
error = new CloneableDOMException(error.message, error.name);
246-
}
247170
this[kState].port.postMessage({ type: 'error', value: error });
248171
this[kState].port.close();
249172
throw error;
@@ -259,10 +182,6 @@ class CrossRealmTransformWritableSink {
259182
try {
260183
this[kState].port.postMessage({ type: 'error', value: reason });
261184
} catch (error) {
262-
if (error instanceof DOMException) {
263-
// eslint-disable-next-line no-ex-assign
264-
error = new CloneableDOMException(error.message, error.name);
265-
}
266185
this[kState].port.postMessage({ type: 'error', value: error });
267186
throw error;
268187
} finally {
@@ -308,6 +227,4 @@ module.exports = {
308227
newCrossRealmWritableSink,
309228
CrossRealmTransformWritableSink,
310229
CrossRealmTransformReadableSource,
311-
CloneableDOMException,
312-
InternalCloneableDOMException,
313230
};

0 commit comments

Comments
 (0)