diff --git a/lib/internal/webstreams/queuingstrategies.js b/lib/internal/webstreams/queuingstrategies.js index df114a44cc8adc..8fbc87642ebc0c 100644 --- a/lib/internal/webstreams/queuingstrategies.js +++ b/lib/internal/webstreams/queuingstrategies.js @@ -8,7 +8,6 @@ const { const { codes: { - ERR_INVALID_THIS, ERR_MISSING_OPTION, }, } = require('internal/errors'); @@ -20,21 +19,12 @@ const { const { customInspect, - isBrandCheck, - kType, - kState, } = require('internal/webstreams/util'); const { validateObject, } = require('internal/validators'); -const isByteLengthQueuingStrategy = - isBrandCheck('ByteLengthQueuingStrategy'); - -const isCountQueuingStrategy = - isBrandCheck('CountQueuingStrategy'); - /** * @callback QueuingStrategySize * @param {any} chunk @@ -68,7 +58,8 @@ const getNonWritablePropertyDescriptor = (value) => { * @type {QueuingStrategy} */ class ByteLengthQueuingStrategy { - [kType] = 'ByteLengthQueuingStrategy'; + #state; + #byteSizeFunction = byteSizeFunction; /** * @param {{ @@ -82,7 +73,7 @@ class ByteLengthQueuingStrategy { // The highWaterMark value is not checked until the strategy // is actually used, per the spec. - this[kState] = { + this.#state = { highWaterMark: +init.highWaterMark, }; } @@ -92,22 +83,18 @@ class ByteLengthQueuingStrategy { * @type {number} */ get highWaterMark() { - if (!isByteLengthQueuingStrategy(this)) - throw new ERR_INVALID_THIS('ByteLengthQueuingStrategy'); - return this[kState].highWaterMark; + return this.#state.highWaterMark; } /** * @type {QueuingStrategySize} */ get size() { - if (!isByteLengthQueuingStrategy(this)) - throw new ERR_INVALID_THIS('ByteLengthQueuingStrategy'); - return byteSizeFunction; + return this.#byteSizeFunction; } [kInspect](depth, options) { - return customInspect(depth, options, this[kType], { + return customInspect(depth, options, 'ByteLengthQueuingStrategy', { highWaterMark: this.highWaterMark, }); } @@ -123,7 +110,8 @@ ObjectDefineProperties(ByteLengthQueuingStrategy.prototype, { * @type {QueuingStrategy} */ class CountQueuingStrategy { - [kType] = 'CountQueuingStrategy'; + #state; + #countSizeFunction = countSizeFunction; /** * @param {{ @@ -137,7 +125,7 @@ class CountQueuingStrategy { // The highWaterMark value is not checked until the strategy // is actually used, per the spec. - this[kState] = { + this.#state = { highWaterMark: +init.highWaterMark, }; } @@ -147,22 +135,18 @@ class CountQueuingStrategy { * @type {number} */ get highWaterMark() { - if (!isCountQueuingStrategy(this)) - throw new ERR_INVALID_THIS('CountQueuingStrategy'); - return this[kState].highWaterMark; + return this.#state.highWaterMark; } /** * @type {QueuingStrategySize} */ get size() { - if (!isCountQueuingStrategy(this)) - throw new ERR_INVALID_THIS('CountQueuingStrategy'); - return countSizeFunction; + return this.#countSizeFunction; } [kInspect](depth, options) { - return customInspect(depth, options, this[kType], { + return customInspect(depth, options, 'CountQueuingStrategy', { highWaterMark: this.highWaterMark, }); } diff --git a/test/parallel/test-whatwg-webstreams-coverage.js b/test/parallel/test-whatwg-webstreams-coverage.js index f0036723b05977..4d0ffe818f43f8 100644 --- a/test/parallel/test-whatwg-webstreams-coverage.js +++ b/test/parallel/test-whatwg-webstreams-coverage.js @@ -26,25 +26,29 @@ assert(isPromisePending(new Promise(() => {}))); assert.throws(() => { Reflect.get(ByteLengthQueuingStrategy.prototype, 'highWaterMark', {}); }, { - code: 'ERR_INVALID_THIS' + name: 'TypeError', + message: /Cannot read private member/, }); assert.throws(() => { Reflect.get(ByteLengthQueuingStrategy.prototype, 'size', {}); }, { - code: 'ERR_INVALID_THIS' + name: 'TypeError', + message: /Cannot read private member/, }); assert.throws(() => { Reflect.get(CountQueuingStrategy.prototype, 'highWaterMark', {}); }, { - code: 'ERR_INVALID_THIS' + name: 'TypeError', + message: /Cannot read private member/, }); assert.throws(() => { Reflect.get(CountQueuingStrategy.prototype, 'size', {}); }, { - code: 'ERR_INVALID_THIS' + name: 'TypeError', + message: /Cannot read private member/, }); // Custom Inspect Works