Files
scriptc/tests/corpus/2572-readable-emitted-readable-flag.cjs
Chris Tate 0423093a99 Node's validation ladders throw where implemented APIs were fenced
- Buffer compare/equals/constructor ladders, URLSearchParams WHATWG brand checks and arity ladders, URL.revokeObjectURL arity, and the max-listeners family answer Node's exact typed errors
- ToPrimitive string-hint coercion runs user toString/valueOf with throw propagation; assert.throws accepts expected-object variables
- Reusable always-throwing libCall shapes (error.nodeThrow, error.argTypeThrow) seed the remaining validation-ladder work
- Two emittedReadable lifecycle bugs fixed; ERR_* codes stamped across the bytes/crypto/fs range ladders

# Conflicts:
#	packages/compiler/test/ts7/baselines/order-parity.json
2026-07-23 23:37:03 -05:00

27 lines
983 B
JavaScript

// The emittedReadable flag's Node-exact lifecycle: a 'readable' listener
// observes TRUE during the emit (emitReadable_ clears it only AFTER a
// real emit), read() with a nonzero/absent size resets it (Node's
// `if (n !== 0)` — the absent form is NaN there, which also clears), and
// read(0) leaves it standing.
'use strict';
const { Readable } = require('stream');
const r = new Readable({ read: () => {} });
r.on('readable', () => {
console.log('readable-fires', r._readableState.emittedReadable);
const c = r.read();
console.log('after-read', c === null ? 'null' : c.toString(), r._readableState.emittedReadable);
});
r.push('abc');
r.push(null);
r.on('end', () => console.log('end'));
const noRead = new Readable({ read: () => {} });
noRead.on('readable', () => {
console.log('noRead-fires', noRead._readableState.emittedReadable);
noRead.read(0);
console.log('after-read0', noRead._readableState.emittedReadable);
});
noRead.push('foo');
noRead.push(null);