1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6const assert = require('assert'); 7const http2 = require('http2'); 8 9const server = http2.createServer(); 10 11const types = [ 12 true, 13 {}, 14 [], 15 null, 16 new Date(), 17]; 18 19server.on('stream', common.mustCall((stream) => { 20 const session = stream.session; 21 22 for (const input of types) { 23 const received = common.invalidArgTypeHelper(input); 24 assert.throws( 25 () => session.goaway(input), 26 { 27 code: 'ERR_INVALID_ARG_TYPE', 28 name: 'TypeError', 29 message: 'The "code" argument must be of type number.' + 30 received 31 } 32 ); 33 assert.throws( 34 () => session.goaway(0, input), 35 { 36 code: 'ERR_INVALID_ARG_TYPE', 37 name: 'TypeError', 38 message: 'The "lastStreamID" argument must be of type number.' + 39 received 40 } 41 ); 42 assert.throws( 43 () => session.goaway(0, 0, input), 44 { 45 code: 'ERR_INVALID_ARG_TYPE', 46 name: 'TypeError', 47 message: 'The "opaqueData" argument must be an instance of Buffer, ' + 48 `TypedArray, or DataView.${received}` 49 } 50 ); 51 } 52 53 stream.session.destroy(); 54})); 55 56server.listen( 57 0, 58 common.mustCall(() => { 59 const client = http2.connect(`http://localhost:${server.address().port}`); 60 const req = client.request(); 61 req.resume(); 62 req.on('close', common.mustCall(() => { 63 client.close(); 64 server.close(); 65 })); 66 }) 67); 68