summaryrefslogtreecommitdiff
path: root/lib/internal/console
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/console
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/console')
-rw-r--r--lib/internal/console/constructor.js38
-rw-r--r--lib/internal/console/global.js15
2 files changed, 33 insertions, 20 deletions
diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js
index c3339241aa..43ae0eee41 100644
--- a/lib/internal/console/constructor.js
+++ b/lib/internal/console/constructor.js
@@ -3,7 +3,15 @@
// The Console constructor is not actually used to construct the global
// console. It's exported for backwards compatibility.
-const { Object, ObjectPrototype, Reflect, Math } = primordials;
+const {
+ MathFloor,
+ ObjectDefineProperties,
+ ObjectDefineProperty,
+ ObjectKeys,
+ ObjectPrototypeHasOwnProperty,
+ ObjectValues,
+ ReflectOwnKeys,
+} = primordials;
const { trace } = internalBinding('trace_events');
const {
@@ -106,7 +114,7 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
}
// Bind the prototype functions to this Console instance
- const keys = Object.keys(Console.prototype);
+ const keys = ObjectKeys(Console.prototype);
for (var v = 0; v < keys.length; v++) {
var k = keys[v];
// We have to bind the methods grabbed from the instance instead of from
@@ -126,7 +134,7 @@ const consolePropAttributes = {
};
// Fixup global.console instanceof global.console.Console
-Object.defineProperty(Console, Symbol.hasInstance, {
+ObjectDefineProperty(Console, Symbol.hasInstance, {
value(instance) {
return instance[kIsConsole];
}
@@ -134,7 +142,7 @@ Object.defineProperty(Console, Symbol.hasInstance, {
// Eager version for the Console constructor
Console.prototype[kBindStreamsEager] = function(stdout, stderr) {
- Object.defineProperties(this, {
+ ObjectDefineProperties(this, {
'_stdout': { ...consolePropAttributes, value: stdout },
'_stderr': { ...consolePropAttributes, value: stderr }
});
@@ -145,7 +153,7 @@ Console.prototype[kBindStreamsEager] = function(stdout, stderr) {
Console.prototype[kBindStreamsLazy] = function(object) {
let stdout;
let stderr;
- Object.defineProperties(this, {
+ ObjectDefineProperties(this, {
'_stdout': {
enumerable: false,
configurable: true,
@@ -168,7 +176,7 @@ Console.prototype[kBindStreamsLazy] = function(object) {
};
Console.prototype[kBindProperties] = function(ignoreErrors, colorMode) {
- Object.defineProperties(this, {
+ ObjectDefineProperties(this, {
'_stdoutErrorHandler': {
...consolePropAttributes,
value: createWriteErrorHandler(this, kUseStdout)
@@ -412,7 +420,7 @@ const consoleMethods = {
const depth = v !== null &&
typeof v === 'object' &&
!isArray(v) &&
- Object.keys(v).length > 2 ? -1 : 0;
+ ObjectKeys(v).length > 2 ? -1 : 0;
const opt = {
depth,
maxArrayLength: 3,
@@ -477,7 +485,7 @@ const consoleMethods = {
const map = {};
let hasPrimitives = false;
const valuesKeyArray = [];
- const indexKeyArray = Object.keys(tabularData);
+ const indexKeyArray = ObjectKeys(tabularData);
for (; i < indexKeyArray.length; i++) {
const item = tabularData[indexKeyArray[i]];
@@ -487,12 +495,12 @@ const consoleMethods = {
hasPrimitives = true;
valuesKeyArray[i] = _inspect(item);
} else {
- const keys = properties || Object.keys(item);
+ const keys = properties || ObjectKeys(item);
for (const key of keys) {
if (map[key] === undefined)
map[key] = [];
if ((primitive && properties) ||
- !ObjectPrototype.hasOwnProperty(item, key))
+ !ObjectPrototypeHasOwnProperty(item, key))
map[key][i] = '';
else
map[key][i] = _inspect(item[key]);
@@ -500,8 +508,8 @@ const consoleMethods = {
}
}
- const keys = Object.keys(map);
- const values = Object.values(map);
+ const keys = ObjectKeys(map);
+ const values = ObjectValues(map);
if (hasPrimitives) {
keys.push(valuesKey);
values.push(valuesKeyArray);
@@ -545,10 +553,10 @@ function formatTime(ms) {
if (ms >= kSecond) {
if (ms >= kMinute) {
if (ms >= kHour) {
- hours = Math.floor(ms / kHour);
+ hours = MathFloor(ms / kHour);
ms = ms % kHour;
}
- minutes = Math.floor(ms / kMinute);
+ minutes = MathFloor(ms / kMinute);
ms = ms % kMinute;
}
seconds = ms / kSecond;
@@ -576,7 +584,7 @@ const isArray = (v) => ArrayIsArray(v) || isTypedArray(v) || isBuffer(v);
function noop() {}
-for (const method of Reflect.ownKeys(consoleMethods))
+for (const method of ReflectOwnKeys(consoleMethods))
Console.prototype[method] = consoleMethods[method];
Console.prototype.debug = Console.prototype.log;
diff --git a/lib/internal/console/global.js b/lib/internal/console/global.js
index bad7478f1e..6a1dc3806f 100644
--- a/lib/internal/console/global.js
+++ b/lib/internal/console/global.js
@@ -12,7 +12,12 @@
// Therefore, the console.Console.prototype is not
// in the global console prototype chain anymore.
-const { Object, Reflect } = primordials;
+const {
+ ObjectCreate,
+ ReflectDefineProperty,
+ ReflectGetOwnPropertyDescriptor,
+ ReflectOwnKeys,
+} = primordials;
const {
Console,
@@ -20,20 +25,20 @@ const {
kBindProperties
} = require('internal/console/constructor');
-const globalConsole = Object.create({});
+const globalConsole = ObjectCreate({});
// Since Console is not on the prototype chain of the global console,
// the symbol properties on Console.prototype have to be looked up from
// the global console itself. In addition, we need to make the global
// console a namespace by binding the console methods directly onto
// the global console with the receiver fixed.
-for (const prop of Reflect.ownKeys(Console.prototype)) {
+for (const prop of ReflectOwnKeys(Console.prototype)) {
if (prop === 'constructor') { continue; }
- const desc = Reflect.getOwnPropertyDescriptor(Console.prototype, prop);
+ const desc = ReflectGetOwnPropertyDescriptor(Console.prototype, prop);
if (typeof desc.value === 'function') { // fix the receiver
desc.value = desc.value.bind(globalConsole);
}
- Reflect.defineProperty(globalConsole, prop, desc);
+ ReflectDefineProperty(globalConsole, prop, desc);
}
globalConsole[kBindStreamsLazy](process);