Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dac8de6

Browse filesBrowse files
anonrignodejs-github-bot
authored andcommitted
stream: use private properties for strategies
PR-URL: #47218 Reviewed-By: Erick Wendel <erick.workspace@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
1 parent 1fa084e commit dac8de6
Copy full SHA for dac8de6

File tree

Expand file treeCollapse file tree

2 files changed

+20
-32
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-32
lines changed
Open diff view settings
Collapse file

‎lib/internal/webstreams/queuingstrategies.js‎

Copy file name to clipboardExpand all lines: lib/internal/webstreams/queuingstrategies.js
+12-28Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const {
88

99
const {
1010
codes: {
11-
ERR_INVALID_THIS,
1211
ERR_MISSING_OPTION,
1312
},
1413
} = require('internal/errors');
@@ -20,21 +19,12 @@ const {
2019

2120
const {
2221
customInspect,
23-
isBrandCheck,
24-
kType,
25-
kState,
2622
} = require('internal/webstreams/util');
2723

2824
const {
2925
validateObject,
3026
} = require('internal/validators');
3127

32-
const isByteLengthQueuingStrategy =
33-
isBrandCheck('ByteLengthQueuingStrategy');
34-
35-
const isCountQueuingStrategy =
36-
isBrandCheck('CountQueuingStrategy');
37-
3828
/**
3929
* @callback QueuingStrategySize
4030
* @param {any} chunk
@@ -68,7 +58,8 @@ const getNonWritablePropertyDescriptor = (value) => {
6858
* @type {QueuingStrategy}
6959
*/
7060
class ByteLengthQueuingStrategy {
71-
[kType] = 'ByteLengthQueuingStrategy';
61+
#state;
62+
#byteSizeFunction = byteSizeFunction;
7263

7364
/**
7465
* @param {{
@@ -82,7 +73,7 @@ class ByteLengthQueuingStrategy {
8273

8374
// The highWaterMark value is not checked until the strategy
8475
// is actually used, per the spec.
85-
this[kState] = {
76+
this.#state = {
8677
highWaterMark: +init.highWaterMark,
8778
};
8879
}
@@ -92,22 +83,18 @@ class ByteLengthQueuingStrategy {
9283
* @type {number}
9384
*/
9485
get highWaterMark() {
95-
if (!isByteLengthQueuingStrategy(this))
96-
throw new ERR_INVALID_THIS('ByteLengthQueuingStrategy');
97-
return this[kState].highWaterMark;
86+
return this.#state.highWaterMark;
9887
}
9988

10089
/**
10190
* @type {QueuingStrategySize}
10291
*/
10392
get size() {
104-
if (!isByteLengthQueuingStrategy(this))
105-
throw new ERR_INVALID_THIS('ByteLengthQueuingStrategy');
106-
return byteSizeFunction;
93+
return this.#byteSizeFunction;
10794
}
10895

10996
[kInspect](depth, options) {
110-
return customInspect(depth, options, this[kType], {
97+
return customInspect(depth, options, 'ByteLengthQueuingStrategy', {
11198
highWaterMark: this.highWaterMark,
11299
});
113100
}
@@ -123,7 +110,8 @@ ObjectDefineProperties(ByteLengthQueuingStrategy.prototype, {
123110
* @type {QueuingStrategy}
124111
*/
125112
class CountQueuingStrategy {
126-
[kType] = 'CountQueuingStrategy';
113+
#state;
114+
#countSizeFunction = countSizeFunction;
127115

128116
/**
129117
* @param {{
@@ -137,7 +125,7 @@ class CountQueuingStrategy {
137125

138126
// The highWaterMark value is not checked until the strategy
139127
// is actually used, per the spec.
140-
this[kState] = {
128+
this.#state = {
141129
highWaterMark: +init.highWaterMark,
142130
};
143131
}
@@ -147,22 +135,18 @@ class CountQueuingStrategy {
147135
* @type {number}
148136
*/
149137
get highWaterMark() {
150-
if (!isCountQueuingStrategy(this))
151-
throw new ERR_INVALID_THIS('CountQueuingStrategy');
152-
return this[kState].highWaterMark;
138+
return this.#state.highWaterMark;
153139
}
154140

155141
/**
156142
* @type {QueuingStrategySize}
157143
*/
158144
get size() {
159-
if (!isCountQueuingStrategy(this))
160-
throw new ERR_INVALID_THIS('CountQueuingStrategy');
161-
return countSizeFunction;
145+
return this.#countSizeFunction;
162146
}
163147

164148
[kInspect](depth, options) {
165-
return customInspect(depth, options, this[kType], {
149+
return customInspect(depth, options, 'CountQueuingStrategy', {
166150
highWaterMark: this.highWaterMark,
167151
});
168152
}
Collapse file

‎test/parallel/test-whatwg-webstreams-coverage.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-webstreams-coverage.js
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,29 @@ assert(isPromisePending(new Promise(() => {})));
2626
assert.throws(() => {
2727
Reflect.get(ByteLengthQueuingStrategy.prototype, 'highWaterMark', {});
2828
}, {
29-
code: 'ERR_INVALID_THIS'
29+
name: 'TypeError',
30+
message: /Cannot read private member/,
3031
});
3132

3233
assert.throws(() => {
3334
Reflect.get(ByteLengthQueuingStrategy.prototype, 'size', {});
3435
}, {
35-
code: 'ERR_INVALID_THIS'
36+
name: 'TypeError',
37+
message: /Cannot read private member/,
3638
});
3739

3840
assert.throws(() => {
3941
Reflect.get(CountQueuingStrategy.prototype, 'highWaterMark', {});
4042
}, {
41-
code: 'ERR_INVALID_THIS'
43+
name: 'TypeError',
44+
message: /Cannot read private member/,
4245
});
4346

4447
assert.throws(() => {
4548
Reflect.get(CountQueuingStrategy.prototype, 'size', {});
4649
}, {
47-
code: 'ERR_INVALID_THIS'
50+
name: 'TypeError',
51+
message: /Cannot read private member/,
4852
});
4953

5054
// Custom Inspect Works

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.