Skip to content

Commit 7a32176

Browse files
aduh95guangwong
authored andcommitted
lib: use null-prototype objects for property descriptors
Refs: nodejs/node#42921 PR-URL: nodejs/node#43270 Backport-PR-URL: nodejs/node#43804 Reviewed-By: Paolo Insogna <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
1 parent db4ef5c commit 7a32176

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+400
-85
lines changed

lib/_http_incoming.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ ObjectSetPrototypeOf(IncomingMessage.prototype, Readable.prototype);
9898
ObjectSetPrototypeOf(IncomingMessage, Readable);
9999

100100
ObjectDefineProperty(IncomingMessage.prototype, 'connection', {
101+
__proto__: null,
101102
get: function() {
102103
return this.socket;
103104
},
@@ -107,6 +108,7 @@ ObjectDefineProperty(IncomingMessage.prototype, 'connection', {
107108
});
108109

109110
ObjectDefineProperty(IncomingMessage.prototype, 'headers', {
111+
__proto__: null,
110112
get: function() {
111113
if (!this[kHeaders]) {
112114
this[kHeaders] = {};
@@ -126,6 +128,7 @@ ObjectDefineProperty(IncomingMessage.prototype, 'headers', {
126128
});
127129

128130
ObjectDefineProperty(IncomingMessage.prototype, 'headersDistinct', {
131+
__proto__: null,
129132
get: function() {
130133
if (!this[kHeadersDistinct]) {
131134
this[kHeadersDistinct] = {};
@@ -145,6 +148,7 @@ ObjectDefineProperty(IncomingMessage.prototype, 'headersDistinct', {
145148
});
146149

147150
ObjectDefineProperty(IncomingMessage.prototype, 'trailers', {
151+
__proto__: null,
148152
get: function() {
149153
if (!this[kTrailers]) {
150154
this[kTrailers] = {};
@@ -164,6 +168,7 @@ ObjectDefineProperty(IncomingMessage.prototype, 'trailers', {
164168
});
165169

166170
ObjectDefineProperty(IncomingMessage.prototype, 'trailersDistinct', {
171+
__proto__: null,
167172
get: function() {
168173
if (!this[kTrailersDistinct]) {
169174
this[kTrailersDistinct] = {};

lib/_http_outgoing.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ ObjectSetPrototypeOf(OutgoingMessage.prototype, Stream.prototype);
145145
ObjectSetPrototypeOf(OutgoingMessage, Stream);
146146

147147
ObjectDefineProperty(OutgoingMessage.prototype, 'writableFinished', {
148+
__proto__: null,
148149
get() {
149150
return (
150151
this.finished &&
@@ -155,31 +156,36 @@ ObjectDefineProperty(OutgoingMessage.prototype, 'writableFinished', {
155156
});
156157

157158
ObjectDefineProperty(OutgoingMessage.prototype, 'writableObjectMode', {
159+
__proto__: null,
158160
get() {
159161
return false;
160162
}
161163
});
162164

163165
ObjectDefineProperty(OutgoingMessage.prototype, 'writableLength', {
166+
__proto__: null,
164167
get() {
165168
return this.outputSize + (this.socket ? this.socket.writableLength : 0);
166169
}
167170
});
168171

169172
ObjectDefineProperty(OutgoingMessage.prototype, 'writableHighWaterMark', {
173+
__proto__: null,
170174
get() {
171175
return this.socket ? this.socket.writableHighWaterMark : HIGH_WATER_MARK;
172176
}
173177
});
174178

175179
ObjectDefineProperty(OutgoingMessage.prototype, 'writableCorked', {
180+
__proto__: null,
176181
get() {
177182
const corked = this.socket ? this.socket.writableCorked : 0;
178183
return corked + this[kCorked];
179184
}
180185
});
181186

182187
ObjectDefineProperty(OutgoingMessage.prototype, '_headers', {
188+
__proto__: null,
183189
get: internalUtil.deprecate(function() {
184190
return this.getHeaders();
185191
}, 'OutgoingMessage.prototype._headers is deprecated', 'DEP0066'),
@@ -200,6 +206,7 @@ ObjectDefineProperty(OutgoingMessage.prototype, '_headers', {
200206
});
201207

202208
ObjectDefineProperty(OutgoingMessage.prototype, 'connection', {
209+
__proto__: null,
203210
get: function() {
204211
return this.socket;
205212
},
@@ -209,6 +216,7 @@ ObjectDefineProperty(OutgoingMessage.prototype, 'connection', {
209216
});
210217

211218
ObjectDefineProperty(OutgoingMessage.prototype, '_headerNames', {
219+
__proto__: null,
212220
get: internalUtil.deprecate(function() {
213221
const headers = this[kOutHeaders];
214222
if (headers !== null) {
@@ -731,16 +739,19 @@ OutgoingMessage.prototype._implicitHeader = function _implicitHeader() {
731739
};
732740

733741
ObjectDefineProperty(OutgoingMessage.prototype, 'headersSent', {
742+
__proto__: null,
734743
configurable: true,
735744
enumerable: true,
736745
get: function() { return !!this._header; }
737746
});
738747

739748
ObjectDefineProperty(OutgoingMessage.prototype, 'writableEnded', {
749+
__proto__: null,
740750
get: function() { return this.finished; }
741751
});
742752

743753
ObjectDefineProperty(OutgoingMessage.prototype, 'writableNeedDrain', {
754+
__proto__: null,
744755
get: function() {
745756
return !this.destroyed && !this.finished && this[kNeedDrain];
746757
}

lib/_tls_wrap.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ TLSSocket.prototype._wrapHandle = function(wrap) {
633633
// Ref: https://github.com/nodejs/node/commit/f7620fb96d339f704932f9bb9a0dceb9952df2d4
634634
function defineHandleReading(socket, handle) {
635635
ObjectDefineProperty(handle, 'reading', {
636+
__proto__: null,
636637
get: () => {
637638
return socket[kRes].reading;
638639
},

lib/async_hooks.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,14 @@ class AsyncResource {
239239
}
240240
ObjectDefineProperties(bound, {
241241
'length': {
242+
__proto__: null,
242243
configurable: true,
243244
enumerable: false,
244245
value: fn.length,
245246
writable: false,
246247
},
247248
'asyncResource': {
249+
__proto__: null,
248250
configurable: true,
249251
enumerable: true,
250252
value: this,

lib/buffer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ function Buffer(arg, encodingOrOffset, length) {
282282
}
283283

284284
ObjectDefineProperty(Buffer, SymbolSpecies, {
285+
__proto__: null,
285286
enumerable: false,
286287
configurable: true,
287288
get() { return FastBuffer; }
@@ -757,6 +758,7 @@ Buffer.byteLength = byteLength;
757758

758759
// For backwards compatibility.
759760
ObjectDefineProperty(Buffer.prototype, 'parent', {
761+
__proto__: null,
760762
enumerable: true,
761763
get() {
762764
if (!(this instanceof Buffer))
@@ -765,6 +767,7 @@ ObjectDefineProperty(Buffer.prototype, 'parent', {
765767
}
766768
});
767769
ObjectDefineProperty(Buffer.prototype, 'offset', {
770+
__proto__: null,
768771
enumerable: true,
769772
get() {
770773
if (!(this instanceof Buffer))
@@ -1284,11 +1287,13 @@ module.exports = {
12841287

12851288
ObjectDefineProperties(module.exports, {
12861289
constants: {
1290+
__proto__: null,
12871291
configurable: false,
12881292
enumerable: true,
12891293
value: constants
12901294
},
12911295
INSPECT_MAX_BYTES: {
1296+
__proto__: null,
12921297
configurable: true,
12931298
enumerable: true,
12941299
get() { return INSPECT_MAX_BYTES; },

lib/child_process.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ const customPromiseExecFunction = (orig) => {
247247
};
248248

249249
ObjectDefineProperty(exec, promisify.custom, {
250+
__proto__: null,
250251
enumerable: false,
251252
value: customPromiseExecFunction(exec)
252253
});
@@ -498,6 +499,7 @@ function execFile(file, args = [], options, callback) {
498499
}
499500

500501
ObjectDefineProperty(execFile, promisify.custom, {
502+
__proto__: null,
501503
enumerable: false,
502504
value: customPromiseExecFunction(execFile)
503505
});

lib/crypto.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,26 +248,31 @@ function getFipsForced() {
248248
}
249249

250250
ObjectDefineProperty(constants, 'defaultCipherList', {
251+
__proto__: null,
251252
value: getOptionValue('--tls-cipher-list')
252253
});
253254

254255
ObjectDefineProperties(module.exports, {
255256
createCipher: {
257+
__proto__: null,
256258
enumerable: false,
257259
value: deprecate(createCipher,
258260
'crypto.createCipher is deprecated.', 'DEP0106')
259261
},
260262
createDecipher: {
263+
__proto__: null,
261264
enumerable: false,
262265
value: deprecate(createDecipher,
263266
'crypto.createDecipher is deprecated.', 'DEP0106')
264267
},
265268
// crypto.fips is deprecated. DEP0093. Use crypto.getFips()/crypto.setFips()
266269
fips: {
270+
__proto__: null,
267271
get: fipsForced ? getFipsForced : getFipsCrypto,
268272
set: fipsForced ? setFipsForced : setFipsCrypto
269273
},
270274
DEFAULT_ENCODING: {
275+
__proto__: null,
271276
enumerable: false,
272277
configurable: true,
273278
get: deprecate(getDefaultEncoding,
@@ -276,12 +281,14 @@ ObjectDefineProperties(module.exports, {
276281
'crypto.DEFAULT_ENCODING is deprecated.', 'DEP0091')
277282
},
278283
constants: {
284+
__proto__: null,
279285
configurable: false,
280286
enumerable: true,
281287
value: constants
282288
},
283289

284290
webcrypto: {
291+
__proto__: null,
285292
configurable: false,
286293
enumerable: true,
287294
get() { return lazyRequire('internal/crypto/webcrypto').crypto; }

lib/dgram.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,7 @@ Socket.prototype.getSendBufferSize = function() {
971971

972972
// Deprecated private APIs.
973973
ObjectDefineProperty(Socket.prototype, '_handle', {
974+
__proto__: null,
974975
get: deprecate(function() {
975976
return this[kStateSymbol].handle;
976977
}, 'Socket.prototype._handle is deprecated', 'DEP0112'),
@@ -981,6 +982,7 @@ ObjectDefineProperty(Socket.prototype, '_handle', {
981982

982983

983984
ObjectDefineProperty(Socket.prototype, '_receiving', {
985+
__proto__: null,
984986
get: deprecate(function() {
985987
return this[kStateSymbol].receiving;
986988
}, 'Socket.prototype._receiving is deprecated', 'DEP0112'),
@@ -991,6 +993,7 @@ ObjectDefineProperty(Socket.prototype, '_receiving', {
991993

992994

993995
ObjectDefineProperty(Socket.prototype, '_bindState', {
996+
__proto__: null,
994997
get: deprecate(function() {
995998
return this[kStateSymbol].bindState;
996999
}, 'Socket.prototype._bindState is deprecated', 'DEP0112'),
@@ -1001,6 +1004,7 @@ ObjectDefineProperty(Socket.prototype, '_bindState', {
10011004

10021005

10031006
ObjectDefineProperty(Socket.prototype, '_queue', {
1007+
__proto__: null,
10041008
get: deprecate(function() {
10051009
return this[kStateSymbol].queue;
10061010
}, 'Socket.prototype._queue is deprecated', 'DEP0112'),
@@ -1011,6 +1015,7 @@ ObjectDefineProperty(Socket.prototype, '_queue', {
10111015

10121016

10131017
ObjectDefineProperty(Socket.prototype, '_reuseAddr', {
1018+
__proto__: null,
10141019
get: deprecate(function() {
10151020
return this[kStateSymbol].reuseAddr;
10161021
}, 'Socket.prototype._reuseAddr is deprecated', 'DEP0112'),
@@ -1033,6 +1038,7 @@ Socket.prototype._stopReceiving = deprecate(function() {
10331038
// Legacy alias on the C++ wrapper object. This is not public API, so we may
10341039
// want to runtime-deprecate it at some point. There's no hurry, though.
10351040
ObjectDefineProperty(UDP.prototype, 'owner', {
1041+
__proto__: null,
10361042
get() { return this[owner_symbol]; },
10371043
set(v) { return this[owner_symbol] = v; }
10381044
});

lib/dns.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function lookup(hostname, options, callback) {
191191
}
192192

193193
ObjectDefineProperty(lookup, customPromisifyArgs,
194-
{ value: ['address', 'family'], enumerable: false });
194+
{ __proto__: null, value: ['address', 'family'], enumerable: false });
195195

196196

197197
function onlookupservice(err, hostname, service) {
@@ -240,7 +240,7 @@ function lookupService(address, port, callback) {
240240
}
241241

242242
ObjectDefineProperty(lookupService, customPromisifyArgs,
243-
{ value: ['hostname', 'service'], enumerable: false });
243+
{ __proto__: null, value: ['hostname', 'service'], enumerable: false });
244244

245245

246246
function onresolve(err, result, ttls) {
@@ -289,7 +289,7 @@ function resolver(bindingName) {
289289
}
290290
return req;
291291
}
292-
ObjectDefineProperty(query, 'name', { value: bindingName });
292+
ObjectDefineProperty(query, 'name', { __proto__: null, value: bindingName });
293293
return query;
294294
}
295295

@@ -382,6 +382,7 @@ bindDefaultResolver(module.exports, getDefaultResolver());
382382

383383
ObjectDefineProperties(module.exports, {
384384
promises: {
385+
__proto__: null,
385386
configurable: true,
386387
enumerable: true,
387388
get() {

lib/domain.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const { WeakReference } = internalBinding('util');
5959
// effective optimizations
6060
const _domain = [null];
6161
ObjectDefineProperty(process, 'domain', {
62+
__proto__: null,
6263
enumerable: true,
6364
get: function() {
6465
return _domain[0];
@@ -78,6 +79,7 @@ const asyncHook = createHook({
7879
// have a domain property as it can be used to escape the sandbox.
7980
if (type !== 'PROMISE' || resource instanceof Promise) {
8081
ObjectDefineProperty(resource, 'domain', {
82+
__proto__: null,
8183
configurable: true,
8284
enumerable: false,
8385
value: process.domain,
@@ -231,6 +233,7 @@ Domain.prototype._errorHandler = function(er) {
231233

232234
if ((typeof er === 'object' && er !== null) || typeof er === 'function') {
233235
ObjectDefineProperty(er, 'domain', {
236+
__proto__: null,
234237
configurable: true,
235238
enumerable: false,
236239
value: this,
@@ -356,6 +359,7 @@ Domain.prototype.add = function(ee) {
356359
}
357360

358361
ObjectDefineProperty(ee, 'domain', {
362+
__proto__: null,
359363
configurable: true,
360364
enumerable: false,
361365
value: this,
@@ -388,6 +392,7 @@ function intercepted(_this, self, cb, fnargs) {
388392
er.domainBound = cb;
389393
er.domainThrown = false;
390394
ObjectDefineProperty(er, 'domain', {
395+
__proto__: null,
391396
configurable: true,
392397
enumerable: false,
393398
value: self,
@@ -433,6 +438,7 @@ Domain.prototype.bind = function(cb) {
433438
}
434439

435440
ObjectDefineProperty(runBound, 'domain', {
441+
__proto__: null,
436442
configurable: true,
437443
enumerable: false,
438444
value: this,
@@ -448,6 +454,7 @@ EventEmitter.usingDomains = true;
448454
const eventInit = EventEmitter.init;
449455
EventEmitter.init = function(opts) {
450456
ObjectDefineProperty(this, 'domain', {
457+
__proto__: null,
451458
configurable: true,
452459
enumerable: false,
453460
value: null,
@@ -482,6 +489,7 @@ EventEmitter.prototype.emit = function emit(...args) {
482489
if (typeof er === 'object') {
483490
er.domainEmitter = this;
484491
ObjectDefineProperty(er, 'domain', {
492+
__proto__: null,
485493
configurable: true,
486494
enumerable: false,
487495
value: domain,

0 commit comments

Comments
 (0)