2014-11-22 15:59:48 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-04-07 08:37:13 +00:00
|
|
|
const uv = process.binding('uv');
|
2015-05-29 17:35:43 +00:00
|
|
|
const Buffer = require('buffer').Buffer;
|
2015-05-28 14:01:56 +00:00
|
|
|
const internalUtil = require('internal/util');
|
2015-09-29 19:30:22 +00:00
|
|
|
const binding = process.binding('util');
|
2015-09-30 00:07:56 +00:00
|
|
|
|
2015-11-25 21:37:43 +00:00
|
|
|
const isError = internalUtil.isError;
|
2016-08-09 18:48:56 +00:00
|
|
|
|
|
|
|
const inspectDefaultOptions = Object.seal({
|
|
|
|
showHidden: false,
|
|
|
|
depth: 2,
|
|
|
|
colors: false,
|
|
|
|
customInspect: true,
|
|
|
|
showProxy: false,
|
|
|
|
maxArrayLength: 100,
|
|
|
|
breakLength: 60
|
|
|
|
});
|
2015-11-25 21:37:43 +00:00
|
|
|
|
2015-07-25 13:01:24 +00:00
|
|
|
var Debug;
|
2016-05-21 14:07:11 +00:00
|
|
|
var simdFormatters;
|
|
|
|
|
|
|
|
// SIMD is only available when --harmony_simd is specified on the command line
|
|
|
|
// and the set of available types differs between v5 and v6, that's why we use
|
|
|
|
// a map to look up and store the formatters. It also provides a modicum of
|
|
|
|
// protection against users monkey-patching the SIMD object.
|
|
|
|
if (typeof global.SIMD === 'object' && global.SIMD !== null) {
|
|
|
|
simdFormatters = new Map();
|
|
|
|
|
|
|
|
const make = (extractLane, count) => {
|
|
|
|
return (ctx, value, recurseTimes, visibleKeys, keys) => {
|
|
|
|
const output = new Array(count);
|
|
|
|
for (let i = 0; i < count; i += 1)
|
|
|
|
output[i] = formatPrimitive(ctx, extractLane(value, i));
|
|
|
|
return output;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const SIMD = global.SIMD; // Pacify eslint.
|
|
|
|
|
|
|
|
if (typeof SIMD.Bool16x8 === 'function')
|
|
|
|
simdFormatters.set(SIMD.Bool16x8, make(SIMD.Bool16x8.extractLane, 8));
|
|
|
|
|
|
|
|
if (typeof SIMD.Bool32x4 === 'function')
|
|
|
|
simdFormatters.set(SIMD.Bool32x4, make(SIMD.Bool32x4.extractLane, 4));
|
|
|
|
|
|
|
|
if (typeof SIMD.Bool8x16 === 'function')
|
|
|
|
simdFormatters.set(SIMD.Bool8x16, make(SIMD.Bool8x16.extractLane, 16));
|
|
|
|
|
|
|
|
if (typeof SIMD.Float32x4 === 'function')
|
|
|
|
simdFormatters.set(SIMD.Float32x4, make(SIMD.Float32x4.extractLane, 4));
|
|
|
|
|
|
|
|
if (typeof SIMD.Int16x8 === 'function')
|
|
|
|
simdFormatters.set(SIMD.Int16x8, make(SIMD.Int16x8.extractLane, 8));
|
|
|
|
|
|
|
|
if (typeof SIMD.Int32x4 === 'function')
|
|
|
|
simdFormatters.set(SIMD.Int32x4, make(SIMD.Int32x4.extractLane, 4));
|
|
|
|
|
|
|
|
if (typeof SIMD.Int8x16 === 'function')
|
|
|
|
simdFormatters.set(SIMD.Int8x16, make(SIMD.Int8x16.extractLane, 16));
|
|
|
|
|
|
|
|
if (typeof SIMD.Uint16x8 === 'function')
|
|
|
|
simdFormatters.set(SIMD.Uint16x8, make(SIMD.Uint16x8.extractLane, 8));
|
|
|
|
|
|
|
|
if (typeof SIMD.Uint32x4 === 'function')
|
|
|
|
simdFormatters.set(SIMD.Uint32x4, make(SIMD.Uint32x4.extractLane, 4));
|
|
|
|
|
|
|
|
if (typeof SIMD.Uint8x16 === 'function')
|
|
|
|
simdFormatters.set(SIMD.Uint8x16, make(SIMD.Uint8x16.extractLane, 16));
|
|
|
|
}
|
2015-04-07 08:37:13 +00:00
|
|
|
|
2016-02-22 08:55:55 +00:00
|
|
|
function tryStringify(arg) {
|
|
|
|
try {
|
|
|
|
return JSON.stringify(arg);
|
|
|
|
} catch (_) {
|
|
|
|
return '[Circular]';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-29 15:26:45 +00:00
|
|
|
exports.format = function(f) {
|
2015-01-29 01:05:53 +00:00
|
|
|
if (typeof f !== 'string') {
|
2016-02-22 08:55:55 +00:00
|
|
|
const objects = new Array(arguments.length);
|
2016-01-30 04:34:13 +00:00
|
|
|
for (var index = 0; index < arguments.length; index++) {
|
2016-02-22 08:55:55 +00:00
|
|
|
objects[index] = inspect(arguments[index]);
|
2011-07-29 15:26:45 +00:00
|
|
|
}
|
|
|
|
return objects.join(' ');
|
|
|
|
}
|
|
|
|
|
2016-02-23 01:47:20 +00:00
|
|
|
var argLen = arguments.length;
|
2015-05-20 19:26:37 +00:00
|
|
|
|
2016-02-23 01:47:20 +00:00
|
|
|
if (argLen === 1) return f;
|
2016-02-22 08:55:55 +00:00
|
|
|
|
2016-02-23 01:47:20 +00:00
|
|
|
var str = '';
|
|
|
|
var a = 1;
|
|
|
|
var lastPos = 0;
|
|
|
|
for (var i = 0; i < f.length;) {
|
|
|
|
if (f.charCodeAt(i) === 37/*'%'*/ && i + 1 < f.length) {
|
|
|
|
switch (f.charCodeAt(i + 1)) {
|
|
|
|
case 100: // 'd'
|
|
|
|
if (a >= argLen)
|
|
|
|
break;
|
|
|
|
if (lastPos < i)
|
|
|
|
str += f.slice(lastPos, i);
|
|
|
|
str += Number(arguments[a++]);
|
|
|
|
lastPos = i = i + 2;
|
|
|
|
continue;
|
|
|
|
case 106: // 'j'
|
|
|
|
if (a >= argLen)
|
|
|
|
break;
|
|
|
|
if (lastPos < i)
|
|
|
|
str += f.slice(lastPos, i);
|
|
|
|
str += tryStringify(arguments[a++]);
|
|
|
|
lastPos = i = i + 2;
|
|
|
|
continue;
|
|
|
|
case 115: // 's'
|
|
|
|
if (a >= argLen)
|
|
|
|
break;
|
|
|
|
if (lastPos < i)
|
|
|
|
str += f.slice(lastPos, i);
|
|
|
|
str += String(arguments[a++]);
|
|
|
|
lastPos = i = i + 2;
|
|
|
|
continue;
|
|
|
|
case 37: // '%'
|
|
|
|
if (lastPos < i)
|
|
|
|
str += f.slice(lastPos, i);
|
|
|
|
str += '%';
|
|
|
|
lastPos = i = i + 2;
|
|
|
|
continue;
|
|
|
|
}
|
2011-07-29 15:26:45 +00:00
|
|
|
}
|
2016-02-23 01:47:20 +00:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if (lastPos === 0)
|
|
|
|
str = f;
|
|
|
|
else if (lastPos < f.length)
|
|
|
|
str += f.slice(lastPos);
|
|
|
|
while (a < argLen) {
|
|
|
|
const x = arguments[a++];
|
2015-02-23 22:32:18 +00:00
|
|
|
if (x === null || (typeof x !== 'object' && typeof x !== 'symbol')) {
|
2011-07-29 15:26:45 +00:00
|
|
|
str += ' ' + x;
|
|
|
|
} else {
|
|
|
|
str += ' ' + inspect(x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return str;
|
2011-10-04 22:08:18 +00:00
|
|
|
};
|
2011-07-29 15:26:45 +00:00
|
|
|
|
|
|
|
|
2015-06-13 16:44:39 +00:00
|
|
|
exports.deprecate = internalUtil._deprecate;
|
2012-06-21 18:42:33 +00:00
|
|
|
|
|
|
|
|
2013-05-21 22:22:05 +00:00
|
|
|
var debugs = {};
|
2013-07-26 21:38:08 +00:00
|
|
|
var debugEnviron;
|
2013-05-21 22:22:05 +00:00
|
|
|
exports.debuglog = function(set) {
|
2015-01-29 01:05:53 +00:00
|
|
|
if (debugEnviron === undefined)
|
2013-07-26 21:38:08 +00:00
|
|
|
debugEnviron = process.env.NODE_DEBUG || '';
|
2013-05-21 22:22:05 +00:00
|
|
|
set = set.toUpperCase();
|
|
|
|
if (!debugs[set]) {
|
|
|
|
if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
|
|
|
|
var pid = process.pid;
|
|
|
|
debugs[set] = function() {
|
|
|
|
var msg = exports.format.apply(exports, arguments);
|
|
|
|
console.error('%s %d: %s', set, pid, msg);
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
debugs[set] = function() {};
|
|
|
|
}
|
2010-10-11 21:04:09 +00:00
|
|
|
}
|
2013-05-21 22:22:05 +00:00
|
|
|
return debugs[set];
|
2010-10-11 21:04:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-02-17 11:40:55 +00:00
|
|
|
* Echos the value of a value. Tries to print the value out
|
2010-10-11 21:04:09 +00:00
|
|
|
* in the best way possible given the different types.
|
|
|
|
*
|
2010-12-02 20:11:23 +00:00
|
|
|
* @param {Object} obj The object to print out.
|
2012-10-10 01:47:08 +00:00
|
|
|
* @param {Object} opts Optional options object that alters the output.
|
2010-10-11 21:04:09 +00:00
|
|
|
*/
|
2012-10-12 18:44:02 +00:00
|
|
|
/* legacy: obj, showHidden, depth, colors*/
|
|
|
|
function inspect(obj, opts) {
|
2012-10-10 01:47:08 +00:00
|
|
|
// default options
|
2011-09-08 12:00:02 +00:00
|
|
|
var ctx = {
|
|
|
|
seen: [],
|
2012-10-10 01:47:08 +00:00
|
|
|
stylize: stylizeNoColor
|
2010-10-11 21:04:09 +00:00
|
|
|
};
|
2012-10-10 01:47:08 +00:00
|
|
|
// legacy...
|
2016-08-09 18:48:56 +00:00
|
|
|
if (arguments[2] !== undefined) ctx.depth = arguments[2];
|
|
|
|
if (arguments[3] !== undefined) ctx.colors = arguments[3];
|
2015-01-29 01:05:53 +00:00
|
|
|
if (typeof opts === 'boolean') {
|
2012-10-10 01:47:08 +00:00
|
|
|
// legacy...
|
|
|
|
ctx.showHidden = opts;
|
|
|
|
}
|
2016-08-09 18:48:56 +00:00
|
|
|
// Set default and user-specified options
|
|
|
|
ctx = Object.assign({}, inspect.defaultOptions, ctx, opts);
|
2012-10-10 01:47:08 +00:00
|
|
|
if (ctx.colors) ctx.stylize = stylizeWithColor;
|
2016-04-21 17:29:24 +00:00
|
|
|
if (ctx.maxArrayLength === null) ctx.maxArrayLength = Infinity;
|
2012-10-10 01:47:08 +00:00
|
|
|
return formatValue(ctx, obj, ctx.depth);
|
2011-09-08 12:00:02 +00:00
|
|
|
}
|
2010-10-11 21:04:09 +00:00
|
|
|
|
2016-08-09 18:48:56 +00:00
|
|
|
Object.defineProperty(inspect, 'defaultOptions', {
|
|
|
|
get: function() {
|
|
|
|
return inspectDefaultOptions;
|
|
|
|
},
|
|
|
|
set: function(options) {
|
|
|
|
if (options === null || typeof options !== 'object') {
|
|
|
|
throw new TypeError('"options" must be an object');
|
|
|
|
}
|
|
|
|
Object.assign(inspectDefaultOptions, options);
|
|
|
|
return inspectDefaultOptions;
|
|
|
|
}
|
|
|
|
});
|
2010-10-11 21:04:09 +00:00
|
|
|
|
2011-09-08 12:00:02 +00:00
|
|
|
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
|
2012-07-16 21:50:15 +00:00
|
|
|
inspect.colors = {
|
2016-05-05 05:20:27 +00:00
|
|
|
'bold': [1, 22],
|
|
|
|
'italic': [3, 23],
|
|
|
|
'underline': [4, 24],
|
|
|
|
'inverse': [7, 27],
|
|
|
|
'white': [37, 39],
|
|
|
|
'grey': [90, 39],
|
|
|
|
'black': [30, 39],
|
|
|
|
'blue': [34, 39],
|
|
|
|
'cyan': [36, 39],
|
|
|
|
'green': [32, 39],
|
|
|
|
'magenta': [35, 39],
|
|
|
|
'red': [31, 39],
|
|
|
|
'yellow': [33, 39]
|
2011-09-08 12:00:02 +00:00
|
|
|
};
|
2010-12-02 20:11:23 +00:00
|
|
|
|
2011-11-11 07:35:35 +00:00
|
|
|
// Don't use 'blue' not visible on cmd.exe
|
2012-07-16 21:50:15 +00:00
|
|
|
inspect.styles = {
|
2011-10-04 22:08:18 +00:00
|
|
|
'special': 'cyan',
|
2011-11-11 07:35:35 +00:00
|
|
|
'number': 'yellow',
|
2011-10-04 22:08:18 +00:00
|
|
|
'boolean': 'yellow',
|
|
|
|
'undefined': 'grey',
|
|
|
|
'null': 'bold',
|
|
|
|
'string': 'green',
|
2014-10-01 02:44:39 +00:00
|
|
|
'symbol': 'green',
|
2011-10-04 22:08:18 +00:00
|
|
|
'date': 'magenta',
|
|
|
|
// "name": intentionally not styling
|
|
|
|
'regexp': 'red'
|
2011-09-08 12:00:02 +00:00
|
|
|
};
|
2010-12-02 20:11:23 +00:00
|
|
|
|
2016-08-18 22:26:36 +00:00
|
|
|
const customInspectSymbol = internalUtil.customInspectSymbol;
|
|
|
|
|
2016-08-09 18:48:56 +00:00
|
|
|
exports.inspect = inspect;
|
2016-08-18 22:26:36 +00:00
|
|
|
exports.inspect.custom = customInspectSymbol;
|
2010-12-02 20:11:23 +00:00
|
|
|
|
2011-09-08 12:00:02 +00:00
|
|
|
function stylizeWithColor(str, styleType) {
|
2012-07-16 21:50:15 +00:00
|
|
|
var style = inspect.styles[styleType];
|
2010-10-11 21:04:09 +00:00
|
|
|
|
2011-09-08 12:00:02 +00:00
|
|
|
if (style) {
|
2012-07-16 21:50:15 +00:00
|
|
|
return '\u001b[' + inspect.colors[style][0] + 'm' + str +
|
|
|
|
'\u001b[' + inspect.colors[style][1] + 'm';
|
2011-09-08 12:00:02 +00:00
|
|
|
} else {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
}
|
2010-10-11 21:04:09 +00:00
|
|
|
|
2011-07-03 06:20:25 +00:00
|
|
|
|
2011-09-08 12:00:02 +00:00
|
|
|
function stylizeNoColor(str, styleType) {
|
|
|
|
return str;
|
|
|
|
}
|
2010-10-11 21:04:09 +00:00
|
|
|
|
|
|
|
|
2012-06-27 17:15:28 +00:00
|
|
|
function arrayToHash(array) {
|
2015-11-15 04:56:05 +00:00
|
|
|
var hash = Object.create(null);
|
2012-06-27 17:15:28 +00:00
|
|
|
|
2015-11-22 09:08:45 +00:00
|
|
|
for (var i = 0; i < array.length; i++) {
|
|
|
|
var val = array[i];
|
2012-06-27 17:15:28 +00:00
|
|
|
hash[val] = true;
|
2015-11-22 09:08:45 +00:00
|
|
|
}
|
2012-06-27 17:15:28 +00:00
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-10 08:25:04 +00:00
|
|
|
function getConstructorOf(obj) {
|
|
|
|
while (obj) {
|
|
|
|
var descriptor = Object.getOwnPropertyDescriptor(obj, 'constructor');
|
|
|
|
if (descriptor !== undefined &&
|
|
|
|
typeof descriptor.value === 'function' &&
|
|
|
|
descriptor.value.name !== '') {
|
|
|
|
return descriptor.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj = Object.getPrototypeOf(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-30 00:07:56 +00:00
|
|
|
function ensureDebugIsInitialized() {
|
|
|
|
if (Debug === undefined) {
|
|
|
|
const runInDebugContext = require('vm').runInDebugContext;
|
2015-10-06 01:44:09 +00:00
|
|
|
Debug = runInDebugContext('Debug');
|
2015-09-30 00:07:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-20 00:29:59 +00:00
|
|
|
function inspectPromise(p) {
|
2015-09-30 00:07:56 +00:00
|
|
|
ensureDebugIsInitialized();
|
2015-10-15 19:55:42 +00:00
|
|
|
// Only create a mirror if the object is a Promise.
|
2015-10-06 01:44:09 +00:00
|
|
|
if (!binding.isPromise(p))
|
2015-04-20 00:29:59 +00:00
|
|
|
return null;
|
2015-09-30 00:07:56 +00:00
|
|
|
const mirror = Debug.MakeMirror(p, true);
|
2015-04-20 00:29:59 +00:00
|
|
|
return {status: mirror.status(), value: mirror.promiseValue().value_};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-08 12:00:02 +00:00
|
|
|
function formatValue(ctx, value, recurseTimes) {
|
2016-04-29 08:06:48 +00:00
|
|
|
if (ctx.showProxy &&
|
|
|
|
((typeof value === 'object' && value !== null) ||
|
|
|
|
typeof value === 'function')) {
|
|
|
|
var proxy = undefined;
|
|
|
|
var proxyCache = ctx.proxyCache;
|
|
|
|
if (!proxyCache)
|
|
|
|
proxyCache = ctx.proxyCache = new Map();
|
|
|
|
// Determine if we've already seen this object and have
|
|
|
|
// determined that it either is or is not a proxy.
|
|
|
|
if (proxyCache.has(value)) {
|
|
|
|
// We've seen it, if the value is not undefined, it's a Proxy.
|
|
|
|
proxy = proxyCache.get(value);
|
|
|
|
} else {
|
|
|
|
// Haven't seen it. Need to check.
|
|
|
|
// If it's not a Proxy, this will return undefined.
|
|
|
|
// Otherwise, it'll return an array. The first item
|
|
|
|
// is the target, the second item is the handler.
|
|
|
|
// We ignore (and do not return) the Proxy isRevoked property.
|
|
|
|
proxy = binding.getProxyDetails(value);
|
|
|
|
if (proxy) {
|
|
|
|
// We know for a fact that this isn't a Proxy.
|
|
|
|
// Mark it as having already been evaluated.
|
|
|
|
// We do this because this object is passed
|
|
|
|
// recursively to formatValue below in order
|
|
|
|
// for it to get proper formatting, and because
|
|
|
|
// the target and handle objects also might be
|
|
|
|
// proxies... it's unfortunate but necessary.
|
|
|
|
proxyCache.set(proxy, undefined);
|
|
|
|
}
|
|
|
|
// If the object is not a Proxy, then this stores undefined.
|
|
|
|
// This tells the code above that we've already checked and
|
|
|
|
// ruled it out. If the object is a proxy, this caches the
|
|
|
|
// results of the getProxyDetails call.
|
|
|
|
proxyCache.set(value, proxy);
|
|
|
|
}
|
|
|
|
if (proxy) {
|
|
|
|
return 'Proxy ' + formatValue(ctx, proxy, recurseTimes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-08 12:00:02 +00:00
|
|
|
// Provide a hook for user-specified inspect functions.
|
|
|
|
// Check that value is an object with an inspect function on it
|
2016-08-18 22:26:36 +00:00
|
|
|
if (ctx.customInspect && value) {
|
|
|
|
const maybeCustomInspect = value[customInspectSymbol] || value.inspect;
|
|
|
|
|
|
|
|
if (typeof maybeCustomInspect === 'function' &&
|
|
|
|
// Filter out the util module, its inspect function is special
|
|
|
|
maybeCustomInspect !== exports.inspect &&
|
|
|
|
// Also filter out any prototype objects using the circular check.
|
|
|
|
!(value.constructor && value.constructor.prototype === value)) {
|
|
|
|
let ret = maybeCustomInspect.call(value, recurseTimes, ctx);
|
2016-08-18 22:44:38 +00:00
|
|
|
|
|
|
|
// If the custom inspection method returned `this`, don't go into
|
|
|
|
// infinite recursion.
|
|
|
|
if (ret !== value) {
|
|
|
|
if (typeof ret !== 'string') {
|
|
|
|
ret = formatValue(ctx, ret, recurseTimes);
|
|
|
|
}
|
|
|
|
return ret;
|
2016-08-18 22:26:36 +00:00
|
|
|
}
|
2013-01-30 03:06:32 +00:00
|
|
|
}
|
2011-09-08 12:00:02 +00:00
|
|
|
}
|
2010-10-11 21:04:09 +00:00
|
|
|
|
2011-09-08 12:00:02 +00:00
|
|
|
// Primitive types cannot have properties
|
|
|
|
var primitive = formatPrimitive(ctx, value);
|
|
|
|
if (primitive) {
|
|
|
|
return primitive;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look up the keys of the object.
|
2012-06-27 17:15:28 +00:00
|
|
|
var keys = Object.keys(value);
|
|
|
|
var visibleKeys = arrayToHash(keys);
|
|
|
|
|
|
|
|
if (ctx.showHidden) {
|
|
|
|
keys = Object.getOwnPropertyNames(value);
|
2015-01-07 21:54:25 +00:00
|
|
|
keys = keys.concat(Object.getOwnPropertySymbols(value));
|
2012-06-27 17:15:28 +00:00
|
|
|
}
|
2011-09-08 12:00:02 +00:00
|
|
|
|
2014-02-06 02:09:23 +00:00
|
|
|
// This could be a boxed primitive (new String(), etc.), check valueOf()
|
|
|
|
// NOTE: Avoid calling `valueOf` on `Date` instance because it will return
|
|
|
|
// a number which, when object has some additional user-stored `keys`,
|
|
|
|
// will be printed out.
|
|
|
|
var formatted;
|
|
|
|
var raw = value;
|
|
|
|
try {
|
|
|
|
// the .valueOf() call can fail for a multitude of reasons
|
|
|
|
if (!isDate(value))
|
|
|
|
raw = value.valueOf();
|
|
|
|
} catch (e) {
|
|
|
|
// ignore...
|
|
|
|
}
|
|
|
|
|
2015-01-29 01:05:53 +00:00
|
|
|
if (typeof raw === 'string') {
|
2014-02-06 02:09:23 +00:00
|
|
|
// for boxed Strings, we have to remove the 0-n indexed entries,
|
2016-02-17 11:40:55 +00:00
|
|
|
// since they just noisy up the output and are redundant
|
2014-02-06 02:09:23 +00:00
|
|
|
keys = keys.filter(function(key) {
|
|
|
|
return !(key >= 0 && key < raw.length);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-09-08 12:00:02 +00:00
|
|
|
// Some type of object without properties can be shortcutted.
|
|
|
|
if (keys.length === 0) {
|
2015-01-29 01:05:53 +00:00
|
|
|
if (typeof value === 'function') {
|
2011-09-08 12:00:02 +00:00
|
|
|
var name = value.name ? ': ' + value.name : '';
|
|
|
|
return ctx.stylize('[Function' + name + ']', 'special');
|
2010-10-11 21:04:09 +00:00
|
|
|
}
|
2011-07-03 06:20:25 +00:00
|
|
|
if (isRegExp(value)) {
|
2011-10-26 06:56:07 +00:00
|
|
|
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
2011-07-03 06:20:25 +00:00
|
|
|
}
|
2010-10-11 21:04:09 +00:00
|
|
|
if (isDate(value)) {
|
2016-05-01 15:44:46 +00:00
|
|
|
if (Number.isNaN(value.getTime())) {
|
|
|
|
return ctx.stylize(value.toString(), 'date');
|
|
|
|
} else {
|
|
|
|
return ctx.stylize(Date.prototype.toISOString.call(value), 'date');
|
|
|
|
}
|
2010-10-11 21:04:09 +00:00
|
|
|
}
|
2011-09-08 16:16:48 +00:00
|
|
|
if (isError(value)) {
|
|
|
|
return formatError(value);
|
|
|
|
}
|
2014-02-06 02:09:23 +00:00
|
|
|
// now check the `raw` value to handle boxed primitives
|
2015-01-29 01:05:53 +00:00
|
|
|
if (typeof raw === 'string') {
|
2014-02-06 02:09:23 +00:00
|
|
|
formatted = formatPrimitiveNoColor(ctx, raw);
|
|
|
|
return ctx.stylize('[String: ' + formatted + ']', 'string');
|
|
|
|
}
|
2016-07-09 20:27:38 +00:00
|
|
|
if (typeof raw === 'symbol') {
|
|
|
|
formatted = formatPrimitiveNoColor(ctx, raw);
|
|
|
|
return ctx.stylize('[Symbol: ' + formatted + ']', 'symbol');
|
|
|
|
}
|
2015-01-29 01:05:53 +00:00
|
|
|
if (typeof raw === 'number') {
|
2014-02-06 02:09:23 +00:00
|
|
|
formatted = formatPrimitiveNoColor(ctx, raw);
|
|
|
|
return ctx.stylize('[Number: ' + formatted + ']', 'number');
|
|
|
|
}
|
2015-01-29 01:05:53 +00:00
|
|
|
if (typeof raw === 'boolean') {
|
2014-02-06 02:09:23 +00:00
|
|
|
formatted = formatPrimitiveNoColor(ctx, raw);
|
|
|
|
return ctx.stylize('[Boolean: ' + formatted + ']', 'boolean');
|
|
|
|
}
|
2015-11-12 12:28:15 +00:00
|
|
|
// Fast path for ArrayBuffer. Can't do the same for DataView because it
|
|
|
|
// has a non-primitive .buffer property that we need to recurse for.
|
2015-12-01 14:11:18 +00:00
|
|
|
if (binding.isArrayBuffer(value)) {
|
2015-11-12 12:28:15 +00:00
|
|
|
return `${getConstructorOf(value).name}` +
|
|
|
|
` { byteLength: ${formatNumber(ctx, value.byteLength)} }`;
|
|
|
|
}
|
2011-09-08 12:00:02 +00:00
|
|
|
}
|
2010-10-11 21:04:09 +00:00
|
|
|
|
2015-06-10 08:25:04 +00:00
|
|
|
var constructor = getConstructorOf(value);
|
2015-11-12 12:28:15 +00:00
|
|
|
var base = '', empty = false, braces;
|
|
|
|
var formatter = formatObject;
|
2010-10-11 21:04:09 +00:00
|
|
|
|
2015-10-15 19:55:42 +00:00
|
|
|
// We can't compare constructors for various objects using a comparison like
|
|
|
|
// `constructor === Array` because the object could have come from a different
|
|
|
|
// context and thus the constructor won't match. Instead we check the
|
|
|
|
// constructor names (including those up the prototype chain where needed) to
|
|
|
|
// determine object types.
|
2015-01-29 01:05:53 +00:00
|
|
|
if (Array.isArray(value)) {
|
2015-10-15 19:55:42 +00:00
|
|
|
// Unset the constructor to prevent "Array [...]" for ordinary arrays.
|
2015-10-05 21:29:27 +00:00
|
|
|
if (constructor && constructor.name === 'Array')
|
2015-06-10 08:25:04 +00:00
|
|
|
constructor = null;
|
2011-09-08 12:00:02 +00:00
|
|
|
braces = ['[', ']'];
|
2015-04-20 00:29:59 +00:00
|
|
|
empty = value.length === 0;
|
|
|
|
formatter = formatArray;
|
2015-12-01 16:27:39 +00:00
|
|
|
} else if (binding.isSet(value)) {
|
2015-06-10 08:25:04 +00:00
|
|
|
braces = ['{', '}'];
|
2015-04-20 00:29:59 +00:00
|
|
|
// With `showHidden`, `length` will display as a hidden property for
|
|
|
|
// arrays. For consistency's sake, do the same for `size`, even though this
|
|
|
|
// property isn't selected by Object.getOwnPropertyNames().
|
|
|
|
if (ctx.showHidden)
|
|
|
|
keys.unshift('size');
|
|
|
|
empty = value.size === 0;
|
|
|
|
formatter = formatSet;
|
2015-12-01 16:27:39 +00:00
|
|
|
} else if (binding.isMap(value)) {
|
2015-06-10 08:25:04 +00:00
|
|
|
braces = ['{', '}'];
|
2015-04-20 00:29:59 +00:00
|
|
|
// Ditto.
|
|
|
|
if (ctx.showHidden)
|
|
|
|
keys.unshift('size');
|
|
|
|
empty = value.size === 0;
|
|
|
|
formatter = formatMap;
|
2015-12-01 14:11:18 +00:00
|
|
|
} else if (binding.isArrayBuffer(value)) {
|
2015-11-12 12:28:15 +00:00
|
|
|
braces = ['{', '}'];
|
|
|
|
keys.unshift('byteLength');
|
|
|
|
visibleKeys.byteLength = true;
|
2015-12-01 14:11:18 +00:00
|
|
|
} else if (binding.isDataView(value)) {
|
2015-11-12 12:28:15 +00:00
|
|
|
braces = ['{', '}'];
|
|
|
|
// .buffer goes last, it's not a primitive like the others.
|
|
|
|
keys.unshift('byteLength', 'byteOffset', 'buffer');
|
|
|
|
visibleKeys.byteLength = true;
|
|
|
|
visibleKeys.byteOffset = true;
|
|
|
|
visibleKeys.buffer = true;
|
2015-12-01 14:11:18 +00:00
|
|
|
} else if (binding.isTypedArray(value)) {
|
2015-11-12 12:28:15 +00:00
|
|
|
braces = ['[', ']'];
|
|
|
|
formatter = formatTypedArray;
|
|
|
|
if (ctx.showHidden) {
|
|
|
|
// .buffer goes last, it's not a primitive like the others.
|
|
|
|
keys.unshift('BYTES_PER_ELEMENT',
|
|
|
|
'length',
|
|
|
|
'byteLength',
|
|
|
|
'byteOffset',
|
|
|
|
'buffer');
|
|
|
|
}
|
2015-04-20 00:29:59 +00:00
|
|
|
} else {
|
2015-10-15 19:55:42 +00:00
|
|
|
var promiseInternals = inspectPromise(value);
|
2015-04-20 00:29:59 +00:00
|
|
|
if (promiseInternals) {
|
2015-06-10 08:25:04 +00:00
|
|
|
braces = ['{', '}'];
|
2015-04-20 00:29:59 +00:00
|
|
|
formatter = formatPromise;
|
|
|
|
} else {
|
2016-07-25 07:06:26 +00:00
|
|
|
let maybeSimdFormatter;
|
2015-09-29 19:30:22 +00:00
|
|
|
if (binding.isMapIterator(value)) {
|
|
|
|
constructor = { name: 'MapIterator' };
|
|
|
|
braces = ['{', '}'];
|
|
|
|
empty = false;
|
|
|
|
formatter = formatCollectionIterator;
|
|
|
|
} else if (binding.isSetIterator(value)) {
|
|
|
|
constructor = { name: 'SetIterator' };
|
|
|
|
braces = ['{', '}'];
|
|
|
|
empty = false;
|
|
|
|
formatter = formatCollectionIterator;
|
2016-07-25 07:06:26 +00:00
|
|
|
} else if (simdFormatters &&
|
|
|
|
typeof constructor === 'function' &&
|
|
|
|
(maybeSimdFormatter = simdFormatters.get(constructor))) {
|
|
|
|
braces = ['[', ']'];
|
|
|
|
formatter = maybeSimdFormatter;
|
2015-09-29 19:30:22 +00:00
|
|
|
} else {
|
2015-10-15 19:55:42 +00:00
|
|
|
// Unset the constructor to prevent "Object {...}" for ordinary objects.
|
|
|
|
if (constructor && constructor.name === 'Object')
|
2015-09-29 19:30:22 +00:00
|
|
|
constructor = null;
|
|
|
|
braces = ['{', '}'];
|
|
|
|
empty = true; // No other data than keys.
|
|
|
|
}
|
2015-04-20 00:29:59 +00:00
|
|
|
}
|
2011-09-08 12:00:02 +00:00
|
|
|
}
|
|
|
|
|
2015-04-20 00:29:59 +00:00
|
|
|
empty = empty === true && keys.length === 0;
|
|
|
|
|
2011-09-08 12:00:02 +00:00
|
|
|
// Make functions say that they are functions
|
2015-01-29 01:05:53 +00:00
|
|
|
if (typeof value === 'function') {
|
2011-09-08 12:00:02 +00:00
|
|
|
var n = value.name ? ': ' + value.name : '';
|
|
|
|
base = ' [Function' + n + ']';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make RegExps say that they are RegExps
|
|
|
|
if (isRegExp(value)) {
|
2011-10-26 06:56:07 +00:00
|
|
|
base = ' ' + RegExp.prototype.toString.call(value);
|
2011-09-08 12:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make dates with properties first say the date
|
|
|
|
if (isDate(value)) {
|
2015-12-17 00:15:40 +00:00
|
|
|
base = ' ' + Date.prototype.toISOString.call(value);
|
2011-09-08 12:00:02 +00:00
|
|
|
}
|
|
|
|
|
2011-09-08 16:16:48 +00:00
|
|
|
// Make error with message first say the error
|
|
|
|
if (isError(value)) {
|
|
|
|
base = ' ' + formatError(value);
|
|
|
|
}
|
|
|
|
|
2014-02-06 02:09:23 +00:00
|
|
|
// Make boxed primitive Strings look like such
|
2015-01-29 01:05:53 +00:00
|
|
|
if (typeof raw === 'string') {
|
2014-02-06 02:09:23 +00:00
|
|
|
formatted = formatPrimitiveNoColor(ctx, raw);
|
|
|
|
base = ' ' + '[String: ' + formatted + ']';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make boxed primitive Numbers look like such
|
2015-01-29 01:05:53 +00:00
|
|
|
if (typeof raw === 'number') {
|
2014-02-06 02:09:23 +00:00
|
|
|
formatted = formatPrimitiveNoColor(ctx, raw);
|
|
|
|
base = ' ' + '[Number: ' + formatted + ']';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make boxed primitive Booleans look like such
|
2015-01-29 01:05:53 +00:00
|
|
|
if (typeof raw === 'boolean') {
|
2014-02-06 02:09:23 +00:00
|
|
|
formatted = formatPrimitiveNoColor(ctx, raw);
|
|
|
|
base = ' ' + '[Boolean: ' + formatted + ']';
|
|
|
|
}
|
|
|
|
|
2015-06-10 08:25:04 +00:00
|
|
|
// Add constructor name if available
|
|
|
|
if (base === '' && constructor)
|
|
|
|
braces[0] = constructor.name + ' ' + braces[0];
|
|
|
|
|
2015-04-20 00:29:59 +00:00
|
|
|
if (empty === true) {
|
2011-09-08 12:00:02 +00:00
|
|
|
return braces[0] + base + braces[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (recurseTimes < 0) {
|
|
|
|
if (isRegExp(value)) {
|
2011-10-26 06:56:07 +00:00
|
|
|
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
2011-09-08 12:00:02 +00:00
|
|
|
} else {
|
|
|
|
return ctx.stylize('[Object]', 'special');
|
2010-10-11 21:04:09 +00:00
|
|
|
}
|
2011-09-08 12:00:02 +00:00
|
|
|
}
|
2010-10-11 21:04:09 +00:00
|
|
|
|
2011-09-08 12:00:02 +00:00
|
|
|
ctx.seen.push(value);
|
|
|
|
|
2015-04-20 00:29:59 +00:00
|
|
|
var output = formatter(ctx, value, recurseTimes, visibleKeys, keys);
|
2011-09-08 12:00:02 +00:00
|
|
|
|
|
|
|
ctx.seen.pop();
|
|
|
|
|
2016-06-30 16:03:02 +00:00
|
|
|
return reduceToSingleString(output, base, braces, ctx.breakLength);
|
2011-09-08 12:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-12 12:28:15 +00:00
|
|
|
function formatNumber(ctx, value) {
|
|
|
|
// Format -0 as '-0'. Strict equality won't distinguish 0 from -0,
|
|
|
|
// so instead we use the fact that 1 / -0 < 0 whereas 1 / 0 > 0 .
|
|
|
|
if (value === 0 && 1 / value < 0)
|
|
|
|
return ctx.stylize('-0', 'number');
|
|
|
|
return ctx.stylize('' + value, 'number');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-08 12:00:02 +00:00
|
|
|
function formatPrimitive(ctx, value) {
|
2015-01-29 01:05:53 +00:00
|
|
|
if (value === undefined)
|
2013-07-24 16:03:53 +00:00
|
|
|
return ctx.stylize('undefined', 'undefined');
|
2015-01-29 01:05:53 +00:00
|
|
|
|
|
|
|
// For some reason typeof null is "object", so special case here.
|
|
|
|
if (value === null)
|
|
|
|
return ctx.stylize('null', 'null');
|
|
|
|
|
|
|
|
var type = typeof value;
|
|
|
|
|
|
|
|
if (type === 'string') {
|
2016-04-16 04:21:12 +00:00
|
|
|
var simple = '\'' +
|
|
|
|
JSON.stringify(value)
|
|
|
|
.replace(/^"|"$/g, '')
|
|
|
|
.replace(/'/g, "\\'")
|
|
|
|
.replace(/\\"/g, '"') +
|
|
|
|
'\'';
|
2013-07-24 16:03:53 +00:00
|
|
|
return ctx.stylize(simple, 'string');
|
|
|
|
}
|
2015-11-12 12:28:15 +00:00
|
|
|
if (type === 'number')
|
|
|
|
return formatNumber(ctx, value);
|
2015-01-29 01:05:53 +00:00
|
|
|
if (type === 'boolean')
|
2013-07-24 16:03:53 +00:00
|
|
|
return ctx.stylize('' + value, 'boolean');
|
2014-10-01 02:44:39 +00:00
|
|
|
// es6 symbol primitive
|
2015-01-29 01:05:53 +00:00
|
|
|
if (type === 'symbol')
|
2014-10-01 02:44:39 +00:00
|
|
|
return ctx.stylize(value.toString(), 'symbol');
|
2011-09-08 12:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-06 02:09:23 +00:00
|
|
|
function formatPrimitiveNoColor(ctx, value) {
|
|
|
|
var stylize = ctx.stylize;
|
|
|
|
ctx.stylize = stylizeNoColor;
|
|
|
|
var str = formatPrimitive(ctx, value);
|
|
|
|
ctx.stylize = stylize;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-08 16:16:48 +00:00
|
|
|
function formatError(value) {
|
2016-01-08 10:25:14 +00:00
|
|
|
return value.stack || '[' + Error.prototype.toString.call(value) + ']';
|
2011-09-08 16:16:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-20 00:29:59 +00:00
|
|
|
function formatObject(ctx, value, recurseTimes, visibleKeys, keys) {
|
|
|
|
return keys.map(function(key) {
|
|
|
|
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-08 15:20:01 +00:00
|
|
|
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
|
|
|
var output = [];
|
2016-04-21 17:29:24 +00:00
|
|
|
const maxLength = Math.min(Math.max(0, ctx.maxArrayLength), value.length);
|
|
|
|
const remaining = value.length - maxLength;
|
|
|
|
for (var i = 0; i < maxLength; ++i) {
|
2012-09-08 22:09:59 +00:00
|
|
|
if (hasOwnProperty(value, String(i))) {
|
2011-09-08 15:20:01 +00:00
|
|
|
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
2011-10-04 22:08:18 +00:00
|
|
|
String(i), true));
|
2011-09-08 15:20:01 +00:00
|
|
|
} else {
|
|
|
|
output.push('');
|
|
|
|
}
|
|
|
|
}
|
2016-04-21 17:29:24 +00:00
|
|
|
if (remaining > 0) {
|
|
|
|
output.push(`... ${remaining} more item${remaining > 1 ? 's' : ''}`);
|
|
|
|
}
|
2011-09-08 15:20:01 +00:00
|
|
|
keys.forEach(function(key) {
|
2015-01-29 01:05:53 +00:00
|
|
|
if (typeof key === 'symbol' || !key.match(/^\d+$/)) {
|
2011-09-08 15:20:01 +00:00
|
|
|
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
2011-10-04 22:08:18 +00:00
|
|
|
key, true));
|
2011-09-08 15:20:01 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-12 12:28:15 +00:00
|
|
|
function formatTypedArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
2016-04-21 17:29:24 +00:00
|
|
|
const maxLength = Math.min(Math.max(0, ctx.maxArrayLength), value.length);
|
|
|
|
const remaining = value.length - maxLength;
|
|
|
|
var output = new Array(maxLength);
|
|
|
|
for (var i = 0; i < maxLength; ++i)
|
2015-11-12 12:28:15 +00:00
|
|
|
output[i] = formatNumber(ctx, value[i]);
|
2016-04-21 17:29:24 +00:00
|
|
|
if (remaining > 0) {
|
|
|
|
output.push(`... ${remaining} more item${remaining > 1 ? 's' : ''}`);
|
|
|
|
}
|
2015-11-12 12:28:15 +00:00
|
|
|
for (const key of keys) {
|
|
|
|
if (typeof key === 'symbol' || !key.match(/^\d+$/)) {
|
|
|
|
output.push(
|
|
|
|
formatProperty(ctx, value, recurseTimes, visibleKeys, key, true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-20 00:29:59 +00:00
|
|
|
function formatSet(ctx, value, recurseTimes, visibleKeys, keys) {
|
|
|
|
var output = [];
|
|
|
|
value.forEach(function(v) {
|
|
|
|
var nextRecurseTimes = recurseTimes === null ? null : recurseTimes - 1;
|
|
|
|
var str = formatValue(ctx, v, nextRecurseTimes);
|
|
|
|
output.push(str);
|
|
|
|
});
|
|
|
|
keys.forEach(function(key) {
|
|
|
|
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
|
|
|
key, false));
|
|
|
|
});
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function formatMap(ctx, value, recurseTimes, visibleKeys, keys) {
|
|
|
|
var output = [];
|
|
|
|
value.forEach(function(v, k) {
|
|
|
|
var nextRecurseTimes = recurseTimes === null ? null : recurseTimes - 1;
|
|
|
|
var str = formatValue(ctx, k, nextRecurseTimes);
|
|
|
|
str += ' => ';
|
|
|
|
str += formatValue(ctx, v, nextRecurseTimes);
|
|
|
|
output.push(str);
|
|
|
|
});
|
|
|
|
keys.forEach(function(key) {
|
|
|
|
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
|
|
|
key, false));
|
|
|
|
});
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2015-09-29 19:30:22 +00:00
|
|
|
function formatCollectionIterator(ctx, value, recurseTimes, visibleKeys, keys) {
|
|
|
|
ensureDebugIsInitialized();
|
|
|
|
const mirror = Debug.MakeMirror(value, true);
|
|
|
|
var nextRecurseTimes = recurseTimes === null ? null : recurseTimes - 1;
|
|
|
|
var vals = mirror.preview();
|
|
|
|
var output = [];
|
2015-10-08 17:41:29 +00:00
|
|
|
for (const o of vals) {
|
2015-09-29 19:30:22 +00:00
|
|
|
output.push(formatValue(ctx, o, nextRecurseTimes));
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2015-04-20 00:29:59 +00:00
|
|
|
function formatPromise(ctx, value, recurseTimes, visibleKeys, keys) {
|
|
|
|
var output = [];
|
|
|
|
var internals = inspectPromise(value);
|
|
|
|
if (internals.status === 'pending') {
|
|
|
|
output.push('<pending>');
|
|
|
|
} else {
|
|
|
|
var nextRecurseTimes = recurseTimes === null ? null : recurseTimes - 1;
|
|
|
|
var str = formatValue(ctx, internals.value, nextRecurseTimes);
|
|
|
|
if (internals.status === 'rejected') {
|
|
|
|
output.push('<rejected> ' + str);
|
|
|
|
} else {
|
|
|
|
output.push(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
keys.forEach(function(key) {
|
|
|
|
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
|
|
|
key, false));
|
|
|
|
});
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-08 12:00:02 +00:00
|
|
|
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
|
2011-11-14 20:42:14 +00:00
|
|
|
var name, str, desc;
|
|
|
|
desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
|
|
|
|
if (desc.get) {
|
|
|
|
if (desc.set) {
|
|
|
|
str = ctx.stylize('[Getter/Setter]', 'special');
|
2011-09-08 12:00:02 +00:00
|
|
|
} else {
|
2011-11-14 20:42:14 +00:00
|
|
|
str = ctx.stylize('[Getter]', 'special');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (desc.set) {
|
|
|
|
str = ctx.stylize('[Setter]', 'special');
|
2011-09-08 12:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-08 22:09:59 +00:00
|
|
|
if (!hasOwnProperty(visibleKeys, key)) {
|
2015-01-29 01:05:53 +00:00
|
|
|
if (typeof key === 'symbol') {
|
2015-01-07 21:54:25 +00:00
|
|
|
name = '[' + ctx.stylize(key.toString(), 'symbol') + ']';
|
|
|
|
} else {
|
|
|
|
name = '[' + key + ']';
|
|
|
|
}
|
2011-09-08 12:00:02 +00:00
|
|
|
}
|
|
|
|
if (!str) {
|
2011-11-14 20:42:14 +00:00
|
|
|
if (ctx.seen.indexOf(desc.value) < 0) {
|
2015-01-29 01:05:53 +00:00
|
|
|
if (recurseTimes === null) {
|
2011-11-14 20:42:14 +00:00
|
|
|
str = formatValue(ctx, desc.value, null);
|
2011-09-08 12:00:02 +00:00
|
|
|
} else {
|
2011-11-14 20:42:14 +00:00
|
|
|
str = formatValue(ctx, desc.value, recurseTimes - 1);
|
2010-10-11 21:04:09 +00:00
|
|
|
}
|
2011-09-08 12:00:02 +00:00
|
|
|
if (str.indexOf('\n') > -1) {
|
|
|
|
if (array) {
|
2015-11-06 09:32:33 +00:00
|
|
|
str = str.replace(/\n/g, '\n ');
|
2010-10-11 21:04:09 +00:00
|
|
|
} else {
|
2015-11-06 09:32:33 +00:00
|
|
|
str = str.replace(/(^|\n)/g, '\n ');
|
2010-10-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2011-09-08 12:00:02 +00:00
|
|
|
str = ctx.stylize('[Circular]', 'special');
|
2010-10-11 21:04:09 +00:00
|
|
|
}
|
2011-09-08 12:00:02 +00:00
|
|
|
}
|
2015-01-29 01:05:53 +00:00
|
|
|
if (name === undefined) {
|
2011-09-08 12:00:02 +00:00
|
|
|
if (array && key.match(/^\d+$/)) {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
name = JSON.stringify('' + key);
|
|
|
|
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
|
|
|
name = name.substr(1, name.length - 2);
|
|
|
|
name = ctx.stylize(name, 'name');
|
|
|
|
} else {
|
|
|
|
name = name.replace(/'/g, "\\'")
|
|
|
|
.replace(/\\"/g, '"')
|
2014-01-10 19:53:47 +00:00
|
|
|
.replace(/(^"|"$)/g, "'")
|
|
|
|
.replace(/\\\\/g, '\\');
|
2011-09-08 12:00:02 +00:00
|
|
|
name = ctx.stylize(name, 'string');
|
|
|
|
}
|
|
|
|
}
|
2010-10-11 21:04:09 +00:00
|
|
|
|
2011-09-08 12:00:02 +00:00
|
|
|
return name + ': ' + str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-30 16:03:02 +00:00
|
|
|
function reduceToSingleString(output, base, braces, breakLength) {
|
2011-09-08 12:00:02 +00:00
|
|
|
var length = output.reduce(function(prev, cur) {
|
2013-03-18 00:44:43 +00:00
|
|
|
return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
|
2011-09-08 12:00:02 +00:00
|
|
|
}, 0);
|
|
|
|
|
2016-06-30 16:03:02 +00:00
|
|
|
if (length > breakLength) {
|
2011-09-08 12:00:02 +00:00
|
|
|
return braces[0] +
|
2015-04-20 00:29:59 +00:00
|
|
|
// If the opening "brace" is too large, like in the case of "Set {",
|
|
|
|
// we need to force the first item to be on the next line or the
|
|
|
|
// items will not line up correctly.
|
2016-08-17 14:47:13 +00:00
|
|
|
(base === '' && braces[0].length === 1 ? '' : base + '\n ') +
|
2011-09-08 12:00:02 +00:00
|
|
|
' ' +
|
2016-08-17 14:47:13 +00:00
|
|
|
output.join(',\n ') +
|
2011-09-08 12:00:02 +00:00
|
|
|
' ' +
|
|
|
|
braces[1];
|
2010-10-11 21:04:09 +00:00
|
|
|
}
|
2011-09-08 12:00:02 +00:00
|
|
|
|
|
|
|
return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
2011-07-29 15:26:45 +00:00
|
|
|
}
|
2010-10-11 21:04:09 +00:00
|
|
|
|
|
|
|
|
2011-10-26 04:42:23 +00:00
|
|
|
// NOTE: These type checking functions intentionally don't use `instanceof`
|
|
|
|
// because it is fragile and can be easily faked with `Object.create()`.
|
2015-03-28 03:04:49 +00:00
|
|
|
exports.isArray = Array.isArray;
|
2010-10-11 21:04:09 +00:00
|
|
|
|
2013-07-26 21:38:08 +00:00
|
|
|
function isBoolean(arg) {
|
2013-12-20 21:44:56 +00:00
|
|
|
return typeof arg === 'boolean';
|
2013-07-26 21:38:08 +00:00
|
|
|
}
|
|
|
|
exports.isBoolean = isBoolean;
|
|
|
|
|
|
|
|
function isNull(arg) {
|
|
|
|
return arg === null;
|
|
|
|
}
|
|
|
|
exports.isNull = isNull;
|
|
|
|
|
|
|
|
function isNullOrUndefined(arg) {
|
2015-01-29 01:05:53 +00:00
|
|
|
return arg === null || arg === undefined;
|
2013-07-26 21:38:08 +00:00
|
|
|
}
|
|
|
|
exports.isNullOrUndefined = isNullOrUndefined;
|
|
|
|
|
|
|
|
function isNumber(arg) {
|
2013-12-20 21:44:56 +00:00
|
|
|
return typeof arg === 'number';
|
2013-07-26 21:38:08 +00:00
|
|
|
}
|
|
|
|
exports.isNumber = isNumber;
|
|
|
|
|
|
|
|
function isString(arg) {
|
2013-12-20 21:44:56 +00:00
|
|
|
return typeof arg === 'string';
|
2013-07-26 21:38:08 +00:00
|
|
|
}
|
|
|
|
exports.isString = isString;
|
|
|
|
|
|
|
|
function isSymbol(arg) {
|
|
|
|
return typeof arg === 'symbol';
|
|
|
|
}
|
|
|
|
exports.isSymbol = isSymbol;
|
|
|
|
|
|
|
|
function isUndefined(arg) {
|
2015-01-29 01:05:53 +00:00
|
|
|
return arg === undefined;
|
2013-07-26 21:38:08 +00:00
|
|
|
}
|
|
|
|
exports.isUndefined = isUndefined;
|
2010-10-11 21:04:09 +00:00
|
|
|
|
2010-12-02 04:59:06 +00:00
|
|
|
function isRegExp(re) {
|
2015-12-01 16:27:39 +00:00
|
|
|
return binding.isRegExp(re);
|
2010-10-11 21:04:09 +00:00
|
|
|
}
|
2011-10-26 18:09:01 +00:00
|
|
|
exports.isRegExp = isRegExp;
|
2010-10-11 21:04:09 +00:00
|
|
|
|
2013-07-26 21:38:08 +00:00
|
|
|
function isObject(arg) {
|
2015-01-29 01:05:53 +00:00
|
|
|
return arg !== null && typeof arg === 'object';
|
2013-07-26 21:38:08 +00:00
|
|
|
}
|
|
|
|
exports.isObject = isObject;
|
2010-10-11 21:04:09 +00:00
|
|
|
|
2010-12-02 04:59:06 +00:00
|
|
|
function isDate(d) {
|
2015-12-01 16:27:39 +00:00
|
|
|
return binding.isDate(d);
|
2011-09-08 16:16:48 +00:00
|
|
|
}
|
2011-10-26 18:09:01 +00:00
|
|
|
exports.isDate = isDate;
|
2011-09-08 16:16:48 +00:00
|
|
|
|
2011-10-26 18:09:01 +00:00
|
|
|
exports.isError = isError;
|
2011-09-08 16:16:48 +00:00
|
|
|
|
2013-07-26 21:38:08 +00:00
|
|
|
function isFunction(arg) {
|
|
|
|
return typeof arg === 'function';
|
|
|
|
}
|
|
|
|
exports.isFunction = isFunction;
|
|
|
|
|
2013-08-02 19:52:34 +00:00
|
|
|
function isPrimitive(arg) {
|
2013-08-12 20:41:51 +00:00
|
|
|
return arg === null ||
|
2015-02-06 13:06:07 +00:00
|
|
|
typeof arg !== 'object' && typeof arg !== 'function';
|
2013-08-02 19:52:34 +00:00
|
|
|
}
|
|
|
|
exports.isPrimitive = isPrimitive;
|
|
|
|
|
2015-06-16 05:01:33 +00:00
|
|
|
exports.isBuffer = Buffer.isBuffer;
|
2011-09-08 16:16:48 +00:00
|
|
|
|
2010-12-02 04:59:06 +00:00
|
|
|
function pad(n) {
|
2010-10-11 21:04:09 +00:00
|
|
|
return n < 10 ? '0' + n.toString(10) : n.toString(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-21 16:36:59 +00:00
|
|
|
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
|
|
|
|
'Oct', 'Nov', 'Dec'];
|
2010-10-11 21:04:09 +00:00
|
|
|
|
|
|
|
// 26 Feb 16:19:34
|
2010-12-02 04:59:06 +00:00
|
|
|
function timestamp() {
|
2010-10-11 21:04:09 +00:00
|
|
|
var d = new Date();
|
2010-12-02 20:11:23 +00:00
|
|
|
var time = [pad(d.getHours()),
|
|
|
|
pad(d.getMinutes()),
|
|
|
|
pad(d.getSeconds())].join(':');
|
|
|
|
return [d.getDate(), months[d.getMonth()], time].join(' ');
|
2010-10-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-10 01:19:02 +00:00
|
|
|
// log is just a thin wrapper to console.log that prepends a timestamp
|
|
|
|
exports.log = function() {
|
|
|
|
console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
|
2010-10-11 21:04:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inherit the prototype methods from one constructor into another.
|
|
|
|
*
|
|
|
|
* The Function.prototype.inherits from lang.js rewritten as a standalone
|
|
|
|
* function (not on Function.prototype). NOTE: If this file is to be loaded
|
2012-02-18 05:28:13 +00:00
|
|
|
* during bootstrapping this function needs to be rewritten using some native
|
2010-10-11 21:04:09 +00:00
|
|
|
* functions as prototype setup using normal JavaScript does not work as
|
|
|
|
* expected during bootstrapping (see mirror.js in r114903).
|
|
|
|
*
|
|
|
|
* @param {function} ctor Constructor function which needs to inherit the
|
2010-12-02 04:59:06 +00:00
|
|
|
* prototype.
|
|
|
|
* @param {function} superCtor Constructor function to inherit prototype from.
|
2015-03-23 00:45:16 +00:00
|
|
|
* @throws {TypeError} Will error if either constructor is null, or if
|
|
|
|
* the super constructor lacks a prototype.
|
2010-10-11 21:04:09 +00:00
|
|
|
*/
|
2010-12-02 04:59:06 +00:00
|
|
|
exports.inherits = function(ctor, superCtor) {
|
2015-03-23 00:45:16 +00:00
|
|
|
|
|
|
|
if (ctor === undefined || ctor === null)
|
2015-10-14 21:10:25 +00:00
|
|
|
throw new TypeError('The constructor to "inherits" must not be ' +
|
|
|
|
'null or undefined');
|
2015-03-23 00:45:16 +00:00
|
|
|
|
|
|
|
if (superCtor === undefined || superCtor === null)
|
2015-10-14 21:10:25 +00:00
|
|
|
throw new TypeError('The super constructor to "inherits" must not ' +
|
|
|
|
'be null or undefined');
|
2015-03-23 00:45:16 +00:00
|
|
|
|
|
|
|
if (superCtor.prototype === undefined)
|
2015-10-14 21:10:25 +00:00
|
|
|
throw new TypeError('The super constructor to "inherits" must ' +
|
|
|
|
'have a prototype');
|
2015-03-23 00:45:16 +00:00
|
|
|
|
2010-12-02 20:11:23 +00:00
|
|
|
ctor.super_ = superCtor;
|
2015-10-20 19:39:49 +00:00
|
|
|
Object.setPrototypeOf(ctor.prototype, superCtor.prototype);
|
2010-10-11 21:04:09 +00:00
|
|
|
};
|
2012-02-20 17:59:56 +00:00
|
|
|
|
|
|
|
exports._extend = function(origin, add) {
|
|
|
|
// Don't do anything if add isn't an object
|
2015-01-29 01:05:53 +00:00
|
|
|
if (add === null || typeof add !== 'object') return origin;
|
2012-02-20 17:59:56 +00:00
|
|
|
|
|
|
|
var keys = Object.keys(add);
|
|
|
|
var i = keys.length;
|
|
|
|
while (i--) {
|
|
|
|
origin[keys[i]] = add[keys[i]];
|
|
|
|
}
|
|
|
|
return origin;
|
|
|
|
};
|
2012-09-08 22:09:59 +00:00
|
|
|
|
|
|
|
function hasOwnProperty(obj, prop) {
|
|
|
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
|
|
}
|
2013-05-21 22:22:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Deprecated old stuff.
|
|
|
|
|
2015-06-13 16:44:39 +00:00
|
|
|
exports.print = internalUtil.deprecate(function() {
|
2013-05-21 22:22:05 +00:00
|
|
|
for (var i = 0, len = arguments.length; i < len; ++i) {
|
|
|
|
process.stdout.write(String(arguments[i]));
|
|
|
|
}
|
2015-06-13 16:44:39 +00:00
|
|
|
}, 'util.print is deprecated. Use console.log instead.');
|
2013-05-21 22:22:05 +00:00
|
|
|
|
|
|
|
|
2015-06-13 16:44:39 +00:00
|
|
|
exports.puts = internalUtil.deprecate(function() {
|
2013-05-21 22:22:05 +00:00
|
|
|
for (var i = 0, len = arguments.length; i < len; ++i) {
|
2016-08-17 14:47:13 +00:00
|
|
|
process.stdout.write(arguments[i] + '\n');
|
2013-05-21 22:22:05 +00:00
|
|
|
}
|
2015-06-13 16:44:39 +00:00
|
|
|
}, 'util.puts is deprecated. Use console.log instead.');
|
2013-05-21 22:22:05 +00:00
|
|
|
|
|
|
|
|
2015-06-13 16:44:39 +00:00
|
|
|
exports.debug = internalUtil.deprecate(function(x) {
|
2016-08-17 14:47:13 +00:00
|
|
|
process.stderr.write('DEBUG: ' + x + '\n');
|
2015-06-13 16:44:39 +00:00
|
|
|
}, 'util.debug is deprecated. Use console.error instead.');
|
2013-05-21 22:22:05 +00:00
|
|
|
|
|
|
|
|
2015-06-13 16:44:39 +00:00
|
|
|
exports.error = internalUtil.deprecate(function(x) {
|
2013-05-21 22:22:05 +00:00
|
|
|
for (var i = 0, len = arguments.length; i < len; ++i) {
|
2016-08-17 14:47:13 +00:00
|
|
|
process.stderr.write(arguments[i] + '\n');
|
2013-05-21 22:22:05 +00:00
|
|
|
}
|
2015-06-13 16:44:39 +00:00
|
|
|
}, 'util.error is deprecated. Use console.error instead.');
|
2013-05-21 22:22:05 +00:00
|
|
|
|
|
|
|
|
2014-01-24 18:08:25 +00:00
|
|
|
exports._errnoException = function(err, syscall, original) {
|
2013-07-16 21:28:38 +00:00
|
|
|
var errname = uv.errname(err);
|
2014-01-24 18:08:25 +00:00
|
|
|
var message = syscall + ' ' + errname;
|
|
|
|
if (original)
|
|
|
|
message += ' ' + original;
|
|
|
|
var e = new Error(message);
|
2013-07-16 21:28:38 +00:00
|
|
|
e.code = errname;
|
|
|
|
e.errno = errname;
|
|
|
|
e.syscall = syscall;
|
|
|
|
return e;
|
|
|
|
};
|
2015-01-08 00:03:24 +00:00
|
|
|
|
|
|
|
|
2015-01-08 19:13:56 +00:00
|
|
|
exports._exceptionWithHostPort = function(err,
|
|
|
|
syscall,
|
|
|
|
address,
|
|
|
|
port,
|
|
|
|
additional) {
|
2015-01-08 00:03:24 +00:00
|
|
|
var details;
|
|
|
|
if (port && port > 0) {
|
|
|
|
details = address + ':' + port;
|
|
|
|
} else {
|
|
|
|
details = address;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (additional) {
|
|
|
|
details += ' - Local (' + additional + ')';
|
|
|
|
}
|
|
|
|
var ex = exports._errnoException(err, syscall, details);
|
|
|
|
ex.address = address;
|
|
|
|
if (port) {
|
|
|
|
ex.port = port;
|
|
|
|
}
|
|
|
|
return ex;
|
|
|
|
};
|