summaryrefslogtreecommitdiff
path: root/lib/internal/http2
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/internal/http2
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/internal/http2')
-rw-r--r--lib/internal/http2/compat.js26
-rw-r--r--lib/internal/http2/core.js36
-rw-r--r--lib/internal/http2/util.js16
3 files changed, 46 insertions, 32 deletions
diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js
index 5bc64504cd..5d9484f204 100644
--- a/lib/internal/http2/compat.js
+++ b/lib/internal/http2/compat.js
@@ -1,6 +1,12 @@
'use strict';
-const { Object, ObjectPrototype, Reflect } = primordials;
+const {
+ ObjectAssign,
+ ObjectCreate,
+ ObjectKeys,
+ ObjectPrototypeHasOwnProperty,
+ ReflectGetPrototypeOf,
+} = primordials;
const assert = require('internal/assert');
const Stream = require('stream');
@@ -120,7 +126,7 @@ function onStreamData(chunk) {
function onStreamTrailers(trailers, flags, rawTrailers) {
const request = this[kRequest];
if (request !== undefined) {
- Object.assign(request[kTrailers], trailers);
+ ObjectAssign(request[kTrailers], trailers);
request[kRawTrailers].push(...rawTrailers);
}
}
@@ -206,8 +212,8 @@ const proxySocketHandler = {
},
getPrototypeOf(stream) {
if (stream.session !== undefined)
- return Reflect.getPrototypeOf(stream.session[kSocket]);
- return Reflect.getPrototypeOf(stream);
+ return ReflectGetPrototypeOf(stream.session[kSocket]);
+ return ReflectGetPrototypeOf(stream);
},
set(stream, prop, value) {
switch (prop) {
@@ -434,8 +440,8 @@ class Http2ServerResponse extends Stream {
sendDate: true,
statusCode: HTTP_STATUS_OK,
};
- this[kHeaders] = Object.create(null);
- this[kTrailers] = Object.create(null);
+ this[kHeaders] = ObjectCreate(null);
+ this[kTrailers] = ObjectCreate(null);
this[kStream] = stream;
stream[kProxySocket] = null;
stream[kResponse] = this;
@@ -524,7 +530,7 @@ class Http2ServerResponse extends Stream {
}
addTrailers(headers) {
- const keys = Object.keys(headers);
+ const keys = ObjectKeys(headers);
let key = '';
for (var i = 0; i < keys.length; i++) {
key = keys[i];
@@ -539,7 +545,7 @@ class Http2ServerResponse extends Stream {
}
getHeaderNames() {
- return Object.keys(this[kHeaders]);
+ return ObjectKeys(this[kHeaders]);
}
getHeaders() {
@@ -549,7 +555,7 @@ class Http2ServerResponse extends Stream {
hasHeader(name) {
validateString(name, 'name');
name = name.trim().toLowerCase();
- return ObjectPrototype.hasOwnProperty(this[kHeaders], name);
+ return ObjectPrototypeHasOwnProperty(this[kHeaders], name);
}
removeHeader(name) {
@@ -617,7 +623,7 @@ class Http2ServerResponse extends Stream {
this[kSetHeader](header[0], header[1]);
}
} else if (typeof headers === 'object') {
- const keys = Object.keys(headers);
+ const keys = ObjectKeys(headers);
let key = '';
for (i = 0; i < keys.length; i++) {
key = keys[i];
diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js
index dfcc9cd5df..94b66d424e 100644
--- a/lib/internal/http2/core.js
+++ b/lib/internal/http2/core.js
@@ -2,7 +2,14 @@
/* eslint-disable no-use-before-define */
-const { Math, Object, Reflect } = primordials;
+const {
+ MathMin,
+ ObjectAssign,
+ ObjectCreate,
+ ObjectDefineProperty,
+ ObjectPrototypeHasOwnProperty,
+ ReflectGetPrototypeOf,
+} = primordials;
const {
assertCrypto,
@@ -124,8 +131,6 @@ const { kTimeout } = require('internal/timers');
const { isArrayBufferView } = require('internal/util/types');
const { format } = require('internal/util/inspect');
-const hasOwnProperty = Object.prototype.hasOwnProperty;
-
const { FileHandle } = internalBinding('fs');
const binding = internalBinding('http2');
const {
@@ -813,7 +818,7 @@ const proxySocketHandler = {
const socket = session[kSocket];
if (socket === undefined)
throw new ERR_HTTP2_SOCKET_UNBOUND();
- return Reflect.getPrototypeOf(socket);
+ return ReflectGetPrototypeOf(socket);
},
set(session, prop, value) {
switch (prop) {
@@ -1545,7 +1550,7 @@ class ClientHttp2Session extends Http2Session {
assertIsObject(headers, 'headers');
assertIsObject(options, 'options');
- headers = Object.assign(Object.create(null), headers);
+ headers = ObjectAssign(ObjectCreate(null), headers);
options = { ...options };
if (headers[HTTP2_HEADER_METHOD] === undefined)
@@ -1992,7 +1997,7 @@ class Http2Stream extends Duplex {
throw new ERR_HTTP2_TRAILERS_NOT_READY();
assertIsObject(headers, 'headers');
- headers = Object.assign(Object.create(null), headers);
+ headers = ObjectAssign(ObjectCreate(null), headers);
debugStreamObj(this, 'sending trailers');
@@ -2123,13 +2128,12 @@ class Http2Stream extends Duplex {
function processHeaders(oldHeaders) {
assertIsObject(oldHeaders, 'headers');
- const headers = Object.create(null);
+ const headers = ObjectCreate(null);
if (oldHeaders !== null && oldHeaders !== undefined) {
- const hop = hasOwnProperty.bind(oldHeaders);
// This loop is here for performance reason. Do not change.
for (const key in oldHeaders) {
- if (hop(key)) {
+ if (ObjectPrototypeHasOwnProperty(oldHeaders, key)) {
headers[key] = oldHeaders[key];
}
}
@@ -2309,8 +2313,8 @@ function doSendFileFD(session, options, fd, headers, streamOptions, err, stat) {
if (stat.isFile()) {
statOptions.length =
statOptions.length < 0 ? stat.size - (+statOptions.offset) :
- Math.min(stat.size - (+statOptions.offset),
- statOptions.length);
+ MathMin(stat.size - (+statOptions.offset),
+ statOptions.length);
headers[HTTP2_HEADER_CONTENT_LENGTH] = statOptions.length;
}
@@ -2387,7 +2391,7 @@ class ServerHttp2Stream extends Http2Stream {
options.endStream = !!options.endStream;
assertIsObject(headers, 'headers');
- headers = Object.assign(Object.create(null), headers);
+ headers = ObjectAssign(ObjectCreate(null), headers);
if (headers[HTTP2_HEADER_METHOD] === undefined)
headers[HTTP2_HEADER_METHOD] = HTTP2_METHOD_GET;
@@ -2619,7 +2623,7 @@ class ServerHttp2Stream extends Http2Stream {
throw new ERR_HTTP2_HEADERS_AFTER_RESPOND();
assertIsObject(headers, 'headers');
- headers = Object.assign(Object.create(null), headers);
+ headers = ObjectAssign(ObjectCreate(null), headers);
debugStreamObj(this, 'sending additional headers');
@@ -2669,8 +2673,8 @@ const setTimeout = {
writable: true,
value: setStreamTimeout
};
-Object.defineProperty(Http2Stream.prototype, 'setTimeout', setTimeout);
-Object.defineProperty(Http2Session.prototype, 'setTimeout', setTimeout);
+ObjectDefineProperty(Http2Stream.prototype, 'setTimeout', setTimeout);
+ObjectDefineProperty(Http2Session.prototype, 'setTimeout', setTimeout);
// When the socket emits an error, destroy the associated Http2Session and
@@ -2923,7 +2927,7 @@ function connect(authority, options, listener) {
}
// Support util.promisify
-Object.defineProperty(connect, promisify.custom, {
+ObjectDefineProperty(connect, promisify.custom, {
value: (authority, options) => {
return new Promise((resolve) => {
const server = connect(authority, options, () => resolve(server));
diff --git a/lib/internal/http2/util.js b/lib/internal/http2/util.js
index a0640b242c..482ae8546a 100644
--- a/lib/internal/http2/util.js
+++ b/lib/internal/http2/util.js
@@ -1,6 +1,10 @@
'use strict';
-const { Math, Object } = primordials;
+const {
+ MathMax,
+ ObjectCreate,
+ ObjectKeys,
+} = primordials;
const binding = internalBinding('http2');
const {
@@ -236,12 +240,12 @@ function updateOptionsBuffer(options) {
if (typeof options.maxOutstandingSettings === 'number') {
flags |= (1 << IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS);
optionsBuffer[IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS] =
- Math.max(1, options.maxOutstandingSettings);
+ MathMax(1, options.maxOutstandingSettings);
}
if (typeof options.maxSessionMemory === 'number') {
flags |= (1 << IDX_OPTIONS_MAX_SESSION_MEMORY);
optionsBuffer[IDX_OPTIONS_MAX_SESSION_MEMORY] =
- Math.max(1, options.maxSessionMemory);
+ MathMax(1, options.maxSessionMemory);
}
optionsBuffer[IDX_OPTIONS_FLAGS] = flags;
}
@@ -249,7 +253,7 @@ function updateOptionsBuffer(options) {
function getDefaultSettings() {
settingsBuffer[IDX_SETTINGS_FLAGS] = 0;
binding.refreshDefaultSettings();
- const holder = Object.create(null);
+ const holder = ObjectCreate(null);
const flags = settingsBuffer[IDX_SETTINGS_FLAGS];
@@ -430,7 +434,7 @@ function mapToHeaders(map,
assertValuePseudoHeader = assertValidPseudoHeader) {
let ret = '';
let count = 0;
- const keys = Object.keys(map);
+ const keys = ObjectKeys(map);
const singles = new Set();
let i;
let isArray;
@@ -525,7 +529,7 @@ const assertWithinRange = hideStackFrames(
);
function toHeaderObject(headers) {
- const obj = Object.create(null);
+ const obj = ObjectCreate(null);
for (var n = 0; n < headers.length; n = n + 2) {
const name = headers[n];
let value = headers[n + 1];