Skip to content

Commit b864460

Browse files
aduh95danielleadams
authored andcommitted
lib: use null-prototype objects for property descriptors
Refs: #42921 PR-URL: #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>
1 parent 7d0f6da commit b864460

Some content is hidden

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

78 files changed

+446
-85
lines changed

lib/_http_incoming.js

+5
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

+11
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

+1
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ TLSSocket.prototype._wrapHandle = function(wrap) {
631631
// Ref: https://github.com/nodejs/node/commit/f7620fb96d339f704932f9bb9a0dceb9952df2d4
632632
function defineHandleReading(socket, handle) {
633633
ObjectDefineProperty(handle, 'reading', {
634+
__proto__: null,
634635
get: () => {
635636
return socket[kRes].reading;
636637
},

lib/async_hooks.js

+2
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,14 @@ class AsyncResource {
238238
}
239239
ObjectDefineProperties(bound, {
240240
'length': {
241+
__proto__: null,
241242
configurable: true,
242243
enumerable: false,
243244
value: fn.length,
244245
writable: false,
245246
},
246247
'asyncResource': {
248+
__proto__: null,
247249
configurable: true,
248250
enumerable: true,
249251
value: this,

lib/buffer.js

+5
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; }
@@ -756,6 +757,7 @@ Buffer.byteLength = byteLength;
756757

757758
// For backwards compatibility.
758759
ObjectDefineProperty(Buffer.prototype, 'parent', {
760+
__proto__: null,
759761
enumerable: true,
760762
get() {
761763
if (!(this instanceof Buffer))
@@ -764,6 +766,7 @@ ObjectDefineProperty(Buffer.prototype, 'parent', {
764766
}
765767
});
766768
ObjectDefineProperty(Buffer.prototype, 'offset', {
769+
__proto__: null,
767770
enumerable: true,
768771
get() {
769772
if (!(this instanceof Buffer))
@@ -1302,11 +1305,13 @@ module.exports = {
13021305

13031306
ObjectDefineProperties(module.exports, {
13041307
constants: {
1308+
__proto__: null,
13051309
configurable: false,
13061310
enumerable: true,
13071311
value: constants
13081312
},
13091313
INSPECT_MAX_BYTES: {
1314+
__proto__: null,
13101315
configurable: true,
13111316
enumerable: true,
13121317
get() { return INSPECT_MAX_BYTES; },

lib/child_process.js

+2
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ const customPromiseExecFunction = (orig) => {
243243
};
244244

245245
ObjectDefineProperty(exec, promisify.custom, {
246+
__proto__: null,
246247
enumerable: false,
247248
value: customPromiseExecFunction(exec)
248249
});
@@ -486,6 +487,7 @@ function execFile(file, args = [], options, callback) {
486487
}
487488

488489
ObjectDefineProperty(execFile, promisify.custom, {
490+
__proto__: null,
489491
enumerable: false,
490492
value: customPromiseExecFunction(execFile)
491493
});

lib/crypto.js

+13
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,11 @@ function getRandomValues(array) {
259259
}
260260

261261
ObjectDefineProperty(constants, 'defaultCipherList', {
262+
__proto__: null,
262263
get() {
263264
const value = getOptionValue('--tls-cipher-list');
264265
ObjectDefineProperty(this, 'defaultCipherList', {
266+
__proto__: null,
265267
writable: true,
266268
configurable: true,
267269
enumerable: true,
@@ -271,6 +273,7 @@ ObjectDefineProperty(constants, 'defaultCipherList', {
271273
},
272274
set(val) {
273275
ObjectDefineProperty(this, 'defaultCipherList', {
276+
__proto__: null,
274277
writable: true,
275278
configurable: true,
276279
enumerable: true,
@@ -299,6 +302,7 @@ function getRandomBytesAlias(key) {
299302
this,
300303
key,
301304
{
305+
__proto__: null,
302306
enumerable: false,
303307
configurable: true,
304308
writable: true,
@@ -312,6 +316,7 @@ function getRandomBytesAlias(key) {
312316
this,
313317
key,
314318
{
319+
__proto__: null,
315320
enumerable: true,
316321
configurable: true,
317322
writable: true,
@@ -324,21 +329,25 @@ function getRandomBytesAlias(key) {
324329

325330
ObjectDefineProperties(module.exports, {
326331
createCipher: {
332+
__proto__: null,
327333
enumerable: false,
328334
value: deprecate(createCipher,
329335
'crypto.createCipher is deprecated.', 'DEP0106')
330336
},
331337
createDecipher: {
338+
__proto__: null,
332339
enumerable: false,
333340
value: deprecate(createDecipher,
334341
'crypto.createDecipher is deprecated.', 'DEP0106')
335342
},
336343
// crypto.fips is deprecated. DEP0093. Use crypto.getFips()/crypto.setFips()
337344
fips: {
345+
__proto__: null,
338346
get: getFips,
339347
set: setFips,
340348
},
341349
DEFAULT_ENCODING: {
350+
__proto__: null,
342351
enumerable: false,
343352
configurable: true,
344353
get: deprecate(getDefaultEncoding,
@@ -347,26 +356,30 @@ ObjectDefineProperties(module.exports, {
347356
'crypto.DEFAULT_ENCODING is deprecated.', 'DEP0091')
348357
},
349358
constants: {
359+
__proto__: null,
350360
configurable: false,
351361
enumerable: true,
352362
value: constants
353363
},
354364

355365
webcrypto: {
366+
__proto__: null,
356367
configurable: false,
357368
enumerable: true,
358369
get() { return lazyWebCrypto().crypto; },
359370
set: undefined,
360371
},
361372

362373
subtle: {
374+
__proto__: null,
363375
configurable: false,
364376
enumerable: true,
365377
get() { return lazyWebCrypto().crypto.subtle; },
366378
set: undefined,
367379
},
368380

369381
getRandomValues: {
382+
__proto__: null,
370383
configurable: false,
371384
enumerable: true,
372385
get: () => getRandomValues,

lib/dgram.js

+6
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

+4-3
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ function lookup(hostname, options, callback) {
198198
}
199199

200200
ObjectDefineProperty(lookup, customPromisifyArgs,
201-
{ value: ['address', 'family'], enumerable: false });
201+
{ __proto__: null, value: ['address', 'family'], enumerable: false });
202202

203203

204204
function onlookupservice(err, hostname, service) {
@@ -243,7 +243,7 @@ function lookupService(address, port, callback) {
243243
}
244244

245245
ObjectDefineProperty(lookupService, customPromisifyArgs,
246-
{ value: ['hostname', 'service'], enumerable: false });
246+
{ __proto__: null, value: ['hostname', 'service'], enumerable: false });
247247

248248

249249
function onresolve(err, result, ttls) {
@@ -288,7 +288,7 @@ function resolver(bindingName) {
288288
});
289289
return req;
290290
}
291-
ObjectDefineProperty(query, 'name', { value: bindingName });
291+
ObjectDefineProperty(query, 'name', { __proto__: null, value: bindingName });
292292
return query;
293293
}
294294

@@ -381,6 +381,7 @@ bindDefaultResolver(module.exports, getDefaultResolver());
381381

382382
ObjectDefineProperties(module.exports, {
383383
promises: {
384+
__proto__: null,
384385
configurable: true,
385386
enumerable: true,
386387
get() {

0 commit comments

Comments
 (0)