From ed9c8b5c9819bef39994f513e907c11b1003129f Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 25 May 2022 22:16:00 +0200 Subject: [PATCH] lib: use null-prototype objects for property descriptors Refs: https://github.com/nodejs/node/pull/42921 --- lib/_http_incoming.js | 5 ++++ lib/_http_outgoing.js | 11 +++++++ lib/_tls_wrap.js | 1 + lib/async_hooks.js | 2 ++ lib/buffer.js | 5 ++++ lib/child_process.js | 2 ++ lib/crypto.js | 13 ++++++++ lib/dgram.js | 6 ++++ lib/dns.js | 7 +++-- lib/domain.js | 8 +++++ lib/events.js | 7 +++++ lib/fs.js | 18 ++++++----- lib/http.js | 2 ++ lib/internal/abort_controller.js | 2 ++ lib/internal/assert/assertion_error.js | 2 +- lib/internal/async_hooks.js | 1 + lib/internal/blob.js | 1 + lib/internal/bootstrap/browser.js | 3 ++ lib/internal/bootstrap/loaders.js | 1 + lib/internal/bootstrap/node.js | 11 +++++++ lib/internal/bootstrap/pre_execution.js | 10 +++++-- .../bootstrap/switches/is_main_thread.js | 1 + .../bootstrap/switches/is_not_main_thread.js | 1 + lib/internal/child_process.js | 1 + lib/internal/console/constructor.js | 30 ++++++++++++++----- lib/internal/crypto/diffiehellman.js | 2 ++ lib/internal/crypto/keygen.js | 1 + lib/internal/crypto/keys.js | 1 + lib/internal/crypto/webcrypto.js | 17 +++++++++++ lib/internal/debugger/inspect_repl.js | 3 +- lib/internal/dns/promises.js | 2 +- lib/internal/encoding.js | 5 ++-- lib/internal/error_serdes.js | 2 ++ lib/internal/errors.js | 13 +++++++- lib/internal/event_target.js | 4 +++ lib/internal/freeze_intrinsics.js | 3 ++ lib/internal/fs/dir.js | 1 + lib/internal/fs/streams.js | 4 +++ lib/internal/fs/watchers.js | 1 + lib/internal/http2/core.js | 1 + lib/internal/http2/util.js | 1 + lib/internal/main/worker_thread.js | 3 ++ lib/internal/modules/cjs/helpers.js | 2 ++ lib/internal/modules/cjs/loader.js | 3 ++ lib/internal/per_context/domexception.js | 10 ++++--- lib/internal/perf/nodetiming.js | 11 +++++++ lib/internal/perf/performance.js | 16 ++++++++++ lib/internal/perf/timerify.js | 2 ++ lib/internal/policy/sri.js | 1 + lib/internal/process/promises.js | 1 + lib/internal/streams/duplex.js | 19 ++++++------ lib/internal/streams/lazy_transform.js | 3 ++ lib/internal/streams/readable.js | 15 ++++++++++ lib/internal/streams/writable.js | 15 ++++++++++ lib/internal/url.js | 10 +++++-- lib/internal/util.js | 8 +++-- lib/internal/util/debuglog.js | 1 + lib/internal/util/inspect.js | 2 ++ lib/internal/util/inspector.js | 1 + lib/internal/util/types.js | 2 ++ lib/internal/vm/module.js | 2 ++ lib/internal/webstreams/readablestream.js | 1 + lib/internal/webstreams/transfer.js | 3 ++ lib/internal/worker/io.js | 9 ++++++ lib/net.js | 10 +++++++ lib/os.js | 3 ++ lib/perf_hooks.js | 1 + lib/readline.js | 30 +++++++++++++++++++ lib/repl.js | 15 +++++++++- lib/stream.js | 13 +++++--- lib/string_decoder.js | 3 ++ lib/timers.js | 2 ++ lib/tls.js | 1 + lib/util.js | 1 + lib/zlib.js | 7 +++++ 75 files changed, 390 insertions(+), 48 deletions(-) diff --git a/lib/_http_incoming.js b/lib/_http_incoming.js index f1e6b7f54ff7d7..950c8c6e08bbc9 100644 --- a/lib/_http_incoming.js +++ b/lib/_http_incoming.js @@ -98,6 +98,7 @@ ObjectSetPrototypeOf(IncomingMessage.prototype, Readable.prototype); ObjectSetPrototypeOf(IncomingMessage, Readable); ObjectDefineProperty(IncomingMessage.prototype, 'connection', { + __proto__: null, get: function() { return this.socket; }, @@ -107,6 +108,7 @@ ObjectDefineProperty(IncomingMessage.prototype, 'connection', { }); ObjectDefineProperty(IncomingMessage.prototype, 'headers', { + __proto__: null, get: function() { if (!this[kHeaders]) { this[kHeaders] = {}; @@ -126,6 +128,7 @@ ObjectDefineProperty(IncomingMessage.prototype, 'headers', { }); ObjectDefineProperty(IncomingMessage.prototype, 'headersDistinct', { + __proto__: null, get: function() { if (!this[kHeadersDistinct]) { this[kHeadersDistinct] = {}; @@ -145,6 +148,7 @@ ObjectDefineProperty(IncomingMessage.prototype, 'headersDistinct', { }); ObjectDefineProperty(IncomingMessage.prototype, 'trailers', { + __proto__: null, get: function() { if (!this[kTrailers]) { this[kTrailers] = {}; @@ -164,6 +168,7 @@ ObjectDefineProperty(IncomingMessage.prototype, 'trailers', { }); ObjectDefineProperty(IncomingMessage.prototype, 'trailersDistinct', { + __proto__: null, get: function() { if (!this[kTrailersDistinct]) { this[kTrailersDistinct] = {}; diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 8b2d24bbf694e6..e02b86e8a84929 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -145,6 +145,7 @@ ObjectSetPrototypeOf(OutgoingMessage.prototype, Stream.prototype); ObjectSetPrototypeOf(OutgoingMessage, Stream); ObjectDefineProperty(OutgoingMessage.prototype, 'writableFinished', { + __proto__: null, get() { return ( this.finished && @@ -155,24 +156,28 @@ ObjectDefineProperty(OutgoingMessage.prototype, 'writableFinished', { }); ObjectDefineProperty(OutgoingMessage.prototype, 'writableObjectMode', { + __proto__: null, get() { return false; } }); ObjectDefineProperty(OutgoingMessage.prototype, 'writableLength', { + __proto__: null, get() { return this.outputSize + (this.socket ? this.socket.writableLength : 0); } }); ObjectDefineProperty(OutgoingMessage.prototype, 'writableHighWaterMark', { + __proto__: null, get() { return this.socket ? this.socket.writableHighWaterMark : HIGH_WATER_MARK; } }); ObjectDefineProperty(OutgoingMessage.prototype, 'writableCorked', { + __proto__: null, get() { const corked = this.socket ? this.socket.writableCorked : 0; return corked + this[kCorked]; @@ -180,6 +185,7 @@ ObjectDefineProperty(OutgoingMessage.prototype, 'writableCorked', { }); ObjectDefineProperty(OutgoingMessage.prototype, '_headers', { + __proto__: null, get: internalUtil.deprecate(function() { return this.getHeaders(); }, 'OutgoingMessage.prototype._headers is deprecated', 'DEP0066'), @@ -200,6 +206,7 @@ ObjectDefineProperty(OutgoingMessage.prototype, '_headers', { }); ObjectDefineProperty(OutgoingMessage.prototype, 'connection', { + __proto__: null, get: function() { return this.socket; }, @@ -209,6 +216,7 @@ ObjectDefineProperty(OutgoingMessage.prototype, 'connection', { }); ObjectDefineProperty(OutgoingMessage.prototype, '_headerNames', { + __proto__: null, get: internalUtil.deprecate(function() { const headers = this[kOutHeaders]; if (headers !== null) { @@ -731,16 +739,19 @@ OutgoingMessage.prototype._implicitHeader = function _implicitHeader() { }; ObjectDefineProperty(OutgoingMessage.prototype, 'headersSent', { + __proto__: null, configurable: true, enumerable: true, get: function() { return !!this._header; } }); ObjectDefineProperty(OutgoingMessage.prototype, 'writableEnded', { + __proto__: null, get: function() { return this.finished; } }); ObjectDefineProperty(OutgoingMessage.prototype, 'writableNeedDrain', { + __proto__: null, get: function() { return !this.destroyed && !this.finished && this[kNeedDrain]; } diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 168df8e585423e..24e04010a28b9a 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -631,6 +631,7 @@ TLSSocket.prototype._wrapHandle = function(wrap) { // Ref: https://github.com/nodejs/node/commit/f7620fb96d339f704932f9bb9a0dceb9952df2d4 function defineHandleReading(socket, handle) { ObjectDefineProperty(handle, 'reading', { + __proto__: null, get: () => { return socket[kRes].reading; }, diff --git a/lib/async_hooks.js b/lib/async_hooks.js index 6cc2052474d9c2..fed0f07e647dcf 100644 --- a/lib/async_hooks.js +++ b/lib/async_hooks.js @@ -238,12 +238,14 @@ class AsyncResource { } ObjectDefineProperties(bound, { 'length': { + __proto__: null, configurable: true, enumerable: false, value: fn.length, writable: false, }, 'asyncResource': { + __proto__: null, configurable: true, enumerable: true, value: this, diff --git a/lib/buffer.js b/lib/buffer.js index bdf01156824180..109e5c45c724dc 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -282,6 +282,7 @@ function Buffer(arg, encodingOrOffset, length) { } ObjectDefineProperty(Buffer, SymbolSpecies, { + __proto__: null, enumerable: false, configurable: true, get() { return FastBuffer; } @@ -756,6 +757,7 @@ Buffer.byteLength = byteLength; // For backwards compatibility. ObjectDefineProperty(Buffer.prototype, 'parent', { + __proto__: null, enumerable: true, get() { if (!(this instanceof Buffer)) @@ -764,6 +766,7 @@ ObjectDefineProperty(Buffer.prototype, 'parent', { } }); ObjectDefineProperty(Buffer.prototype, 'offset', { + __proto__: null, enumerable: true, get() { if (!(this instanceof Buffer)) @@ -1302,11 +1305,13 @@ module.exports = { ObjectDefineProperties(module.exports, { constants: { + __proto__: null, configurable: false, enumerable: true, value: constants }, INSPECT_MAX_BYTES: { + __proto__: null, configurable: true, enumerable: true, get() { return INSPECT_MAX_BYTES; }, diff --git a/lib/child_process.js b/lib/child_process.js index 4b5da300b6295d..7c1b588995dbc5 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -243,6 +243,7 @@ const customPromiseExecFunction = (orig) => { }; ObjectDefineProperty(exec, promisify.custom, { + __proto__: null, enumerable: false, value: customPromiseExecFunction(exec) }); @@ -486,6 +487,7 @@ function execFile(file, args = [], options, callback) { } ObjectDefineProperty(execFile, promisify.custom, { + __proto__: null, enumerable: false, value: customPromiseExecFunction(execFile) }); diff --git a/lib/crypto.js b/lib/crypto.js index 77de7cda9d08a2..77debb9471f03c 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -259,9 +259,11 @@ function getRandomValues(array) { } ObjectDefineProperty(constants, 'defaultCipherList', { + __proto__: null, get() { const value = getOptionValue('--tls-cipher-list'); ObjectDefineProperty(this, 'defaultCipherList', { + __proto__: null, writable: true, configurable: true, enumerable: true, @@ -271,6 +273,7 @@ ObjectDefineProperty(constants, 'defaultCipherList', { }, set(val) { ObjectDefineProperty(this, 'defaultCipherList', { + __proto__: null, writable: true, configurable: true, enumerable: true, @@ -299,6 +302,7 @@ function getRandomBytesAlias(key) { this, key, { + __proto__: null, enumerable: false, configurable: true, writable: true, @@ -312,6 +316,7 @@ function getRandomBytesAlias(key) { this, key, { + __proto__: null, enumerable: true, configurable: true, writable: true, @@ -324,21 +329,25 @@ function getRandomBytesAlias(key) { ObjectDefineProperties(module.exports, { createCipher: { + __proto__: null, enumerable: false, value: deprecate(createCipher, 'crypto.createCipher is deprecated.', 'DEP0106') }, createDecipher: { + __proto__: null, enumerable: false, value: deprecate(createDecipher, 'crypto.createDecipher is deprecated.', 'DEP0106') }, // crypto.fips is deprecated. DEP0093. Use crypto.getFips()/crypto.setFips() fips: { + __proto__: null, get: getFips, set: setFips, }, DEFAULT_ENCODING: { + __proto__: null, enumerable: false, configurable: true, get: deprecate(getDefaultEncoding, @@ -347,12 +356,14 @@ ObjectDefineProperties(module.exports, { 'crypto.DEFAULT_ENCODING is deprecated.', 'DEP0091') }, constants: { + __proto__: null, configurable: false, enumerable: true, value: constants }, webcrypto: { + __proto__: null, configurable: false, enumerable: true, get() { return lazyWebCrypto().crypto; }, @@ -360,6 +371,7 @@ ObjectDefineProperties(module.exports, { }, subtle: { + __proto__: null, configurable: false, enumerable: true, get() { return lazyWebCrypto().crypto.subtle; }, @@ -367,6 +379,7 @@ ObjectDefineProperties(module.exports, { }, getRandomValues: { + __proto__: null, configurable: false, enumerable: true, get: () => getRandomValues, diff --git a/lib/dgram.js b/lib/dgram.js index 5dbc2f22dab658..5f644d2a6c30e3 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -971,6 +971,7 @@ Socket.prototype.getSendBufferSize = function() { // Deprecated private APIs. ObjectDefineProperty(Socket.prototype, '_handle', { + __proto__: null, get: deprecate(function() { return this[kStateSymbol].handle; }, 'Socket.prototype._handle is deprecated', 'DEP0112'), @@ -981,6 +982,7 @@ ObjectDefineProperty(Socket.prototype, '_handle', { ObjectDefineProperty(Socket.prototype, '_receiving', { + __proto__: null, get: deprecate(function() { return this[kStateSymbol].receiving; }, 'Socket.prototype._receiving is deprecated', 'DEP0112'), @@ -991,6 +993,7 @@ ObjectDefineProperty(Socket.prototype, '_receiving', { ObjectDefineProperty(Socket.prototype, '_bindState', { + __proto__: null, get: deprecate(function() { return this[kStateSymbol].bindState; }, 'Socket.prototype._bindState is deprecated', 'DEP0112'), @@ -1001,6 +1004,7 @@ ObjectDefineProperty(Socket.prototype, '_bindState', { ObjectDefineProperty(Socket.prototype, '_queue', { + __proto__: null, get: deprecate(function() { return this[kStateSymbol].queue; }, 'Socket.prototype._queue is deprecated', 'DEP0112'), @@ -1011,6 +1015,7 @@ ObjectDefineProperty(Socket.prototype, '_queue', { ObjectDefineProperty(Socket.prototype, '_reuseAddr', { + __proto__: null, get: deprecate(function() { return this[kStateSymbol].reuseAddr; }, 'Socket.prototype._reuseAddr is deprecated', 'DEP0112'), @@ -1033,6 +1038,7 @@ Socket.prototype._stopReceiving = deprecate(function() { // Legacy alias on the C++ wrapper object. This is not public API, so we may // want to runtime-deprecate it at some point. There's no hurry, though. ObjectDefineProperty(UDP.prototype, 'owner', { + __proto__: null, get() { return this[owner_symbol]; }, set(v) { return this[owner_symbol] = v; } }); diff --git a/lib/dns.js b/lib/dns.js index af5416c62478cc..2e1a37b0818a14 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -198,7 +198,7 @@ function lookup(hostname, options, callback) { } ObjectDefineProperty(lookup, customPromisifyArgs, - { value: ['address', 'family'], enumerable: false }); + { __proto__: null, value: ['address', 'family'], enumerable: false }); function onlookupservice(err, hostname, service) { @@ -243,7 +243,7 @@ function lookupService(address, port, callback) { } ObjectDefineProperty(lookupService, customPromisifyArgs, - { value: ['hostname', 'service'], enumerable: false }); + { __proto__: null, value: ['hostname', 'service'], enumerable: false }); function onresolve(err, result, ttls) { @@ -288,7 +288,7 @@ function resolver(bindingName) { }); return req; } - ObjectDefineProperty(query, 'name', { value: bindingName }); + ObjectDefineProperty(query, 'name', { __proto__: null, value: bindingName }); return query; } @@ -381,6 +381,7 @@ bindDefaultResolver(module.exports, getDefaultResolver()); ObjectDefineProperties(module.exports, { promises: { + __proto__: null, configurable: true, enumerable: true, get() { diff --git a/lib/domain.js b/lib/domain.js index fbce94bad5fe28..20cdd4090d9c1f 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -59,6 +59,7 @@ const { WeakReference } = internalBinding('util'); // effective optimizations const _domain = [null]; ObjectDefineProperty(process, 'domain', { + __proto__: null, enumerable: true, get: function() { return _domain[0]; @@ -78,6 +79,7 @@ const asyncHook = createHook({ // have a domain property as it can be used to escape the sandbox. if (type !== 'PROMISE' || resource instanceof Promise) { ObjectDefineProperty(resource, 'domain', { + __proto__: null, configurable: true, enumerable: false, value: process.domain, @@ -231,6 +233,7 @@ Domain.prototype._errorHandler = function(er) { if ((typeof er === 'object' && er !== null) || typeof er === 'function') { ObjectDefineProperty(er, 'domain', { + __proto__: null, configurable: true, enumerable: false, value: this, @@ -356,6 +359,7 @@ Domain.prototype.add = function(ee) { } ObjectDefineProperty(ee, 'domain', { + __proto__: null, configurable: true, enumerable: false, value: this, @@ -388,6 +392,7 @@ function intercepted(_this, self, cb, fnargs) { er.domainBound = cb; er.domainThrown = false; ObjectDefineProperty(er, 'domain', { + __proto__: null, configurable: true, enumerable: false, value: self, @@ -433,6 +438,7 @@ Domain.prototype.bind = function(cb) { } ObjectDefineProperty(runBound, 'domain', { + __proto__: null, configurable: true, enumerable: false, value: this, @@ -448,6 +454,7 @@ EventEmitter.usingDomains = true; const eventInit = EventEmitter.init; EventEmitter.init = function(opts) { ObjectDefineProperty(this, 'domain', { + __proto__: null, configurable: true, enumerable: false, value: null, @@ -482,6 +489,7 @@ EventEmitter.prototype.emit = function emit(...args) { if (typeof er === 'object') { er.domainEmitter = this; ObjectDefineProperty(er, 'domain', { + __proto__: null, configurable: true, enumerable: false, value: domain, diff --git a/lib/events.js b/lib/events.js index 7b5de246b9cf99..ad5ded2d0e9fc0 100644 --- a/lib/events.js +++ b/lib/events.js @@ -219,6 +219,7 @@ EventEmitter.usingDomains = false; EventEmitter.captureRejectionSymbol = kRejection; ObjectDefineProperty(EventEmitter, 'captureRejections', { + __proto__: null, get() { return EventEmitter.prototype[kCapture]; }, @@ -231,6 +232,7 @@ ObjectDefineProperty(EventEmitter, 'captureRejections', { }); ObjectDefineProperty(EventEmitter, 'EventEmitterAsyncResource', { + __proto__: null, enumerable: true, get: lazyEventEmitterAsyncResource, set: undefined, @@ -241,6 +243,7 @@ EventEmitter.errorMonitor = kErrorMonitor; // The default for captureRejections is false ObjectDefineProperty(EventEmitter.prototype, kCapture, { + __proto__: null, value: false, writable: true, enumerable: false @@ -260,6 +263,7 @@ function checkListener(listener) { } ObjectDefineProperty(EventEmitter, 'defaultMaxListeners', { + __proto__: null, enumerable: true, get: function() { return defaultMaxListeners; @@ -276,12 +280,14 @@ ObjectDefineProperty(EventEmitter, 'defaultMaxListeners', { ObjectDefineProperties(EventEmitter, { kMaxEventTargetListeners: { + __proto__: null, value: kMaxEventTargetListeners, enumerable: false, configurable: false, writable: false, }, kMaxEventTargetListenersWarned: { + __proto__: null, value: kMaxEventTargetListenersWarned, enumerable: false, configurable: false, @@ -493,6 +499,7 @@ EventEmitter.prototype.emit = function emit(type, ...args) { const capture = {}; ErrorCaptureStackTrace(capture, EventEmitter.prototype.emit); ObjectDefineProperty(er, kEnhanceStackBeforeInspector, { + __proto__: null, value: FunctionPrototypeBind(enhanceStackTrace, this, er, capture), configurable: true }); diff --git a/lib/fs.js b/lib/fs.js index 912ca0503d5a25..b251761bd420a2 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -277,6 +277,7 @@ function exists(path, callback) { } ObjectDefineProperty(exists, internalUtil.promisify.custom, { + __proto__: null, value: (path) => { return new Promise((resolve) => fs.exists(path, resolve)); } @@ -679,7 +680,7 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) { } ObjectDefineProperty(read, internalUtil.customPromisifyArgs, - { value: ['bytesRead', 'buffer'], enumerable: false }); + { __proto__: null, value: ['bytesRead', 'buffer'], enumerable: false }); /** * Synchronously reads the file from the @@ -772,7 +773,7 @@ function readv(fd, buffers, position, callback) { } ObjectDefineProperty(readv, internalUtil.customPromisifyArgs, - { value: ['bytesRead', 'buffers'], enumerable: false }); + { __proto__: null, value: ['bytesRead', 'buffers'], enumerable: false }); /** * Synchronously reads file from the @@ -872,7 +873,7 @@ function write(fd, buffer, offsetOrOptions, length, position, callback) { } ObjectDefineProperty(write, internalUtil.customPromisifyArgs, - { value: ['bytesWritten', 'buffer'], enumerable: false }); + { __proto__: null, value: ['bytesWritten', 'buffer'], enumerable: false }); /** * Synchronously writes `buffer` to the @@ -962,6 +963,7 @@ function writev(fd, buffers, position, callback) { } ObjectDefineProperty(writev, internalUtil.customPromisifyArgs, { + __proto__: null, value: ['bytesWritten', 'buffer'], enumerable: false }); @@ -3083,16 +3085,18 @@ module.exports = fs = { }; ObjectDefineProperties(fs, { - F_OK: { enumerable: true, value: F_OK || 0 }, - R_OK: { enumerable: true, value: R_OK || 0 }, - W_OK: { enumerable: true, value: W_OK || 0 }, - X_OK: { enumerable: true, value: X_OK || 0 }, + F_OK: { __proto__: null, enumerable: true, value: F_OK || 0 }, + R_OK: { __proto__: null, enumerable: true, value: R_OK || 0 }, + W_OK: { __proto__: null, enumerable: true, value: W_OK || 0 }, + X_OK: { __proto__: null, enumerable: true, value: X_OK || 0 }, constants: { + __proto__: null, configurable: false, enumerable: true, value: constants }, promises: { + __proto__: null, configurable: true, enumerable: true, get() { diff --git a/lib/http.js b/lib/http.js index 5120ec65e3f25b..1366656e42eb94 100644 --- a/lib/http.js +++ b/lib/http.js @@ -127,6 +127,7 @@ module.exports = { }; ObjectDefineProperty(module.exports, 'maxHeaderSize', { + __proto__: null, configurable: true, enumerable: true, get() { @@ -140,6 +141,7 @@ ObjectDefineProperty(module.exports, 'maxHeaderSize', { }); ObjectDefineProperty(module.exports, 'globalAgent', { + __proto__: null, configurable: true, enumerable: true, get() { diff --git a/lib/internal/abort_controller.js b/lib/internal/abort_controller.js index 7e89e43cc7cead..e4f5f14f1e4cbe 100644 --- a/lib/internal/abort_controller.js +++ b/lib/internal/abort_controller.js @@ -265,6 +265,7 @@ ObjectDefineProperties(AbortSignal.prototype, { }); ObjectDefineProperty(AbortSignal.prototype, SymbolToStringTag, { + __proto__: null, writable: false, enumerable: false, configurable: true, @@ -334,6 +335,7 @@ ObjectDefineProperties(AbortController.prototype, { }); ObjectDefineProperty(AbortController.prototype, SymbolToStringTag, { + __proto__: null, writable: false, enumerable: false, configurable: true, diff --git a/lib/internal/assert/assertion_error.js b/lib/internal/assert/assertion_error.js index e160d6d7e868eb..3deb8185229d7f 100644 --- a/lib/internal/assert/assertion_error.js +++ b/lib/internal/assert/assertion_error.js @@ -55,7 +55,7 @@ function copyError(source) { for (const key of keys) { target[key] = source[key]; } - ObjectDefineProperty(target, 'message', { value: source.message }); + ObjectDefineProperty(target, 'message', { __proto__: null, value: source.message }); return target; } diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index 107aab227e4637..25f0075bf45a07 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -255,6 +255,7 @@ function emitHookFactory(symbol, name) { // Set the name property of the function as it looks good in the stack trace. ObjectDefineProperty(fn, 'name', { + __proto__: null, value: name }); return fn; diff --git a/lib/internal/blob.js b/lib/internal/blob.js index 8fee1d91f79448..723e0983435a75 100644 --- a/lib/internal/blob.js +++ b/lib/internal/blob.js @@ -356,6 +356,7 @@ function createBlob(handle, length, type = '') { } ObjectDefineProperty(Blob.prototype, SymbolToStringTag, { + __proto__: null, configurable: true, value: 'Blob', }); diff --git a/lib/internal/bootstrap/browser.js b/lib/internal/bootstrap/browser.js index 5704dedecb2ef8..92c98a7fa9cc55 100644 --- a/lib/internal/bootstrap/browser.js +++ b/lib/internal/bootstrap/browser.js @@ -87,6 +87,7 @@ function createGlobalConsole() { // https://heycam.github.io/webidl/#es-namespaces function exposeNamespace(target, name, namespaceObject) { ObjectDefineProperty(target, name, { + __proto__: null, writable: true, enumerable: false, configurable: true, @@ -96,6 +97,7 @@ function exposeNamespace(target, name, namespaceObject) { function exposeGetterAndSetter(target, name, getter, setter = undefined) { ObjectDefineProperty(target, name, { + __proto__: null, enumerable: false, configurable: true, get: getter, @@ -106,6 +108,7 @@ function exposeGetterAndSetter(target, name, getter, setter = undefined) { // https://heycam.github.io/webidl/#Replaceable function defineReplacableAttribute(target, name, value) { ObjectDefineProperty(target, name, { + __proto__: null, writable: true, enumerable: true, configurable: true, diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index bc2a83034256d6..41162fabcbc589 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -64,6 +64,7 @@ const { // Set up process.moduleLoadList. const moduleLoadList = []; ObjectDefineProperty(process, 'moduleLoadList', { + __proto__: null, value: moduleLoadList, configurable: true, enumerable: true, diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 0be64e136d19a6..e58538b34cb17e 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -134,6 +134,7 @@ let processConfig = new Proxy( deprecationHandler); ObjectDefineProperty(process, 'config', { + __proto__: null, enumerable: true, configurable: true, get() { return processConfig; }, @@ -233,6 +234,7 @@ setTraceCategoryStateUpdateHandler(perThreadSetup.toggleTraceCategoryState); // process.allowedNodeEnvironmentFlags ObjectDefineProperty(process, 'allowedNodeEnvironmentFlags', { + __proto__: null, get() { const flags = perThreadSetup.buildAllowedFlags(); process.allowedNodeEnvironmentFlags = flags; @@ -242,6 +244,7 @@ ObjectDefineProperty(process, 'allowedNodeEnvironmentFlags', { // this completely to that value. set(value) { ObjectDefineProperty(this, 'allowedNodeEnvironmentFlags', { + __proto__: null, value, configurable: true, enumerable: true, @@ -278,6 +281,7 @@ const features = { }; ObjectDefineProperty(process, 'features', { + __proto__: null, enumerable: true, writable: false, configurable: false, @@ -367,6 +371,7 @@ function setupProcessObject() { ObjectSetPrototypeOf(origProcProto, EventEmitter.prototype); FunctionPrototypeCall(EventEmitter, process); ObjectDefineProperty(process, SymbolToStringTag, { + __proto__: null, enumerable: false, writable: true, configurable: false, @@ -374,6 +379,7 @@ function setupProcessObject() { }); // Make process globally available to users by putting it on the global proxy ObjectDefineProperty(globalThis, 'process', { + __proto__: null, value: process, enumerable: false, writable: true, @@ -383,6 +389,7 @@ function setupProcessObject() { function setupGlobalProxy() { ObjectDefineProperty(globalThis, SymbolToStringTag, { + __proto__: null, value: 'global', writable: false, enumerable: false, @@ -406,24 +413,28 @@ function setupBuffer() { ObjectDefineProperties(globalThis, { 'Blob': { + __proto__: null, value: Blob, enumerable: false, writable: true, configurable: true, }, 'Buffer': { + __proto__: null, value: Buffer, enumerable: false, writable: true, configurable: true, }, 'atob': { + __proto__: null, value: atob, enumerable: false, writable: true, configurable: true, }, 'btoa': { + __proto__: null, value: btoa, enumerable: false, writable: true, diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index e2f3037ffd486c..dc8cb637870744 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -108,6 +108,7 @@ function patchProcessObject(expandArgv1) { require('internal/process/per_thread').refreshHrtimeBuffer(); ObjectDefineProperty(process, 'argv0', { + __proto__: null, enumerable: true, // Only set it to true during snapshot building. configurable: getOptionValue('--build-snapshot'), @@ -156,6 +157,7 @@ function addReadOnlyProcessAlias(name, option, enumerable = true) { const value = getOptionValue(option); if (value) { ObjectDefineProperty(process, name, { + __proto__: null, writable: false, configurable: true, enumerable, @@ -233,12 +235,12 @@ function setupWebCrypto() { let webcrypto; ObjectDefineProperty(globalThis, 'crypto', - ObjectGetOwnPropertyDescriptor({ + { __proto__: null, ...ObjectGetOwnPropertyDescriptor({ get crypto() { webcrypto ??= require('internal/crypto/webcrypto'); return webcrypto.crypto; } - }, 'crypto')); + }, 'crypto') }); if (internalBinding('config').hasOpenSSL) { webcrypto ??= require('internal/crypto/webcrypto'); exposeInterface(globalThis, 'Crypto', webcrypto.Crypto); @@ -281,6 +283,7 @@ function setupStacktracePrinterOnSigint() { function initializeReport() { const { report } = require('internal/process/report'); ObjectDefineProperty(process, 'report', { + __proto__: null, enumerable: true, configurable: true, get() { @@ -388,6 +391,7 @@ function initializeDeprecations() { const { noBrowserGlobals } = internalBinding('config'); if (noBrowserGlobals) { ObjectDefineProperty(process, '_noBrowserGlobals', { + __proto__: null, writable: false, enumerable: true, configurable: true, @@ -410,6 +414,7 @@ function initializeDeprecations() { // See https://github.com/nodejs/node/pull/26334. let _process = process; ObjectDefineProperty(globalThis, 'process', { + __proto__: null, get() { return _process; }, @@ -422,6 +427,7 @@ function initializeDeprecations() { let _Buffer = Buffer; ObjectDefineProperty(globalThis, 'Buffer', { + __proto__: null, get() { return _Buffer; }, diff --git a/lib/internal/bootstrap/switches/is_main_thread.js b/lib/internal/bootstrap/switches/is_main_thread.js index b7bd79e09c4acf..0b2ca03192dcb1 100644 --- a/lib/internal/bootstrap/switches/is_main_thread.js +++ b/lib/internal/bootstrap/switches/is_main_thread.js @@ -15,6 +15,7 @@ process._stopProfilerIdleNotifier = () => {}; function defineStream(name, getter) { ObjectDefineProperty(process, name, { + __proto__: null, configurable: true, enumerable: true, get: getter diff --git a/lib/internal/bootstrap/switches/is_not_main_thread.js b/lib/internal/bootstrap/switches/is_not_main_thread.js index 379ad0a587a22a..cb129189b200a3 100644 --- a/lib/internal/bootstrap/switches/is_not_main_thread.js +++ b/lib/internal/bootstrap/switches/is_not_main_thread.js @@ -7,6 +7,7 @@ delete process._debugEnd; function defineStream(name, getter) { ObjectDefineProperty(process, name, { + __proto__: null, configurable: true, enumerable: true, get: getter diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index 0e4cfc2ead2bf4..9ad7bf8fd8593c 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -572,6 +572,7 @@ function setupChannel(target, channel, serializationMode) { target[kChannelHandle] = channel; ObjectDefineProperty(target, '_channel', { + __proto__: null, get: deprecate(() => { return target.channel; }, channelDeprecationMsg, 'DEP0129'), diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index 18e66a7afee0ee..bba2784bb92d44 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -154,6 +154,7 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) { // from the prototype chain of the subclass. this[key] = FunctionPrototypeBind(this[key], this); ObjectDefineProperty(this[key], 'name', { + __proto__: null, value: key }); }); @@ -170,6 +171,7 @@ const consolePropAttributes = { // Fixup global.console instanceof global.console.Console ObjectDefineProperty(Console, SymbolHasInstance, { + __proto__: null, value(instance) { return instance[kIsConsole]; } @@ -180,16 +182,18 @@ const kNoColorInspectOptions = {}; ObjectDefineProperties(Console.prototype, { [kBindStreamsEager]: { + __proto__: null, ...consolePropAttributes, // Eager version for the Console constructor value: function(stdout, stderr) { ObjectDefineProperties(this, { - '_stdout': { ...consolePropAttributes, value: stdout }, - '_stderr': { ...consolePropAttributes, value: stderr } + '_stdout': { __proto__: null, ...consolePropAttributes, value: stdout }, + '_stderr': { __proto__: null, ...consolePropAttributes, value: stderr }, }); } }, [kBindStreamsLazy]: { + __proto__: null, ...consolePropAttributes, // Lazily load the stdout and stderr from an object so we don't // create the stdio streams when they are not even accessed @@ -198,6 +202,7 @@ ObjectDefineProperties(Console.prototype, { let stderr; ObjectDefineProperties(this, { '_stdout': { + __proto__: null, enumerable: false, configurable: true, get() { @@ -207,6 +212,7 @@ ObjectDefineProperties(Console.prototype, { set(value) { stdout = value; } }, '_stderr': { + __proto__: null, enumerable: false, configurable: true, get() { @@ -219,32 +225,38 @@ ObjectDefineProperties(Console.prototype, { } }, [kBindProperties]: { + __proto__: null, ...consolePropAttributes, value: function(ignoreErrors, colorMode, groupIndentation = 2) { ObjectDefineProperties(this, { '_stdoutErrorHandler': { + __proto__: null, ...consolePropAttributes, value: createWriteErrorHandler(this, kUseStdout) }, '_stderrErrorHandler': { ...consolePropAttributes, + __proto__: null, value: createWriteErrorHandler(this, kUseStderr) }, '_ignoreErrors': { + __proto__: null, ...consolePropAttributes, value: Boolean(ignoreErrors) }, - '_times': { ...consolePropAttributes, value: new SafeMap() }, + '_times': { __proto__: null, ...consolePropAttributes, value: new SafeMap() }, // Corresponds to https://console.spec.whatwg.org/#count-map - [kCounts]: { ...consolePropAttributes, value: new SafeMap() }, - [kColorMode]: { ...consolePropAttributes, value: colorMode }, - [kIsConsole]: { ...consolePropAttributes, value: true }, - [kGroupIndent]: { ...consolePropAttributes, value: '' }, + [kCounts]: { __proto__: null, ...consolePropAttributes, value: new SafeMap() }, + [kColorMode]: { __proto__: null, ...consolePropAttributes, value: colorMode }, + [kIsConsole]: { __proto__: null, ...consolePropAttributes, value: true }, + [kGroupIndent]: { __proto__: null, ...consolePropAttributes, value: '' }, [kGroupIndentationWidth]: { + __proto__: null, ...consolePropAttributes, value: groupIndentation }, [SymbolToStringTag]: { + __proto__: null, writable: false, enumerable: false, configurable: true, @@ -254,6 +266,7 @@ ObjectDefineProperties(Console.prototype, { } }, [kWriteToConsole]: { + __proto__: null, ...consolePropAttributes, value: function(streamSymbol, string) { const ignoreErrors = this._ignoreErrors; @@ -296,6 +309,7 @@ ObjectDefineProperties(Console.prototype, { } }, [kGetInspectOptions]: { + __proto__: null, ...consolePropAttributes, value: function(stream) { let color = this[kColorMode]; @@ -317,6 +331,7 @@ ObjectDefineProperties(Console.prototype, { } }, [kFormatForStdout]: { + __proto__: null, ...consolePropAttributes, value: function(args) { const opts = this[kGetInspectOptions](this._stdout); @@ -325,6 +340,7 @@ ObjectDefineProperties(Console.prototype, { } }, [kFormatForStderr]: { + __proto__: null, ...consolePropAttributes, value: function(args) { const opts = this[kGetInspectOptions](this._stderr); diff --git a/lib/internal/crypto/diffiehellman.js b/lib/internal/crypto/diffiehellman.js index 598db4052b976c..7a735e17184413 100644 --- a/lib/internal/crypto/diffiehellman.js +++ b/lib/internal/crypto/diffiehellman.js @@ -138,6 +138,7 @@ function DiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding) { this[kHandle] = new _DiffieHellman(sizeOrKey, generator); ObjectDefineProperty(this, 'verifyError', { + __proto__: null, enumerable: true, value: this[kHandle].verifyError, writable: false @@ -150,6 +151,7 @@ function DiffieHellmanGroup(name) { return new DiffieHellmanGroup(name); this[kHandle] = new _DiffieHellmanGroup(name); ObjectDefineProperty(this, 'verifyError', { + __proto__: null, enumerable: true, value: this[kHandle].verifyError, writable: false diff --git a/lib/internal/crypto/keygen.js b/lib/internal/crypto/keygen.js index a2dad1154f0c41..b6c3d966712cda 100644 --- a/lib/internal/crypto/keygen.js +++ b/lib/internal/crypto/keygen.js @@ -93,6 +93,7 @@ function generateKeyPair(type, options, callback) { } ObjectDefineProperty(generateKeyPair, customPromisifyArgs, { + __proto__: null, value: ['publicKey', 'privateKey'], enumerable: false }); diff --git a/lib/internal/crypto/keys.js b/lib/internal/crypto/keys.js index 5c9f1fd0926506..143b602d2a7265 100644 --- a/lib/internal/crypto/keys.js +++ b/lib/internal/crypto/keys.js @@ -108,6 +108,7 @@ const { this[kKeyType] = type; ObjectDefineProperty(this, kHandle, { + __proto__: null, value: handle, enumerable: false, configurable: false, diff --git a/lib/internal/crypto/webcrypto.js b/lib/internal/crypto/webcrypto.js index 3b7e4d13d8b1c0..b31f1b1d7a054d 100644 --- a/lib/internal/crypto/webcrypto.js +++ b/lib/internal/crypto/webcrypto.js @@ -773,6 +773,7 @@ function getRandomValues(array) { ObjectDefineProperties( Crypto.prototype, { [SymbolToStringTag]: { + __proto__: null, enumerable: false, configurable: true, writable: false, @@ -780,18 +781,21 @@ ObjectDefineProperties( }, subtle: kEnumerableProperty, getRandomValues: { + __proto__: null, enumerable: true, configurable: true, writable: true, value: getRandomValues, }, randomUUID: { + __proto__: null, enumerable: true, configurable: true, writable: true, value: randomUUID, }, CryptoKey: { + __proto__: null, enumerable: true, configurable: true, writable: true, @@ -802,78 +806,91 @@ ObjectDefineProperties( ObjectDefineProperties( SubtleCrypto.prototype, { [SymbolToStringTag]: { + __proto__: null, enumerable: false, configurable: true, writable: false, value: 'SubtleCrypto', }, encrypt: { + __proto__: null, enumerable: true, configurable: true, writable: true, value: encrypt, }, decrypt: { + __proto__: null, enumerable: true, configurable: true, writable: true, value: decrypt, }, sign: { + __proto__: null, enumerable: true, configurable: true, writable: true, value: sign, }, verify: { + __proto__: null, enumerable: true, configurable: true, writable: true, value: verify, }, digest: { + __proto__: null, enumerable: true, configurable: true, writable: true, value: digest, }, generateKey: { + __proto__: null, enumerable: true, configurable: true, writable: true, value: generateKey, }, deriveKey: { + __proto__: null, enumerable: true, configurable: true, writable: true, value: deriveKey, }, deriveBits: { + __proto__: null, enumerable: true, configurable: true, writable: true, value: deriveBits, }, importKey: { + __proto__: null, enumerable: true, configurable: true, writable: true, value: importKey, }, exportKey: { + __proto__: null, enumerable: true, configurable: true, writable: true, value: exportKey, }, wrapKey: { + __proto__: null, enumerable: true, configurable: true, writable: true, value: wrapKey, }, unwrapKey: { + __proto__: null, enumerable: true, configurable: true, writable: true, diff --git a/lib/internal/debugger/inspect_repl.js b/lib/internal/debugger/inspect_repl.js index 742a7d64705043..49b41ef2af311f 100644 --- a/lib/internal/debugger/inspect_repl.js +++ b/lib/internal/debugger/inspect_repl.js @@ -179,7 +179,7 @@ function convertResultToError(result) { const { className, description } = result; const err = new ERR_DEBUGGER_ERROR(extractErrorMessage(description)); err.stack = description; - ObjectDefineProperty(err, 'name', { value: className }); + ObjectDefineProperty(err, 'name', { __proto__: null, value: className }); return err; } @@ -939,6 +939,7 @@ function createRepl(inspector) { function initializeContext(context) { ArrayPrototypeForEach(inspector.domainNames, (domain) => { ObjectDefineProperty(context, domain, { + __proto__: null, value: inspector[domain], enumerable: true, configurable: true, diff --git a/lib/internal/dns/promises.js b/lib/internal/dns/promises.js index 9625e9e7b9b6ea..9591c5826a5a96 100644 --- a/lib/internal/dns/promises.js +++ b/lib/internal/dns/promises.js @@ -262,7 +262,7 @@ function resolver(bindingName) { return createResolverPromise(this, bindingName, name, ttl); } - ObjectDefineProperty(query, 'name', { value: bindingName }); + ObjectDefineProperty(query, 'name', { __proto__: null, value: bindingName }); return query; } diff --git a/lib/internal/encoding.js b/lib/internal/encoding.js index def0e9223b84c7..7d0e5d4353fc86 100644 --- a/lib/internal/encoding.js +++ b/lib/internal/encoding.js @@ -362,7 +362,7 @@ ObjectDefineProperties( 'encode': kEnumerableProperty, 'encodeInto': kEnumerableProperty, 'encoding': kEnumerableProperty, - [SymbolToStringTag]: { configurable: true, value: 'TextEncoder' }, + [SymbolToStringTag]: { __proto__: null, configurable: true, value: 'TextEncoder' }, }); const TextDecoder = @@ -571,8 +571,9 @@ ObjectDefineProperties( ObjectDefineProperties(TextDecoder.prototype, { decode: kEnumerableProperty, - [inspect]: { enumerable: false }, + [inspect]: { __proto__: null, enumerable: false }, [SymbolToStringTag]: { + __proto__: null, configurable: true, value: 'TextDecoder' } diff --git a/lib/internal/error_serdes.js b/lib/internal/error_serdes.js index c364820f60b1aa..68576c1c24d7a7 100644 --- a/lib/internal/error_serdes.js +++ b/lib/internal/error_serdes.js @@ -70,6 +70,7 @@ function GetConstructors(object) { const desc = ObjectGetOwnPropertyDescriptor(current, 'constructor'); if (desc && desc.value) { ObjectDefineProperty(constructors, constructors.length, { + __proto__: null, value: desc.value, enumerable: true }); } @@ -130,6 +131,7 @@ function deserializeError(error) { const { constructor, properties } = deserialize(error.subarray(1)); const ctor = errors[constructor]; ObjectDefineProperty(properties, SymbolToStringTag, { + __proto__: null, value: { value: 'Error', configurable: true }, enumerable: true }); diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 9289d50c008e13..cf54bbe6fb35e1 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -242,30 +242,35 @@ class SystemError extends Error { ObjectDefineProperties(this, { [kIsNodeError]: { + __proto__: null, value: true, enumerable: false, writable: false, configurable: true, }, name: { + __proto__: null, value: 'SystemError', enumerable: false, writable: true, configurable: true, }, message: { + __proto__: null, value: message, enumerable: false, writable: true, configurable: true, }, info: { + __proto__: null, value: context, enumerable: true, configurable: true, writable: false, }, errno: { + __proto__: null, get() { return context.errno; }, @@ -276,6 +281,7 @@ class SystemError extends Error { configurable: true, }, syscall: { + __proto__: null, get() { return context.syscall; }, @@ -294,6 +300,7 @@ class SystemError extends Error { // `.toString()` and `Buffer.from()` operations and set the value on the // context as the user did. ObjectDefineProperty(this, 'path', { + __proto__: null, get() { return context.path != null ? context.path.toString() : context.path; @@ -309,6 +316,7 @@ class SystemError extends Error { if (context.dest !== undefined) { ObjectDefineProperty(this, 'dest', { + __proto__: null, get() { return context.dest != null ? context.dest.toString() : context.dest; @@ -354,18 +362,21 @@ function makeNodeErrorWithCode(Base, key) { const message = getMessage(key, args, error); ObjectDefineProperties(error, { [kIsNodeError]: { + __proto__: null, value: true, enumerable: false, writable: false, configurable: true, }, message: { + __proto__: null, value: message, enumerable: false, writable: true, configurable: true, }, toString: { + __proto__: null, value() { return `${this.name} [${key}]: ${this.message}`; }, @@ -389,7 +400,7 @@ function hideStackFrames(fn) { // We rename the functions that will be hidden to cut off the stacktrace // at the outermost one const hidden = nodeInternalPrefix + fn.name; - ObjectDefineProperty(fn, 'name', { value: hidden }); + ObjectDefineProperty(fn, 'name', { __proto__: null, value: hidden }); return fn; } diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index 0f9a896396f79c..d005e9edc08c13 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -110,6 +110,7 @@ class Event { // isTrusted is special (LegacyUnforgeable) ObjectDefineProperty(this, 'isTrusted', { + __proto__: null, get: isTrusted, enumerable: true, configurable: false @@ -296,6 +297,7 @@ class Event { ObjectDefineProperties( Event.prototype, { [SymbolToStringTag]: { + __proto__: null, writable: false, enumerable: false, configurable: true, @@ -677,6 +679,7 @@ ObjectDefineProperties(EventTarget.prototype, { removeEventListener: kEnumerableProperty, dispatchEvent: kEnumerableProperty, [SymbolToStringTag]: { + __proto__: null, writable: false, enumerable: false, configurable: true, @@ -924,6 +927,7 @@ function makeEventHandler(handler) { function defineEventHandler(emitter, name) { // 8.1.5.1 Event handlers - basically `on[eventName]` attributes ObjectDefineProperty(emitter, `on${name}`, { + __proto__: null, get() { return this[kHandlers]?.get(name)?.handler ?? null; }, diff --git a/lib/internal/freeze_intrinsics.js b/lib/internal/freeze_intrinsics.js index 0dcfea1ef2ec28..cb1d28f4b0feb4 100644 --- a/lib/internal/freeze_intrinsics.js +++ b/lib/internal/freeze_intrinsics.js @@ -372,6 +372,7 @@ module.exports = function() { // 19.1 Value Properties of the Global Object ObjectDefineProperty(globalThis, 'globalThis', { + __proto__: null, configurable: false, writable: false, value: globalThis, @@ -510,6 +511,7 @@ module.exports = function() { this[prop] = newValue; } else { ObjectDefineProperty(this, prop, { + __proto__: null, value: newValue, writable: true, enumerable: true, @@ -519,6 +521,7 @@ module.exports = function() { } ObjectDefineProperty(obj, prop, { + __proto__: null, get: getter, set: setter, enumerable: desc.enumerable, diff --git a/lib/internal/fs/dir.js b/lib/internal/fs/dir.js index 5fda9d8a7f3ef4..f2bf2485e11b1c 100644 --- a/lib/internal/fs/dir.js +++ b/lib/internal/fs/dir.js @@ -226,6 +226,7 @@ class Dir { } ObjectDefineProperty(Dir.prototype, SymbolAsyncIterator, { + __proto__: null, value: Dir.prototype.entries, enumerable: false, writable: true, diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js index c7ecbff76cefd6..b59199e59e582e 100644 --- a/lib/internal/fs/streams.js +++ b/lib/internal/fs/streams.js @@ -212,6 +212,7 @@ ObjectSetPrototypeOf(ReadStream.prototype, Readable.prototype); ObjectSetPrototypeOf(ReadStream, Readable); ObjectDefineProperty(ReadStream.prototype, 'autoClose', { + __proto__: null, get() { return this._readableState.autoDestroy; }, @@ -295,6 +296,7 @@ ReadStream.prototype.close = function(cb) { }; ObjectDefineProperty(ReadStream.prototype, 'pending', { + __proto__: null, get() { return this.fd === null; }, configurable: true }); @@ -371,6 +373,7 @@ ObjectSetPrototypeOf(WriteStream.prototype, Writable.prototype); ObjectSetPrototypeOf(WriteStream, Writable); ObjectDefineProperty(WriteStream.prototype, 'autoClose', { + __proto__: null, get() { return this._writableState.autoDestroy; }, @@ -479,6 +482,7 @@ WriteStream.prototype.close = function(cb) { WriteStream.prototype.destroySoon = WriteStream.prototype.end; ObjectDefineProperty(WriteStream.prototype, 'pending', { + __proto__: null, get() { return this.fd === null; }, configurable: true }); diff --git a/lib/internal/fs/watchers.js b/lib/internal/fs/watchers.js index f86860f8fc0aed..7b820e70df1613 100644 --- a/lib/internal/fs/watchers.js +++ b/lib/internal/fs/watchers.js @@ -291,6 +291,7 @@ function emitCloseNT(self) { // Legacy alias on the C++ wrapper object. This is not public API, so we may // want to runtime-deprecate it at some point. There's no hurry, though. ObjectDefineProperty(FSEvent.prototype, 'owner', { + __proto__: null, get() { return this[owner_symbol]; }, set(v) { return this[owner_symbol] = v; } }); diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 7a7c9906c03a05..9268f5ea908527 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -3302,6 +3302,7 @@ function connect(authority, options, listener) { // Support util.promisify ObjectDefineProperty(connect, promisify.custom, { + __proto__: null, value: (authority, options) => { return new Promise((resolve) => { const server = connect(authority, options, () => resolve(server)); diff --git a/lib/internal/http2/util.js b/lib/internal/http2/util.js index 962bdd753c2717..ecb943c9b8e37d 100644 --- a/lib/internal/http2/util.js +++ b/lib/internal/http2/util.js @@ -555,6 +555,7 @@ class NghttpError extends Error { this.errno = integerCode; captureLargerStackTrace(this); ObjectDefineProperty(this, kIsNodeError, { + __proto__: null, value: true, enumerable: false, writable: false, diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js index a8167b86ca2e5a..91ca93e6e10062 100644 --- a/lib/internal/main/worker_thread.js +++ b/lib/internal/main/worker_thread.js @@ -90,11 +90,13 @@ const port = getEnvMessagePort(); if (process.env.NODE_CHANNEL_FD) { const workerThreadSetup = require('internal/process/worker_thread_only'); ObjectDefineProperty(process, 'channel', { + __proto__: null, enumerable: false, get: workerThreadSetup.unavailable('process.channel') }); ObjectDefineProperty(process, 'connected', { + __proto__: null, enumerable: false, get: workerThreadSetup.unavailable('process.connected') }); @@ -172,6 +174,7 @@ port.on('message', (message) => { // This is necessary for CJS module compilation. // TODO: pass this with something really internal. ObjectDefineProperty(process, '_eval', { + __proto__: null, configurable: true, enumerable: true, value: filename, diff --git a/lib/internal/modules/cjs/helpers.js b/lib/internal/modules/cjs/helpers.js index 3ae63b46195f75..ef4544ca0aaa52 100644 --- a/lib/internal/modules/cjs/helpers.js +++ b/lib/internal/modules/cjs/helpers.js @@ -171,6 +171,7 @@ function addBuiltinLibsToObject(object, dummyModuleName) { }; ObjectDefineProperty(object, name, { + __proto__: null, get: () => { const lib = dummyModule.require(name); @@ -178,6 +179,7 @@ function addBuiltinLibsToObject(object, dummyModuleName) { // non-enumerable property. delete object[name]; ObjectDefineProperty(object, name, { + __proto__: null, get: () => lib, set: setReal, configurable: true, diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index de919e7406b4e7..9eaac14bcaa2a0 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -222,6 +222,7 @@ let wrapperProxy = new Proxy(wrapper, { }); ObjectDefineProperty(Module, 'wrap', { + __proto__: null, get() { return wrap; }, @@ -233,6 +234,7 @@ ObjectDefineProperty(Module, 'wrap', { }); ObjectDefineProperty(Module, 'wrapper', { + __proto__: null, get() { return wrapperProxy; }, @@ -256,6 +258,7 @@ function setModuleParent(value) { } ObjectDefineProperty(Module.prototype, 'parent', { + __proto__: null, get: pendingDeprecation ? deprecate( getModuleParent, 'module.parent is deprecated due to accuracy issues. Please use ' + diff --git a/lib/internal/per_context/domexception.js b/lib/internal/per_context/domexception.js index 1dd7a2a7f5a819..917e2c00bccda9 100644 --- a/lib/internal/per_context/domexception.js +++ b/lib/internal/per_context/domexception.js @@ -18,12 +18,14 @@ function throwInvalidThisError(Base, type) { const key = 'ERR_INVALID_THIS'; ObjectDefineProperties(err, { message: { + __proto__: null, value: `Value of "this" must be of ${type}`, enumerable: false, writable: true, configurable: true, }, toString: { + __proto__: null, value() { return `${this.name} [${key}]: ${this.message}`; }, @@ -88,10 +90,10 @@ class DOMException { ObjectSetPrototypeOf(DOMException.prototype, ErrorPrototype); ObjectDefineProperties(DOMException.prototype, { - [SymbolToStringTag]: { configurable: true, value: 'DOMException' }, - name: { enumerable: true, configurable: true }, - message: { enumerable: true, configurable: true }, - code: { enumerable: true, configurable: true } + [SymbolToStringTag]: { __proto__: null, configurable: true, value: 'DOMException' }, + name: { __proto__: null, enumerable: true, configurable: true }, + message: { __proto__: null, enumerable: true, configurable: true }, + code: { __proto__: null, enumerable: true, configurable: true } }); for (const { 0: name, 1: codeName, 2: value } of [ diff --git a/lib/internal/perf/nodetiming.js b/lib/internal/perf/nodetiming.js index fcbd7efff49099..b0ab9df4473d63 100644 --- a/lib/internal/perf/nodetiming.js +++ b/lib/internal/perf/nodetiming.js @@ -34,30 +34,35 @@ class PerformanceNodeTiming { constructor() { ObjectDefineProperties(this, { name: { + __proto__: null, enumerable: true, configurable: true, value: 'node' }, entryType: { + __proto__: null, enumerable: true, configurable: true, value: 'node' }, startTime: { + __proto__: null, enumerable: true, configurable: true, value: 0 }, duration: { + __proto__: null, enumerable: true, configurable: true, get: now }, nodeStart: { + __proto__: null, enumerable: true, configurable: true, get() { @@ -66,6 +71,7 @@ class PerformanceNodeTiming { }, v8Start: { + __proto__: null, enumerable: true, configurable: true, get() { @@ -74,6 +80,7 @@ class PerformanceNodeTiming { }, environment: { + __proto__: null, enumerable: true, configurable: true, get() { @@ -82,6 +89,7 @@ class PerformanceNodeTiming { }, loopStart: { + __proto__: null, enumerable: true, configurable: true, get() { @@ -90,6 +98,7 @@ class PerformanceNodeTiming { }, loopExit: { + __proto__: null, enumerable: true, configurable: true, get() { @@ -98,6 +107,7 @@ class PerformanceNodeTiming { }, bootstrapComplete: { + __proto__: null, enumerable: true, configurable: true, get() { @@ -107,6 +117,7 @@ class PerformanceNodeTiming { }, idleTime: { + __proto__: null, enumerable: true, configurable: true, get: loopIdleTime, diff --git a/lib/internal/perf/performance.js b/lib/internal/perf/performance.js index 5c7c008ee14a8e..26a80f51cf66c4 100644 --- a/lib/internal/perf/performance.js +++ b/lib/internal/perf/performance.js @@ -117,51 +117,61 @@ ObjectSetPrototypeOf(InternalPerformance.prototype, Performance.prototype); ObjectDefineProperties(Performance.prototype, { clearMarks: { + __proto__: null, configurable: true, enumerable: false, value: clearMarks, }, clearMeasures: { + __proto__: null, configurable: true, enumerable: false, value: clearMeasures, }, clearResourceTimings: { + __proto__: null, configurable: true, enumerable: false, value: clearResourceTimings, }, eventLoopUtilization: { + __proto__: null, configurable: true, enumerable: false, value: eventLoopUtilization, }, getEntries: { + __proto__: null, configurable: true, enumerable: false, value: getEntries, }, getEntriesByName: { + __proto__: null, configurable: true, enumerable: false, value: getEntriesByName, }, getEntriesByType: { + __proto__: null, configurable: true, enumerable: false, value: getEntriesByType, }, mark: { + __proto__: null, configurable: true, enumerable: false, value: mark, }, measure: { + __proto__: null, configurable: true, enumerable: false, value: measure, }, nodeTiming: { + __proto__: null, configurable: true, enumerable: false, value: nodeTiming, @@ -169,16 +179,19 @@ ObjectDefineProperties(Performance.prototype, { // In the browser, this function is not public. However, it must be used inside fetch // which is a Node.js dependency, not a internal module markResourceTiming: { + __proto__: null, configurable: true, enumerable: false, value: markResourceTiming, }, now: { + __proto__: null, configurable: true, enumerable: false, value: now, }, timerify: { + __proto__: null, configurable: true, enumerable: false, value: timerify, @@ -188,11 +201,13 @@ ObjectDefineProperties(Performance.prototype, { // TODO(joyeecheung): we may want to warn about access to // this during snapshot building. timeOrigin: { + __proto__: null, configurable: true, enumerable: true, value: getTimeOriginTimestamp(), }, toJSON: { + __proto__: null, configurable: true, enumerable: true, value: toJSON, @@ -201,6 +216,7 @@ ObjectDefineProperties(Performance.prototype, { function refreshTimeOrigin() { ObjectDefineProperty(Performance.prototype, 'timeOrigin', { + __proto__: null, configurable: true, enumerable: true, value: getTimeOriginTimestamp(), diff --git a/lib/internal/perf/timerify.js b/lib/internal/perf/timerify.js index 6bfede7aa1fa20..38f6b3d37acdd2 100644 --- a/lib/internal/perf/timerify.js +++ b/lib/internal/perf/timerify.js @@ -91,11 +91,13 @@ function timerify(fn, options = {}) { ObjectDefineProperties(timerified, { length: { + __proto__: null, configurable: false, enumerable: true, value: fn.length, }, name: { + __proto__: null, configurable: false, enumerable: true, value: `timerified ${fn.name}` diff --git a/lib/internal/policy/sri.js b/lib/internal/policy/sri.js index 22704704a310bc..0d8c24e89ae8aa 100644 --- a/lib/internal/policy/sri.js +++ b/lib/internal/policy/sri.js @@ -48,6 +48,7 @@ const parse = (str) => { // Avoid setters being fired ObjectDefineProperty(entries, entries.length, { + __proto__: null, enumerable: true, configurable: true, value: ObjectFreeze({ diff --git a/lib/internal/process/promises.js b/lib/internal/process/promises.js index 8f0899039b114e..421538373e0399 100644 --- a/lib/internal/process/promises.js +++ b/lib/internal/process/promises.js @@ -320,6 +320,7 @@ function getErrorWithoutStack(name, message) { const err = new Error(message); if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = tmp; ObjectDefineProperty(err, 'name', { + __proto__: null, value: name, enumerable: false, writable: true, diff --git a/lib/internal/streams/duplex.js b/lib/internal/streams/duplex.js index 79f91fa0866e25..4b9ca227ed5aa9 100644 --- a/lib/internal/streams/duplex.js +++ b/lib/internal/streams/duplex.js @@ -80,25 +80,26 @@ function Duplex(options) { ObjectDefineProperties(Duplex.prototype, { writable: - ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writable'), + { __proto__: null, ...ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writable') }, writableHighWaterMark: - ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableHighWaterMark'), + { __proto__: null, ...ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableHighWaterMark') }, writableObjectMode: - ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableObjectMode'), + { __proto__: null, ...ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableObjectMode') }, writableBuffer: - ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableBuffer'), + { __proto__: null, ...ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableBuffer') }, writableLength: - ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableLength'), + { __proto__: null, ...ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableLength') }, writableFinished: - ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableFinished'), + { __proto__: null, ...ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableFinished') }, writableCorked: - ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableCorked'), + { __proto__: null, ...ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableCorked') }, writableEnded: - ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableEnded'), + { __proto__: null, ...ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableEnded') }, writableNeedDrain: - ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableNeedDrain'), + { __proto__: null, ...ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableNeedDrain') }, destroyed: { + __proto__: null, get() { if (this._readableState === undefined || this._writableState === undefined) { diff --git a/lib/internal/streams/lazy_transform.js b/lib/internal/streams/lazy_transform.js index 555e6430e33588..fc3e9815a37648 100644 --- a/lib/internal/streams/lazy_transform.js +++ b/lib/internal/streams/lazy_transform.js @@ -39,6 +39,7 @@ function makeGetter(name) { function makeSetter(name) { return function(val) { ObjectDefineProperty(this, name, { + __proto__: null, value: val, enumerable: true, configurable: true, @@ -49,12 +50,14 @@ function makeSetter(name) { ObjectDefineProperties(LazyTransform.prototype, { _readableState: { + __proto__: null, get: makeGetter('_readableState'), set: makeSetter('_readableState'), configurable: true, enumerable: true }, _writableState: { + __proto__: null, get: makeGetter('_writableState'), set: makeSetter('_writableState'), configurable: true, diff --git a/lib/internal/streams/readable.js b/lib/internal/streams/readable.js index 8081e8fde13e0c..4164f7b27d56b2 100644 --- a/lib/internal/streams/readable.js +++ b/lib/internal/streams/readable.js @@ -1151,6 +1151,7 @@ async function* createAsyncIterator(stream, options) { // userland will fail. ObjectDefineProperties(Readable.prototype, { readable: { + __proto__: null, get() { const r = this._readableState; // r.readable === false means that this is part of a Duplex stream @@ -1169,6 +1170,7 @@ ObjectDefineProperties(Readable.prototype, { }, readableDidRead: { + __proto__: null, enumerable: false, get: function() { return this._readableState.dataEmitted; @@ -1176,6 +1178,7 @@ ObjectDefineProperties(Readable.prototype, { }, readableAborted: { + __proto__: null, enumerable: false, get: function() { return !!( @@ -1187,6 +1190,7 @@ ObjectDefineProperties(Readable.prototype, { }, readableHighWaterMark: { + __proto__: null, enumerable: false, get: function() { return this._readableState.highWaterMark; @@ -1194,6 +1198,7 @@ ObjectDefineProperties(Readable.prototype, { }, readableBuffer: { + __proto__: null, enumerable: false, get: function() { return this._readableState && this._readableState.buffer; @@ -1201,6 +1206,7 @@ ObjectDefineProperties(Readable.prototype, { }, readableFlowing: { + __proto__: null, enumerable: false, get: function() { return this._readableState.flowing; @@ -1213,6 +1219,7 @@ ObjectDefineProperties(Readable.prototype, { }, readableLength: { + __proto__: null, enumerable: false, get() { return this._readableState.length; @@ -1220,6 +1227,7 @@ ObjectDefineProperties(Readable.prototype, { }, readableObjectMode: { + __proto__: null, enumerable: false, get() { return this._readableState ? this._readableState.objectMode : false; @@ -1227,6 +1235,7 @@ ObjectDefineProperties(Readable.prototype, { }, readableEncoding: { + __proto__: null, enumerable: false, get() { return this._readableState ? this._readableState.encoding : null; @@ -1234,6 +1243,7 @@ ObjectDefineProperties(Readable.prototype, { }, errored: { + __proto__: null, enumerable: false, get() { return this._readableState ? this._readableState.errored : null; @@ -1241,12 +1251,14 @@ ObjectDefineProperties(Readable.prototype, { }, closed: { + __proto__: null, get() { return this._readableState ? this._readableState.closed : false; } }, destroyed: { + __proto__: null, enumerable: false, get() { return this._readableState ? this._readableState.destroyed : false; @@ -1265,6 +1277,7 @@ ObjectDefineProperties(Readable.prototype, { }, readableEnded: { + __proto__: null, enumerable: false, get() { return this._readableState ? this._readableState.endEmitted : false; @@ -1276,6 +1289,7 @@ ObjectDefineProperties(Readable.prototype, { ObjectDefineProperties(ReadableState.prototype, { // Legacy getter for `pipesCount`. pipesCount: { + __proto__: null, get() { return this.pipes.length; } @@ -1283,6 +1297,7 @@ ObjectDefineProperties(ReadableState.prototype, { // Legacy property for `paused`. paused: { + __proto__: null, get() { return this[kPaused] !== false; }, diff --git a/lib/internal/streams/writable.js b/lib/internal/streams/writable.js index 5ee0cbc969f2ad..1054631ddfee1a 100644 --- a/lib/internal/streams/writable.js +++ b/lib/internal/streams/writable.js @@ -211,6 +211,7 @@ WritableState.prototype.getBuffer = function getBuffer() { }; ObjectDefineProperty(WritableState.prototype, 'bufferedRequestCount', { + __proto__: null, get() { return this.buffered.length - this.bufferedIndex; } @@ -268,6 +269,7 @@ function Writable(options) { } ObjectDefineProperty(Writable, SymbolHasInstance, { + __proto__: null, value: function(object) { if (FunctionPrototypeSymbolHasInstance(this, object)) return true; if (this !== Writable) return false; @@ -764,12 +766,14 @@ function finish(stream, state) { ObjectDefineProperties(Writable.prototype, { closed: { + __proto__: null, get() { return this._writableState ? this._writableState.closed : false; } }, destroyed: { + __proto__: null, get() { return this._writableState ? this._writableState.destroyed : false; }, @@ -782,6 +786,7 @@ ObjectDefineProperties(Writable.prototype, { }, writable: { + __proto__: null, get() { const w = this._writableState; // w.writable === false means that this is part of a Duplex stream @@ -800,30 +805,35 @@ ObjectDefineProperties(Writable.prototype, { }, writableFinished: { + __proto__: null, get() { return this._writableState ? this._writableState.finished : false; } }, writableObjectMode: { + __proto__: null, get() { return this._writableState ? this._writableState.objectMode : false; } }, writableBuffer: { + __proto__: null, get() { return this._writableState && this._writableState.getBuffer(); } }, writableEnded: { + __proto__: null, get() { return this._writableState ? this._writableState.ending : false; } }, writableNeedDrain: { + __proto__: null, get() { const wState = this._writableState; if (!wState) return false; @@ -832,24 +842,28 @@ ObjectDefineProperties(Writable.prototype, { }, writableHighWaterMark: { + __proto__: null, get() { return this._writableState && this._writableState.highWaterMark; } }, writableCorked: { + __proto__: null, get() { return this._writableState ? this._writableState.corked : 0; } }, writableLength: { + __proto__: null, get() { return this._writableState && this._writableState.length; } }, errored: { + __proto__: null, enumerable: false, get() { return this._writableState ? this._writableState.errored : null; @@ -857,6 +871,7 @@ ObjectDefineProperties(Writable.prototype, { }, writableAborted: { + __proto__: null, enumerable: false, get: function() { return !!( diff --git a/lib/internal/url.js b/lib/internal/url.js index 1b85660e07c73a..b483b4440ebf23 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -530,10 +530,11 @@ ObjectDefineProperties(URLSearchParams.prototype, { keys: kEnumerableProperty, values: kEnumerableProperty, toString: kEnumerableProperty, - [SymbolToStringTag]: { configurable: true, value: 'URLSearchParams' }, + [SymbolToStringTag]: { __proto__: null, configurable: true, value: 'URLSearchParams' }, // https://heycam.github.io/webidl/#es-iterable-entries [SymbolIterator]: { + __proto__: null, configurable: true, writable: true, value: URLSearchParams.prototype.entries, @@ -1045,8 +1046,8 @@ class URL { } ObjectDefineProperties(URL.prototype, { - [kFormat]: { configurable: false, writable: false }, - [SymbolToStringTag]: { configurable: true, value: 'URL' }, + [kFormat]: { __proto__: null, configurable: false, writable: false }, + [SymbolToStringTag]: { __proto__: null, configurable: true, value: 'URL' }, toString: kEnumerableProperty, href: kEnumerableProperty, origin: kEnumerableProperty, @@ -1229,6 +1230,7 @@ function serializeParams(array) { function defineIDLClass(proto, classStr, obj) { // https://heycam.github.io/webidl/#dfn-class-string ObjectDefineProperty(proto, SymbolToStringTag, { + __proto__: null, writable: false, enumerable: false, configurable: true, @@ -1238,6 +1240,7 @@ function defineIDLClass(proto, classStr, obj) { // https://heycam.github.io/webidl/#es-operations for (const key of ObjectKeys(obj)) { ObjectDefineProperty(proto, key, { + __proto__: null, writable: true, enumerable: true, configurable: true, @@ -1246,6 +1249,7 @@ function defineIDLClass(proto, classStr, obj) { } for (const key of ObjectGetOwnPropertySymbols(obj)) { ObjectDefineProperty(proto, key, { + __proto__: null, writable: true, enumerable: false, configurable: true, diff --git a/lib/internal/util.js b/lib/internal/util.js index 52039d0595c629..61e58a5d69d1cf 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -259,8 +259,8 @@ function createClassWrapper(type) { } // Mask the wrapper function name and length values ObjectDefineProperties(fn, { - name: { value: type.name }, - length: { value: type.length } + name: { __proto__: null, value: type.name }, + length: { __proto__: null, value: type.length }, }); ObjectSetPrototypeOf(fn, type); fn.prototype = type.prototype; @@ -334,6 +334,7 @@ function promisify(original) { validateFunction(fn, 'util.promisify.custom'); return ObjectDefineProperty(fn, kCustomPromisifiedSymbol, { + __proto__: null, value: fn, enumerable: false, writable: false, configurable: true }); } @@ -364,6 +365,7 @@ function promisify(original) { ObjectSetPrototypeOf(fn, ObjectGetPrototypeOf(original)); ObjectDefineProperty(fn, kCustomPromisifiedSymbol, { + __proto__: null, value: fn, enumerable: false, writable: false, configurable: true }); return ObjectDefineProperties( @@ -469,6 +471,7 @@ function createDeferredPromise() { // https://heycam.github.io/webidl/#define-the-operations function defineOperation(target, name, method) { ObjectDefineProperty(target, name, { + __proto__: null, writable: true, enumerable: true, configurable: true, @@ -479,6 +482,7 @@ function defineOperation(target, name, method) { // https://heycam.github.io/webidl/#es-interfaces function exposeInterface(target, name, interfaceObject) { ObjectDefineProperty(target, name, { + __proto__: null, writable: true, enumerable: false, configurable: true, diff --git a/lib/internal/util/debuglog.js b/lib/internal/util/debuglog.js index 4b5c7cab44ad77..de39457db2b47b 100644 --- a/lib/internal/util/debuglog.js +++ b/lib/internal/util/debuglog.js @@ -100,6 +100,7 @@ function debuglog(set, cb) { } }; ObjectDefineProperty(logger, 'enabled', { + __proto__: null, get() { return test(); }, diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 7285014e803cd7..6569822096a689 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -349,6 +349,7 @@ function inspect(value, opts) { inspect.custom = customInspectSymbol; ObjectDefineProperty(inspect, 'defaultOptions', { + __proto__: null, get() { return inspectDefaultOptions; }, @@ -413,6 +414,7 @@ inspect.colors = ObjectAssign(ObjectCreate(null), { function defineColorAlias(target, alias) { ObjectDefineProperty(inspect.colors, alias, { + __proto__: null, get() { return this[target]; }, diff --git a/lib/internal/util/inspector.js b/lib/internal/util/inspector.js index 5bc4fe5351ac86..d78467136c4918 100644 --- a/lib/internal/util/inspector.js +++ b/lib/internal/util/inspector.js @@ -52,6 +52,7 @@ function wrapConsole(consoleFromNode) { consoleFromNode[key] ); ObjectDefineProperty(consoleFromNode[key], 'name', { + __proto__: null, value: key }); } else { diff --git a/lib/internal/util/types.js b/lib/internal/util/types.js index 6671e87b66dd08..544f4c3da49c72 100644 --- a/lib/internal/util/types.js +++ b/lib/internal/util/types.js @@ -76,6 +76,7 @@ let isKeyObject; ObjectDefineProperties(module.exports, { isKeyObject: { + __proto__: null, configurable: false, enumerable: true, value(obj) { @@ -91,6 +92,7 @@ ObjectDefineProperties(module.exports, { } }, isCryptoKey: { + __proto__: null, configurable: false, enumerable: true, value(obj) { diff --git a/lib/internal/vm/module.js b/lib/internal/vm/module.js index eee629dda4fd05..a5024d97051b63 100644 --- a/lib/internal/vm/module.js +++ b/lib/internal/vm/module.js @@ -112,6 +112,7 @@ class Module { } else { identifier = `${defaultModuleName}(0)`; ObjectDefineProperty(context, kPerContextModuleId, { + __proto__: null, value: 1, writable: true, enumerable: false, @@ -239,6 +240,7 @@ class Module { ObjectSetPrototypeOf(o, ObjectGetPrototypeOf(this)); ObjectDefineProperty(o, SymbolToStringTag, { + __proto__: null, value: constructor.name, configurable: true }); diff --git a/lib/internal/webstreams/readablestream.js b/lib/internal/webstreams/readablestream.js index bea1084bdd72ad..33496587043523 100644 --- a/lib/internal/webstreams/readablestream.js +++ b/lib/internal/webstreams/readablestream.js @@ -585,6 +585,7 @@ class ReadableStream { ObjectDefineProperties(ReadableStream.prototype, { [SymbolAsyncIterator]: { + __proto__: null, configurable: true, enumerable: false, writable: true, diff --git a/lib/internal/webstreams/transfer.js b/lib/internal/webstreams/transfer.js index 985d7e86738f35..4467d90bb5a90f 100644 --- a/lib/internal/webstreams/transfer.js +++ b/lib/internal/webstreams/transfer.js @@ -73,16 +73,19 @@ class CloneableDOMException extends DOMException { [kDeserialize]({ message, name, code }) { ObjectDefineProperties(this, { message: { + __proto__: null, configurable: true, enumerable: true, get() { return message; }, }, name: { + __proto__: null, configurable: true, enumerable: true, get() { return name; }, }, code: { + __proto__: null, configurable: true, enumerable: true, get() { return code; }, diff --git a/lib/internal/worker/io.js b/lib/internal/worker/io.js index 996d98995108d0..97d7d1d408ee5d 100644 --- a/lib/internal/worker/io.js +++ b/lib/internal/worker/io.js @@ -140,6 +140,7 @@ class MessageEvent extends Event { ObjectDefineProperties(MessageEvent.prototype, { data: { + __proto__: null, get() { if (!isMessageEvent(this)) throw new ERR_INVALID_THIS('MessageEvent'); @@ -150,6 +151,7 @@ ObjectDefineProperties(MessageEvent.prototype, { set: undefined, }, origin: { + __proto__: null, get() { if (!isMessageEvent(this)) throw new ERR_INVALID_THIS('MessageEvent'); @@ -160,6 +162,7 @@ ObjectDefineProperties(MessageEvent.prototype, { set: undefined, }, lastEventId: { + __proto__: null, get() { if (!isMessageEvent(this)) throw new ERR_INVALID_THIS('MessageEvent'); @@ -170,6 +173,7 @@ ObjectDefineProperties(MessageEvent.prototype, { set: undefined, }, source: { + __proto__: null, get() { if (!isMessageEvent(this)) throw new ERR_INVALID_THIS('MessageEvent'); @@ -180,6 +184,7 @@ ObjectDefineProperties(MessageEvent.prototype, { set: undefined, }, ports: { + __proto__: null, get() { if (!isMessageEvent(this)) throw new ERR_INVALID_THIS('MessageEvent'); @@ -196,6 +201,7 @@ ObjectDefineProperty( MessagePort.prototype, kCreateEvent, { + __proto__: null, value: function(data, type) { if (type !== 'message' && type !== 'messageerror') { return ReflectApply(originalCreateEvent, this, arguments); @@ -220,6 +226,7 @@ defineEventHandler(MessagePort.prototype, 'message'); defineEventHandler(MessagePort.prototype, 'messageerror'); ObjectDefineProperty(MessagePort.prototype, onInitSymbol, { + __proto__: null, enumerable: true, writable: false, value: oninit @@ -237,6 +244,7 @@ function onclose() { } ObjectDefineProperty(MessagePort.prototype, handleOnCloseSymbol, { + __proto__: null, enumerable: false, writable: false, value: onclose @@ -249,6 +257,7 @@ MessagePort.prototype.close = function(cb) { }; ObjectDefineProperty(MessagePort.prototype, inspect.custom, { + __proto__: null, enumerable: false, writable: false, value: function inspect() { // eslint-disable-line func-name-matching diff --git a/lib/net.js b/lib/net.js index 0110531619ab69..c8c5b5447be29d 100644 --- a/lib/net.js +++ b/lib/net.js @@ -380,6 +380,7 @@ function Socket(options) { // we need to let it do that by turning it into a writable, own // property. ObjectDefineProperty(this._handle, 'bytesWritten', { + __proto__: null, value: 0, writable: true }); } @@ -568,12 +569,14 @@ Socket.prototype.address = function() { ObjectDefineProperty(Socket.prototype, '_connecting', { + __proto__: null, get: function() { return this.connecting; } }); ObjectDefineProperty(Socket.prototype, 'pending', { + __proto__: null, get() { return !this._handle || this.connecting; }, @@ -582,6 +585,7 @@ ObjectDefineProperty(Socket.prototype, 'pending', { ObjectDefineProperty(Socket.prototype, 'readyState', { + __proto__: null, get: function() { if (this.connecting) { return 'opening'; @@ -598,6 +602,7 @@ ObjectDefineProperty(Socket.prototype, 'readyState', { ObjectDefineProperty(Socket.prototype, 'bufferSize', { + __proto__: null, get: function() { if (this._handle) { return this.writableLength; @@ -606,6 +611,7 @@ ObjectDefineProperty(Socket.prototype, 'bufferSize', { }); ObjectDefineProperty(Socket.prototype, kUpdateTimer, { + __proto__: null, get: function() { return this._unrefTimer; } @@ -777,6 +783,7 @@ Socket.prototype._getpeername = function() { function protoGetter(name, callback) { ObjectDefineProperty(Socket.prototype, name, { + __proto__: null, configurable: false, enumerable: true, get: callback @@ -1605,6 +1612,7 @@ function lookupAndListen(self, port, address, backlog, exclusive, flags) { } ObjectDefineProperty(Server.prototype, 'listening', { + __proto__: null, get: function() { return !!this._handle; }, @@ -1787,11 +1795,13 @@ Server.prototype[EventEmitter.captureRejectionSymbol] = function( // Legacy alias on the C++ wrapper object. This is not public API, so we may // want to runtime-deprecate it at some point. There's no hurry, though. ObjectDefineProperty(TCP.prototype, 'owner', { + __proto__: null, get() { return this[owner_symbol]; }, set(v) { return this[owner_symbol] = v; } }); ObjectDefineProperty(Socket.prototype, '_handle', { + __proto__: null, get() { return this[kHandle]; }, set(v) { return this[kHandle] = v; } }); diff --git a/lib/os.js b/lib/os.js index e8a6e252198aa5..90920b67b37aa7 100644 --- a/lib/os.js +++ b/lib/os.js @@ -372,12 +372,14 @@ module.exports = { ObjectDefineProperties(module.exports, { constants: { + __proto__: null, configurable: false, enumerable: true, value: constants }, EOL: { + __proto__: null, configurable: true, enumerable: true, writable: false, @@ -385,6 +387,7 @@ ObjectDefineProperties(module.exports, { }, devNull: { + __proto__: null, configurable: true, enumerable: true, writable: false, diff --git a/lib/perf_hooks.js b/lib/perf_hooks.js index 2456bcb7e7e029..e84c8948f3c609 100644 --- a/lib/perf_hooks.js +++ b/lib/perf_hooks.js @@ -39,6 +39,7 @@ module.exports = { }; ObjectDefineProperty(module.exports, 'constants', { + __proto__: null, configurable: false, enumerable: true, value: constants diff --git a/lib/readline.js b/lib/readline.js index 11514614c33ab9..0957de58506a66 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -208,111 +208,133 @@ ObjectDefineProperties(Interface.prototype, { // Redirect internal prototype methods to the underscore notation for backward // compatibility. [kSetRawMode]: { + __proto__: null, get() { return this._setRawMode; } }, [kOnLine]: { + __proto__: null, get() { return this._onLine; } }, [kWriteToOutput]: { + __proto__: null, get() { return this._writeToOutput; } }, [kAddHistory]: { + __proto__: null, get() { return this._addHistory; } }, [kRefreshLine]: { + __proto__: null, get() { return this._refreshLine; } }, [kNormalWrite]: { + __proto__: null, get() { return this._normalWrite; } }, [kInsertString]: { + __proto__: null, get() { return this._insertString; } }, [kTabComplete]: { + __proto__: null, get() { return this._tabComplete; } }, [kWordLeft]: { + __proto__: null, get() { return this._wordLeft; } }, [kWordRight]: { + __proto__: null, get() { return this._wordRight; } }, [kDeleteLeft]: { + __proto__: null, get() { return this._deleteLeft; } }, [kDeleteRight]: { + __proto__: null, get() { return this._deleteRight; } }, [kDeleteWordLeft]: { + __proto__: null, get() { return this._deleteWordLeft; } }, [kDeleteWordRight]: { + __proto__: null, get() { return this._deleteWordRight; } }, [kDeleteLineLeft]: { + __proto__: null, get() { return this._deleteLineLeft; } }, [kDeleteLineRight]: { + __proto__: null, get() { return this._deleteLineRight; } }, [kLine]: { + __proto__: null, get() { return this._line; } }, [kHistoryNext]: { + __proto__: null, get() { return this._historyNext; } }, [kHistoryPrev]: { + __proto__: null, get() { return this._historyPrev; } }, [kGetDisplayPos]: { + __proto__: null, get() { return this._getDisplayPos; } }, [kMoveCursor]: { + __proto__: null, get() { return this._moveCursor; } }, [kTtyWrite]: { + __proto__: null, get() { return this._ttyWrite; } @@ -321,6 +343,7 @@ ObjectDefineProperties(Interface.prototype, { // Defining proxies for the internal instance properties for backward // compatibility. _decoder: { + __proto__: null, get() { return this[kDecoder]; }, @@ -329,6 +352,7 @@ ObjectDefineProperties(Interface.prototype, { }, }, _line_buffer: { + __proto__: null, get() { return this[kLine_buffer]; }, @@ -337,6 +361,7 @@ ObjectDefineProperties(Interface.prototype, { }, }, _oldPrompt: { + __proto__: null, get() { return this[kOldPrompt]; }, @@ -345,6 +370,7 @@ ObjectDefineProperties(Interface.prototype, { }, }, _previousKey: { + __proto__: null, get() { return this[kPreviousKey]; }, @@ -353,6 +379,7 @@ ObjectDefineProperties(Interface.prototype, { }, }, _prompt: { + __proto__: null, get() { return this[kPrompt]; }, @@ -361,6 +388,7 @@ ObjectDefineProperties(Interface.prototype, { }, }, _questionCallback: { + __proto__: null, get() { return this[kQuestionCallback]; }, @@ -369,6 +397,7 @@ ObjectDefineProperties(Interface.prototype, { }, }, _sawKeyPress: { + __proto__: null, get() { return this[kSawKeyPress]; }, @@ -377,6 +406,7 @@ ObjectDefineProperties(Interface.prototype, { }, }, _sawReturnAt: { + __proto__: null, get() { return this[kSawReturnAt]; }, diff --git a/lib/repl.js b/lib/repl.js index af9b607b022372..7c17272f6e63ee 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -285,6 +285,7 @@ function REPLServer(prompt, (options.preview !== undefined ? !!options.preview : !eval_); ObjectDefineProperty(this, 'inputStream', { + __proto__: null, get: pendingDeprecation ? deprecate(() => this.input, 'repl.inputStream and repl.outputStream are deprecated. ' + @@ -301,6 +302,7 @@ function REPLServer(prompt, configurable: true }); ObjectDefineProperty(this, 'outputStream', { + __proto__: null, get: pendingDeprecation ? deprecate(() => this.output, 'repl.inputStream and repl.outputStream are deprecated. ' + @@ -783,6 +785,7 @@ function REPLServer(prompt, if (options[kStandaloneREPL]) { ObjectDefineProperty(inspect, 'replDefaults', { + __proto__: null, get() { return writer.options; }, @@ -1083,12 +1086,16 @@ REPLServer.prototype.createContext = function() { // Only set properties that do not already exist as a global builtin. if (!globalBuiltins.has(name)) { ObjectDefineProperty(context, name, - ObjectGetOwnPropertyDescriptor(globalThis, name)); + { + __proto__: null, + ...ObjectGetOwnPropertyDescriptor(globalThis, name), + }); } }); context.global = context; const _console = new Console(this.output); ObjectDefineProperty(context, 'console', { + __proto__: null, configurable: true, writable: true, value: _console @@ -1099,11 +1106,13 @@ REPLServer.prototype.createContext = function() { replModule.paths = CJSModule._resolveLookupPaths('', parentModule); ObjectDefineProperty(context, 'module', { + __proto__: null, configurable: true, writable: true, value: replModule }); ObjectDefineProperty(context, 'require', { + __proto__: null, configurable: true, writable: true, value: makeRequireFunction(replModule) @@ -1123,6 +1132,7 @@ REPLServer.prototype.resetContext = function() { this.lines.level = []; ObjectDefineProperty(this.context, '_', { + __proto__: null, configurable: true, get: () => this.last, set: (value) => { @@ -1135,6 +1145,7 @@ REPLServer.prototype.resetContext = function() { }); ObjectDefineProperty(this.context, '_error', { + __proto__: null, configurable: true, get: () => this.lastError, set: (value) => { @@ -1805,6 +1816,7 @@ module.exports = { }; ObjectDefineProperty(module.exports, 'builtinModules', { + __proto__: null, get: () => _builtinLibs, set: (val) => _builtinLibs = val, enumerable: true, @@ -1812,6 +1824,7 @@ ObjectDefineProperty(module.exports, 'builtinModules', { }); ObjectDefineProperty(module.exports, '_builtinLibs', { + __proto__: null, get: pendingDeprecation ? deprecate( () => _builtinLibs, 'repl._builtinLibs is deprecated. Check module.builtinModules instead', diff --git a/lib/stream.js b/lib/stream.js index 55f903f295fecf..e8a38120cb2ceb 100644 --- a/lib/stream.js +++ b/lib/stream.js @@ -63,9 +63,10 @@ for (const key of ObjectKeys(streamReturningOperators)) { } return Stream.Readable.from(ReflectApply(op, this, args)); } - ObjectDefineProperty(fn, 'name', { value: op.name }); - ObjectDefineProperty(fn, 'length', { value: op.length }); + ObjectDefineProperty(fn, 'name', { __proto__: null, value: op.name }); + ObjectDefineProperty(fn, 'length', { __proto__: null, value: op.length }); ObjectDefineProperty(Stream.Readable.prototype, key, { + __proto__: null, value: fn, enumerable: false, configurable: true, @@ -80,9 +81,10 @@ for (const key of ObjectKeys(promiseReturningOperators)) { } return ReflectApply(op, this, args); } - ObjectDefineProperty(fn, 'name', { value: op.name }); - ObjectDefineProperty(fn, 'length', { value: op.length }); + ObjectDefineProperty(fn, 'name', { __proto__: null, value: op.name }); + ObjectDefineProperty(fn, 'length', { __proto__: null, value: op.length }); ObjectDefineProperty(Stream.Readable.prototype, key, { + __proto__: null, value: fn, enumerable: false, configurable: true, @@ -101,6 +103,7 @@ Stream.destroy = destroyer; Stream.compose = compose; ObjectDefineProperty(Stream, 'promises', { + __proto__: null, configurable: true, enumerable: true, get() { @@ -109,6 +112,7 @@ ObjectDefineProperty(Stream, 'promises', { }); ObjectDefineProperty(pipeline, customPromisify, { + __proto__: null, enumerable: true, get() { return promises.pipeline; @@ -116,6 +120,7 @@ ObjectDefineProperty(pipeline, customPromisify, { }); ObjectDefineProperty(eos, customPromisify, { + __proto__: null, enumerable: true, get() { return promises.finished; diff --git a/lib/string_decoder.js b/lib/string_decoder.js index 9eae594aaa27ea..a22da17f505efb 100644 --- a/lib/string_decoder.js +++ b/lib/string_decoder.js @@ -140,6 +140,7 @@ StringDecoder.prototype.text = function text(buf, offset) { ObjectDefineProperties(StringDecoder.prototype, { lastChar: { + __proto__: null, configurable: true, enumerable: true, get() { @@ -149,6 +150,7 @@ ObjectDefineProperties(StringDecoder.prototype, { } }, lastNeed: { + __proto__: null, configurable: true, enumerable: true, get() { @@ -156,6 +158,7 @@ ObjectDefineProperties(StringDecoder.prototype, { } }, lastTotal: { + __proto__: null, configurable: true, enumerable: true, get() { diff --git a/lib/timers.js b/lib/timers.js index cd721ad4550164..b2126d9711fc8e 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -168,6 +168,7 @@ function setTimeout(callback, after, arg1, arg2, arg3) { } ObjectDefineProperty(setTimeout, customPromisify, { + __proto__: null, enumerable: true, get() { if (!timersPromises) @@ -302,6 +303,7 @@ function setImmediate(callback, arg1, arg2, arg3) { } ObjectDefineProperty(setImmediate, customPromisify, { + __proto__: null, enumerable: true, get() { if (!timersPromises) diff --git a/lib/tls.js b/lib/tls.js index 17ad9fb24a0898..136fe50c78eed2 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -110,6 +110,7 @@ function cacheRootCertificates() { } ObjectDefineProperty(exports, 'rootCertificates', { + __proto__: null, configurable: false, enumerable: true, get: () => { diff --git a/lib/util.js b/lib/util.js index 05c4d4f98da9ec..78e6b807ee5ef6 100644 --- a/lib/util.js +++ b/lib/util.js @@ -244,6 +244,7 @@ function inherits(ctor, superCtor) { 'Object', superCtor.prototype); } ObjectDefineProperty(ctor, 'super_', { + __proto__: null, value: superCtor, writable: true, configurable: true diff --git a/lib/zlib.js b/lib/zlib.js index 718f72af67650e..9bde1997d95720 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -308,6 +308,7 @@ ObjectSetPrototypeOf(ZlibBase.prototype, Transform.prototype); ObjectSetPrototypeOf(ZlibBase, Transform); ObjectDefineProperty(ZlibBase.prototype, '_closed', { + __proto__: null, configurable: true, enumerable: true, get() { @@ -320,6 +321,7 @@ ObjectDefineProperty(ZlibBase.prototype, '_closed', { // that have this concept, where it stands for the number of bytes read // *from* the stream (that is, net.Socket/tls.Socket & file system streams). ObjectDefineProperty(ZlibBase.prototype, 'bytesRead', { + __proto__: null, configurable: true, enumerable: true, get: deprecate(function() { @@ -871,6 +873,7 @@ ObjectSetPrototypeOf(BrotliDecompress, Brotli); function createProperty(ctor) { return { + __proto__: null, configurable: true, enumerable: true, value: function(options) { @@ -882,6 +885,7 @@ function createProperty(ctor) { // Legacy alias on the C++ wrapper object. This is not public API, so we may // want to runtime-deprecate it at some point. There's no hurry, though. ObjectDefineProperty(binding.Zlib.prototype, 'jsref', { + __proto__: null, get() { return this[owner_symbol]; }, set(v) { return this[owner_symbol] = v; } }); @@ -930,11 +934,13 @@ ObjectDefineProperties(module.exports, { createBrotliCompress: createProperty(BrotliCompress), createBrotliDecompress: createProperty(BrotliDecompress), constants: { + __proto__: null, configurable: false, enumerable: true, value: constants }, codes: { + __proto__: null, enumerable: true, writable: false, value: ObjectFreeze(codes) @@ -946,6 +952,7 @@ ObjectDefineProperties(module.exports, { for (const bkey of ObjectKeys(constants)) { if (StringPrototypeStartsWith(bkey, 'BROTLI')) continue; ObjectDefineProperty(module.exports, bkey, { + __proto__: null, enumerable: false, value: constants[bkey], writable: false }); }