Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: move kEnumerableProperty to internal/util #41877

Merged
merged 2 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/internal/abort_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const {
} = require('internal/event_target');
const {
customInspectSymbol,
kEnumerableProperty,
} = require('internal/util');
const { inspect } = require('internal/util/inspect');
const {
Expand Down Expand Up @@ -260,7 +261,7 @@ function ClonedAbortSignal() {
ClonedAbortSignal.prototype[kDeserialize] = () => {};

ObjectDefineProperties(AbortSignal.prototype, {
aborted: { enumerable: true }
aborted: kEnumerableProperty,
});

ObjectDefineProperty(AbortSignal.prototype, SymbolToStringTag, {
Expand Down Expand Up @@ -329,8 +330,8 @@ class AbortController {
}

ObjectDefineProperties(AbortController.prototype, {
signal: { enumerable: true },
abort: { enumerable: true }
signal: kEnumerableProperty,
abort: kEnumerableProperty,
});

ObjectDefineProperty(AbortController.prototype, SymbolToStringTag, {
Expand Down
7 changes: 2 additions & 5 deletions lib/internal/crypto/webcrypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const {
JSONParse,
JSONStringify,
ObjectDefineProperties,
ObjectGetOwnPropertyDescriptor,
SafeSet,
SymbolToStringTag,
StringPrototypeRepeat,
Expand Down Expand Up @@ -60,6 +59,7 @@ const {
} = require('internal/crypto/util');

const {
kEnumerableProperty,
lazyDOMException,
} = require('internal/util');

Expand Down Expand Up @@ -703,10 +703,7 @@ ObjectDefineProperties(
writable: false,
value: 'Crypto',
},
subtle: {
...ObjectGetOwnPropertyDescriptor(Crypto.prototype, 'subtle'),
enumerable: true,
},
subtle: kEnumerableProperty,
getRandomValues: {
enumerable: true,
configurable: true,
Expand Down
11 changes: 6 additions & 5 deletions lib/internal/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const kEncoder = Symbol('encoder');

const {
getConstructorOf,
customInspectSymbol: inspect
customInspectSymbol: inspect,
kEnumerableProperty,
} = require('internal/util');

const {
Expand Down Expand Up @@ -358,9 +359,9 @@ class TextEncoder {

ObjectDefineProperties(
TextEncoder.prototype, {
'encode': { enumerable: true },
'encodeInto': { enumerable: true },
'encoding': { enumerable: true },
'encode': kEnumerableProperty,
'encodeInto': kEnumerableProperty,
'encoding': kEnumerableProperty,
[SymbolToStringTag]: { configurable: true, value: 'TextEncoder' },
});

Expand Down Expand Up @@ -569,7 +570,7 @@ ObjectDefineProperties(
);

ObjectDefineProperties(TextDecoder.prototype, {
decode: { enumerable: true },
decode: kEnumerableProperty,
[inspect]: { enumerable: false },
[SymbolToStringTag]: {
configurable: true,
Expand Down
6 changes: 1 addition & 5 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const {
FunctionPrototypeCall,
NumberIsInteger,
ObjectAssign,
ObjectCreate,
ObjectDefineProperties,
ObjectDefineProperty,
ObjectGetOwnPropertyDescriptor,
Expand Down Expand Up @@ -36,7 +35,7 @@ const {
} = require('internal/errors');
const { validateObject, validateString } = require('internal/validators');

const { customInspectSymbol } = require('internal/util');
const { customInspectSymbol, kEnumerableProperty } = require('internal/util');
const { inspect } = require('util');

const kIsEventTarget = SymbolFor('nodejs.event_target');
Expand Down Expand Up @@ -298,9 +297,6 @@ class Event {
static BUBBLING_PHASE = 3;
}

const kEnumerableProperty = ObjectCreate(null);
kEnumerableProperty.enumerable = true;

ObjectDefineProperties(
Event.prototype, {
[SymbolToStringTag]: {
Expand Down
53 changes: 27 additions & 26 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const {
getConstructorOf,
removeColors,
toUSVString,
kEnumerableProperty,
} = require('internal/util');

const {
Expand Down Expand Up @@ -517,18 +518,18 @@ class URLSearchParams {
}

ObjectDefineProperties(URLSearchParams.prototype, {
append: { enumerable: true },
delete: { enumerable: true },
get: { enumerable: true },
getAll: { enumerable: true },
has: { enumerable: true },
set: { enumerable: true },
sort: { enumerable: true },
entries: { enumerable: true },
forEach: { enumerable: true },
keys: { enumerable: true },
values: { enumerable: true },
toString: { enumerable: true },
append: kEnumerableProperty,
delete: kEnumerableProperty,
get: kEnumerableProperty,
getAll: kEnumerableProperty,
has: kEnumerableProperty,
set: kEnumerableProperty,
sort: kEnumerableProperty,
entries: kEnumerableProperty,
forEach: kEnumerableProperty,
keys: kEnumerableProperty,
values: kEnumerableProperty,
toString: kEnumerableProperty,
[SymbolToStringTag]: { configurable: true, value: 'URLSearchParams' },

// https://heycam.github.io/webidl/#es-iterable-entries
Expand Down Expand Up @@ -1044,20 +1045,20 @@ class URL {
ObjectDefineProperties(URL.prototype, {
[kFormat]: { configurable: false, writable: false },
[SymbolToStringTag]: { configurable: true, value: 'URL' },
toString: { enumerable: true },
href: { enumerable: true },
origin: { enumerable: true },
protocol: { enumerable: true },
username: { enumerable: true },
password: { enumerable: true },
host: { enumerable: true },
hostname: { enumerable: true },
port: { enumerable: true },
pathname: { enumerable: true },
search: { enumerable: true },
searchParams: { enumerable: true },
hash: { enumerable: true },
toJSON: { enumerable: true },
toString: kEnumerableProperty,
href: kEnumerableProperty,
origin: kEnumerableProperty,
protocol: kEnumerableProperty,
username: kEnumerableProperty,
password: kEnumerableProperty,
host: kEnumerableProperty,
hostname: kEnumerableProperty,
port: kEnumerableProperty,
pathname: kEnumerableProperty,
search: kEnumerableProperty,
searchParams: kEnumerableProperty,
hash: kEnumerableProperty,
toJSON: kEnumerableProperty,
});

function update(url, params) {
Expand Down
7 changes: 6 additions & 1 deletion lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,9 @@ const lazyDOMException = hideStackFrames((message, name) => {
return new _DOMException(message, name);
});

const kEnumerableProperty = ObjectCreate(null);
kEnumerableProperty.enumerable = true;

module.exports = {
assertCrypto,
cachedResult,
Expand Down Expand Up @@ -535,5 +538,7 @@ module.exports = {
// Used by the buffer module to capture an internal reference to the
// default isEncoding implementation, just in case userland overrides it.
kIsEncodingSymbol: Symbol('kIsEncodingSymbol'),
kVmBreakFirstLineSymbol: Symbol('kVmBreakFirstLineSymbol')
kVmBreakFirstLineSymbol: Symbol('kVmBreakFirstLineSymbol'),

kEnumerableProperty,
};
6 changes: 2 additions & 4 deletions lib/internal/webstreams/compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ const {
newReadableWritablePairFromDuplex,
} = require('internal/webstreams/adapters');

const {
customInspect,
kEnumerableProperty,
} = require('internal/webstreams/util');
const { customInspect } = require('internal/webstreams/util');

const {
customInspectSymbol: kInspect,
kEnumerableProperty,
} = require('internal/util');

let zlib;
Expand Down
8 changes: 3 additions & 5 deletions lib/internal/webstreams/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ const {
TransformStream,
} = require('internal/webstreams/transformstream');

const {
customInspect,
kEnumerableProperty,
} = require('internal/webstreams/util');
const { customInspect } = require('internal/webstreams/util');

const {
codes: {
Expand All @@ -26,7 +23,8 @@ const {
} = require('internal/errors');

const {
customInspectSymbol: kInspect
customInspectSymbol: kInspect,
kEnumerableProperty,
} = require('internal/util');

const kHandle = Symbol('kHandle');
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/webstreams/queuingstrategies.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ const {

const {
customInspectSymbol: kInspect,
kEnumerableProperty,
} = require('internal/util');

const {
customInspect,
isBrandCheck,
kType,
kState,
kEnumerableProperty,
} = require('internal/webstreams/util');

const {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const {
const {
createDeferredPromise,
customInspectSymbol: kInspect,
kEnumerableProperty,
} = require('internal/util');

const {
Expand Down Expand Up @@ -109,7 +110,6 @@ const {
nonOpStart,
kType,
kState,
kEnumerableProperty,
} = require('internal/webstreams/util');

const {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/webstreams/transformstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {
const {
createDeferredPromise,
customInspectSymbol: kInspect,
kEnumerableProperty,
} = require('internal/util');

const {
Expand All @@ -45,7 +46,6 @@ const {
nonOpFlush,
kType,
kState,
kEnumerableProperty,
} = require('internal/webstreams/util');

const {
Expand Down
4 changes: 0 additions & 4 deletions lib/internal/webstreams/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,6 @@ function lazyTransfer() {
return transfer;
}

const kEnumerableProperty = ObjectCreate(null);
kEnumerableProperty.enumerable = true;

module.exports = {
ArrayBufferViewGetBuffer,
ArrayBufferViewGetByteLength,
Expand Down Expand Up @@ -237,5 +234,4 @@ module.exports = {
nonOpWrite,
kType,
kState,
kEnumerableProperty,
};
2 changes: 1 addition & 1 deletion lib/internal/webstreams/writablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const {
const {
createDeferredPromise,
customInspectSymbol: kInspect,
kEnumerableProperty,
} = require('internal/util');

const {
Expand Down Expand Up @@ -64,7 +65,6 @@ const {
nonOpWrite,
kType,
kState,
kEnumerableProperty,
} = require('internal/webstreams/util');

const {
Expand Down
5 changes: 2 additions & 3 deletions lib/internal/worker/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const {
SymbolFor,
} = primordials;

const { kEnumerableProperty } = require('internal/util');

const {
handle_onclose: handleOnCloseSymbol,
oninit: onInitSymbol,
Expand Down Expand Up @@ -501,9 +503,6 @@ class BroadcastChannel extends EventTarget {
}
}

const kEnumerableProperty = ObjectCreate(null);
kEnumerableProperty.enumerable = true;

ObjectDefineProperties(BroadcastChannel.prototype, {
name: kEnumerableProperty,
close: kEnumerableProperty,
Expand Down