Skip to content

Commit 9a26546

Browse files
committedDec 12, 2018
zlib: throw TypeError if callback is missing
Get a proper stack trace when no callback is passed. PR-URL: #24929 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent a0bdeb5 commit 9a26546

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
 

‎lib/zlib.js

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ for (var ck = 0; ck < ckeys.length; ck++) {
7373
}
7474

7575
function zlibBuffer(engine, buffer, callback) {
76+
if (typeof callback !== 'function')
77+
throw new ERR_INVALID_ARG_TYPE('callback', 'function', callback);
7678
// Streams do not support non-Buffer ArrayBufferViews yet. Convert it to a
7779
// Buffer without copying.
7880
if (isArrayBufferView(buffer) &&

‎test/parallel/test-zlib-convenience-methods.js

+10
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,13 @@ for (const [type, expect] of [
119119
}
120120
}
121121
}
122+
123+
common.expectsError(
124+
() => zlib.gzip('abc'),
125+
{
126+
code: 'ERR_INVALID_ARG_TYPE',
127+
type: TypeError,
128+
message: 'The "callback" argument must be of type function. ' +
129+
'Received type undefined'
130+
}
131+
);

0 commit comments

Comments
 (0)
Please sign in to comment.