diff options
author | Michaƫl Zasso <targos@protonmail.com> | 2019-04-09 09:55:53 +0200 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2019-04-12 05:38:45 +0200 |
commit | 908292cf1f551c614a733d858528ffb13fb3a524 (patch) | |
tree | 5d3b3a020a6936203b36b82e77a970d8339966de /lib/internal | |
parent | 9ad5106934a21416a2391890ea28bde8b42a6c60 (diff) | |
download | android-node-v8-908292cf1f551c614a733d858528ffb13fb3a524.tar.gz android-node-v8-908292cf1f551c614a733d858528ffb13fb3a524.tar.bz2 android-node-v8-908292cf1f551c614a733d858528ffb13fb3a524.zip |
lib: enforce the use of Object from primordials
PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'lib/internal')
46 files changed, 94 insertions, 41 deletions
diff --git a/lib/internal/assert/assertion_error.js b/lib/internal/assert/assertion_error.js index 5cefbf568f..7ab74e6777 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 9d30ad133d..cba8d15a6c 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 c1c58a81ff..e2b1103f8c 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 86736b1bd8..8e6a303a2e 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 d2f38a6b76..e7bddc1d0b 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 3869ebbd8a..a881021c5e 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 8033f82f2e..9d9c5dce83 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 46fd1e9c62..d3db1ec1ae 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 { @@ -33,11 +33,6 @@ const kTraceEnd = 'e'.charCodeAt(0); const kTraceInstant = 'n'.charCodeAt(0); const { - keys: ObjectKeys, - values: ObjectValues, -} = Object; - -const { isArray: ArrayIsArray, from: ArrayFrom, } = Array; @@ -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 aac67fde15..bad7478f1e 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 28bd1e57a6..e2fe291526 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 7ec2ce6e41..7e0fde38bc 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 89ab29d845..a581648021 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 10ab49760b..f646f436f7 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 93d350e4e7..321506eaf4 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 eb75907217..b6a3376e73 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 25696bf222..cd4607f485 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 b45a074f38..2de2cc565c 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 d2bf1999c0..6334626d3c 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 3b797edc58..97a8856797 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 0af289d7f4..522bfc829d 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 2de58b7a1d..d29ed90258 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 ba52c9adea..37f8242b00 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 2e5db4006f..ca6e23e061 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 d22310f19d..9cc2a30897 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 71babafd0e..0e463dc935 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 fd24a6fb3c..4b35302944 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 14afb4e1db..5d0e777774 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 5666032df1..5ae3fabae7 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 795acf76c0..729fe3757a 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 ef9012535f..35e861df2b 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 98c535f870..215e1420af 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 7ef14d33b3..cb368ea612 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 bcc94ef186..ac0445311b 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 16d1316b16..defba235ad 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 7fc7f899c6..0036bf306c 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 44ebfc6bd9..06e48e8b15 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 0c7388b7bb..aef099b4b9 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 4e468a2dd7..80f6d80e18 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 3b69a85fab..4485b7a8c8 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 442c164829..a920511df4 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 e7dca9a23c..82c42e2772 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 579f93d540..70868e7324 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 28ef7f27a6..3f05ad06ac 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 6840b4281f..1c9e6da4c3 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 c0a2baa869..53e3c7668c 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 ece0f2741a..04f8f9ad59 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 |