lib: use null-prototype objects for property descriptors

Refs: https://github.com/nodejs/node/pull/42921

PR-URL: https://github.com/nodejs/node/pull/43270
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
This commit is contained in:
Antoine du Hamel 2022-06-03 10:23:58 +02:00 committed by GitHub
parent 218664f638
commit 06d8606960
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
78 changed files with 444 additions and 83 deletions

View File

@ -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] = {};

View File

@ -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];
}

View File

@ -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;
},

View File

@ -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,

View File

@ -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; },

View File

@ -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)
});

View File

@ -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,

View File

@ -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; }
});

View File

@ -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() {

View File

@ -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,

View File

@ -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
});

View File

@ -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() {

View File

@ -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() {

View File

@ -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,

View File

@ -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;
}

View File

@ -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;

View File

@ -356,6 +356,7 @@ function createBlob(handle, length, type = '') {
}
ObjectDefineProperty(Blob.prototype, SymbolToStringTag, {
__proto__: null,
configurable: true,
value: 'Blob',
});

View File

@ -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,

View File

@ -64,6 +64,7 @@ const {
// Set up process.moduleLoadList.
const moduleLoadList = [];
ObjectDefineProperty(process, 'moduleLoadList', {
__proto__: null,
value: moduleLoadList,
configurable: true,
enumerable: true,

View File

@ -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,

View File

@ -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;
},

View File

@ -15,6 +15,7 @@ process._stopProfilerIdleNotifier = () => {};
function defineStream(name, getter) {
ObjectDefineProperty(process, name, {
__proto__: null,
configurable: true,
enumerable: true,
get: getter

View File

@ -7,6 +7,7 @@ delete process._debugEnd;
function defineStream(name, getter) {
ObjectDefineProperty(process, name, {
__proto__: null,
configurable: true,
enumerable: true,
get: getter

View File

@ -572,6 +572,7 @@ function setupChannel(target, channel, serializationMode) {
target[kChannelHandle] = channel;
ObjectDefineProperty(target, '_channel', {
__proto__: null,
get: deprecate(() => {
return target.channel;
}, channelDeprecationMsg, 'DEP0129'),

View File

@ -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);

View File

@ -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);
}

View File

@ -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

View File

@ -93,6 +93,7 @@ function generateKeyPair(type, options, callback) {
}
ObjectDefineProperty(generateKeyPair, customPromisifyArgs, {
__proto__: null,
value: ['publicKey', 'privateKey'],
enumerable: false
});

View File

@ -108,6 +108,7 @@ const {
this[kKeyType] = type;
ObjectDefineProperty(this, kHandle, {
__proto__: null,
value: handle,
enumerable: false,
configurable: false,

View File

@ -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,

View File

@ -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,

View File

@ -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;
}

View File

@ -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];
},
const sharedProperties = ObjectGetOwnPropertyDescriptors({
get encoding() {
validateDecoder(this);
return this[kEncoding];
},
get fatal() {
validateDecoder(this);
return (this[kFlags] & CONVERTER_FLAGS_FATAL) === CONVERTER_FLAGS_FATAL;
},
get fatal() {
validateDecoder(this);
return (this[kFlags] & CONVERTER_FLAGS_FATAL) === CONVERTER_FLAGS_FATAL;
},
get ignoreBOM() {
validateDecoder(this);
return (this[kFlags] & CONVERTER_FLAGS_IGNORE_BOM) ===
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'
}

View File

@ -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
});

View File

@ -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;
}

View File

@ -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;
},

View File

@ -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,

View File

@ -226,6 +226,7 @@ class Dir {
}
ObjectDefineProperty(Dir.prototype, SymbolAsyncIterator, {
__proto__: null,
value: Dir.prototype.entries,
enumerable: false,
writable: true,

View File

@ -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
});

View File

@ -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; }
});

View File

@ -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));

View File

@ -555,6 +555,7 @@ class NghttpError extends Error {
this.errno = integerCode;
captureLargerStackTrace(this);
ObjectDefineProperty(this, kIsNodeError, {
__proto__: null,
value: true,
enumerable: false,
writable: false,

View File

@ -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,

View File

@ -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,

View File

@ -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 ' +

View File

@ -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 [

View File

@ -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),
});
}

View File

@ -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,

View File

@ -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(),

View File

@ -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}`

View File

@ -48,6 +48,7 @@ const parse = (str) => {
// Avoid setters being fired
ObjectDefineProperty(entries, entries.length, {
__proto__: null,
enumerable: true,
configurable: true,
value: ObjectFreeze({

View File

@ -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,

View File

@ -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) {

View File

@ -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,

View File

@ -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;
},

View File

@ -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 !!(

View File

@ -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,

View File

@ -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,

View File

@ -100,6 +100,7 @@ function debuglog(set, cb) {
}
};
ObjectDefineProperty(logger, 'enabled', {
__proto__: null,
get() {
return test();
},

View File

@ -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];
},

View File

@ -52,6 +52,7 @@ function wrapConsole(consoleFromNode) {
consoleFromNode[key]
);
ObjectDefineProperty(consoleFromNode[key], 'name', {
__proto__: null,
value: key
});
} else {

View File

@ -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) {

View File

@ -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
});

View File

@ -585,6 +585,7 @@ class ReadableStream {
ObjectDefineProperties(ReadableStream.prototype, {
[SymbolAsyncIterator]: {
__proto__: null,
configurable: true,
enumerable: false,
writable: true,

View File

@ -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; },

View File

@ -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

View File

@ -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;
}

View File

@ -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; }
});

View File

@ -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,

View File

@ -39,6 +39,7 @@ module.exports = {
};
ObjectDefineProperty(module.exports, 'constants', {
__proto__: null,
configurable: false,
enumerable: true,
value: constants

View File

@ -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];
},

View File

@ -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('<repl>', 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',

View File

@ -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;

View File

@ -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() {

View File

@ -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)

View File

@ -110,6 +110,7 @@ function cacheRootCertificates() {
}
ObjectDefineProperty(exports, 'rootCertificates', {
__proto__: null,
configurable: false,
enumerable: true,
get: () => {

View File

@ -244,6 +244,7 @@ function inherits(ctor, superCtor) {
'Object', superCtor.prototype);
}
ObjectDefineProperty(ctor, 'super_', {
__proto__: null,
value: superCtor,
writable: true,
configurable: true

View File

@ -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
});
}