11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciif (!common.hasCrypto) 51cb0ef41Sopenharmony_ci common.skip('missing crypto'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst assert = require('assert'); 81cb0ef41Sopenharmony_ciconst http2 = require('http2'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst server = http2.createServer(); 111cb0ef41Sopenharmony_ciserver.on('stream', (stream) => { 121cb0ef41Sopenharmony_ci stream.respond(); 131cb0ef41Sopenharmony_ci stream.end('ok'); 141cb0ef41Sopenharmony_ci}); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciconst types = { 171cb0ef41Sopenharmony_ci boolean: true, 181cb0ef41Sopenharmony_ci function: () => {}, 191cb0ef41Sopenharmony_ci number: 1, 201cb0ef41Sopenharmony_ci object: {}, 211cb0ef41Sopenharmony_ci array: [], 221cb0ef41Sopenharmony_ci null: null, 231cb0ef41Sopenharmony_ci symbol: Symbol('test') 241cb0ef41Sopenharmony_ci}; 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 271cb0ef41Sopenharmony_ci const client = http2.connect(`http://localhost:${server.address().port}`); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci client.on('connect', () => { 301cb0ef41Sopenharmony_ci const outOfRangeNum = 2 ** 32; 311cb0ef41Sopenharmony_ci assert.throws( 321cb0ef41Sopenharmony_ci () => client.setNextStreamID(outOfRangeNum), 331cb0ef41Sopenharmony_ci { 341cb0ef41Sopenharmony_ci name: 'RangeError', 351cb0ef41Sopenharmony_ci code: 'ERR_OUT_OF_RANGE', 361cb0ef41Sopenharmony_ci message: 'The value of "id" is out of range.' + 371cb0ef41Sopenharmony_ci ' It must be > 0 and <= 4294967295. Received ' + outOfRangeNum 381cb0ef41Sopenharmony_ci } 391cb0ef41Sopenharmony_ci ); 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci // Should throw if something other than number is passed to setNextStreamID 421cb0ef41Sopenharmony_ci Object.entries(types).forEach(([type, value]) => { 431cb0ef41Sopenharmony_ci if (type === 'number') { 441cb0ef41Sopenharmony_ci return; 451cb0ef41Sopenharmony_ci } 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ci assert.throws( 481cb0ef41Sopenharmony_ci () => client.setNextStreamID(value), 491cb0ef41Sopenharmony_ci { 501cb0ef41Sopenharmony_ci name: 'TypeError', 511cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 521cb0ef41Sopenharmony_ci message: 'The "id" argument must be of type number.' + 531cb0ef41Sopenharmony_ci common.invalidArgTypeHelper(value) 541cb0ef41Sopenharmony_ci } 551cb0ef41Sopenharmony_ci ); 561cb0ef41Sopenharmony_ci }); 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci server.close(); 591cb0ef41Sopenharmony_ci client.close(); 601cb0ef41Sopenharmony_ci }); 611cb0ef41Sopenharmony_ci})); 62