Skip to content

Commit e2ae4c1

Browse files
targosBethGriggs
authored andcommitted
lib: flatten access to primordials
Store all primordials as properties of the primordials object. Static functions are prefixed by the constructor's name and prototype methods are prefixed by the constructor's name followed by "Prototype". For example: primordials.Object.keys becomes primordials.ObjectKeys. Backport-PR-URL: #30731 PR-URL: #30610 Refs: #29766 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 25b88ac commit e2ae4c1

File tree

117 files changed

+1300
-932
lines changed

Some content is hidden

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

117 files changed

+1300
-932
lines changed

‎lib/_http_agent.js‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
'use strict';
2323

2424
const{
25-
Object: {
26-
setPrototypeOf: ObjectSetPrototypeOf,
27-
keys: ObjectKeys,
28-
values: ObjectValues
29-
}
25+
ObjectKeys,
26+
ObjectSetPrototypeOf,
27+
ObjectValues,
3028
}=primordials;
3129

3230
constnet=require('net');

‎lib/_http_client.js‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121

2222
'use strict';
2323

24-
const{ Object }=primordials;
24+
const{
25+
ObjectAssign,
26+
ObjectKeys,
27+
ObjectSetPrototypeOf,
28+
}=primordials;
2529

2630
constnet=require('net');
2731
consturl=require('url');
@@ -108,7 +112,7 @@ function ClientRequest(input, options, cb){
108112
cb=options;
109113
options=input||{};
110114
}else{
111-
options=Object.assign(input||{},options);
115+
options=ObjectAssign(input||{},options);
112116
}
113117

114118
letagent=options.agent;
@@ -225,7 +229,7 @@ function ClientRequest(input, options, cb){
225229
constheadersArray=Array.isArray(options.headers);
226230
if(!headersArray){
227231
if(options.headers){
228-
constkeys=Object.keys(options.headers);
232+
constkeys=ObjectKeys(options.headers);
229233
for(leti=0;i<keys.length;i++){
230234
constkey=keys[i];
231235
this.setHeader(key,options.headers[key]);
@@ -304,8 +308,8 @@ function ClientRequest(input, options, cb){
304308

305309
this._deferToConnect(null,null,()=>this._flush());
306310
}
307-
Object.setPrototypeOf(ClientRequest.prototype,OutgoingMessage.prototype);
308-
Object.setPrototypeOf(ClientRequest,OutgoingMessage);
311+
ObjectSetPrototypeOf(ClientRequest.prototype,OutgoingMessage.prototype);
312+
ObjectSetPrototypeOf(ClientRequest,OutgoingMessage);
309313

310314
ClientRequest.prototype._finish=function_finish(){
311315
DTRACE_HTTP_CLIENT_REQUEST(this,this.connection);

‎lib/_http_common.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121

2222
'use strict';
2323

24-
const{ Math }=primordials;
24+
const{
25+
MathMin,
26+
}=primordials;
2527
const{ setImmediate }=require('timers');
2628

2729
const{ getOptionValue }=require('internal/options');
@@ -100,7 +102,7 @@ function parserOnHeadersComplete(versionMajor, versionMinor, headers, method,
100102

101103
// If parser.maxHeaderPairs <= 0 assume that there's no limit.
102104
if(parser.maxHeaderPairs>0)
103-
n=Math.min(n,parser.maxHeaderPairs);
105+
n=MathMin(n,parser.maxHeaderPairs);
104106

105107
incoming._addHeaderLines(headers,n);
106108

‎lib/_http_incoming.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121

2222
'use strict';
2323

24-
const{ Object }=primordials;
24+
const{
25+
ObjectSetPrototypeOf,
26+
}=primordials;
2527

2628
constStream=require('stream');
2729

@@ -81,8 +83,8 @@ function IncomingMessage(socket){
8183
// read by the user, so there's no point continuing to handle it.
8284
this._dumped=false;
8385
}
84-
Object.setPrototypeOf(IncomingMessage.prototype,Stream.Readable.prototype);
85-
Object.setPrototypeOf(IncomingMessage,Stream.Readable);
86+
ObjectSetPrototypeOf(IncomingMessage.prototype,Stream.Readable.prototype);
87+
ObjectSetPrototypeOf(IncomingMessage,Stream.Readable);
8688

8789
IncomingMessage.prototype.setTimeout=functionsetTimeout(msecs,callback){
8890
if(callback)

‎lib/_http_outgoing.js‎

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@
2121

2222
'use strict';
2323

24-
const{ Object, ObjectPrototype }=primordials;
24+
const{
25+
ObjectCreate,
26+
ObjectDefineProperty,
27+
ObjectKeys,
28+
ObjectPrototypeHasOwnProperty,
29+
ObjectSetPrototypeOf,
30+
}=primordials;
2531

2632
const{ getDefaultHighWaterMark }=require('internal/streams/state');
2733
constassert=require('internal/assert');
@@ -109,10 +115,10 @@ function OutgoingMessage(){
109115

110116
this._onPendingData=noopPendingOutput;
111117
}
112-
Object.setPrototypeOf(OutgoingMessage.prototype,Stream.prototype);
113-
Object.setPrototypeOf(OutgoingMessage,Stream);
118+
ObjectSetPrototypeOf(OutgoingMessage.prototype,Stream.prototype);
119+
ObjectSetPrototypeOf(OutgoingMessage,Stream);
114120

115-
Object.defineProperty(OutgoingMessage.prototype,'writableFinished',{
121+
ObjectDefineProperty(OutgoingMessage.prototype,'writableFinished',{
116122
get(){
117123
return(
118124
this.finished&&
@@ -122,41 +128,41 @@ Object.defineProperty(OutgoingMessage.prototype, 'writableFinished',{
122128
}
123129
});
124130

125-
Object.defineProperty(OutgoingMessage.prototype,'writableObjectMode',{
131+
ObjectDefineProperty(OutgoingMessage.prototype,'writableObjectMode',{
126132
get(){
127133
returnfalse;
128134
}
129135
});
130136

131-
Object.defineProperty(OutgoingMessage.prototype,'writableLength',{
137+
ObjectDefineProperty(OutgoingMessage.prototype,'writableLength',{
132138
get(){
133139
returnthis.outputSize+(this.socket ? this.socket.writableLength : 0);
134140
}
135141
});
136142

137-
Object.defineProperty(OutgoingMessage.prototype,'writableHighWaterMark',{
143+
ObjectDefineProperty(OutgoingMessage.prototype,'writableHighWaterMark',{
138144
get(){
139145
returnthis.socket ? this.socket.writableHighWaterMark : HIGH_WATER_MARK;
140146
}
141147
});
142148

143-
Object.defineProperty(OutgoingMessage.prototype,'writableCorked',{
149+
ObjectDefineProperty(OutgoingMessage.prototype,'writableCorked',{
144150
get(){
145151
constcorked=this.socket ? this.socket.writableCorked : 0;
146152
returncorked+this[kCorked];
147153
}
148154
});
149155

150-
Object.defineProperty(OutgoingMessage.prototype,'_headers',{
156+
ObjectDefineProperty(OutgoingMessage.prototype,'_headers',{
151157
get: internalUtil.deprecate(function(){
152158
returnthis.getHeaders();
153159
},'OutgoingMessage.prototype._headers is deprecated','DEP0066'),
154160
set: internalUtil.deprecate(function(val){
155161
if(val==null){
156162
this[kOutHeaders]=null;
157163
}elseif(typeofval==='object'){
158-
constheaders=this[kOutHeaders]=Object.create(null);
159-
constkeys=Object.keys(val);
164+
constheaders=this[kOutHeaders]=ObjectCreate(null);
165+
constkeys=ObjectKeys(val);
160166
for(vari=0;i<keys.length;++i){
161167
constname=keys[i];
162168
headers[name.toLowerCase()]=[name,val[name]];
@@ -165,12 +171,12 @@ Object.defineProperty(OutgoingMessage.prototype, '_headers',{
165171
},'OutgoingMessage.prototype._headers is deprecated','DEP0066')
166172
});
167173

168-
Object.defineProperty(OutgoingMessage.prototype,'_headerNames',{
174+
ObjectDefineProperty(OutgoingMessage.prototype,'_headerNames',{
169175
get: internalUtil.deprecate(function(){
170176
constheaders=this[kOutHeaders];
171177
if(headers!==null){
172-
constout=Object.create(null);
173-
constkeys=Object.keys(headers);
178+
constout=ObjectCreate(null);
179+
constkeys=ObjectKeys(headers);
174180
for(vari=0;i<keys.length;++i){
175181
constkey=keys[i];
176182
constval=headers[key][0];
@@ -185,7 +191,7 @@ Object.defineProperty(OutgoingMessage.prototype, '_headerNames',{
185191
constheaders=this[kOutHeaders];
186192
if(!headers)
187193
return;
188-
constkeys=Object.keys(val);
194+
constkeys=ObjectKeys(val);
189195
for(vari=0;i<keys.length;++i){
190196
constheader=headers[keys[i]];
191197
if(header)
@@ -205,7 +211,7 @@ OutgoingMessage.prototype._renderHeaders = function _renderHeaders(){
205211
constheaders={};
206212

207213
if(headersMap!==null){
208-
constkeys=Object.keys(headersMap);
214+
constkeys=ObjectKeys(headersMap);
209215
for(vari=0,l=keys.length;i<l;i++){
210216
constkey=keys[i];
211217
headers[headersMap[key][0]]=headersMap[key][1];
@@ -350,7 +356,7 @@ function _storeHeader(firstLine, headers){
350356
}
351357
}else{
352358
for(constkeyinheaders){
353-
if(ObjectPrototype.hasOwnProperty(headers,key)){
359+
if(ObjectPrototypeHasOwnProperty(headers,key)){
354360
processHeader(this,state,key,headers[key],true);
355361
}
356362
}
@@ -511,7 +517,7 @@ OutgoingMessage.prototype.setHeader = function setHeader(name, value){
511517

512518
letheaders=this[kOutHeaders];
513519
if(headers===null)
514-
this[kOutHeaders]=headers=Object.create(null);
520+
this[kOutHeaders]=headers=ObjectCreate(null);
515521

516522
headers[name.toLowerCase()]=[name,value];
517523
};
@@ -531,16 +537,16 @@ OutgoingMessage.prototype.getHeader = function getHeader(name){
531537

532538
// Returns an array of the names of the current outgoing headers.
533539
OutgoingMessage.prototype.getHeaderNames=functiongetHeaderNames(){
534-
returnthis[kOutHeaders]!==null ? Object.keys(this[kOutHeaders]) : [];
540+
returnthis[kOutHeaders]!==null ? ObjectKeys(this[kOutHeaders]) : [];
535541
};
536542

537543

538544
// Returns a shallow copy of the current outgoing headers.
539545
OutgoingMessage.prototype.getHeaders=functiongetHeaders(){
540546
constheaders=this[kOutHeaders];
541-
constret=Object.create(null);
547+
constret=ObjectCreate(null);
542548
if(headers){
543-
constkeys=Object.keys(headers);
549+
constkeys=ObjectKeys(headers);
544550
for(vari=0;i<keys.length;++i){
545551
constkey=keys[i];
546552
constval=headers[key][1];
@@ -592,13 +598,13 @@ OutgoingMessage.prototype._implicitHeader = function _implicitHeader(){
592598
this.emit('error',newERR_METHOD_NOT_IMPLEMENTED('_implicitHeader()'));
593599
};
594600

595-
Object.defineProperty(OutgoingMessage.prototype,'headersSent',{
601+
ObjectDefineProperty(OutgoingMessage.prototype,'headersSent',{
596602
configurable: true,
597603
enumerable: true,
598604
get: function(){return!!this._header;}
599605
});
600606

601-
Object.defineProperty(OutgoingMessage.prototype,'writableEnded',{
607+
ObjectDefineProperty(OutgoingMessage.prototype,'writableEnded',{
602608
get: function(){returnthis.finished;}
603609
});
604610

@@ -679,7 +685,7 @@ function connectionCorkNT(conn){
679685

680686
OutgoingMessage.prototype.addTrailers=functionaddTrailers(headers){
681687
this._trailer='';
682-
constkeys=Object.keys(headers);
688+
constkeys=ObjectKeys(headers);
683689
constisArray=Array.isArray(headers);
684690
varfield,value;
685691
for(vari=0,l=keys.length;i<l;i++){

‎lib/_http_server.js‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
'use strict';
2323

2424
const{
25-
Object: {
26-
setPrototypeOf: ObjectSetPrototypeOf,
27-
keys: ObjectKeys,
28-
}
25+
ObjectKeys,
26+
ObjectSetPrototypeOf,
2927
}=primordials;
3028

3129
constnet=require('net');
@@ -265,7 +263,7 @@ function writeHead(statusCode, reason, obj){
265263
letk;
266264
if(obj){
267265
constkeys=ObjectKeys(obj);
268-
for(vari=0;i<keys.length;i++){
266+
for(leti=0;i<keys.length;i++){
269267
k=keys[i];
270268
if(k)this.setHeader(k,obj[k]);
271269
}

‎lib/_stream_duplex.js‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,23 @@
2626

2727
'use strict';
2828

29-
const{ Object }=primordials;
29+
const{
30+
ObjectDefineProperty,
31+
ObjectKeys,
32+
ObjectSetPrototypeOf,
33+
}=primordials;
3034

3135
module.exports=Duplex;
3236

3337
constReadable=require('_stream_readable');
3438
constWritable=require('_stream_writable');
3539

36-
Object.setPrototypeOf(Duplex.prototype,Readable.prototype);
37-
Object.setPrototypeOf(Duplex,Readable);
40+
ObjectSetPrototypeOf(Duplex.prototype,Readable.prototype);
41+
ObjectSetPrototypeOf(Duplex,Readable);
3842

3943
{
4044
// Allow the keys array to be GC'ed.
41-
constkeys=Object.keys(Writable.prototype);
45+
constkeys=ObjectKeys(Writable.prototype);
4246
for(letv=0;v<keys.length;v++){
4347
constmethod=keys[v];
4448
if(!Duplex.prototype[method])
@@ -68,7 +72,7 @@ function Duplex(options){
6872
}
6973
}
7074

71-
Object.defineProperty(Duplex.prototype,'writableHighWaterMark',{
75+
ObjectDefineProperty(Duplex.prototype,'writableHighWaterMark',{
7276
// Making it explicit this property is not enumerable
7377
// because otherwise some prototype manipulation in
7478
// userland will fail
@@ -78,7 +82,7 @@ Object.defineProperty(Duplex.prototype, 'writableHighWaterMark',{
7882
}
7983
});
8084

81-
Object.defineProperty(Duplex.prototype,'writableBuffer',{
85+
ObjectDefineProperty(Duplex.prototype,'writableBuffer',{
8286
// Making it explicit this property is not enumerable
8387
// because otherwise some prototype manipulation in
8488
// userland will fail
@@ -88,7 +92,7 @@ Object.defineProperty(Duplex.prototype, 'writableBuffer',{
8892
}
8993
});
9094

91-
Object.defineProperty(Duplex.prototype,'writableLength',{
95+
ObjectDefineProperty(Duplex.prototype,'writableLength',{
9296
// Making it explicit this property is not enumerable
9397
// because otherwise some prototype manipulation in
9498
// userland will fail
@@ -98,7 +102,7 @@ Object.defineProperty(Duplex.prototype, 'writableLength',{
98102
}
99103
});
100104

101-
Object.defineProperty(Duplex.prototype,'writableFinished',{
105+
ObjectDefineProperty(Duplex.prototype,'writableFinished',{
102106
// Making it explicit this property is not enumerable
103107
// because otherwise some prototype manipulation in
104108
// userland will fail
@@ -108,7 +112,7 @@ Object.defineProperty(Duplex.prototype, 'writableFinished',{
108112
}
109113
});
110114

111-
Object.defineProperty(Duplex.prototype,'writableCorked',{
115+
ObjectDefineProperty(Duplex.prototype,'writableCorked',{
112116
// Making it explicit this property is not enumerable
113117
// because otherwise some prototype manipulation in
114118
// userland will fail
@@ -118,7 +122,7 @@ Object.defineProperty(Duplex.prototype, 'writableCorked',{
118122
}
119123
});
120124

121-
Object.defineProperty(Duplex.prototype,'writableEnded',{
125+
ObjectDefineProperty(Duplex.prototype,'writableEnded',{
122126
// Making it explicit this property is not enumerable
123127
// because otherwise some prototype manipulation in
124128
// userland will fail
@@ -143,7 +147,7 @@ function onEndNT(self){
143147
self.end();
144148
}
145149

146-
Object.defineProperty(Duplex.prototype,'destroyed',{
150+
ObjectDefineProperty(Duplex.prototype,'destroyed',{
147151
// Making it explicit this property is not enumerable
148152
// because otherwise some prototype manipulation in
149153
// userland will fail

0 commit comments

Comments
(0)