Skip to content
Permalink
Browse files

lib: enforce the use of Object from primordials

PR-URL: #27146
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
  • Loading branch information...
targos authored and danbev committed Apr 9, 2019
1 parent 9ad5106 commit 908292cf1f551c614a733d858528ffb13fb3a524
Showing with 167 additions and 64 deletions.
  1. +2 −0 lib/.eslintrc.yaml
  2. +2 −0 lib/_http_agent.js
  3. +2 −0 lib/_http_client.js
  4. +2 −0 lib/_http_incoming.js
  5. +1 −1 lib/_http_outgoing.js
  6. +2 −0 lib/_http_server.js
  7. +2 −0 lib/_stream_duplex.js
  8. +2 −0 lib/_stream_passthrough.js
  9. +2 −0 lib/_stream_readable.js
  10. +2 −0 lib/_stream_transform.js
  11. +2 −0 lib/_stream_writable.js
  12. +2 −0 lib/_tls_common.js
  13. +2 −0 lib/_tls_wrap.js
  14. +2 −0 lib/assert.js
  15. +1 −1 lib/buffer.js
  16. +3 −2 lib/child_process.js
  17. +2 −0 lib/constants.js
  18. +2 −0 lib/crypto.js
  19. +2 −0 lib/dgram.js
  20. +2 −0 lib/dns.js
  21. +1 −1 lib/domain.js
  22. +1 −1 lib/events.js
  23. +1 −1 lib/fs.js
  24. +2 −0 lib/http.js
  25. +2 −0 lib/https.js
  26. +1 −1 lib/internal/assert/assertion_error.js
  27. +1 −1 lib/internal/async_hooks.js
  28. +2 −0 lib/internal/bootstrap/pre_execution.js
  29. +1 −1 lib/internal/child_process.js
  30. +3 −0 lib/internal/cluster/child.js
  31. +5 −3 lib/internal/cluster/master.js
  32. +3 −0 lib/internal/cluster/worker.js
  33. +6 −11 lib/internal/console/constructor.js
  34. +1 −1 lib/internal/console/global.js
  35. +2 −0 lib/internal/crypto/cipher.js
  36. +2 −0 lib/internal/crypto/diffiehellman.js
  37. +2 −0 lib/internal/crypto/hash.js
  38. +2 −0 lib/internal/crypto/keygen.js
  39. +2 −0 lib/internal/crypto/keys.js
  40. +2 −0 lib/internal/crypto/sig.js
  41. +3 −0 lib/internal/dns/promises.js
  42. +2 −0 lib/internal/encoding.js
  43. +5 −4 lib/internal/errors.js
  44. +1 −1 lib/internal/fs/streams.js
  45. +2 −0 lib/internal/fs/sync_write_stream.js
  46. +2 −0 lib/internal/fs/watchers.js
  47. +2 −2 lib/internal/http2/compat.js
  48. +1 −1 lib/internal/http2/core.js
  49. +1 −1 lib/internal/http2/util.js
  50. +2 −0 lib/internal/main/worker_thread.js
  51. +2 −0 lib/internal/modules/cjs/helpers.js
  52. +1 −1 lib/internal/modules/cjs/loader.js
  53. +3 −1 lib/internal/modules/esm/module_job.js
  54. +4 −0 lib/internal/per_context/domexception.js
  55. +1 −0 lib/internal/process/per_thread.js
  56. +1 −1 lib/internal/process/policy.js
  57. +2 −0 lib/internal/repl.js
  58. +2 −0 lib/internal/repl/await.js
  59. +2 −0 lib/internal/streams/async_iterator.js
  60. +2 −0 lib/internal/streams/lazy_transform.js
  61. +2 −0 lib/internal/streams/legacy.js
  62. +1 −1 lib/internal/timers.js
  63. +2 −0 lib/internal/tls.js
  64. +2 −1 lib/internal/trace_events_async_hooks.js
  65. +1 −1 lib/internal/url.js
  66. +1 −6 lib/internal/util.js
  67. +2 −0 lib/internal/util/inspector.js
  68. +1 −1 lib/internal/util/types.js
  69. +2 −1 lib/internal/vm/source_text_module.js
  70. +2 −0 lib/internal/worker.js
  71. +2 −0 lib/internal/worker/io.js
  72. +2 −0 lib/net.js
  73. +2 −0 lib/os.js
  74. +2 −0 lib/perf_hooks.js
  75. +2 −0 lib/querystring.js
  76. +1 −1 lib/readline.js
  77. +2 −9 lib/repl.js
  78. +2 −0 lib/stream.js
  79. +2 −0 lib/string_decoder.js
  80. +2 −0 lib/tty.js
  81. +2 −1 lib/url.js
  82. +1 −1 lib/util.js
  83. +4 −3 lib/v8.js
  84. +1 −1 lib/zlib.js
  85. +2 −0 src/node.cc
@@ -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:
@@ -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');
@@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

const net = require('net');
const url = require('url');
const assert = require('internal/assert');
@@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

const Stream = require('stream');

function readStart(socket) {
@@ -21,7 +21,7 @@

'use strict';

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

const assert = require('internal/assert');
const Stream = require('stream');
@@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

const net = require('net');
const assert = require('internal/assert');
const {
@@ -26,6 +26,8 @@

'use strict';

const { Object } = primordials;

module.exports = Duplex;

const Readable = require('_stream_readable');
@@ -25,6 +25,8 @@

'use strict';

const { Object } = primordials;

module.exports = PassThrough;

const Transform = require('_stream_transform');
@@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

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

@@ -63,6 +63,8 @@

'use strict';

const { Object } = primordials;

module.exports = Transform;
const {
ERR_METHOD_NOT_IMPLEMENTED,
@@ -25,6 +25,8 @@

'use strict';

const { Object } = primordials;

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

@@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

const { parseCertString } = require('internal/tls');
const { isArrayBufferView } = require('internal/util/types');
const tls = require('tls');
@@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

const {
assertCrypto,
deprecate
@@ -20,6 +20,8 @@

'use strict';

const { Object } = primordials;

const { Buffer } = require('buffer');
const { codes: {
ERR_AMBIGUOUS_ARGUMENT,
@@ -21,7 +21,7 @@

'use strict';

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

const {
byteLengthUtf8,
@@ -21,6 +21,8 @@

'use strict';

const { Object, ObjectPrototype } = primordials;

const {
promisify,
convertToValidSignal,
@@ -515,8 +517,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;
}

@@ -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.
@@ -24,6 +24,8 @@

'use strict';

const { Object } = primordials;

const {
assertCrypto,
deprecate
@@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

const errors = require('internal/errors');
const {
kStateSymbol,
@@ -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');
@@ -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');
@@ -21,7 +21,7 @@

'use strict';

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

var spliceOne;

@@ -24,7 +24,7 @@

'use strict';

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

const { fs: constants } = internalBinding('constants');
const {
@@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

const httpAgent = require('_http_agent');
const { ClientRequest } = require('_http_client');
const { methods } = require('_http_common');
@@ -21,6 +21,8 @@

'use strict';

const { Object } = primordials;

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

const tls = require('tls');
@@ -1,6 +1,6 @@
'use strict';

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

const { inspect } = require('internal/util/inspect');
const { codes: {
@@ -1,6 +1,6 @@
'use strict';

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

const {
ERR_ASYNC_TYPE,
@@ -1,5 +1,7 @@
'use strict';

const { Object } = primordials;

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

@@ -1,6 +1,6 @@
'use strict';

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

const {
errnoException,
@@ -1,4 +1,7 @@
'use strict';

const { Object } = primordials;

const assert = require('internal/assert');
const path = require('path');
const EventEmitter = require('events');
@@ -1,4 +1,7 @@
'use strict';

const { Object } = primordials;

const assert = require('internal/assert');
const { fork } = require('child_process');
const path = require('path');
@@ -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;
@@ -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');
}
@@ -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'));
@@ -1,4 +1,7 @@
'use strict';

const { Object } = primordials;

const EventEmitter = require('events');

module.exports = Worker;
@@ -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 {
@@ -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,
@@ -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,
@@ -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]];
@@ -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] = [];
@@ -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);
@@ -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,
@@ -1,5 +1,7 @@
'use strict';

const { Object } = primordials;

const {
RSA_PKCS1_OAEP_PADDING,
RSA_PKCS1_PADDING
Oops, something went wrong.

0 comments on commit 908292c

Please sign in to comment.
You can’t perform that action at this time.