diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index 12375c06eded90..ef3236b362a00a 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -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: diff --git a/lib/_http_agent.js b/lib/_http_agent.js index 41fe003c08db44..32dbf27abc0dff 100644 --- a/lib/_http_agent.js +++ b/lib/_http_agent.js @@ -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'); diff --git a/lib/_http_client.js b/lib/_http_client.js index 3c3bc53e694084..c8ff9e64947386 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -21,6 +21,8 @@ 'use strict'; +const { Object } = primordials; + const net = require('net'); const url = require('url'); const assert = require('internal/assert'); diff --git a/lib/_http_incoming.js b/lib/_http_incoming.js index 5d098a17819ae7..3ec23616b15b02 100644 --- a/lib/_http_incoming.js +++ b/lib/_http_incoming.js @@ -21,6 +21,8 @@ 'use strict'; +const { Object } = primordials; + const Stream = require('stream'); function readStart(socket) { diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 2c2346d21125de..388204fbf2ceb4 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -21,7 +21,7 @@ 'use strict'; -const { ObjectPrototype } = primordials; +const { Object, ObjectPrototype } = primordials; const assert = require('internal/assert'); const Stream = require('stream'); diff --git a/lib/_http_server.js b/lib/_http_server.js index ea5362b347fd7d..f479d07d6991df 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -21,6 +21,8 @@ 'use strict'; +const { Object } = primordials; + const net = require('net'); const assert = require('internal/assert'); const { diff --git a/lib/_stream_duplex.js b/lib/_stream_duplex.js index 11651e2ace65a5..49520c4074e5a2 100644 --- a/lib/_stream_duplex.js +++ b/lib/_stream_duplex.js @@ -26,6 +26,8 @@ 'use strict'; +const { Object } = primordials; + module.exports = Duplex; const Readable = require('_stream_readable'); diff --git a/lib/_stream_passthrough.js b/lib/_stream_passthrough.js index 404617f58eab1f..205a14b65fe243 100644 --- a/lib/_stream_passthrough.js +++ b/lib/_stream_passthrough.js @@ -25,6 +25,8 @@ 'use strict'; +const { Object } = primordials; + module.exports = PassThrough; const Transform = require('_stream_transform'); diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 43b5b43fc77a5e..22f7e38459c573 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -21,6 +21,8 @@ 'use strict'; +const { Object } = primordials; + module.exports = Readable; Readable.ReadableState = ReadableState; diff --git a/lib/_stream_transform.js b/lib/_stream_transform.js index cec617dfb6bca7..ab6ada8dec0a4f 100644 --- a/lib/_stream_transform.js +++ b/lib/_stream_transform.js @@ -63,6 +63,8 @@ 'use strict'; +const { Object } = primordials; + module.exports = Transform; const { ERR_METHOD_NOT_IMPLEMENTED, diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index 7f9eeb67932ebd..9d06adc775d240 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -25,6 +25,8 @@ 'use strict'; +const { Object } = primordials; + module.exports = Writable; Writable.WritableState = WritableState; diff --git a/lib/_tls_common.js b/lib/_tls_common.js index a0ef6934e3e586..2a4ad9b24e8a8a 100644 --- a/lib/_tls_common.js +++ b/lib/_tls_common.js @@ -21,6 +21,8 @@ 'use strict'; +const { Object } = primordials; + const { parseCertString } = require('internal/tls'); const { isArrayBufferView } = require('internal/util/types'); const tls = require('tls'); diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index f8a9e938c0414d..51cd5ae32bdda4 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -21,6 +21,8 @@ 'use strict'; +const { Object } = primordials; + const { assertCrypto, deprecate diff --git a/lib/assert.js b/lib/assert.js index db0a2283e63db9..0ed8a4b2d86826 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -20,6 +20,8 @@ 'use strict'; +const { Object } = primordials; + const { Buffer } = require('buffer'); const { codes: { ERR_AMBIGUOUS_ARGUMENT, diff --git a/lib/buffer.js b/lib/buffer.js index 1a9d81ab3af982..005532bbee3e27 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -21,7 +21,7 @@ 'use strict'; -const { Math } = primordials; +const { Math, Object } = primordials; const { byteLengthUtf8, diff --git a/lib/child_process.js b/lib/child_process.js index 7d0b692141a86d..fffd3333dab4dc 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -21,6 +21,8 @@ 'use strict'; +const { Object, ObjectPrototype } = primordials; + const { promisify, convertToValidSignal, @@ -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; } diff --git a/lib/constants.js b/lib/constants.js index 44c7388580d440..77341c064640f1 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -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. diff --git a/lib/crypto.js b/lib/crypto.js index 44d4800624e291..6bfa8319c1b2b5 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -24,6 +24,8 @@ 'use strict'; +const { Object } = primordials; + const { assertCrypto, deprecate diff --git a/lib/dgram.js b/lib/dgram.js index 54cbc0faed32aa..64192c4b52e65d 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -21,6 +21,8 @@ 'use strict'; +const { Object } = primordials; + const errors = require('internal/errors'); const { kStateSymbol, diff --git a/lib/dns.js b/lib/dns.js index f9c724e7b6d944..b212983c4412f7 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -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'); diff --git a/lib/domain.js b/lib/domain.js index 608d5dacebee9a..eab0b352bc4838 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -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'); diff --git a/lib/events.js b/lib/events.js index 847074206e2056..3deb155479187f 100644 --- a/lib/events.js +++ b/lib/events.js @@ -21,7 +21,7 @@ 'use strict'; -const { Math, Reflect } = primordials; +const { Math, Object, Reflect } = primordials; var spliceOne; diff --git a/lib/fs.js b/lib/fs.js index e7f5f69bdf4c99..38c13613cb352a 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -24,7 +24,7 @@ 'use strict'; -const { Math, Reflect } = primordials; +const { Math, Object, Reflect } = primordials; const { fs: constants } = internalBinding('constants'); const { diff --git a/lib/http.js b/lib/http.js index 5f0b383a480440..8582557446397e 100644 --- a/lib/http.js +++ b/lib/http.js @@ -21,6 +21,8 @@ 'use strict'; +const { Object } = primordials; + const httpAgent = require('_http_agent'); const { ClientRequest } = require('_http_client'); const { methods } = require('_http_common'); diff --git a/lib/https.js b/lib/https.js index 715f86878ae99b..4e649017312a24 100644 --- a/lib/https.js +++ b/lib/https.js @@ -21,6 +21,8 @@ 'use strict'; +const { Object } = primordials; + require('internal/util').assertCrypto(); const tls = require('tls'); diff --git a/lib/internal/assert/assertion_error.js b/lib/internal/assert/assertion_error.js index 5cefbf568fddb4..7ab74e6777cdc1 100644 --- a/lib/internal/assert/assertion_error.js +++ b/lib/internal/assert/assertion_error.js @@ -1,6 +1,6 @@ 'use strict'; -const { Math } = primordials; +const { Math, Object } = primordials; const { inspect } = require('internal/util/inspect'); const { codes: { diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index 9d30ad133dca6d..cba8d15a6cb06a 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -1,6 +1,6 @@ 'use strict'; -const { FunctionPrototype, Reflect } = primordials; +const { FunctionPrototype, Object, Reflect } = primordials; const { ERR_ASYNC_TYPE, diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index c1c58a81ff36b5..e2b1103f8cfbd8 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object } = primordials; + const { getOptionValue } = require('internal/options'); const { Buffer } = require('buffer'); diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index 86736b1bd80132..8e6a303a2e27a5 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -1,6 +1,6 @@ 'use strict'; -const { JSON } = primordials; +const { JSON, Object } = primordials; const { errnoException, diff --git a/lib/internal/cluster/child.js b/lib/internal/cluster/child.js index d2f38a6b762b95..e7bddc1d0bc1f9 100644 --- a/lib/internal/cluster/child.js +++ b/lib/internal/cluster/child.js @@ -1,4 +1,7 @@ 'use strict'; + +const { Object } = primordials; + const assert = require('internal/assert'); const path = require('path'); const EventEmitter = require('events'); diff --git a/lib/internal/cluster/master.js b/lib/internal/cluster/master.js index 3869ebbd8a40a2..a881021c5e01ce 100644 --- a/lib/internal/cluster/master.js +++ b/lib/internal/cluster/master.js @@ -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')); diff --git a/lib/internal/cluster/worker.js b/lib/internal/cluster/worker.js index 8033f82f2e24d0..9d9c5dce839035 100644 --- a/lib/internal/cluster/worker.js +++ b/lib/internal/cluster/worker.js @@ -1,4 +1,7 @@ 'use strict'; + +const { Object } = primordials; + const EventEmitter = require('events'); module.exports = Worker; diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index 46fd1e9c625082..d3db1ec1ae8511 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -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); diff --git a/lib/internal/console/global.js b/lib/internal/console/global.js index aac67fde15e253..bad7478f1e1131 100644 --- a/lib/internal/console/global.js +++ b/lib/internal/console/global.js @@ -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, diff --git a/lib/internal/crypto/cipher.js b/lib/internal/crypto/cipher.js index 28bd1e57a62a67..e2fe29152616ce 100644 --- a/lib/internal/crypto/cipher.js +++ b/lib/internal/crypto/cipher.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object } = primordials; + const { RSA_PKCS1_OAEP_PADDING, RSA_PKCS1_PADDING diff --git a/lib/internal/crypto/diffiehellman.js b/lib/internal/crypto/diffiehellman.js index 7ec2ce6e4124f0..7e0fde38bcbe10 100644 --- a/lib/internal/crypto/diffiehellman.js +++ b/lib/internal/crypto/diffiehellman.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object } = primordials; + const { Buffer } = require('buffer'); const { ERR_CRYPTO_ECDH_INVALID_FORMAT, diff --git a/lib/internal/crypto/hash.js b/lib/internal/crypto/hash.js index 89ab29d845e749..a58164802124d3 100644 --- a/lib/internal/crypto/hash.js +++ b/lib/internal/crypto/hash.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object } = primordials; + const { Hash: _Hash, Hmac: _Hmac diff --git a/lib/internal/crypto/keygen.js b/lib/internal/crypto/keygen.js index 10ab49760bcda6..f646f436f7678a 100644 --- a/lib/internal/crypto/keygen.js +++ b/lib/internal/crypto/keygen.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object } = primordials; + const { AsyncWrap, Providers } = internalBinding('async_wrap'); const { generateKeyPairRSA, diff --git a/lib/internal/crypto/keys.js b/lib/internal/crypto/keys.js index 93d350e4e74320..321506eaf4a531 100644 --- a/lib/internal/crypto/keys.js +++ b/lib/internal/crypto/keys.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object } = primordials; + const { KeyObject: KeyObjectHandle, kKeyTypeSecret, diff --git a/lib/internal/crypto/sig.js b/lib/internal/crypto/sig.js index eb75907217f81a..b6a3376e735094 100644 --- a/lib/internal/crypto/sig.js +++ b/lib/internal/crypto/sig.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object } = primordials; + const { ERR_CRYPTO_SIGN_KEY_REQUIRED, ERR_INVALID_ARG_TYPE, diff --git a/lib/internal/dns/promises.js b/lib/internal/dns/promises.js index 25696bf2228b64..cd4607f4857927 100644 --- a/lib/internal/dns/promises.js +++ b/lib/internal/dns/promises.js @@ -1,4 +1,7 @@ 'use strict'; + +const { Object } = primordials; + const { bindDefaultResolver, Resolver: CallbackResolver, diff --git a/lib/internal/encoding.js b/lib/internal/encoding.js index b45a074f382980..2de2cc565ca3c2 100644 --- a/lib/internal/encoding.js +++ b/lib/internal/encoding.js @@ -3,6 +3,8 @@ // An implementation of the WHATWG Encoding Standard // https://encoding.spec.whatwg.org +const { Object } = primordials; + const { ERR_ENCODING_INVALID_ENCODED_DATA, ERR_ENCODING_NOT_SUPPORTED, diff --git a/lib/internal/errors.js b/lib/internal/errors.js index d2bf1999c0933b..6334626d3cd1fb 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -10,13 +10,14 @@ // value statically and permanently identifies the error. While the error // message may change, the code should not. +const { Object } = primordials; + const kCode = Symbol('code'); const kInfo = Symbol('info'); const messages = new Map(); const codes = {}; const { kMaxLength } = internalBinding('buffer'); -const { defineProperty } = Object; let excludedStackFn; @@ -100,7 +101,7 @@ class SystemError extends Error { } set code(value) { - defineProperty(this, 'code', { + Object.defineProperty(this, 'code', { configurable: true, enumerable: true, value, @@ -188,7 +189,7 @@ function makeNodeErrorWithCode(Base, key) { } set code(value) { - defineProperty(this, 'code', { + Object.defineProperty(this, 'code', { configurable: true, enumerable: true, value, @@ -234,7 +235,7 @@ function addCodeToName(err, name, code) { err.stack; // Reset the name to the actual name. if (name === 'SystemError') { - defineProperty(err, 'name', { + Object.defineProperty(err, 'name', { value: name, enumerable: false, writable: true, diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js index 3b797edc582f02..97a8856797ac52 100644 --- a/lib/internal/fs/streams.js +++ b/lib/internal/fs/streams.js @@ -1,6 +1,6 @@ 'use strict'; -const { Math } = primordials; +const { Math, Object } = primordials; const { FSReqCallback, diff --git a/lib/internal/fs/sync_write_stream.js b/lib/internal/fs/sync_write_stream.js index 0af289d7f45bd2..522bfc829df303 100644 --- a/lib/internal/fs/sync_write_stream.js +++ b/lib/internal/fs/sync_write_stream.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object } = primordials; + const { Writable } = require('stream'); const { closeSync, writeSync } = require('fs'); diff --git a/lib/internal/fs/watchers.js b/lib/internal/fs/watchers.js index 2de58b7a1debd6..d29ed902587d6b 100644 --- a/lib/internal/fs/watchers.js +++ b/lib/internal/fs/watchers.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object } = primordials; + const errors = require('internal/errors'); const { kFsStatsFieldsNumber, diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index ba52c9adea887a..37f8242b0068f3 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -1,6 +1,6 @@ 'use strict'; -const { Reflect } = primordials; +const { Object, ObjectPrototype, Reflect } = primordials; const assert = require('internal/assert'); const Stream = require('stream'); @@ -539,7 +539,7 @@ class Http2ServerResponse extends Stream { hasHeader(name) { validateString(name, 'name'); name = name.trim().toLowerCase(); - return Object.prototype.hasOwnProperty.call(this[kHeaders], name); + return ObjectPrototype.hasOwnProperty(this[kHeaders], name); } removeHeader(name) { diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 2e5db4006f11c4..ca6e23e061664b 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -2,7 +2,7 @@ /* eslint-disable no-use-before-define */ -const { Math, Reflect } = primordials; +const { Math, Object, Reflect } = primordials; const { assertCrypto, diff --git a/lib/internal/http2/util.js b/lib/internal/http2/util.js index d22310f19d8a92..9cc2a30897b6ae 100644 --- a/lib/internal/http2/util.js +++ b/lib/internal/http2/util.js @@ -1,6 +1,6 @@ 'use strict'; -const { Math } = primordials; +const { Math, Object } = primordials; const binding = internalBinding('http2'); const { diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js index 71babafd0e867e..0e463dc9357841 100644 --- a/lib/internal/main/worker_thread.js +++ b/lib/internal/main/worker_thread.js @@ -3,6 +3,8 @@ // In worker threads, execute the script sent through the // message port. +const { Object } = primordials; + const { patchProcessObject, setupCoverageHooks, diff --git a/lib/internal/modules/cjs/helpers.js b/lib/internal/modules/cjs/helpers.js index fd24a6fb3c9c39..4b35302944f111 100644 --- a/lib/internal/modules/cjs/helpers.js +++ b/lib/internal/modules/cjs/helpers.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object } = primordials; + const { validateString } = require('internal/validators'); const path = require('path'); const { pathToFileURL } = require('internal/url'); diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 14afb4e1dbd4dd..5d0e7777742db1 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -21,7 +21,7 @@ 'use strict'; -const { JSON, Reflect } = primordials; +const { JSON, Object, Reflect } = primordials; const { NativeModule } = require('internal/bootstrap/loaders'); const { pathToFileURL } = require('internal/url'); diff --git a/lib/internal/modules/esm/module_job.js b/lib/internal/modules/esm/module_job.js index 5666032df1d6d8..5ae3fabae7e091 100644 --- a/lib/internal/modules/esm/module_job.js +++ b/lib/internal/modules/esm/module_job.js @@ -1,11 +1,13 @@ 'use strict'; -const { ModuleWrap } = internalBinding('module_wrap'); const { + Object, SafeSet, SafePromise } = primordials; +const { ModuleWrap } = internalBinding('module_wrap'); + const { decorateErrorStack } = require('internal/util'); const assert = require('internal/assert'); const resolvedPromise = SafePromise.resolve(); diff --git a/lib/internal/per_context/domexception.js b/lib/internal/per_context/domexception.js index 795acf76c09303..729fe3757ada5b 100644 --- a/lib/internal/per_context/domexception.js +++ b/lib/internal/per_context/domexception.js @@ -1,5 +1,9 @@ 'use strict'; +// `per_context` scripts are executed before creating the primordials so we +// cannot use them here. +/* eslint-disable no-restricted-globals */ + class ERR_INVALID_THIS extends TypeError { constructor(type) { super('Value of "this" must be of ' + type); diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index ef9012535f7e7e..35e861df2b73f9 100644 --- a/lib/internal/process/per_thread.js +++ b/lib/internal/process/per_thread.js @@ -5,6 +5,7 @@ // thread and the worker threads. const { + Object, RegExpPrototype, SetPrototype, StringPrototype diff --git a/lib/internal/process/policy.js b/lib/internal/process/policy.js index 98c535f8704f79..215e1420af1d1d 100644 --- a/lib/internal/process/policy.js +++ b/lib/internal/process/policy.js @@ -1,6 +1,6 @@ 'use strict'; -const { JSON, Reflect } = primordials; +const { JSON, Object, Reflect } = primordials; const { ERR_MANIFEST_TDZ, diff --git a/lib/internal/repl.js b/lib/internal/repl.js index 7ef14d33b341fe..cb368ea6121ec3 100644 --- a/lib/internal/repl.js +++ b/lib/internal/repl.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object } = primordials; + const REPL = require('repl'); const { kStandaloneREPL } = require('internal/repl/utils'); diff --git a/lib/internal/repl/await.js b/lib/internal/repl/await.js index bcc94ef1864266..ac0445311b7ba9 100644 --- a/lib/internal/repl/await.js +++ b/lib/internal/repl/await.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object } = primordials; + const acorn = require('internal/deps/acorn/acorn/dist/acorn'); const walk = require('internal/deps/acorn/acorn-walk/dist/walk'); diff --git a/lib/internal/streams/async_iterator.js b/lib/internal/streams/async_iterator.js index 16d1316b168f01..defba235adbd56 100644 --- a/lib/internal/streams/async_iterator.js +++ b/lib/internal/streams/async_iterator.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object } = primordials; + const finished = require('internal/streams/end-of-stream'); const kLastResolve = Symbol('lastResolve'); diff --git a/lib/internal/streams/lazy_transform.js b/lib/internal/streams/lazy_transform.js index 7fc7f899c606cb..0036bf306c3193 100644 --- a/lib/internal/streams/lazy_transform.js +++ b/lib/internal/streams/lazy_transform.js @@ -3,6 +3,8 @@ // for the stream, one conventional and one non-conventional. 'use strict'; +const { Object } = primordials; + const stream = require('stream'); const { diff --git a/lib/internal/streams/legacy.js b/lib/internal/streams/legacy.js index 44ebfc6bd91831..06e48e8b15d839 100644 --- a/lib/internal/streams/legacy.js +++ b/lib/internal/streams/legacy.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object } = primordials; + const EE = require('events'); function Stream() { diff --git a/lib/internal/timers.js b/lib/internal/timers.js index 0c7388b7bbd6d2..aef099b4b997f9 100644 --- a/lib/internal/timers.js +++ b/lib/internal/timers.js @@ -72,7 +72,7 @@ // timers within (or creation of a new list). However, these operations combined // have shown to be trivial in comparison to other timers architectures. -const { Math, Reflect } = primordials; +const { Math, Object, Reflect } = primordials; const { scheduleTimer, diff --git a/lib/internal/tls.js b/lib/internal/tls.js index 4e468a2dd72a74..80f6d80e18ccc8 100644 --- a/lib/internal/tls.js +++ b/lib/internal/tls.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object } = primordials; + // Example: // C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=ca1\nemailAddress=ry@clouds.org function parseCertString(s) { diff --git a/lib/internal/trace_events_async_hooks.js b/lib/internal/trace_events_async_hooks.js index 3b69a85fabf5c7..4485b7a8c820a0 100644 --- a/lib/internal/trace_events_async_hooks.js +++ b/lib/internal/trace_events_async_hooks.js @@ -1,9 +1,10 @@ 'use strict'; +const { Object, SafeMap, SafeSet } = primordials; + const { trace } = internalBinding('trace_events'); const async_wrap = internalBinding('async_wrap'); const async_hooks = require('async_hooks'); -const { SafeMap, SafeSet } = primordials; // Use small letters such that chrome://tracing groups by the name. // The behavior is not only useful but the same as the events emitted using diff --git a/lib/internal/url.js b/lib/internal/url.js index 442c164829f742..a920511df489dc 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -1,6 +1,6 @@ 'use strict'; -const { Reflect } = primordials; +const { Object, Reflect } = primordials; const { inspect } = require('internal/util/inspect'); const { diff --git a/lib/internal/util.js b/lib/internal/util.js index e7dca9a23ce454..82c42e2772d890 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -1,6 +1,6 @@ 'use strict'; -const { Reflect } = primordials; +const { Object, Reflect } = primordials; const { ERR_INVALID_ARG_TYPE, @@ -33,10 +33,6 @@ function isError(e) { return isNativeError(e) || e instanceof Error; } -function objectToString(o) { - return Object.prototype.toString.call(o); -} - // Keep a list of deprecation codes that have been warned on so we only warn on // each one once. const codesWarned = {}; @@ -402,7 +398,6 @@ module.exports = { isInsideNodeModules, join, normalizeEncoding, - objectToString, once, promisify, spliceOne, diff --git a/lib/internal/util/inspector.js b/lib/internal/util/inspector.js index 579f93d540faa3..70868e73244813 100644 --- a/lib/internal/util/inspector.js +++ b/lib/internal/util/inspector.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object } = primordials; + let session; function sendInspectorCommand(cb, onError) { const { hasInspector } = internalBinding('config'); diff --git a/lib/internal/util/types.js b/lib/internal/util/types.js index 28ef7f27a68a6e..3f05ad06ac53be 100644 --- a/lib/internal/util/types.js +++ b/lib/internal/util/types.js @@ -1,6 +1,6 @@ 'use strict'; -const { uncurryThis } = primordials; +const { Object, uncurryThis } = primordials; const TypedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype); diff --git a/lib/internal/vm/source_text_module.js b/lib/internal/vm/source_text_module.js index 6840b4281f46f1..1c9e6da4c37f79 100644 --- a/lib/internal/vm/source_text_module.js +++ b/lib/internal/vm/source_text_module.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object, SafePromise } = primordials; + const { isModuleNamespaceObject } = require('util').types; const { URL } = require('internal/url'); const { isContext } = internalBinding('contextify'); @@ -17,7 +19,6 @@ const { customInspectSymbol, emitExperimentalWarning } = require('internal/util'); -const { SafePromise } = primordials; const { validateInt32, validateUint32, diff --git a/lib/internal/worker.js b/lib/internal/worker.js index c0a2baa86921b5..53e3c7668c31a0 100644 --- a/lib/internal/worker.js +++ b/lib/internal/worker.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object } = primordials; + const EventEmitter = require('events'); const assert = require('internal/assert'); const path = require('path'); diff --git a/lib/internal/worker/io.js b/lib/internal/worker/io.js index ece0f2741a3811..04f8f9ad5974d4 100644 --- a/lib/internal/worker/io.js +++ b/lib/internal/worker/io.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object } = primordials; + const { handle_onclose: handleOnCloseSymbol, oninit: onInitSymbol diff --git a/lib/net.js b/lib/net.js index 99d3fc2ed7b6bf..deab076bf5b235 100644 --- a/lib/net.js +++ b/lib/net.js @@ -21,6 +21,8 @@ 'use strict'; +const { Object } = primordials; + const EventEmitter = require('events'); const stream = require('stream'); const { inspect } = require('internal/util/inspect'); diff --git a/lib/os.js b/lib/os.js index af97f40e57e9ba..d312c7d298e3ec 100644 --- a/lib/os.js +++ b/lib/os.js @@ -21,6 +21,8 @@ 'use strict'; +const { Object } = primordials; + const { safeGetenv } = internalBinding('credentials'); const constants = internalBinding('constants').os; const { deprecate } = require('internal/util'); diff --git a/lib/perf_hooks.js b/lib/perf_hooks.js index 6345bc7a465256..e090ef47c15ebd 100644 --- a/lib/perf_hooks.js +++ b/lib/perf_hooks.js @@ -1,5 +1,7 @@ 'use strict'; +const { Object } = primordials; + const { ELDHistogram: _ELDHistogram, PerformanceEntry, diff --git a/lib/querystring.js b/lib/querystring.js index 8d97e288c12271..a09dc7d4261250 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -23,6 +23,8 @@ 'use strict'; +const { Object } = primordials; + const { Buffer } = require('buffer'); const { encodeStr, diff --git a/lib/readline.js b/lib/readline.js index e621cde3092fd2..250be8ca761fdb 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -27,7 +27,7 @@ 'use strict'; -const { Math } = primordials; +const { Math, Object } = primordials; const { ERR_INVALID_CURSOR_POS, diff --git a/lib/repl.js b/lib/repl.js index 78bcbbb608579b..7140e1b56c3dfa 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -42,7 +42,7 @@ 'use strict'; -const { Math } = primordials; +const { Math, Object, ObjectPrototype } = primordials; const { builtinLibs, @@ -116,13 +116,6 @@ try { // Hack for repl require to work properly with node_modules folders module.paths = CJSModule._nodeModulePaths(module.filename); -// If obj.hasOwnProperty has been overridden, then calling -// obj.hasOwnProperty(prop) will break. -// See: https://github.com/joyent/node/issues/1707 -function hasOwnProperty(obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -} - // This is the default "writer" value, if none is passed in the REPL options, // and it can be overridden by custom print functions, such as `probe` or // `eyes.js`. @@ -1263,7 +1256,7 @@ function complete(line, callback) { group.sort(); for (var j = group.length - 1; j >= 0; j--) { c = group[j]; - if (!hasOwnProperty(uniq, c)) { + if (!ObjectPrototype.hasOwnProperty(uniq, c)) { completions.unshift(c); uniq[c] = true; } diff --git a/lib/stream.js b/lib/stream.js index 97c86f7d6faad9..4918434167c535 100644 --- a/lib/stream.js +++ b/lib/stream.js @@ -21,6 +21,8 @@ 'use strict'; +const { Object } = primordials; + const { Buffer } = require('buffer'); const pipeline = require('internal/streams/pipeline'); const eos = require('internal/streams/end-of-stream'); diff --git a/lib/string_decoder.js b/lib/string_decoder.js index b460da19840c00..fec30beb0a15d4 100644 --- a/lib/string_decoder.js +++ b/lib/string_decoder.js @@ -21,6 +21,8 @@ 'use strict'; +const { Object } = primordials; + const { Buffer } = require('buffer'); const { kIncompleteCharactersStart, diff --git a/lib/tty.js b/lib/tty.js index aef2d6c54ee53a..9e7d7dbb31885a 100644 --- a/lib/tty.js +++ b/lib/tty.js @@ -21,6 +21,8 @@ 'use strict'; +const { Object } = primordials; + const net = require('net'); const { TTY, isTTY } = internalBinding('tty_wrap'); const errors = require('internal/errors'); diff --git a/lib/url.js b/lib/url.js index eb60fe477fdf77..be483ae2bcf95a 100644 --- a/lib/url.js +++ b/lib/url.js @@ -21,9 +21,10 @@ 'use strict'; +const { Object, SafeSet } = primordials; + const { toASCII } = require('internal/idna'); const { encodeStr, hexTable } = require('internal/querystring'); -const { SafeSet } = primordials; const { ERR_INVALID_ARG_TYPE diff --git a/lib/util.js b/lib/util.js index 4b35784dc4bd69..74269f83b834aa 100644 --- a/lib/util.js +++ b/lib/util.js @@ -21,7 +21,7 @@ 'use strict'; -const { ObjectPrototype, Reflect } = primordials; +const { Object, ObjectPrototype, Reflect } = primordials; const { codes: { diff --git a/lib/v8.js b/lib/v8.js index eb46cd4cc64592..efce85533dd8b6 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -14,6 +14,8 @@ 'use strict'; +const { ObjectPrototype } = primordials; + const { Buffer } = require('buffer'); const { validateString } = require('internal/validators'); const { @@ -22,7 +24,6 @@ const { } = internalBinding('serdes'); const assert = require('internal/assert'); const { copy } = internalBinding('buffer'); -const { objectToString } = require('internal/util'); const { FastBuffer } = require('internal/buffer'); const { toPathIfFileURL } = require('internal/url'); const { validatePath } = require('internal/fs/utils'); @@ -193,7 +194,7 @@ const arrayBufferViewTypeToIndex = new Map(); { const dummy = new ArrayBuffer(); for (const [i, ctor] of arrayBufferViewTypes.entries()) { - const tag = objectToString(new ctor(dummy)); + const tag = ObjectPrototype.toString(new ctor(dummy)); arrayBufferViewTypeToIndex.set(tag, i); } } @@ -212,7 +213,7 @@ class DefaultSerializer extends Serializer { if (abView.constructor === Buffer) { i = bufferConstructorIndex; } else { - const tag = objectToString(abView); + const tag = ObjectPrototype.toString(abView); i = arrayBufferViewTypeToIndex.get(tag); if (i === undefined) { diff --git a/lib/zlib.js b/lib/zlib.js index 1d19210d70c512..a8a1e09a7068e1 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -21,7 +21,7 @@ 'use strict'; -const { Math } = primordials; +const { Math, Object } = primordials; const { codes: { diff --git a/src/node.cc b/src/node.cc index 6e2327ef5180bb..adf4a832094be5 100644 --- a/src/node.cc +++ b/src/node.cc @@ -381,12 +381,14 @@ MaybeLocal StartExecution(Environment* env, const char* main_script_id) { env->process_string(), env->require_string(), env->internal_binding_string(), + env->primordials_string(), FIXED_ONE_BYTE_STRING(env->isolate(), "markBootstrapComplete")}; std::vector> arguments = { env->process_object(), env->native_module_require(), env->internal_binding_loader(), + env->primordials(), env->NewFunctionTemplate(MarkBootstrapComplete) ->GetFunction(env->context()) .ToLocalChecked()};