diff --git a/lib/_http_incoming.js b/lib/_http_incoming.js index 3c8c58d0d1f..51ceb96d4c1 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 8b2d24bbf69..e02b86e8a84 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 5f1f326c487..be2c8269871 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -633,6 +633,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 52ef6e9f92a..8638bb4d7b3 100644 --- a/lib/async_hooks.js +++ b/lib/async_hooks.js @@ -239,12 +239,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 8e1361b2e4b..f86deb03d82 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; } @@ -757,6 +758,7 @@ Buffer.byteLength = byteLength; // For backwards compatibility. ObjectDefineProperty(Buffer.prototype, 'parent', { + __proto__: null, enumerable: true, get() { if (!(this instanceof Buffer)) @@ -765,6 +767,7 @@ ObjectDefineProperty(Buffer.prototype, 'parent', { } }); ObjectDefineProperty(Buffer.prototype, 'offset', { + __proto__: null, enumerable: true, get() { if (!(this instanceof Buffer)) @@ -1284,11 +1287,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 20c069599d3..12c2d7e572c 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -247,6 +247,7 @@ const customPromiseExecFunction = (orig) => { }; ObjectDefineProperty(exec, promisify.custom, { + __proto__: null, enumerable: false, value: customPromiseExecFunction(exec) }); @@ -498,6 +499,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 6e050068b20..be1cf7a99cf 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -248,26 +248,31 @@ function getFipsForced() { } ObjectDefineProperty(constants, 'defaultCipherList', { + __proto__: null, value: getOptionValue('--tls-cipher-list') }); 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: fipsForced ? getFipsForced : getFipsCrypto, set: fipsForced ? setFipsForced : setFipsCrypto }, DEFAULT_ENCODING: { + __proto__: null, enumerable: false, configurable: true, get: deprecate(getDefaultEncoding, @@ -276,12 +281,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 lazyRequire('internal/crypto/webcrypto').crypto; } diff --git a/lib/dgram.js b/lib/dgram.js index 2d41ef5eb48..6125adff0b5 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 a805521495b..d768a863326 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -191,7 +191,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) { @@ -240,7 +240,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) { @@ -289,7 +289,7 @@ function resolver(bindingName) { } return req; } - ObjectDefineProperty(query, 'name', { value: bindingName }); + ObjectDefineProperty(query, 'name', { __proto__: null, value: bindingName }); return query; } @@ -382,6 +382,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 fbce94bad5f..20cdd4090d9 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 50708f70058..dafcdea7b57 100644 --- a/lib/events.js +++ b/lib/events.js @@ -222,6 +222,7 @@ EventEmitter.usingDomains = false; EventEmitter.captureRejectionSymbol = kRejection; ObjectDefineProperty(EventEmitter, 'captureRejections', { + __proto__: null, get() { return EventEmitter.prototype[kCapture]; }, @@ -234,6 +235,7 @@ ObjectDefineProperty(EventEmitter, 'captureRejections', { }); ObjectDefineProperty(EventEmitter, 'EventEmitterAsyncResource', { + __proto__: null, enumerable: true, get: lazyEventEmitterAsyncResource, set: undefined, @@ -244,6 +246,7 @@ EventEmitter.errorMonitor = kErrorMonitor; // The default for captureRejections is false ObjectDefineProperty(EventEmitter.prototype, kCapture, { + __proto__: null, value: false, writable: true, enumerable: false @@ -263,6 +266,7 @@ function checkListener(listener) { } ObjectDefineProperty(EventEmitter, 'defaultMaxListeners', { + __proto__: null, enumerable: true, get: function() { return defaultMaxListeners; @@ -279,12 +283,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, @@ -496,6 +502,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 89883db955c..dc7d535e423 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -273,6 +273,7 @@ function exists(path, callback) { } ObjectDefineProperty(exists, internalUtil.promisify.custom, { + __proto__: null, value: (path) => { return new Promise((resolve) => fs.exists(path, resolve)); } @@ -675,7 +676,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 @@ -768,7 +769,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 @@ -865,7 +866,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 @@ -955,6 +956,7 @@ function writev(fd, buffers, position, callback) { } ObjectDefineProperty(writev, internalUtil.customPromisifyArgs, { + __proto__: null, value: ['bytesWritten', 'buffer'], enumerable: false }); @@ -3070,16 +3072,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 5120ec65e3f..1366656e42e 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 3233fb8c0c2..7a281edcdf1 100644 --- a/lib/internal/abort_controller.js +++ b/lib/internal/abort_controller.js @@ -258,6 +258,7 @@ ObjectDefineProperties(AbortSignal.prototype, { }); ObjectDefineProperty(AbortSignal.prototype, SymbolToStringTag, { + __proto__: null, writable: false, enumerable: false, configurable: true, @@ -328,6 +329,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 e160d6d7e86..3deb8185229 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 107aab227e4..25f0075bf45 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 720d0c99e0e..166cd12731f 100644 --- a/lib/internal/blob.js +++ b/lib/internal/blob.js @@ -357,6 +357,7 @@ function createBlob(handle, length, type = '') { } ObjectDefineProperty(Blob.prototype, SymbolToStringTag, { + __proto__: null, configurable: true, value: 'Blob', }); diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index d6869ef6334..f5ea60a6ab6 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -63,6 +63,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 dfae7675e16..6d8baf469ad 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -130,6 +130,7 @@ let processConfig = new Proxy( deprecationHandler); ObjectDefineProperty(process, 'config', { + __proto__: null, enumerable: true, configurable: true, get() { return processConfig; }, @@ -275,6 +276,7 @@ setTraceCategoryStateUpdateHandler(perThreadSetup.toggleTraceCategoryState); // process.allowedNodeEnvironmentFlags ObjectDefineProperty(process, 'allowedNodeEnvironmentFlags', { + __proto__: null, get() { const flags = perThreadSetup.buildAllowedFlags(); process.allowedNodeEnvironmentFlags = flags; @@ -284,6 +286,7 @@ ObjectDefineProperty(process, 'allowedNodeEnvironmentFlags', { // this completely to that value. set(value) { ObjectDefineProperty(this, 'allowedNodeEnvironmentFlags', { + __proto__: null, value, configurable: true, enumerable: true, @@ -321,6 +324,7 @@ const features = { }; ObjectDefineProperty(process, 'features', { + __proto__: null, enumerable: true, writable: false, configurable: false, @@ -407,6 +411,7 @@ function setupProcessObject() { ObjectSetPrototypeOf(origProcProto, EventEmitter.prototype); FunctionPrototypeCall(EventEmitter, process); ObjectDefineProperty(process, SymbolToStringTag, { + __proto__: null, enumerable: false, writable: true, configurable: false, @@ -414,6 +419,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, @@ -423,6 +429,7 @@ function setupProcessObject() { function setupGlobalProxy() { ObjectDefineProperty(globalThis, SymbolToStringTag, { + __proto__: null, value: 'global', writable: false, enumerable: false, @@ -445,18 +452,21 @@ function setupBuffer() { ObjectDefineProperties(globalThis, { '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 4b912accaff..f28ba5ccf60 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -105,6 +105,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'), @@ -153,6 +154,7 @@ function addReadOnlyProcessAlias(name, option, enumerable = true) { const value = getOptionValue(option); if (value) { ObjectDefineProperty(process, name, { + __proto__: null, writable: false, configurable: true, enumerable, @@ -197,12 +199,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'); ObjectDefineProperty(globalThis, 'Crypto', { @@ -260,6 +262,7 @@ function setupStacktracePrinterOnSigint() { function initializeReport() { const { report } = require('internal/process/report'); ObjectDefineProperty(process, 'report', { + __proto__: null, enumerable: true, configurable: true, get() { @@ -367,6 +370,7 @@ function initializeDeprecations() { const { noBrowserGlobals } = internalBinding('config'); if (noBrowserGlobals) { ObjectDefineProperty(process, '_noBrowserGlobals', { + __proto__: null, writable: false, enumerable: true, configurable: true, @@ -389,6 +393,7 @@ function initializeDeprecations() { // See https://github.com/nodejs/node/pull/26334. let _process = process; ObjectDefineProperty(globalThis, 'process', { + __proto__: null, get() { return _process; }, @@ -401,6 +406,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 54a2863c73b..777c911972b 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 379ad0a587a..cb129189b20 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 5b212d345d5..cba612823d0 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -574,6 +574,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 18e66a7afee..bba2784bb92 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/console/global.js b/lib/internal/console/global.js index 782a585957f..dd293b9f195 100644 --- a/lib/internal/console/global.js +++ b/lib/internal/console/global.js @@ -37,7 +37,7 @@ for (const prop of ReflectOwnKeys(Console.prototype)) { if (typeof desc.value === 'function') { // fix the receiver const name = desc.value.name; desc.value = FunctionPrototypeBind(desc.value, globalConsole); - ReflectDefineProperty(desc.value, 'name', { value: name }); + ReflectDefineProperty(desc.value, 'name', { __proto__: null, value: name }); } ReflectDefineProperty(globalConsole, prop, desc); } diff --git a/lib/internal/crypto/diffiehellman.js b/lib/internal/crypto/diffiehellman.js index 43530b56d5d..b1091c5b5d4 100644 --- a/lib/internal/crypto/diffiehellman.js +++ b/lib/internal/crypto/diffiehellman.js @@ -125,6 +125,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 @@ -137,6 +138,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 93c23d4d38b..af9c7eb231a 100644 --- a/lib/internal/crypto/keygen.js +++ b/lib/internal/crypto/keygen.js @@ -96,6 +96,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 4931d206929..5d007278132 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 53fa1e41f7c..a5f442b0e57 100644 --- a/lib/internal/crypto/webcrypto.js +++ b/lib/internal/crypto/webcrypto.js @@ -749,6 +749,7 @@ function getRandomValues(array) { ObjectDefineProperties( Crypto.prototype, { [SymbolToStringTag]: { + __proto__: null, enumerable: false, configurable: true, writable: false, @@ -756,18 +757,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, @@ -778,78 +782,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 a2d83da4388..1a93b59fec2 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; } @@ -936,6 +936,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 2141b9cc54a..90ae3fcdc2b 100644 --- a/lib/internal/dns/promises.js +++ b/lib/internal/dns/promises.js @@ -258,7 +258,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 def0e9223b8..1c0c17d534f 100644 --- a/lib/internal/encoding.js +++ b/lib/internal/encoding.js @@ -7,6 +7,8 @@ const { ObjectCreate, ObjectDefineProperties, ObjectGetOwnPropertyDescriptors, + ObjectSetPrototypeOf, + ObjectValues, SafeMap, StringPrototypeSlice, Symbol, @@ -362,7 +364,7 @@ ObjectDefineProperties( 'encode': kEnumerableProperty, 'encodeInto': kEnumerableProperty, 'encoding': kEnumerableProperty, - [SymbolToStringTag]: { configurable: true, value: 'TextEncoder' }, + [SymbolToStringTag]: { __proto__: null, configurable: true, value: 'TextEncoder' }, }); const TextDecoder = @@ -530,49 +532,54 @@ function makeTextDecoderJS() { } // Mix in some shared properties. -ObjectDefineProperties( - TextDecoder.prototype, - ObjectGetOwnPropertyDescriptors({ - get encoding() { - validateDecoder(this); - return this[kEncoding]; - }, - - get fatal() { - validateDecoder(this); - return (this[kFlags] & CONVERTER_FLAGS_FATAL) === CONVERTER_FLAGS_FATAL; - }, - - get ignoreBOM() { - validateDecoder(this); - return (this[kFlags] & CONVERTER_FLAGS_IGNORE_BOM) === +const sharedProperties = ObjectGetOwnPropertyDescriptors({ + get encoding() { + validateDecoder(this); + return this[kEncoding]; + }, + + get fatal() { + validateDecoder(this); + return (this[kFlags] & CONVERTER_FLAGS_FATAL) === CONVERTER_FLAGS_FATAL; + }, + + get ignoreBOM() { + validateDecoder(this); + return (this[kFlags] & CONVERTER_FLAGS_IGNORE_BOM) === CONVERTER_FLAGS_IGNORE_BOM; - }, + }, - [inspect](depth, opts) { - validateDecoder(this); - if (typeof depth === 'number' && depth < 0) - return this; - const constructor = getConstructorOf(this) || TextDecoder; - const obj = ObjectCreate({ constructor }); - obj.encoding = this.encoding; - obj.fatal = this.fatal; - obj.ignoreBOM = this.ignoreBOM; - if (opts.showHidden) { - obj[kFlags] = this[kFlags]; - obj[kHandle] = this[kHandle]; - } - // Lazy to avoid circular dependency - const { inspect } = require('internal/util/inspect'); - return `${constructor.name} ${inspect(obj)}`; + [inspect](depth, opts) { + validateDecoder(this); + if (typeof depth === 'number' && depth < 0) + return this; + const constructor = getConstructorOf(this) || TextDecoder; + const obj = ObjectCreate({ constructor }); + obj.encoding = this.encoding; + obj.fatal = this.fatal; + obj.ignoreBOM = this.ignoreBOM; + if (opts.showHidden) { + obj[kFlags] = this[kFlags]; + obj[kHandle] = this[kHandle]; } - }) -); + // Lazy to avoid circular dependency + const { inspect } = require('internal/util/inspect'); + return `${constructor.name} ${inspect(obj)}`; + } +}); +const propertiesValues = ObjectValues(sharedProperties); +for (let i = 0; i < propertiesValues.length; i++) { + // We want to use null-prototype objects to not rely on globally mutable + // %Object.prototype%. + ObjectSetPrototypeOf(propertiesValues[i], null); +} +sharedProperties[inspect].enumerable = false; ObjectDefineProperties(TextDecoder.prototype, { decode: kEnumerableProperty, - [inspect]: { enumerable: false }, + ...sharedProperties, [SymbolToStringTag]: { + __proto__: null, configurable: true, value: 'TextDecoder' } diff --git a/lib/internal/error_serdes.js b/lib/internal/error_serdes.js index c364820f60b..68576c1c24d 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 ddef255d1c3..1bb41fb0540 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -232,30 +232,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; }, @@ -266,6 +271,7 @@ class SystemError extends Error { configurable: true, }, syscall: { + __proto__: null, get() { return context.syscall; }, @@ -284,6 +290,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; @@ -299,6 +306,7 @@ class SystemError extends Error { if (context.dest !== undefined) { ObjectDefineProperty(this, 'dest', { + __proto__: null, get() { return context.dest != null ? context.dest.toString() : context.dest; @@ -344,18 +352,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}`; }, @@ -379,7 +390,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 9e92a1cb50a..27c1263acc4 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -118,6 +118,7 @@ class Event { // isTrusted is special (LegacyUnforgeable) ObjectDefineProperty(this, 'isTrusted', { + __proto__: null, get: isTrusted, enumerable: true, configurable: false @@ -304,6 +305,7 @@ class Event { ObjectDefineProperties( Event.prototype, { [SymbolToStringTag]: { + __proto__: null, writable: false, enumerable: false, configurable: true, @@ -685,6 +687,7 @@ ObjectDefineProperties(EventTarget.prototype, { removeEventListener: kEnumerableProperty, dispatchEvent: kEnumerableProperty, [SymbolToStringTag]: { + __proto__: null, writable: false, enumerable: false, configurable: true, @@ -932,6 +935,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 0dcfea1ef2e..cb1d28f4b0f 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 917319661a6..b6e8d4a4b09 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 5e9e338ab1f..8eb011dc0fc 100644 --- a/lib/internal/fs/streams.js +++ b/lib/internal/fs/streams.js @@ -216,6 +216,7 @@ ObjectSetPrototypeOf(ReadStream.prototype, Readable.prototype); ObjectSetPrototypeOf(ReadStream, Readable); ObjectDefineProperty(ReadStream.prototype, 'autoClose', { + __proto__: null, get() { return this._readableState.autoDestroy; }, @@ -299,6 +300,7 @@ ReadStream.prototype.close = function(cb) { }; ObjectDefineProperty(ReadStream.prototype, 'pending', { + __proto__: null, get() { return this.fd === null; }, configurable: true }); @@ -377,6 +379,7 @@ ObjectSetPrototypeOf(WriteStream.prototype, Writable.prototype); ObjectSetPrototypeOf(WriteStream, Writable); ObjectDefineProperty(WriteStream.prototype, 'autoClose', { + __proto__: null, get() { return this._writableState.autoDestroy; }, @@ -485,6 +488,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 b45af42d12f..d0f5ceefa5d 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 b2c8b147b56..4b39384014c 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -3295,6 +3295,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 962bdd753c2..ecb943c9b8e 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 a8167b86ca2..91ca93e6e10 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 3ae63b46195..ef4544ca0aa 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 b4902850c7f..e8aaa941d6f 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -221,6 +221,7 @@ let wrapperProxy = new Proxy(wrapper, { }); ObjectDefineProperty(Module, 'wrap', { + __proto__: null, get() { return wrap; }, @@ -232,6 +233,7 @@ ObjectDefineProperty(Module, 'wrap', { }); ObjectDefineProperty(Module, 'wrapper', { + __proto__: null, get() { return wrapperProxy; }, @@ -255,6 +257,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 06bb3fa3053..c03359f30b7 100644 --- a/lib/internal/per_context/domexception.js +++ b/lib/internal/per_context/domexception.js @@ -77,10 +77,10 @@ class DOMException extends Error { } 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 } }); function forEachCode(fn) { diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index 7d9368e678c..5c8df35522b 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -57,11 +57,13 @@ function getNewKey(key) { function copyAccessor(dest, prefix, key, { enumerable, get, set }) { ReflectDefineProperty(dest, `${prefix}Get${key}`, { + __proto__: null, value: uncurryThis(get), enumerable }); if (set !== undefined) { ReflectDefineProperty(dest, `${prefix}Set${key}`, { + __proto__: null, value: uncurryThis(set), enumerable }); @@ -79,6 +81,7 @@ function copyPropsRenamed(src, dest, prefix) { ReflectDefineProperty(dest, name, desc); if (varargsMethods.includes(name)) { ReflectDefineProperty(dest, `${name}Apply`, { + __proto__: null, // `src` is bound as the `this` so that the static `this` points // to the object it was defined on, // e.g.: `ArrayOfApply` gets a `this` of `Array`: @@ -105,6 +108,7 @@ function copyPropsRenamedBound(src, dest, prefix) { ReflectDefineProperty(dest, name, desc); if (varargsMethods.includes(name)) { ReflectDefineProperty(dest, `${name}Apply`, { + __proto__: null, value: applyBind(value, src), }); } @@ -128,6 +132,7 @@ function copyPrototype(src, dest, prefix) { ReflectDefineProperty(dest, name, desc); if (varargsMethods.includes(name)) { ReflectDefineProperty(dest, `${name}Apply`, { + __proto__: null, value: applyBind(value), }); } diff --git a/lib/internal/perf/nodetiming.js b/lib/internal/perf/nodetiming.js index fcbd7efff49..b0ab9df4473 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 5c7c008ee14..26a80f51cf6 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 42b2faf02ef..35024d8cf0c 100644 --- a/lib/internal/perf/timerify.js +++ b/lib/internal/perf/timerify.js @@ -86,11 +86,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 22704704a31..0d8c24e89ae 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 fd5cb73fbbe..00a81c014e1 100644 --- a/lib/internal/process/promises.js +++ b/lib/internal/process/promises.js @@ -311,6 +311,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 785f505d932..170690f99c7 100644 --- a/lib/internal/streams/duplex.js +++ b/lib/internal/streams/duplex.js @@ -74,25 +74,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 555e6430e33..fc3e9815a37 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 afef1edfb0b..c617f6584d3 100644 --- a/lib/internal/streams/readable.js +++ b/lib/internal/streams/readable.js @@ -1162,6 +1162,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 @@ -1180,6 +1181,7 @@ ObjectDefineProperties(Readable.prototype, { }, readableDidRead: { + __proto__: null, enumerable: false, get: function() { return this._readableState.dataEmitted; @@ -1187,6 +1189,7 @@ ObjectDefineProperties(Readable.prototype, { }, readableAborted: { + __proto__: null, enumerable: false, get: function() { return !!( @@ -1198,6 +1201,7 @@ ObjectDefineProperties(Readable.prototype, { }, readableHighWaterMark: { + __proto__: null, enumerable: false, get: function() { return this._readableState.highWaterMark; @@ -1205,6 +1209,7 @@ ObjectDefineProperties(Readable.prototype, { }, readableBuffer: { + __proto__: null, enumerable: false, get: function() { return this._readableState && this._readableState.buffer; @@ -1212,6 +1217,7 @@ ObjectDefineProperties(Readable.prototype, { }, readableFlowing: { + __proto__: null, enumerable: false, get: function() { return this._readableState.flowing; @@ -1224,6 +1230,7 @@ ObjectDefineProperties(Readable.prototype, { }, readableLength: { + __proto__: null, enumerable: false, get() { return this._readableState.length; @@ -1231,6 +1238,7 @@ ObjectDefineProperties(Readable.prototype, { }, readableObjectMode: { + __proto__: null, enumerable: false, get() { return this._readableState ? this._readableState.objectMode : false; @@ -1238,6 +1246,7 @@ ObjectDefineProperties(Readable.prototype, { }, readableEncoding: { + __proto__: null, enumerable: false, get() { return this._readableState ? this._readableState.encoding : null; @@ -1245,6 +1254,7 @@ ObjectDefineProperties(Readable.prototype, { }, destroyed: { + __proto__: null, enumerable: false, get() { if (this._readableState === undefined) { @@ -1266,6 +1276,7 @@ ObjectDefineProperties(Readable.prototype, { }, readableEnded: { + __proto__: null, enumerable: false, get() { return this._readableState ? this._readableState.endEmitted : false; @@ -1277,6 +1288,7 @@ ObjectDefineProperties(Readable.prototype, { ObjectDefineProperties(ReadableState.prototype, { // Legacy getter for `pipesCount`. pipesCount: { + __proto__: null, get() { return this.pipes.length; } @@ -1284,6 +1296,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 f0b872014e0..f5378ce7d05 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; } @@ -267,6 +268,7 @@ function Writable(options) { } ObjectDefineProperty(Writable, SymbolHasInstance, { + __proto__: null, value: function(object) { if (FunctionPrototypeSymbolHasInstance(this, object)) return true; if (this !== Writable) return false; @@ -772,6 +774,7 @@ function finish(stream, state) { ObjectDefineProperties(Writable.prototype, { destroyed: { + __proto__: null, get() { return this._writableState ? this._writableState.destroyed : false; }, @@ -784,6 +787,7 @@ ObjectDefineProperties(Writable.prototype, { }, writable: { + __proto__: null, get() { const w = this._writableState; // w.writable === false means that this is part of a Duplex stream @@ -802,30 +806,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; @@ -834,24 +843,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; } }, writableAborted: { + __proto__: null, enumerable: false, get: function() { return !!( diff --git a/lib/internal/url.js b/lib/internal/url.js index 939374a4958..aadc54c529e 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -520,10 +520,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, @@ -983,8 +984,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, @@ -1167,6 +1168,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, @@ -1176,6 +1178,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, @@ -1184,6 +1187,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 23e5620ea44..b90a769f482 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -260,8 +260,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; @@ -335,6 +335,7 @@ function promisify(original) { validateFunction(fn, 'util.promisify.custom'); return ObjectDefineProperty(fn, kCustomPromisifiedSymbol, { + __proto__: null, value: fn, enumerable: false, writable: false, configurable: true }); } @@ -365,6 +366,7 @@ function promisify(original) { ObjectSetPrototypeOf(fn, ObjectGetPrototypeOf(original)); ObjectDefineProperty(fn, kCustomPromisifiedSymbol, { + __proto__: null, value: fn, enumerable: false, writable: false, configurable: true }); return ObjectDefineProperties( @@ -470,6 +472,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, @@ -480,6 +483,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 4b5c7cab44a..de39457db2b 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 7285014e803..6569822096a 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 a94289b17d0..95ef370c3c4 100644 --- a/lib/internal/util/inspector.js +++ b/lib/internal/util/inspector.js @@ -52,6 +52,7 @@ function wrapConsole(consoleFromNode, consoleFromVM) { 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 aca7dbc4b2f..0811a68f82a 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 e47b7b59602..d3818e6fd6c 100644 --- a/lib/internal/vm/module.js +++ b/lib/internal/vm/module.js @@ -113,6 +113,7 @@ class Module { } else { identifier = `${defaultModuleName}(0)`; ObjectDefineProperty(context, kPerContextModuleId, { + __proto__: null, value: 1, writable: true, enumerable: false, @@ -240,6 +241,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 e49aa5c358b..b44df2ff778 100644 --- a/lib/internal/webstreams/readablestream.js +++ b/lib/internal/webstreams/readablestream.js @@ -586,6 +586,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 985d7e86738..4467d90bb5a 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 0331c466332..f7e6e51ae27 100644 --- a/lib/internal/worker/io.js +++ b/lib/internal/worker/io.js @@ -143,6 +143,7 @@ class MessageEvent extends Event { ObjectDefineProperties(MessageEvent.prototype, { data: { + __proto__: null, get() { if (!isMessageEvent(this)) throw new ERR_INVALID_THIS('MessageEvent'); @@ -153,6 +154,7 @@ ObjectDefineProperties(MessageEvent.prototype, { set: undefined, }, origin: { + __proto__: null, get() { if (!isMessageEvent(this)) throw new ERR_INVALID_THIS('MessageEvent'); @@ -163,6 +165,7 @@ ObjectDefineProperties(MessageEvent.prototype, { set: undefined, }, lastEventId: { + __proto__: null, get() { if (!isMessageEvent(this)) throw new ERR_INVALID_THIS('MessageEvent'); @@ -173,6 +176,7 @@ ObjectDefineProperties(MessageEvent.prototype, { set: undefined, }, source: { + __proto__: null, get() { if (!isMessageEvent(this)) throw new ERR_INVALID_THIS('MessageEvent'); @@ -183,6 +187,7 @@ ObjectDefineProperties(MessageEvent.prototype, { set: undefined, }, ports: { + __proto__: null, get() { if (!isMessageEvent(this)) throw new ERR_INVALID_THIS('MessageEvent'); @@ -199,6 +204,7 @@ ObjectDefineProperty( MessagePort.prototype, kCreateEvent, { + __proto__: null, value: function(data, type) { if (type !== 'message' && type !== 'messageerror') { return ReflectApply(originalCreateEvent, this, arguments); @@ -223,6 +229,7 @@ defineEventHandler(MessagePort.prototype, 'message'); defineEventHandler(MessagePort.prototype, 'messageerror'); ObjectDefineProperty(MessagePort.prototype, onInitSymbol, { + __proto__: null, enumerable: true, writable: false, value: oninit @@ -240,6 +247,7 @@ function onclose() { } ObjectDefineProperty(MessagePort.prototype, handleOnCloseSymbol, { + __proto__: null, enumerable: false, writable: false, value: onclose @@ -252,6 +260,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/internal/worker/js_transferable.js b/lib/internal/worker/js_transferable.js index 7bd6c8cafc3..337413f0258 100644 --- a/lib/internal/worker/js_transferable.js +++ b/lib/internal/worker/js_transferable.js @@ -5,6 +5,7 @@ const { ObjectGetOwnPropertyDescriptors, ObjectGetPrototypeOf, ObjectSetPrototypeOf, + ObjectValues, ReflectConstruct, StringPrototypeSplit, } = primordials; @@ -40,7 +41,14 @@ function setup() { function makeTransferable(obj) { const inst = ReflectConstruct(JSTransferable, [], obj.constructor); - ObjectDefineProperties(inst, ObjectGetOwnPropertyDescriptors(obj)); + const properties = ObjectGetOwnPropertyDescriptors(obj); + const propertiesValues = ObjectValues(properties); + for (let i = 0; i < propertiesValues.length; i++) { + // We want to use null-prototype objects to not rely on globally mutable + // %Object.prototype%. + ObjectSetPrototypeOf(propertiesValues[i], null); + } + ObjectDefineProperties(inst, properties); ObjectSetPrototypeOf(inst, ObjectGetPrototypeOf(obj)); return inst; } diff --git a/lib/net.js b/lib/net.js index 44511de84e7..d4305639cc5 100644 --- a/lib/net.js +++ b/lib/net.js @@ -381,6 +381,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 }); } @@ -569,12 +570,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; }, @@ -583,6 +586,7 @@ ObjectDefineProperty(Socket.prototype, 'pending', { ObjectDefineProperty(Socket.prototype, 'readyState', { + __proto__: null, get: function() { if (this.connecting) { return 'opening'; @@ -599,6 +603,7 @@ ObjectDefineProperty(Socket.prototype, 'readyState', { ObjectDefineProperty(Socket.prototype, 'bufferSize', { + __proto__: null, get: function() { if (this._handle) { return this.writableLength; @@ -607,6 +612,7 @@ ObjectDefineProperty(Socket.prototype, 'bufferSize', { }); ObjectDefineProperty(Socket.prototype, kUpdateTimer, { + __proto__: null, get: function() { return this._unrefTimer; } @@ -778,6 +784,7 @@ Socket.prototype._getpeername = function() { function protoGetter(name, callback) { ObjectDefineProperty(Socket.prototype, name, { + __proto__: null, configurable: false, enumerable: true, get: callback @@ -1606,6 +1613,7 @@ function lookupAndListen(self, port, address, backlog, exclusive, flags) { } ObjectDefineProperty(Server.prototype, 'listening', { + __proto__: null, get: function() { return !!this._handle; }, @@ -1788,11 +1796,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 bef901d9486..81bbe15a9d2 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 2456bcb7e7e..e84c8948f3c 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/repl.js b/lib/repl.js index 3b7eefe9cc6..d84c1922d9e 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -281,6 +281,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. ' + @@ -297,6 +298,7 @@ function REPLServer(prompt, configurable: true }); ObjectDefineProperty(this, 'outputStream', { + __proto__: null, get: pendingDeprecation ? deprecate(() => this.output, 'repl.inputStream and repl.outputStream are deprecated. ' + @@ -779,6 +781,7 @@ function REPLServer(prompt, if (options[kStandaloneREPL]) { ObjectDefineProperty(inspect, 'replDefaults', { + __proto__: null, get() { return writer.options; }, @@ -1079,12 +1082,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 @@ -1095,11 +1102,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) @@ -1119,6 +1128,7 @@ REPLServer.prototype.resetContext = function() { this.lines.level = []; ObjectDefineProperty(this.context, '_', { + __proto__: null, configurable: true, get: () => this.last, set: (value) => { @@ -1131,6 +1141,7 @@ REPLServer.prototype.resetContext = function() { }); ObjectDefineProperty(this.context, '_error', { + __proto__: null, configurable: true, get: () => this.lastError, set: (value) => { @@ -1806,6 +1817,7 @@ module.exports = { }; ObjectDefineProperty(module.exports, 'builtinModules', { + __proto__: null, get: () => _builtinLibs, set: (val) => _builtinLibs = val, enumerable: true, @@ -1813,6 +1825,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 55f903f295f..e8a38120cb2 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 9eae594aaa2..a22da17f505 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 a4543fea1df..213996eefa1 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 9a183844995..78e62091657 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -111,6 +111,7 @@ function cacheRootCertificates() { } ObjectDefineProperty(exports, 'rootCertificates', { + __proto__: null, configurable: false, enumerable: true, get: () => { diff --git a/lib/util.js b/lib/util.js index fbd8c550318..67a295011b5 100644 --- a/lib/util.js +++ b/lib/util.js @@ -243,6 +243,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 718f72af676..9bde1997d95 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 }); }