summaryrefslogtreecommitdiff
path: root/lib/_http_outgoing.js
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2019-11-22 18:04:46 +0100
committerMichaël Zasso <targos@protonmail.com>2019-11-25 10:28:15 +0100
commit0646eda4fc0affb98e13c30acb522e63b7fd6dde (patch)
tree078209f50b044e24ea2c72cbbe7dca6e34bb7e25 /lib/_http_outgoing.js
parent35c6e0cc2b56a5380e6808ef5603ecc2b167e032 (diff)
downloadandroid-node-v8-0646eda4fc0affb98e13c30acb522e63b7fd6dde.tar.gz
android-node-v8-0646eda4fc0affb98e13c30acb522e63b7fd6dde.tar.bz2
android-node-v8-0646eda4fc0affb98e13c30acb522e63b7fd6dde.zip
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. PR-URL: https://github.com/nodejs/node/pull/30610 Refs: https://github.com/nodejs/node/issues/29766 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'lib/_http_outgoing.js')
-rw-r--r--lib/_http_outgoing.js56
1 files changed, 31 insertions, 25 deletions
diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js
index 0dc13f19fe..466d634acb 100644
--- a/lib/_http_outgoing.js
+++ b/lib/_http_outgoing.js
@@ -21,7 +21,13 @@
'use strict';
-const { Object, ObjectPrototype } = primordials;
+const {
+ ObjectCreate,
+ ObjectDefineProperty,
+ ObjectKeys,
+ ObjectPrototypeHasOwnProperty,
+ ObjectSetPrototypeOf,
+} = primordials;
const { getDefaultHighWaterMark } = require('internal/streams/state');
const assert = require('internal/assert');
@@ -109,10 +115,10 @@ function OutgoingMessage() {
this._onPendingData = noopPendingOutput;
}
-Object.setPrototypeOf(OutgoingMessage.prototype, Stream.prototype);
-Object.setPrototypeOf(OutgoingMessage, Stream);
+ObjectSetPrototypeOf(OutgoingMessage.prototype, Stream.prototype);
+ObjectSetPrototypeOf(OutgoingMessage, Stream);
-Object.defineProperty(OutgoingMessage.prototype, 'writableFinished', {
+ObjectDefineProperty(OutgoingMessage.prototype, 'writableFinished', {
get() {
return (
this.finished &&
@@ -122,32 +128,32 @@ Object.defineProperty(OutgoingMessage.prototype, 'writableFinished', {
}
});
-Object.defineProperty(OutgoingMessage.prototype, 'writableObjectMode', {
+ObjectDefineProperty(OutgoingMessage.prototype, 'writableObjectMode', {
get() {
return false;
}
});
-Object.defineProperty(OutgoingMessage.prototype, 'writableLength', {
+ObjectDefineProperty(OutgoingMessage.prototype, 'writableLength', {
get() {
return this.outputSize + (this.socket ? this.socket.writableLength : 0);
}
});
-Object.defineProperty(OutgoingMessage.prototype, 'writableHighWaterMark', {
+ObjectDefineProperty(OutgoingMessage.prototype, 'writableHighWaterMark', {
get() {
return this.socket ? this.socket.writableHighWaterMark : HIGH_WATER_MARK;
}
});
-Object.defineProperty(OutgoingMessage.prototype, 'writableCorked', {
+ObjectDefineProperty(OutgoingMessage.prototype, 'writableCorked', {
get() {
const corked = this.socket ? this.socket.writableCorked : 0;
return corked + this[kCorked];
}
});
-Object.defineProperty(OutgoingMessage.prototype, '_headers', {
+ObjectDefineProperty(OutgoingMessage.prototype, '_headers', {
get: internalUtil.deprecate(function() {
return this.getHeaders();
}, 'OutgoingMessage.prototype._headers is deprecated', 'DEP0066'),
@@ -155,8 +161,8 @@ Object.defineProperty(OutgoingMessage.prototype, '_headers', {
if (val == null) {
this[kOutHeaders] = null;
} else if (typeof val === 'object') {
- const headers = this[kOutHeaders] = Object.create(null);
- const keys = Object.keys(val);
+ const headers = this[kOutHeaders] = ObjectCreate(null);
+ const keys = ObjectKeys(val);
for (var i = 0; i < keys.length; ++i) {
const name = keys[i];
headers[name.toLowerCase()] = [name, val[name]];
@@ -165,7 +171,7 @@ Object.defineProperty(OutgoingMessage.prototype, '_headers', {
}, 'OutgoingMessage.prototype._headers is deprecated', 'DEP0066')
});
-Object.defineProperty(OutgoingMessage.prototype, 'connection', {
+ObjectDefineProperty(OutgoingMessage.prototype, 'connection', {
get: function() {
return this.socket;
},
@@ -174,12 +180,12 @@ Object.defineProperty(OutgoingMessage.prototype, 'connection', {
}
});
-Object.defineProperty(OutgoingMessage.prototype, '_headerNames', {
+ObjectDefineProperty(OutgoingMessage.prototype, '_headerNames', {
get: internalUtil.deprecate(function() {
const headers = this[kOutHeaders];
if (headers !== null) {
- const out = Object.create(null);
- const keys = Object.keys(headers);
+ const out = ObjectCreate(null);
+ const keys = ObjectKeys(headers);
for (var i = 0; i < keys.length; ++i) {
const key = keys[i];
const val = headers[key][0];
@@ -194,7 +200,7 @@ Object.defineProperty(OutgoingMessage.prototype, '_headerNames', {
const headers = this[kOutHeaders];
if (!headers)
return;
- const keys = Object.keys(val);
+ const keys = ObjectKeys(val);
for (var i = 0; i < keys.length; ++i) {
const header = headers[keys[i]];
if (header)
@@ -214,7 +220,7 @@ OutgoingMessage.prototype._renderHeaders = function _renderHeaders() {
const headers = {};
if (headersMap !== null) {
- const keys = Object.keys(headersMap);
+ const keys = ObjectKeys(headersMap);
for (var i = 0, l = keys.length; i < l; i++) {
const key = keys[i];
headers[headersMap[key][0]] = headersMap[key][1];
@@ -359,7 +365,7 @@ function _storeHeader(firstLine, headers) {
}
} else {
for (const key in headers) {
- if (ObjectPrototype.hasOwnProperty(headers, key)) {
+ if (ObjectPrototypeHasOwnProperty(headers, key)) {
processHeader(this, state, key, headers[key], true);
}
}
@@ -520,7 +526,7 @@ OutgoingMessage.prototype.setHeader = function setHeader(name, value) {
let headers = this[kOutHeaders];
if (headers === null)
- this[kOutHeaders] = headers = Object.create(null);
+ this[kOutHeaders] = headers = ObjectCreate(null);
headers[name.toLowerCase()] = [name, value];
};
@@ -540,16 +546,16 @@ OutgoingMessage.prototype.getHeader = function getHeader(name) {
// Returns an array of the names of the current outgoing headers.
OutgoingMessage.prototype.getHeaderNames = function getHeaderNames() {
- return this[kOutHeaders] !== null ? Object.keys(this[kOutHeaders]) : [];
+ return this[kOutHeaders] !== null ? ObjectKeys(this[kOutHeaders]) : [];
};
// Returns a shallow copy of the current outgoing headers.
OutgoingMessage.prototype.getHeaders = function getHeaders() {
const headers = this[kOutHeaders];
- const ret = Object.create(null);
+ const ret = ObjectCreate(null);
if (headers) {
- const keys = Object.keys(headers);
+ const keys = ObjectKeys(headers);
for (var i = 0; i < keys.length; ++i) {
const key = keys[i];
const val = headers[key][1];
@@ -601,13 +607,13 @@ OutgoingMessage.prototype._implicitHeader = function _implicitHeader() {
this.emit('error', new ERR_METHOD_NOT_IMPLEMENTED('_implicitHeader()'));
};
-Object.defineProperty(OutgoingMessage.prototype, 'headersSent', {
+ObjectDefineProperty(OutgoingMessage.prototype, 'headersSent', {
configurable: true,
enumerable: true,
get: function() { return !!this._header; }
});
-Object.defineProperty(OutgoingMessage.prototype, 'writableEnded', {
+ObjectDefineProperty(OutgoingMessage.prototype, 'writableEnded', {
get: function() { return this.finished; }
});
@@ -688,7 +694,7 @@ function connectionCorkNT(conn) {
OutgoingMessage.prototype.addTrailers = function addTrailers(headers) {
this._trailer = '';
- const keys = Object.keys(headers);
+ const keys = ObjectKeys(headers);
const isArray = Array.isArray(headers);
var field, value;
for (var i = 0, l = keys.length; i < l; i++) {