Skip to content

Commit bcb83f7

Browse files
apapirovskiMylesBorins
authored andcommitted
http2: remove unnecessary asserts in core
options.getTrailers & options.selectPadding will always be a function by the time the code reaches the assert checks. And even if not (which seems currently impossible), the assert failure will be almost the same as calling something that is not a function. The downside of leaving these is that typeof checks are decently expensive. PR-URL: #16327 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 098cd90 commit bcb83f7

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

lib/internal/http2/core.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,8 @@ function onSessionTrailers(id) {
218218
assert(stream !== undefined,
219219
'Internal HTTP/2 Failure. Stream does not exist. Please ' +
220220
'report this as a bug in Node.js');
221-
const getTrailers = stream[kState].getTrailers;
222-
// We should not have been able to get here at all if getTrailers
223-
// was not a function, and there's no code that could have changed
224-
// it between there and here.
225-
assert.strictEqual(typeof getTrailers, 'function');
226221
const trailers = Object.create(null);
227-
getTrailers.call(stream, trailers);
222+
stream[kState].getTrailers.call(stream, trailers);
228223
const headersList = mapToHeaders(trailers, assertValidPseudoHeaderTrailer);
229224
if (!Array.isArray(headersList)) {
230225
process.nextTick(emit, stream, 'error', headersList);
@@ -382,9 +377,6 @@ function onGoawayData(code, lastStreamID, buf) {
382377
// maxPayloadLen. The method must return a numeric value within the range
383378
// frameLen <= n <= maxPayloadLen.
384379
function onSelectPadding(fn) {
385-
assert(typeof fn === 'function',
386-
'options.selectPadding must be a function. Please report this as a ' +
387-
'bug in Node.js');
388380
return function getPadding() {
389381
debug('fetching padding for frame');
390382
const frameLen = paddingBuffer[PADDING_BUF_FRAME_LENGTH];

0 commit comments

Comments
 (0)