@@ -17,6 +17,14 @@ const harden = /** @type {import('ses').Harden & { isFake?: boolean }} */ (
17
17
global . harden
18
18
) ;
19
19
20
+ // Unknown error names decode as generic Errors.
21
+ // TODO: Remove after dropping support for pre-AggregateError implementations.
22
+ const supportsAggregateError = typeof AggregateError !== 'undefined' ;
23
+ const decodedAggregateErrorCtor = supportsAggregateError
24
+ ? AggregateError
25
+ : Error ;
26
+ const testIfAggregateError = supportsAggregateError ? test : test . skip ;
27
+
20
28
// this only includes the tests that do not use liveSlots
21
29
22
30
/**
@@ -153,10 +161,6 @@ test('unserialize errors', t => {
153
161
} ) ;
154
162
155
163
test ( 'unserialize extended errors' , t => {
156
- if ( typeof AggregateError === 'undefined' ) {
157
- t . pass ( 'skip test on platforms prior to AggregateError' ) ;
158
- return ;
159
- }
160
164
const { unserialize } = makeTestMarshal ( ) ;
161
165
const uns = body => unserialize ( { body, slots : [ ] } ) ;
162
166
@@ -171,10 +175,14 @@ test('unserialize extended errors', t => {
171
175
const aggErr = uns (
172
176
'{"@qclass":"error","message":"msg","name":"AggregateError","extraProp":"foo","cause":"bar","errors":["zip","zap"]}' ,
173
177
) ;
174
- t . is ( getPrototypeOf ( aggErr ) , AggregateError . prototype ) ; // direct instance of
178
+ t . is ( getPrototypeOf ( aggErr ) , decodedAggregateErrorCtor . prototype ) ; // direct instance of
175
179
t . false ( 'extraProp' in aggErr ) ;
176
180
t . false ( 'cause' in aggErr ) ;
177
- t . is ( aggErr . errors . length , 0 ) ;
181
+ if ( supportsAggregateError ) {
182
+ t . is ( aggErr . errors . length , 0 ) ;
183
+ } else {
184
+ t . false ( 'errors' in aggErr ) ;
185
+ }
178
186
179
187
const unkErr = uns (
180
188
'{"@qclass":"error","message":"msg","name":"UnknownError","extraProp":"foo","cause":"bar","errors":["zip","zap"]}' ,
@@ -185,10 +193,7 @@ test('unserialize extended errors', t => {
185
193
t . false ( 'errors' in unkErr ) ;
186
194
} ) ;
187
195
188
- const testIfAggregateError =
189
- typeof AggregateError !== 'undefined' ? test : test . skip ;
190
-
191
- testIfAggregateError ( 'unserialize errors w recognized extensions' , t => {
196
+ testIfAggregateError ( 'unserialize recognized error extensions' , t => {
192
197
const { unserialize } = makeTestMarshal ( ) ;
193
198
const uns = body => unserialize ( { body, slots : [ ] } ) ;
194
199
@@ -205,7 +210,7 @@ testIfAggregateError('unserialize errors w recognized extensions', t => {
205
210
const aggErr = uns (
206
211
`{"@qclass":"error","message":"msg","name":"AggregateError","extraProp":"foo","cause":${ errEnc } ,"errors":[${ errEnc } ]}` ,
207
212
) ;
208
- t . is ( getPrototypeOf ( aggErr ) , AggregateError . prototype ) ; // direct instance of
213
+ t . is ( getPrototypeOf ( aggErr ) , decodedAggregateErrorCtor . prototype ) ; // direct instance of
209
214
t . false ( 'extraProp' in aggErr ) ;
210
215
t . is ( getPrototypeOf ( aggErr . cause ) , URIError . prototype ) ;
211
216
t . is ( getPrototypeOf ( aggErr . errors [ 0 ] ) , URIError . prototype ) ;
0 commit comments