11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst { 41cb0ef41Sopenharmony_ci ObjectDefineProperties, 51cb0ef41Sopenharmony_ci ObjectDefineProperty, 61cb0ef41Sopenharmony_ci SymbolToStringTag, 71cb0ef41Sopenharmony_ci} = primordials; 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst { 101cb0ef41Sopenharmony_ci codes: { 111cb0ef41Sopenharmony_ci ERR_INVALID_THIS, 121cb0ef41Sopenharmony_ci ERR_MISSING_OPTION, 131cb0ef41Sopenharmony_ci }, 141cb0ef41Sopenharmony_ci} = require('internal/errors'); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciconst { 171cb0ef41Sopenharmony_ci customInspectSymbol: kInspect, 181cb0ef41Sopenharmony_ci kEnumerableProperty, 191cb0ef41Sopenharmony_ci} = require('internal/util'); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ciconst { 221cb0ef41Sopenharmony_ci customInspect, 231cb0ef41Sopenharmony_ci isBrandCheck, 241cb0ef41Sopenharmony_ci kType, 251cb0ef41Sopenharmony_ci kState, 261cb0ef41Sopenharmony_ci} = require('internal/webstreams/util'); 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ciconst { 291cb0ef41Sopenharmony_ci validateObject, 301cb0ef41Sopenharmony_ci} = require('internal/validators'); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ciconst isByteLengthQueuingStrategy = 331cb0ef41Sopenharmony_ci isBrandCheck('ByteLengthQueuingStrategy'); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ciconst isCountQueuingStrategy = 361cb0ef41Sopenharmony_ci isBrandCheck('CountQueuingStrategy'); 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci/** 391cb0ef41Sopenharmony_ci * @callback QueuingStrategySize 401cb0ef41Sopenharmony_ci * @param {any} chunk 411cb0ef41Sopenharmony_ci * @returns {number} 421cb0ef41Sopenharmony_ci */ 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci/** 451cb0ef41Sopenharmony_ci * @typedef {{ 461cb0ef41Sopenharmony_ci * highWaterMark : number, 471cb0ef41Sopenharmony_ci * size? : QueuingStrategySize, 481cb0ef41Sopenharmony_ci * }} QueuingStrategy 491cb0ef41Sopenharmony_ci */ 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ciconst nameDescriptor = { __proto__: null, value: 'size' }; 521cb0ef41Sopenharmony_ciconst byteSizeFunction = ObjectDefineProperty( 531cb0ef41Sopenharmony_ci (chunk) => chunk.byteLength, 541cb0ef41Sopenharmony_ci 'name', 551cb0ef41Sopenharmony_ci nameDescriptor, 561cb0ef41Sopenharmony_ci); 571cb0ef41Sopenharmony_ciconst countSizeFunction = ObjectDefineProperty(() => 1, 'name', nameDescriptor); 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ciconst getNonWritablePropertyDescriptor = (value) => { 601cb0ef41Sopenharmony_ci return { 611cb0ef41Sopenharmony_ci __proto__: null, 621cb0ef41Sopenharmony_ci configurable: true, 631cb0ef41Sopenharmony_ci value, 641cb0ef41Sopenharmony_ci }; 651cb0ef41Sopenharmony_ci}; 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_ci/** 681cb0ef41Sopenharmony_ci * @type {QueuingStrategy} 691cb0ef41Sopenharmony_ci */ 701cb0ef41Sopenharmony_ciclass ByteLengthQueuingStrategy { 711cb0ef41Sopenharmony_ci [kType] = 'ByteLengthQueuingStrategy'; 721cb0ef41Sopenharmony_ci 731cb0ef41Sopenharmony_ci /** 741cb0ef41Sopenharmony_ci * @param {{ 751cb0ef41Sopenharmony_ci * highWaterMark : number 761cb0ef41Sopenharmony_ci * }} init 771cb0ef41Sopenharmony_ci */ 781cb0ef41Sopenharmony_ci constructor(init) { 791cb0ef41Sopenharmony_ci validateObject(init, 'init'); 801cb0ef41Sopenharmony_ci if (init.highWaterMark === undefined) 811cb0ef41Sopenharmony_ci throw new ERR_MISSING_OPTION('init.highWaterMark'); 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ci // The highWaterMark value is not checked until the strategy 841cb0ef41Sopenharmony_ci // is actually used, per the spec. 851cb0ef41Sopenharmony_ci this[kState] = { 861cb0ef41Sopenharmony_ci highWaterMark: +init.highWaterMark, 871cb0ef41Sopenharmony_ci }; 881cb0ef41Sopenharmony_ci } 891cb0ef41Sopenharmony_ci 901cb0ef41Sopenharmony_ci /** 911cb0ef41Sopenharmony_ci * @readonly 921cb0ef41Sopenharmony_ci * @type {number} 931cb0ef41Sopenharmony_ci */ 941cb0ef41Sopenharmony_ci get highWaterMark() { 951cb0ef41Sopenharmony_ci if (!isByteLengthQueuingStrategy(this)) 961cb0ef41Sopenharmony_ci throw new ERR_INVALID_THIS('ByteLengthQueuingStrategy'); 971cb0ef41Sopenharmony_ci return this[kState].highWaterMark; 981cb0ef41Sopenharmony_ci } 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ci /** 1011cb0ef41Sopenharmony_ci * @type {QueuingStrategySize} 1021cb0ef41Sopenharmony_ci */ 1031cb0ef41Sopenharmony_ci get size() { 1041cb0ef41Sopenharmony_ci if (!isByteLengthQueuingStrategy(this)) 1051cb0ef41Sopenharmony_ci throw new ERR_INVALID_THIS('ByteLengthQueuingStrategy'); 1061cb0ef41Sopenharmony_ci return byteSizeFunction; 1071cb0ef41Sopenharmony_ci } 1081cb0ef41Sopenharmony_ci 1091cb0ef41Sopenharmony_ci [kInspect](depth, options) { 1101cb0ef41Sopenharmony_ci return customInspect(depth, options, this[kType], { 1111cb0ef41Sopenharmony_ci highWaterMark: this.highWaterMark, 1121cb0ef41Sopenharmony_ci }); 1131cb0ef41Sopenharmony_ci } 1141cb0ef41Sopenharmony_ci} 1151cb0ef41Sopenharmony_ci 1161cb0ef41Sopenharmony_ciObjectDefineProperties(ByteLengthQueuingStrategy.prototype, { 1171cb0ef41Sopenharmony_ci highWaterMark: kEnumerableProperty, 1181cb0ef41Sopenharmony_ci size: kEnumerableProperty, 1191cb0ef41Sopenharmony_ci [SymbolToStringTag]: getNonWritablePropertyDescriptor(ByteLengthQueuingStrategy.name), 1201cb0ef41Sopenharmony_ci}); 1211cb0ef41Sopenharmony_ci 1221cb0ef41Sopenharmony_ci/** 1231cb0ef41Sopenharmony_ci * @type {QueuingStrategy} 1241cb0ef41Sopenharmony_ci */ 1251cb0ef41Sopenharmony_ciclass CountQueuingStrategy { 1261cb0ef41Sopenharmony_ci [kType] = 'CountQueuingStrategy'; 1271cb0ef41Sopenharmony_ci 1281cb0ef41Sopenharmony_ci /** 1291cb0ef41Sopenharmony_ci * @param {{ 1301cb0ef41Sopenharmony_ci * highWaterMark : number 1311cb0ef41Sopenharmony_ci * }} init 1321cb0ef41Sopenharmony_ci */ 1331cb0ef41Sopenharmony_ci constructor(init) { 1341cb0ef41Sopenharmony_ci validateObject(init, 'init'); 1351cb0ef41Sopenharmony_ci if (init.highWaterMark === undefined) 1361cb0ef41Sopenharmony_ci throw new ERR_MISSING_OPTION('init.highWaterMark'); 1371cb0ef41Sopenharmony_ci 1381cb0ef41Sopenharmony_ci // The highWaterMark value is not checked until the strategy 1391cb0ef41Sopenharmony_ci // is actually used, per the spec. 1401cb0ef41Sopenharmony_ci this[kState] = { 1411cb0ef41Sopenharmony_ci highWaterMark: +init.highWaterMark, 1421cb0ef41Sopenharmony_ci }; 1431cb0ef41Sopenharmony_ci } 1441cb0ef41Sopenharmony_ci 1451cb0ef41Sopenharmony_ci /** 1461cb0ef41Sopenharmony_ci * @readonly 1471cb0ef41Sopenharmony_ci * @type {number} 1481cb0ef41Sopenharmony_ci */ 1491cb0ef41Sopenharmony_ci get highWaterMark() { 1501cb0ef41Sopenharmony_ci if (!isCountQueuingStrategy(this)) 1511cb0ef41Sopenharmony_ci throw new ERR_INVALID_THIS('CountQueuingStrategy'); 1521cb0ef41Sopenharmony_ci return this[kState].highWaterMark; 1531cb0ef41Sopenharmony_ci } 1541cb0ef41Sopenharmony_ci 1551cb0ef41Sopenharmony_ci /** 1561cb0ef41Sopenharmony_ci * @type {QueuingStrategySize} 1571cb0ef41Sopenharmony_ci */ 1581cb0ef41Sopenharmony_ci get size() { 1591cb0ef41Sopenharmony_ci if (!isCountQueuingStrategy(this)) 1601cb0ef41Sopenharmony_ci throw new ERR_INVALID_THIS('CountQueuingStrategy'); 1611cb0ef41Sopenharmony_ci return countSizeFunction; 1621cb0ef41Sopenharmony_ci } 1631cb0ef41Sopenharmony_ci 1641cb0ef41Sopenharmony_ci [kInspect](depth, options) { 1651cb0ef41Sopenharmony_ci return customInspect(depth, options, this[kType], { 1661cb0ef41Sopenharmony_ci highWaterMark: this.highWaterMark, 1671cb0ef41Sopenharmony_ci }); 1681cb0ef41Sopenharmony_ci } 1691cb0ef41Sopenharmony_ci} 1701cb0ef41Sopenharmony_ci 1711cb0ef41Sopenharmony_ciObjectDefineProperties(CountQueuingStrategy.prototype, { 1721cb0ef41Sopenharmony_ci highWaterMark: kEnumerableProperty, 1731cb0ef41Sopenharmony_ci size: kEnumerableProperty, 1741cb0ef41Sopenharmony_ci [SymbolToStringTag]: getNonWritablePropertyDescriptor(CountQueuingStrategy.name), 1751cb0ef41Sopenharmony_ci}); 1761cb0ef41Sopenharmony_ci 1771cb0ef41Sopenharmony_cimodule.exports = { 1781cb0ef41Sopenharmony_ci ByteLengthQueuingStrategy, 1791cb0ef41Sopenharmony_ci CountQueuingStrategy, 1801cb0ef41Sopenharmony_ci}; 181