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>
This commit is contained in:
Michaël Zasso
2019-11-22 18:04:46 +01:00
parent 35c6e0cc2b
commit 0646eda4fc
117 changed files with 1317 additions and 943 deletions

View File

@@ -1,6 +1,10 @@
'use strict';
const { Math, ObjectPrototype } = primordials;
const {
MathCeil,
MathMax,
ObjectPrototypeHasOwnProperty,
} = primordials;
const { getStringWidth } = require('internal/readline/utils');
@@ -36,7 +40,7 @@ const renderRow = (row, columnWidths) => {
const needed = (columnWidths[i] - len) / 2;
// round(needed) + ceil(needed) will always add up to the amount
// of spaces we need while also left justifying the output.
out += `${' '.repeat(needed)}${cell}${' '.repeat(Math.ceil(needed))}`;
out += `${' '.repeat(needed)}${cell}${' '.repeat(MathCeil(needed))}`;
if (i !== row.length - 1)
out += tableChars.middle;
}
@@ -47,7 +51,7 @@ const renderRow = (row, columnWidths) => {
const table = (head, columns) => {
const rows = [];
const columnWidths = head.map((h) => getStringWidth(h));
const longestColumn = columns.reduce((n, a) => Math.max(n, a.length), 0);
const longestColumn = columns.reduce((n, a) => MathMax(n, a.length), 0);
for (let i = 0; i < head.length; i++) {
const column = columns[i];
@@ -55,10 +59,10 @@ const table = (head, columns) => {
if (rows[j] === undefined)
rows[j] = [];
const value = rows[j][i] =
ObjectPrototype.hasOwnProperty(column, j) ? column[j] : '';
ObjectPrototypeHasOwnProperty(column, j) ? column[j] : '';
const width = columnWidths[i] || 0;
const counted = getStringWidth(value);
columnWidths[i] = Math.max(width, counted);
columnWidths[i] = MathMax(width, counted);
}
}