Skip to content

Commit 5ede458

Browse files
Mesteerybengl
authored andcommitted
lib: move kEnumerableProperty to internal/util
PR-URL: #41877 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent eeb3a68 commit 5ede458

14 files changed

+57
-65
lines changed

lib/internal/abort_controller.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const {
2525
} = require('internal/event_target');
2626
const {
2727
customInspectSymbol,
28+
kEnumerableProperty,
2829
} = require('internal/util');
2930
const { inspect } = require('internal/util/inspect');
3031
const {
@@ -260,7 +261,7 @@ function ClonedAbortSignal() {
260261
ClonedAbortSignal.prototype[kDeserialize] = () => {};
261262

262263
ObjectDefineProperties(AbortSignal.prototype, {
263-
aborted: { enumerable: true }
264+
aborted: kEnumerableProperty,
264265
});
265266

266267
ObjectDefineProperty(AbortSignal.prototype, SymbolToStringTag, {
@@ -329,8 +330,8 @@ class AbortController {
329330
}
330331

331332
ObjectDefineProperties(AbortController.prototype, {
332-
signal: { enumerable: true },
333-
abort: { enumerable: true }
333+
signal: kEnumerableProperty,
334+
abort: kEnumerableProperty,
334335
});
335336

336337
ObjectDefineProperty(AbortController.prototype, SymbolToStringTag, {

lib/internal/crypto/webcrypto.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const {
55
JSONParse,
66
JSONStringify,
77
ObjectDefineProperties,
8-
ObjectGetOwnPropertyDescriptor,
98
SafeSet,
109
SymbolToStringTag,
1110
StringPrototypeRepeat,
@@ -60,6 +59,7 @@ const {
6059
} = require('internal/crypto/util');
6160

6261
const {
62+
kEnumerableProperty,
6363
lazyDOMException,
6464
} = require('internal/util');
6565

@@ -703,10 +703,7 @@ ObjectDefineProperties(
703703
writable: false,
704704
value: 'Crypto',
705705
},
706-
subtle: {
707-
...ObjectGetOwnPropertyDescriptor(Crypto.prototype, 'subtle'),
708-
enumerable: true,
709-
},
706+
subtle: kEnumerableProperty,
710707
getRandomValues: {
711708
enumerable: true,
712709
configurable: true,

lib/internal/encoding.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ const kEncoder = Symbol('encoder');
3030

3131
const {
3232
getConstructorOf,
33-
customInspectSymbol: inspect
33+
customInspectSymbol: inspect,
34+
kEnumerableProperty,
3435
} = require('internal/util');
3536

3637
const {
@@ -358,9 +359,9 @@ class TextEncoder {
358359

359360
ObjectDefineProperties(
360361
TextEncoder.prototype, {
361-
'encode': { enumerable: true },
362-
'encodeInto': { enumerable: true },
363-
'encoding': { enumerable: true },
362+
'encode': kEnumerableProperty,
363+
'encodeInto': kEnumerableProperty,
364+
'encoding': kEnumerableProperty,
364365
[SymbolToStringTag]: { configurable: true, value: 'TextEncoder' },
365366
});
366367

@@ -569,7 +570,7 @@ ObjectDefineProperties(
569570
);
570571

571572
ObjectDefineProperties(TextDecoder.prototype, {
572-
decode: { enumerable: true },
573+
decode: kEnumerableProperty,
573574
[inspect]: { enumerable: false },
574575
[SymbolToStringTag]: {
575576
configurable: true,

lib/internal/event_target.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const {
88
FunctionPrototypeCall,
99
NumberIsInteger,
1010
ObjectAssign,
11-
ObjectCreate,
1211
ObjectDefineProperties,
1312
ObjectDefineProperty,
1413
ObjectGetOwnPropertyDescriptor,
@@ -36,7 +35,7 @@ const {
3635
} = require('internal/errors');
3736
const { validateObject, validateString } = require('internal/validators');
3837

39-
const { customInspectSymbol } = require('internal/util');
38+
const { customInspectSymbol, kEnumerableProperty } = require('internal/util');
4039
const { inspect } = require('util');
4140

4241
const kIsEventTarget = SymbolFor('nodejs.event_target');
@@ -298,9 +297,6 @@ class Event {
298297
static BUBBLING_PHASE = 3;
299298
}
300299

301-
const kEnumerableProperty = ObjectCreate(null);
302-
kEnumerableProperty.enumerable = true;
303-
304300
ObjectDefineProperties(
305301
Event.prototype, {
306302
[SymbolToStringTag]: {

lib/internal/url.js

+27-26
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const {
4343
getConstructorOf,
4444
removeColors,
4545
toUSVString,
46+
kEnumerableProperty,
4647
} = require('internal/util');
4748

4849
const {
@@ -517,18 +518,18 @@ class URLSearchParams {
517518
}
518519

519520
ObjectDefineProperties(URLSearchParams.prototype, {
520-
append: { enumerable: true },
521-
delete: { enumerable: true },
522-
get: { enumerable: true },
523-
getAll: { enumerable: true },
524-
has: { enumerable: true },
525-
set: { enumerable: true },
526-
sort: { enumerable: true },
527-
entries: { enumerable: true },
528-
forEach: { enumerable: true },
529-
keys: { enumerable: true },
530-
values: { enumerable: true },
531-
toString: { enumerable: true },
521+
append: kEnumerableProperty,
522+
delete: kEnumerableProperty,
523+
get: kEnumerableProperty,
524+
getAll: kEnumerableProperty,
525+
has: kEnumerableProperty,
526+
set: kEnumerableProperty,
527+
sort: kEnumerableProperty,
528+
entries: kEnumerableProperty,
529+
forEach: kEnumerableProperty,
530+
keys: kEnumerableProperty,
531+
values: kEnumerableProperty,
532+
toString: kEnumerableProperty,
532533
[SymbolToStringTag]: { configurable: true, value: 'URLSearchParams' },
533534

534535
// https://heycam.github.io/webidl/#es-iterable-entries
@@ -1044,20 +1045,20 @@ class URL {
10441045
ObjectDefineProperties(URL.prototype, {
10451046
[kFormat]: { configurable: false, writable: false },
10461047
[SymbolToStringTag]: { configurable: true, value: 'URL' },
1047-
toString: { enumerable: true },
1048-
href: { enumerable: true },
1049-
origin: { enumerable: true },
1050-
protocol: { enumerable: true },
1051-
username: { enumerable: true },
1052-
password: { enumerable: true },
1053-
host: { enumerable: true },
1054-
hostname: { enumerable: true },
1055-
port: { enumerable: true },
1056-
pathname: { enumerable: true },
1057-
search: { enumerable: true },
1058-
searchParams: { enumerable: true },
1059-
hash: { enumerable: true },
1060-
toJSON: { enumerable: true },
1048+
toString: kEnumerableProperty,
1049+
href: kEnumerableProperty,
1050+
origin: kEnumerableProperty,
1051+
protocol: kEnumerableProperty,
1052+
username: kEnumerableProperty,
1053+
password: kEnumerableProperty,
1054+
host: kEnumerableProperty,
1055+
hostname: kEnumerableProperty,
1056+
port: kEnumerableProperty,
1057+
pathname: kEnumerableProperty,
1058+
search: kEnumerableProperty,
1059+
searchParams: kEnumerableProperty,
1060+
hash: kEnumerableProperty,
1061+
toJSON: kEnumerableProperty,
10611062
});
10621063

10631064
function update(url, params) {

lib/internal/util.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,9 @@ const lazyDOMException = hideStackFrames((message, name) => {
477477
return new _DOMException(message, name);
478478
});
479479

480+
const kEnumerableProperty = ObjectCreate(null);
481+
kEnumerableProperty.enumerable = true;
482+
480483
module.exports = {
481484
assertCrypto,
482485
cachedResult,
@@ -513,5 +516,7 @@ module.exports = {
513516
// Used by the buffer module to capture an internal reference to the
514517
// default isEncoding implementation, just in case userland overrides it.
515518
kIsEncodingSymbol: Symbol('kIsEncodingSymbol'),
516-
kVmBreakFirstLineSymbol: Symbol('kVmBreakFirstLineSymbol')
519+
kVmBreakFirstLineSymbol: Symbol('kVmBreakFirstLineSymbol'),
520+
521+
kEnumerableProperty,
517522
};

lib/internal/webstreams/compression.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ const {
1616
newReadableWritablePairFromDuplex,
1717
} = require('internal/webstreams/adapters');
1818

19-
const {
20-
customInspect,
21-
kEnumerableProperty,
22-
} = require('internal/webstreams/util');
19+
const { customInspect } = require('internal/webstreams/util');
2320

2421
const {
2522
customInspectSymbol: kInspect,
23+
kEnumerableProperty,
2624
} = require('internal/util');
2725

2826
let zlib;

lib/internal/webstreams/encoding.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ const {
1414
TransformStream,
1515
} = require('internal/webstreams/transformstream');
1616

17-
const {
18-
customInspect,
19-
kEnumerableProperty,
20-
} = require('internal/webstreams/util');
17+
const { customInspect } = require('internal/webstreams/util');
2118

2219
const {
2320
codes: {
@@ -26,7 +23,8 @@ const {
2623
} = require('internal/errors');
2724

2825
const {
29-
customInspectSymbol: kInspect
26+
customInspectSymbol: kInspect,
27+
kEnumerableProperty,
3028
} = require('internal/util');
3129

3230
const kHandle = Symbol('kHandle');

lib/internal/webstreams/queuingstrategies.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ const {
1414

1515
const {
1616
customInspectSymbol: kInspect,
17+
kEnumerableProperty,
1718
} = require('internal/util');
1819

1920
const {
2021
customInspect,
2122
isBrandCheck,
2223
kType,
2324
kState,
24-
kEnumerableProperty,
2525
} = require('internal/webstreams/util');
2626

2727
const {

lib/internal/webstreams/readablestream.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const {
5050
const {
5151
createDeferredPromise,
5252
customInspectSymbol: kInspect,
53+
kEnumerableProperty,
5354
} = require('internal/util');
5455

5556
const {
@@ -109,7 +110,6 @@ const {
109110
nonOpStart,
110111
kType,
111112
kState,
112-
kEnumerableProperty,
113113
} = require('internal/webstreams/util');
114114

115115
const {

lib/internal/webstreams/transformstream.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const {
2727
const {
2828
createDeferredPromise,
2929
customInspectSymbol: kInspect,
30+
kEnumerableProperty,
3031
} = require('internal/util');
3132

3233
const {
@@ -45,7 +46,6 @@ const {
4546
nonOpFlush,
4647
kType,
4748
kState,
48-
kEnumerableProperty,
4949
} = require('internal/webstreams/util');
5050

5151
const {

lib/internal/webstreams/util.js

-4
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,6 @@ function lazyTransfer() {
207207
return transfer;
208208
}
209209

210-
const kEnumerableProperty = ObjectCreate(null);
211-
kEnumerableProperty.enumerable = true;
212-
213210
module.exports = {
214211
ArrayBufferViewGetBuffer,
215212
ArrayBufferViewGetByteLength,
@@ -237,5 +234,4 @@ module.exports = {
237234
nonOpWrite,
238235
kType,
239236
kState,
240-
kEnumerableProperty,
241237
};

lib/internal/webstreams/writablestream.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const {
3333
const {
3434
createDeferredPromise,
3535
customInspectSymbol: kInspect,
36+
kEnumerableProperty,
3637
} = require('internal/util');
3738

3839
const {
@@ -64,7 +65,6 @@ const {
6465
nonOpWrite,
6566
kType,
6667
kState,
67-
kEnumerableProperty,
6868
} = require('internal/webstreams/util');
6969

7070
const {

lib/internal/worker/io.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const {
1818
SymbolFor,
1919
} = primordials;
2020

21+
const { kEnumerableProperty } = require('internal/util');
22+
2123
const {
2224
handle_onclose: handleOnCloseSymbol,
2325
oninit: onInitSymbol,
@@ -481,9 +483,6 @@ class BroadcastChannel extends EventTarget {
481483
}
482484
}
483485

484-
const kEnumerableProperty = ObjectCreate(null);
485-
kEnumerableProperty.enumerable = true;
486-
487486
ObjectDefineProperties(BroadcastChannel.prototype, {
488487
name: kEnumerableProperty,
489488
close: kEnumerableProperty,

0 commit comments

Comments
 (0)