Skip to content

Commit 908292c

Browse files
targosdanbev
authored andcommitted
lib: enforce the use of Object from primordials
PR-URL: #27146 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
1 parent 9ad5106 commit 908292c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+167
-64
lines changed

lib/.eslintrc.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ rules:
1010
message: "Use `const { JSON } = primordials;` instead of the global."
1111
- name: Math
1212
message: "Use `const { Math } = primordials;` instead of the global."
13+
- name: Object
14+
message: "Use `const { Object } = primordials;` instead of the global."
1315
- name: Reflect
1416
message: "Use `const { Reflect } = primordials;` instead of the global."
1517
no-restricted-syntax:

lib/_http_agent.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { Object } = primordials;
25+
2426
const net = require('net');
2527
const EventEmitter = require('events');
2628
const debug = require('internal/util/debuglog').debuglog('http');

lib/_http_client.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { Object } = primordials;
25+
2426
const net = require('net');
2527
const url = require('url');
2628
const assert = require('internal/assert');

lib/_http_incoming.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { Object } = primordials;
25+
2426
const Stream = require('stream');
2527

2628
function readStart(socket) {

lib/_http_outgoing.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
'use strict';
2323

24-
const { ObjectPrototype } = primordials;
24+
const { Object, ObjectPrototype } = primordials;
2525

2626
const assert = require('internal/assert');
2727
const Stream = require('stream');

lib/_http_server.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { Object } = primordials;
25+
2426
const net = require('net');
2527
const assert = require('internal/assert');
2628
const {

lib/_stream_duplex.js

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
'use strict';
2828

29+
const { Object } = primordials;
30+
2931
module.exports = Duplex;
3032

3133
const Readable = require('_stream_readable');

lib/_stream_passthrough.js

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
'use strict';
2727

28+
const { Object } = primordials;
29+
2830
module.exports = PassThrough;
2931

3032
const Transform = require('_stream_transform');

lib/_stream_readable.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { Object } = primordials;
25+
2426
module.exports = Readable;
2527
Readable.ReadableState = ReadableState;
2628

lib/_stream_transform.js

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363

6464
'use strict';
6565

66+
const { Object } = primordials;
67+
6668
module.exports = Transform;
6769
const {
6870
ERR_METHOD_NOT_IMPLEMENTED,

lib/_stream_writable.js

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
'use strict';
2727

28+
const { Object } = primordials;
29+
2830
module.exports = Writable;
2931
Writable.WritableState = WritableState;
3032

lib/_tls_common.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { Object } = primordials;
25+
2426
const { parseCertString } = require('internal/tls');
2527
const { isArrayBufferView } = require('internal/util/types');
2628
const tls = require('tls');

lib/_tls_wrap.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { Object } = primordials;
25+
2426
const {
2527
assertCrypto,
2628
deprecate

lib/assert.js

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
'use strict';
2222

23+
const { Object } = primordials;
24+
2325
const { Buffer } = require('buffer');
2426
const { codes: {
2527
ERR_AMBIGUOUS_ARGUMENT,

lib/buffer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
'use strict';
2323

24-
const { Math } = primordials;
24+
const { Math, Object } = primordials;
2525

2626
const {
2727
byteLengthUtf8,

lib/child_process.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { Object, ObjectPrototype } = primordials;
25+
2426
const {
2527
promisify,
2628
convertToValidSignal,
@@ -515,8 +517,7 @@ function normalizeSpawnArguments(file, args, options) {
515517
// process.env.NODE_V8_COVERAGE always propagates, making it possible to
516518
// collect coverage for programs that spawn with white-listed environment.
517519
if (process.env.NODE_V8_COVERAGE &&
518-
!Object.prototype.hasOwnProperty.call(options.env || {},
519-
'NODE_V8_COVERAGE')) {
520+
!ObjectPrototype.hasOwnProperty(options.env || {}, 'NODE_V8_COVERAGE')) {
520521
env.NODE_V8_COVERAGE = process.env.NODE_V8_COVERAGE;
521522
}
522523

lib/constants.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { Object } = primordials;
25+
2426
// This module is deprecated in documentation only. Users should be directed
2527
// towards using the specific constants exposed by the individual modules on
2628
// which they are most relevant.

lib/crypto.js

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
'use strict';
2626

27+
const { Object } = primordials;
28+
2729
const {
2830
assertCrypto,
2931
deprecate

lib/dgram.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { Object } = primordials;
25+
2426
const errors = require('internal/errors');
2527
const {
2628
kStateSymbol,

lib/dns.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { Object } = primordials;
25+
2426
const cares = internalBinding('cares_wrap');
2527
const { toASCII } = require('internal/idna');
2628
const { isIP, isIPv4, isLegalPort } = require('internal/net');

lib/domain.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// No new pull requests targeting this module will be accepted
2727
// unless they address existing, critical bugs.
2828

29-
const { Reflect } = primordials;
29+
const { Object, Reflect } = primordials;
3030

3131
const util = require('util');
3232
const EventEmitter = require('events');

lib/events.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
'use strict';
2323

24-
const { Math, Reflect } = primordials;
24+
const { Math, Object, Reflect } = primordials;
2525

2626
var spliceOne;
2727

lib/fs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
'use strict';
2626

27-
const { Math, Reflect } = primordials;
27+
const { Math, Object, Reflect } = primordials;
2828

2929
const { fs: constants } = internalBinding('constants');
3030
const {

lib/http.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { Object } = primordials;
25+
2426
const httpAgent = require('_http_agent');
2527
const { ClientRequest } = require('_http_client');
2628
const { methods } = require('_http_common');

lib/https.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { Object } = primordials;
25+
2426
require('internal/util').assertCrypto();
2527

2628
const tls = require('tls');

lib/internal/assert/assertion_error.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { Math } = primordials;
3+
const { Math, Object } = primordials;
44

55
const { inspect } = require('internal/util/inspect');
66
const { codes: {

lib/internal/async_hooks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { FunctionPrototype, Reflect } = primordials;
3+
const { FunctionPrototype, Object, Reflect } = primordials;
44

55
const {
66
ERR_ASYNC_TYPE,

lib/internal/bootstrap/pre_execution.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { Object } = primordials;
4+
35
const { getOptionValue } = require('internal/options');
46
const { Buffer } = require('buffer');
57

lib/internal/child_process.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { JSON } = primordials;
3+
const { JSON, Object } = primordials;
44

55
const {
66
errnoException,

lib/internal/cluster/child.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
'use strict';
2+
3+
const { Object } = primordials;
4+
25
const assert = require('internal/assert');
36
const path = require('path');
47
const EventEmitter = require('events');

lib/internal/cluster/master.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
'use strict';
2+
3+
const { Object } = primordials;
4+
25
const assert = require('internal/assert');
36
const { fork } = require('child_process');
47
const path = require('path');
@@ -8,7 +11,6 @@ const SharedHandle = require('internal/cluster/shared_handle');
811
const Worker = require('internal/cluster/worker');
912
const { internal, sendHelper } = require('internal/cluster/utils');
1013
const { ERR_SOCKET_BAD_PORT } = require('internal/errors').codes;
11-
const keys = Object.keys;
1214
const cluster = new EventEmitter();
1315
const intercom = new EventEmitter();
1416
const SCHED_NONE = 1;
@@ -141,7 +143,7 @@ function removeWorker(worker) {
141143
assert(worker);
142144
delete cluster.workers[worker.id];
143145

144-
if (keys(cluster.workers).length === 0) {
146+
if (Object.keys(cluster.workers).length === 0) {
145147
assert(handles.size === 0, 'Resource leak detected.');
146148
intercom.emit('disconnect');
147149
}
@@ -219,7 +221,7 @@ function emitForkNT(worker) {
219221
}
220222

221223
cluster.disconnect = function(cb) {
222-
const workers = keys(cluster.workers);
224+
const workers = Object.keys(cluster.workers);
223225

224226
if (workers.length === 0) {
225227
process.nextTick(() => intercom.emit('disconnect'));

lib/internal/cluster/worker.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
'use strict';
2+
3+
const { Object } = primordials;
4+
25
const EventEmitter = require('events');
36

47
module.exports = Worker;

lib/internal/console/constructor.js

+6-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// The Console constructor is not actually used to construct the global
44
// console. It's exported for backwards compatibility.
55

6-
const { ObjectPrototype, Reflect } = primordials;
6+
const { Object, ObjectPrototype, Reflect } = primordials;
77

88
const { trace } = internalBinding('trace_events');
99
const {
@@ -32,11 +32,6 @@ const kTraceBegin = 'b'.charCodeAt(0);
3232
const kTraceEnd = 'e'.charCodeAt(0);
3333
const kTraceInstant = 'n'.charCodeAt(0);
3434

35-
const {
36-
keys: ObjectKeys,
37-
values: ObjectValues,
38-
} = Object;
39-
4035
const {
4136
isArray: ArrayIsArray,
4237
from: ArrayFrom,
@@ -414,7 +409,7 @@ const consoleMethods = {
414409
const depth = v !== null &&
415410
typeof v === 'object' &&
416411
!isArray(v) &&
417-
ObjectKeys(v).length > 2 ? -1 : 0;
412+
Object.keys(v).length > 2 ? -1 : 0;
418413
const opt = {
419414
depth,
420415
maxArrayLength: 3,
@@ -478,7 +473,7 @@ const consoleMethods = {
478473
const map = {};
479474
let hasPrimitives = false;
480475
const valuesKeyArray = [];
481-
const indexKeyArray = ObjectKeys(tabularData);
476+
const indexKeyArray = Object.keys(tabularData);
482477

483478
for (; i < indexKeyArray.length; i++) {
484479
const item = tabularData[indexKeyArray[i]];
@@ -488,7 +483,7 @@ const consoleMethods = {
488483
hasPrimitives = true;
489484
valuesKeyArray[i] = _inspect(item);
490485
} else {
491-
const keys = properties || ObjectKeys(item);
486+
const keys = properties || Object.keys(item);
492487
for (const key of keys) {
493488
if (map[key] === undefined)
494489
map[key] = [];
@@ -501,8 +496,8 @@ const consoleMethods = {
501496
}
502497
}
503498

504-
const keys = ObjectKeys(map);
505-
const values = ObjectValues(map);
499+
const keys = Object.keys(map);
500+
const values = Object.values(map);
506501
if (hasPrimitives) {
507502
keys.push(valuesKey);
508503
values.push(valuesKeyArray);

lib/internal/console/global.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// Therefore, the console.Console.prototype is not
1313
// in the global console prototype chain anymore.
1414

15-
const { Reflect } = primordials;
15+
const { Object, Reflect } = primordials;
1616

1717
const {
1818
Console,

lib/internal/crypto/cipher.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { Object } = primordials;
4+
35
const {
46
RSA_PKCS1_OAEP_PADDING,
57
RSA_PKCS1_PADDING

0 commit comments

Comments
 (0)