@@ -81,6 +81,34 @@ async function testPlanBackpressure() {
8181 ) ;
8282}
8383
84+ async function testDestroyWhileBlocked ( ) {
85+ const runner = createRunner ( { yieldBetweenSamples : false } ) ;
86+ const completions = [ ] ;
87+ for ( let i = 0 ; i < 32 ; i ++ ) {
88+ completions . push ( runner . bench ( `destroyed ${ i } ` , {
89+ samples : 1 ,
90+ } , recordSample ) ) ;
91+ }
92+ const stream = runner . run ( ) ;
93+ const unblocked = stream . waitForDrain ( ) ;
94+ const iterator = stream [ Symbol . asyncIterator ] ( ) ;
95+ await iterator . next ( ) ;
96+ await unblocked ;
97+ for ( let i = 0 ; i < 100 &&
98+ stream . readableLength < stream . readableHighWaterMark ; i ++ ) {
99+ await setImmediate ( ) ;
100+ }
101+ assert . strictEqual ( stream . readableLength , stream . readableHighWaterMark ) ;
102+
103+ const draining = stream . waitForDrain ( ) ;
104+ const closed = new Promise ( ( resolve ) => stream . once ( 'close' , resolve ) ) ;
105+ stream . destroy ( ) ;
106+ await assert . rejects ( draining , { code : 'ERR_INVALID_STATE' } ) ;
107+ await assert . rejects ( stream . waitForDrain ( ) , { code : 'ERR_INVALID_STATE' } ) ;
108+ await closed ;
109+ await Promise . all ( completions ) ;
110+ }
111+
84112async function testNamedEventsWithoutReading ( ) {
85113 const runner = createRunner ( ) ;
86114 const sampleCount = 64 ;
@@ -192,7 +220,13 @@ async function testRecordOwnership() {
192220 expectedError . context = {
193221 note : 'preserved' ,
194222 callback ( ) { } ,
223+ get accessor ( ) { return 'value' ; } ,
224+ } ;
225+ expectedError . customContext = {
226+ __proto__ : { } ,
227+ note : 'preserved' ,
195228 } ;
229+ expectedError . arrayPayload = [ new WeakMap ( ) ] ;
196230 const innerError = new Error ( 'inner failure' ) ;
197231 innerError . code = 'ERR_INNER' ;
198232 const aggregate = new AggregateError ( [ innerError ] , 'aggregate failure' ) ;
@@ -217,6 +251,16 @@ async function testRecordOwnership() {
217251 const caused = runner . bench ( 'owned cause' , { samples : 1 } , ( ) => {
218252 throw causedError ;
219253 } ) ;
254+ const throwingNameError = new Error ( 'throwing name' ) ;
255+ Object . defineProperty ( throwingNameError , 'name' , {
256+ configurable : true ,
257+ get ( ) { throw new Error ( 'name getter' ) ; } ,
258+ } ) ;
259+ const throwingName = runner . bench ( 'throwing name' , {
260+ samples : 1 ,
261+ } , ( ) => {
262+ throw throwingNameError ;
263+ } ) ;
220264 const thrownValue = new WeakMap ( ) ;
221265 const uncloneable = runner . bench ( 'uncloneable error' , {
222266 samples : 1 ,
@@ -265,6 +309,7 @@ async function testRecordOwnership() {
265309 const measuredResult = await measured ;
266310 const failedResult = await failed ;
267311 await caused ;
312+ const throwingNameResult = await throwingName ;
268313 const uncloneableResult = await uncloneable ;
269314 const trappedResult = await trapped ;
270315 const afterTrapResult = await afterTrap ;
@@ -278,6 +323,8 @@ async function testRecordOwnership() {
278323 ( { name } ) => name === 'owned error' ) ;
279324 const streamCaused = streamResults . find (
280325 ( { name } ) => name === 'owned cause' ) ;
326+ const streamThrowingName = streamResults . find (
327+ ( { name } ) => name === 'throwing name' ) ;
281328 const streamSummary = records . find (
282329 ( { type } ) => type === 'bench:summary' ) . data ;
283330
@@ -299,12 +346,18 @@ async function testRecordOwnership() {
299346 assert . strictEqual ( streamFailed . error . cause , streamFailed . error ) ;
300347 assert . strictEqual ( streamFailed . error . context . note , 'preserved' ) ;
301348 assert . strictEqual ( streamFailed . error . context . callback , undefined ) ;
349+ assert . strictEqual ( streamFailed . error . context . accessor , undefined ) ;
350+ assert . strictEqual ( streamFailed . error . customContext . note , 'preserved' ) ;
351+ assert . deepStrictEqual ( streamFailed . error . arrayPayload , [ undefined ] ) ;
302352 assert . strictEqual ( failedResult . error , expectedError ) ;
303353 assert . strictEqual ( failedResult . error . code , 'ERR_EXPECTED' ) ;
304354 assert . strictEqual ( failedResult . error . cause , failedResult . error ) ;
305355 assert . strictEqual ( uncloneableResult . error , thrownValue ) ;
306356 assert . strictEqual ( trappedResult . error , proxyError ) ;
307357 assert . strictEqual ( afterTrapResult . error , undefined ) ;
358+ assert . strictEqual ( throwingNameResult . error , throwingNameError ) ;
359+ assert . strictEqual ( streamThrowingName . error . name , 'Error' ) ;
360+ assert . strictEqual ( streamThrowingName . error . message , 'throwing name' ) ;
308361 assert ( streamCaused . error . cause instanceof AggregateError ) ;
309362 assert . strictEqual ( streamCaused . error . cause . name , 'AggregateError' ) ;
310363 assert . strictEqual ( streamCaused . error . cause . code , 'ERR_AGGREGATE' ) ;
@@ -313,12 +366,13 @@ async function testRecordOwnership() {
313366 streamCaused . error . references . get ( 'self' ) , streamCaused . error ) ;
314367 assert . strictEqual ( streamCaused . error . members . has ( streamCaused . error ) , true ) ;
315368 assert . notStrictEqual ( eventSummary , streamSummary ) ;
316- assert . strictEqual ( streamSummary . counts . total , 6 ) ;
369+ assert . strictEqual ( streamSummary . counts . total , 7 ) ;
317370}
318371
319372( async ( ) => {
320373 await testReadableBackpressure ( ) ;
321374 await testPlanBackpressure ( ) ;
375+ await testDestroyWhileBlocked ( ) ;
322376 await testNamedEventsWithoutReading ( ) ;
323377 await testCancellationCompletesBenchmarks ( ) ;
324378 await testDeliveryDoesNotConsumeTimeout ( ) ;
0 commit comments