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: enforce the use of Object from primordials #27146

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ rules:
message: "Use `const { JSON } = primordials;` instead of the global."
- name: Math
message: "Use `const { Math } = primordials;` instead of the global."
- name: Object
message: "Use `const { Object } = primordials;` instead of the global."
- name: Reflect
message: "Use `const { Reflect } = primordials;` instead of the global."
no-restricted-syntax:
Expand Down
2 changes: 2 additions & 0 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

const net = require('net');
const EventEmitter = require('events');
const debug = require('internal/util/debuglog').debuglog('http');
Expand Down
2 changes: 2 additions & 0 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

const net = require('net');
const url = require('url');
const assert = require('internal/assert');
Expand Down
2 changes: 2 additions & 0 deletions lib/_http_incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

const Stream = require('stream');

function readStart(socket) {
Expand Down
2 changes: 1 addition & 1 deletion lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

'use strict';

const { ObjectPrototype } = primordials;
const { Object, ObjectPrototype } = primordials;

const assert = require('internal/assert');
const Stream = require('stream');
Expand Down
2 changes: 2 additions & 0 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

const net = require('net');
const assert = require('internal/assert');
const {
Expand Down
2 changes: 2 additions & 0 deletions lib/_stream_duplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

'use strict';

const { Object } = primordials;

module.exports = Duplex;

const Readable = require('_stream_readable');
Expand Down
2 changes: 2 additions & 0 deletions lib/_stream_passthrough.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

'use strict';

const { Object } = primordials;

module.exports = PassThrough;

const Transform = require('_stream_transform');
Expand Down
2 changes: 2 additions & 0 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

module.exports = Readable;
Readable.ReadableState = ReadableState;

Expand Down
2 changes: 2 additions & 0 deletions lib/_stream_transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@

'use strict';

const { Object } = primordials;

module.exports = Transform;
const {
ERR_METHOD_NOT_IMPLEMENTED,
Expand Down
2 changes: 2 additions & 0 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

'use strict';

const { Object } = primordials;

module.exports = Writable;
Writable.WritableState = WritableState;

Expand Down
2 changes: 2 additions & 0 deletions lib/_tls_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

const { parseCertString } = require('internal/tls');
const { isArrayBufferView } = require('internal/util/types');
const tls = require('tls');
Expand Down
2 changes: 2 additions & 0 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

const {
assertCrypto,
deprecate
Expand Down
2 changes: 2 additions & 0 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

'use strict';

const { Object } = primordials;

const { Buffer } = require('buffer');
const { codes: {
ERR_AMBIGUOUS_ARGUMENT,
Expand Down
2 changes: 1 addition & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

'use strict';

const { Math } = primordials;
const { Math, Object } = primordials;

const {
byteLengthUtf8,
Expand Down
5 changes: 3 additions & 2 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const { Object, ObjectPrototype } = primordials;

const {
promisify,
convertToValidSignal,
Expand Down Expand Up @@ -512,8 +514,7 @@ function normalizeSpawnArguments(file, args, options) {
// process.env.NODE_V8_COVERAGE always propagates, making it possible to
// collect coverage for programs that spawn with white-listed environment.
if (process.env.NODE_V8_COVERAGE &&
!Object.prototype.hasOwnProperty.call(options.env || {},
'NODE_V8_COVERAGE')) {
!ObjectPrototype.hasOwnProperty(options.env || {}, 'NODE_V8_COVERAGE')) {
env.NODE_V8_COVERAGE = process.env.NODE_V8_COVERAGE;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

// This module is deprecated in documentation only. Users should be directed
// towards using the specific constants exposed by the individual modules on
// which they are most relevant.
Expand Down
2 changes: 2 additions & 0 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

'use strict';

const { Object } = primordials;

const {
assertCrypto,
deprecate
Expand Down
2 changes: 2 additions & 0 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

const errors = require('internal/errors');
const {
kStateSymbol,
Expand Down
2 changes: 2 additions & 0 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

const cares = internalBinding('cares_wrap');
const { toASCII } = require('internal/idna');
const { isIP, isIPv4, isLegalPort } = require('internal/net');
Expand Down
2 changes: 1 addition & 1 deletion lib/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// No new pull requests targeting this module will be accepted
// unless they address existing, critical bugs.

const { Reflect } = primordials;
const { Object, Reflect } = primordials;

const util = require('util');
const EventEmitter = require('events');
Expand Down
2 changes: 1 addition & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

'use strict';

const { Math, Reflect } = primordials;
const { Math, Object, Reflect } = primordials;

var spliceOne;

Expand Down
2 changes: 1 addition & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

'use strict';

const { Math, Reflect } = primordials;
const { Math, Object, Reflect } = primordials;

const { fs: constants } = internalBinding('constants');
const {
Expand Down
2 changes: 2 additions & 0 deletions lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

const httpAgent = require('_http_agent');
const { ClientRequest } = require('_http_client');
const { methods } = require('_http_common');
Expand Down
2 changes: 2 additions & 0 deletions lib/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

require('internal/util').assertCrypto();

const tls = require('tls');
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/assert/assertion_error.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { Math } = primordials;
const { Math, Object } = primordials;

const { inspect } = require('internal/util/inspect');
const { codes: {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/async_hooks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { FunctionPrototype, Reflect } = primordials;
const { FunctionPrototype, Object, Reflect } = primordials;

const {
ERR_ASYNC_TYPE,
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/bootstrap/pre_execution.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { Object } = primordials;

const { getOptionValue } = require('internal/options');
const { Buffer } = require('buffer');

Expand Down
2 changes: 1 addition & 1 deletion lib/internal/child_process.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { JSON } = primordials;
const { JSON, Object } = primordials;

const {
errnoException,
Expand Down
3 changes: 3 additions & 0 deletions lib/internal/cluster/child.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
'use strict';

const { Object } = primordials;

const assert = require('internal/assert');
const path = require('path');
const EventEmitter = require('events');
Expand Down
8 changes: 5 additions & 3 deletions lib/internal/cluster/master.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
'use strict';

const { Object } = primordials;

const assert = require('internal/assert');
const { fork } = require('child_process');
const path = require('path');
Expand All @@ -8,7 +11,6 @@ const SharedHandle = require('internal/cluster/shared_handle');
const Worker = require('internal/cluster/worker');
const { internal, sendHelper } = require('internal/cluster/utils');
const { ERR_SOCKET_BAD_PORT } = require('internal/errors').codes;
const keys = Object.keys;
const cluster = new EventEmitter();
const intercom = new EventEmitter();
const SCHED_NONE = 1;
Expand Down Expand Up @@ -141,7 +143,7 @@ function removeWorker(worker) {
assert(worker);
delete cluster.workers[worker.id];

if (keys(cluster.workers).length === 0) {
if (Object.keys(cluster.workers).length === 0) {
assert(handles.size === 0, 'Resource leak detected.');
intercom.emit('disconnect');
}
Expand Down Expand Up @@ -219,7 +221,7 @@ function emitForkNT(worker) {
}

cluster.disconnect = function(cb) {
const workers = keys(cluster.workers);
const workers = Object.keys(cluster.workers);

if (workers.length === 0) {
process.nextTick(() => intercom.emit('disconnect'));
Expand Down
3 changes: 3 additions & 0 deletions lib/internal/cluster/worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
'use strict';

const { Object } = primordials;

const EventEmitter = require('events');

module.exports = Worker;
Expand Down
17 changes: 6 additions & 11 deletions lib/internal/console/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// The Console constructor is not actually used to construct the global
// console. It's exported for backwards compatibility.

const { ObjectPrototype, Reflect } = primordials;
const { Object, ObjectPrototype, Reflect } = primordials;

const { trace } = internalBinding('trace_events');
const {
Expand Down Expand Up @@ -32,11 +32,6 @@ const kTraceBegin = 'b'.charCodeAt(0);
const kTraceEnd = 'e'.charCodeAt(0);
const kTraceInstant = 'n'.charCodeAt(0);

const {
keys: ObjectKeys,
values: ObjectValues,
} = Object;

const {
isArray: ArrayIsArray,
from: ArrayFrom,
Expand Down Expand Up @@ -414,7 +409,7 @@ const consoleMethods = {
const depth = v !== null &&
typeof v === 'object' &&
!isArray(v) &&
ObjectKeys(v).length > 2 ? -1 : 0;
Object.keys(v).length > 2 ? -1 : 0;
const opt = {
depth,
maxArrayLength: 3,
Expand Down Expand Up @@ -478,7 +473,7 @@ const consoleMethods = {
const map = {};
let hasPrimitives = false;
const valuesKeyArray = [];
const indexKeyArray = ObjectKeys(tabularData);
const indexKeyArray = Object.keys(tabularData);

for (; i < indexKeyArray.length; i++) {
const item = tabularData[indexKeyArray[i]];
Expand All @@ -488,7 +483,7 @@ const consoleMethods = {
hasPrimitives = true;
valuesKeyArray[i] = _inspect(item);
} else {
const keys = properties || ObjectKeys(item);
const keys = properties || Object.keys(item);
for (const key of keys) {
if (map[key] === undefined)
map[key] = [];
Expand All @@ -501,8 +496,8 @@ const consoleMethods = {
}
}

const keys = ObjectKeys(map);
const values = ObjectValues(map);
const keys = Object.keys(map);
const values = Object.values(map);
if (hasPrimitives) {
keys.push(valuesKey);
values.push(valuesKeyArray);
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/console/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// Therefore, the console.Console.prototype is not
// in the global console prototype chain anymore.

const { Reflect } = primordials;
const { Object, Reflect } = primordials;

const {
Console,
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/crypto/cipher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { Object } = primordials;

const {
RSA_PKCS1_OAEP_PADDING,
RSA_PKCS1_PADDING
Expand Down
Loading