Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/browsers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js 16
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20
- name: Restore cached dependencies
uses: actions/cache@v3
with:
Expand Down
14 changes: 14 additions & 0 deletions build/replacements.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ const internalStreamsRequireErrors = ["require\\('internal/errors'\\)", "require

const internalStreamsRequireEventEmitter = ['const EE =', 'const { EventEmitter: EE } =']

const internalStreamsLegacyListenerCount = [
"EE\\.listenerCount\\(this, 'error'\\) === 0",
"this.listenerCount?.('error') === 0"
]

const internalStreamsRequirePrimordials = ['= primordials', "= require('../../ours/primordials')"]

const internalStreamsRequireRelativeUtil = [
Expand Down Expand Up @@ -157,6 +162,7 @@ const testCommonKnownGlobals = [
typeof AbortSignal !== 'undefined' ? AbortSignal : require('abort-controller').AbortSignal,
typeof EventTarget !== 'undefined' ? EventTarget : require('event-target-shim').EventTarget,
typeof navigator !== 'undefined' ? navigator : {},
typeof sessionStorage !== 'undefined' ? sessionStorage : {},
`
]

Expand Down Expand Up @@ -214,6 +220,12 @@ const testParallelReadableBufferListInspect = [

const testParallelRequireStream = ["require\\('stream'\\)", "require('../../lib/ours/index')"]

const testParallelStreamBaseTypecheckingError = [
"code: 'ERR_INVALID_ARG_TYPE',\\n\\s+message: 'Second argument must be a buffer'",
`code: /^ERR_(?:INVALID_ARG_TYPE|UNKNOWN_ENCODING)$/,
message: /^(?:Second argument must be a buffer|Unknown encoding: buffer)$/`
]

const testParallelRequireStreamConsumer = ["require\\('stream/consumer'\\)", "require('../../lib/stream/consumer')"]

const testParallelRequireStreamInternals = ["require\\('(internal/.+)'\\)", "require('../../lib/$1')"]
Expand Down Expand Up @@ -317,6 +329,7 @@ export const replacements = {
removetoWebReadableMethod,
stringDecoderRequirePackage
],
'lib/internal/streams/legacy.js': [internalStreamsLegacyListenerCount],
'lib/internal/streams/.+': [
internalStreamsRequireErrors,
internalStreamsRequireEventEmitter,
Expand Down Expand Up @@ -358,6 +371,7 @@ export const replacements = {
'test/common/index.js': [testCommonKnownGlobals],
'test/parallel/.+': [
testParallelIncludeTap,
testParallelStreamBaseTypecheckingError,
testParallelRequireStream,
testParallelRequireStreamConsumer,
testParallelRequireStreamInternals,
Expand Down
7 changes: 6 additions & 1 deletion lib/internal/streams/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ Stream.prototype.pipe = function (dest, options) {

// Don't leave dangling pipes when there are errors.
function onerror(er) {
var _this$listenerCount
cleanup()
if (EE.listenerCount(this, 'error') === 0) {
if (
((_this$listenerCount = this.listenerCount) === null || _this$listenerCount === undefined
? undefined
: _this$listenerCount.call(this, 'error')) === 0
) {
this.emit('error', er)
}
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@rollup/plugin-inject": "^4.0.4",
"@rollup/plugin-node-resolve": "^13.3.0",
"@sinonjs/fake-timers": "^9.1.2",
"ajv": "^8.20.0",
"browserify": "^17.0.0",
"c8": "^7.11.2",
"esbuild": "^0.19.9",
Expand Down
3 changes: 2 additions & 1 deletion src/test/browser/test-stream-pipe-without-listenerCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ module.exports = function (t) {
read: function () {}
})
r.listenerCount = undefined
r.on('error', function () {})

const w = new Stream()
w.on('pipe', function () {
r.emit('error', new Error('Readable Error'))
})

t.throws(() => r.pipe(w), 'TypeError: this.listenerCount is not a function')
t.doesNotThrow(() => r.pipe(w))
}

module.exports[kReadableStreamSuiteName] = 'stream-pipe-without-listenerCount'
3 changes: 2 additions & 1 deletion test/browser/test-stream-pipe-without-listenerCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ module.exports = function (t) {
read: function () {}
})
r.listenerCount = undefined
r.on('error', function () {})
const w = new Stream()
w.on('pipe', function () {
r.emit('error', new Error('Readable Error'))
})
t.throws(() => r.pipe(w), 'TypeError: this.listenerCount is not a function')
t.doesNotThrow(() => r.pipe(w))
}
module.exports[kReadableStreamSuiteName] = 'stream-pipe-without-listenerCount'
1 change: 1 addition & 0 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ let knownGlobals = [
typeof AbortSignal !== 'undefined' ? AbortSignal : require('abort-controller').AbortSignal,
typeof EventTarget !== 'undefined' ? EventTarget : require('event-target-shim').EventTarget,
typeof navigator !== 'undefined' ? navigator : {},
typeof sessionStorage !== 'undefined' ? sessionStorage : {},
atob,
btoa,
clearImmediate,
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-stream-base-typechecking.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const server = net.createServer().listen(
},
{
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'Second argument must be a buffer'
code: /^ERR_(?:INVALID_ARG_TYPE|UNKNOWN_ENCODING)$/,
message: /^(?:Second argument must be a buffer|Unknown encoding: buffer)$/
}
)
client.destroy()
Expand Down
Loading