2015-05-28 17:01:56 +03:00
|
|
|
'use strict';
|
|
|
|
|
2019-04-09 09:55:53 +02:00
|
|
|
const { Object, Reflect } = primordials;
|
2019-03-31 13:30:12 +02:00
|
|
|
|
2018-03-04 22:16:24 +01:00
|
|
|
const {
|
|
|
|
ERR_INVALID_ARG_TYPE,
|
|
|
|
ERR_NO_CRYPTO,
|
|
|
|
ERR_UNKNOWN_SIGNAL
|
|
|
|
} = require('internal/errors').codes;
|
2018-10-15 01:41:32 +02:00
|
|
|
const { signals } = internalBinding('constants').os;
|
2017-10-26 21:34:15 -07:00
|
|
|
const {
|
|
|
|
getHiddenValue,
|
|
|
|
setHiddenValue,
|
|
|
|
arrow_message_private_symbol: kArrowMessagePrivateSymbolIndex,
|
|
|
|
decorated_private_symbol: kDecoratedPrivateSymbolIndex
|
2018-09-03 11:16:48 -04:00
|
|
|
} = internalBinding('util');
|
2019-03-19 13:09:42 +08:00
|
|
|
const { isNativeError } = internalBinding('types');
|
2018-08-06 14:40:30 -07:00
|
|
|
|
2017-02-15 13:00:21 -08:00
|
|
|
const noCrypto = !process.versions.openssl;
|
2016-05-31 19:58:31 +02:00
|
|
|
|
2017-10-25 12:11:10 -07:00
|
|
|
const experimentalWarnings = new Set();
|
|
|
|
|
2018-03-21 22:42:35 -07:00
|
|
|
const colorRegExp = /\u001b\[\d\d?m/g; // eslint-disable-line no-control-regex
|
2017-12-11 06:32:59 -02:00
|
|
|
|
|
|
|
function removeColors(str) {
|
|
|
|
return str.replace(colorRegExp, '');
|
|
|
|
}
|
|
|
|
|
2017-02-15 13:00:21 -08:00
|
|
|
function isError(e) {
|
2018-11-18 04:19:16 +01:00
|
|
|
// An error could be an instance of Error while not being a native error
|
|
|
|
// or could be from a different realm and not be instance of Error but still
|
|
|
|
// be a native error.
|
|
|
|
return isNativeError(e) || e instanceof Error;
|
2017-02-15 13:00:21 -08:00
|
|
|
}
|
|
|
|
|
2017-10-22 12:26:32 -07:00
|
|
|
// Keep a list of deprecation codes that have been warned on so we only warn on
|
|
|
|
// each one once.
|
|
|
|
const codesWarned = {};
|
|
|
|
|
2015-06-15 21:51:41 -07:00
|
|
|
// Mark that a method should not be used.
|
|
|
|
// Returns a modified function which warns once by default.
|
|
|
|
// If --no-deprecation is set, then it is a no-op.
|
2017-02-15 13:00:21 -08:00
|
|
|
function deprecate(fn, msg, code) {
|
2015-06-15 21:51:41 -07:00
|
|
|
if (process.noDeprecation === true) {
|
|
|
|
return fn;
|
|
|
|
}
|
|
|
|
|
2016-12-04 12:47:01 -08:00
|
|
|
if (code !== undefined && typeof code !== 'string')
|
2018-03-19 13:33:46 +01:00
|
|
|
throw new ERR_INVALID_ARG_TYPE('code', 'string', code);
|
2016-12-04 12:47:01 -08:00
|
|
|
|
2018-02-16 07:28:38 -05:00
|
|
|
let warned = false;
|
2017-02-15 13:00:21 -08:00
|
|
|
function deprecated(...args) {
|
2016-08-18 11:51:10 -07:00
|
|
|
if (!warned) {
|
|
|
|
warned = true;
|
2016-12-04 12:47:01 -08:00
|
|
|
if (code !== undefined) {
|
2017-10-22 12:26:32 -07:00
|
|
|
if (!codesWarned[code]) {
|
|
|
|
process.emitWarning(msg, 'DeprecationWarning', code, deprecated);
|
|
|
|
codesWarned[code] = true;
|
|
|
|
}
|
2016-12-04 12:47:01 -08:00
|
|
|
} else {
|
|
|
|
process.emitWarning(msg, 'DeprecationWarning', deprecated);
|
|
|
|
}
|
2016-08-18 11:51:10 -07:00
|
|
|
}
|
2016-07-12 23:09:12 +02:00
|
|
|
if (new.target) {
|
2017-02-15 13:00:21 -08:00
|
|
|
return Reflect.construct(fn, args, new.target);
|
2016-07-12 23:09:12 +02:00
|
|
|
}
|
2017-02-15 13:00:21 -08:00
|
|
|
return fn.apply(this, args);
|
2015-06-15 21:51:41 -07:00
|
|
|
}
|
|
|
|
|
2016-07-12 23:09:12 +02:00
|
|
|
// The wrapper will keep the same prototype as fn to maintain prototype chain
|
|
|
|
Object.setPrototypeOf(deprecated, fn);
|
|
|
|
if (fn.prototype) {
|
2016-08-14 15:27:40 -07:00
|
|
|
// Setting this (rather than using Object.setPrototype, as above) ensures
|
|
|
|
// that calling the unwrapped constructor gives an instanceof the wrapped
|
|
|
|
// constructor.
|
|
|
|
deprecated.prototype = fn.prototype;
|
2016-07-12 23:09:12 +02:00
|
|
|
}
|
|
|
|
|
2015-06-15 21:51:41 -07:00
|
|
|
return deprecated;
|
2017-02-15 13:00:21 -08:00
|
|
|
}
|
2015-11-25 22:37:43 +01:00
|
|
|
|
2017-02-15 13:00:21 -08:00
|
|
|
function decorateErrorStack(err) {
|
|
|
|
if (!(isError(err) && err.stack) ||
|
2017-10-26 21:34:15 -07:00
|
|
|
getHiddenValue(err, kDecoratedPrivateSymbolIndex) === true)
|
2015-11-25 22:37:43 +01:00
|
|
|
return;
|
|
|
|
|
2017-10-26 21:34:15 -07:00
|
|
|
const arrow = getHiddenValue(err, kArrowMessagePrivateSymbolIndex);
|
2015-11-25 22:37:43 +01:00
|
|
|
|
2015-12-15 03:55:35 -05:00
|
|
|
if (arrow) {
|
2015-11-25 22:37:43 +01:00
|
|
|
err.stack = arrow + err.stack;
|
2017-10-26 21:34:15 -07:00
|
|
|
setHiddenValue(err, kDecoratedPrivateSymbolIndex, true);
|
2015-12-15 03:55:35 -05:00
|
|
|
}
|
2017-02-15 13:00:21 -08:00
|
|
|
}
|
2016-03-08 15:31:31 -08:00
|
|
|
|
2017-02-15 13:00:21 -08:00
|
|
|
function assertCrypto() {
|
2016-03-08 15:31:31 -08:00
|
|
|
if (noCrypto)
|
2018-03-04 22:16:24 +01:00
|
|
|
throw new ERR_NO_CRYPTO();
|
2017-02-15 13:00:21 -08:00
|
|
|
}
|
2016-12-25 03:32:26 +08:00
|
|
|
|
|
|
|
// Return undefined if there is no match.
|
2018-02-14 23:48:35 +01:00
|
|
|
// Move the "slow cases" to a separate function to make sure this function gets
|
|
|
|
// inlined properly. That prioritizes the common case.
|
2017-02-15 13:00:21 -08:00
|
|
|
function normalizeEncoding(enc) {
|
2018-02-14 23:48:35 +01:00
|
|
|
if (enc == null || enc === 'utf8' || enc === 'utf-8') return 'utf8';
|
|
|
|
return slowCases(enc);
|
|
|
|
}
|
|
|
|
|
|
|
|
function slowCases(enc) {
|
|
|
|
switch (enc.length) {
|
|
|
|
case 4:
|
|
|
|
if (enc === 'UTF8') return 'utf8';
|
|
|
|
if (enc === 'ucs2' || enc === 'UCS2') return 'utf16le';
|
|
|
|
enc = `${enc}`.toLowerCase();
|
|
|
|
if (enc === 'utf8') return 'utf8';
|
2018-06-22 19:08:58 +08:00
|
|
|
if (enc === 'ucs2') return 'utf16le';
|
2018-02-14 23:48:35 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (enc === 'hex' || enc === 'HEX' || `${enc}`.toLowerCase() === 'hex')
|
|
|
|
return 'hex';
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
if (enc === 'ascii') return 'ascii';
|
|
|
|
if (enc === 'ucs-2') return 'utf16le';
|
|
|
|
if (enc === 'UTF-8') return 'utf8';
|
|
|
|
if (enc === 'ASCII') return 'ascii';
|
|
|
|
if (enc === 'UCS-2') return 'utf16le';
|
|
|
|
enc = `${enc}`.toLowerCase();
|
|
|
|
if (enc === 'utf-8') return 'utf8';
|
|
|
|
if (enc === 'ascii') return 'ascii';
|
2018-06-22 19:08:58 +08:00
|
|
|
if (enc === 'ucs-2') return 'utf16le';
|
2018-02-14 23:48:35 +01:00
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
if (enc === 'base64') return 'base64';
|
|
|
|
if (enc === 'latin1' || enc === 'binary') return 'latin1';
|
|
|
|
if (enc === 'BASE64') return 'base64';
|
|
|
|
if (enc === 'LATIN1' || enc === 'BINARY') return 'latin1';
|
|
|
|
enc = `${enc}`.toLowerCase();
|
|
|
|
if (enc === 'base64') return 'base64';
|
|
|
|
if (enc === 'latin1' || enc === 'binary') return 'latin1';
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
if (enc === 'utf16le' || enc === 'UTF16LE' ||
|
|
|
|
`${enc}`.toLowerCase() === 'utf16le')
|
2016-06-07 16:03:27 -07:00
|
|
|
return 'utf16le';
|
2018-02-14 23:48:35 +01:00
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
if (enc === 'utf-16le' || enc === 'UTF-16LE' ||
|
|
|
|
`${enc}`.toLowerCase() === 'utf-16le')
|
|
|
|
return 'utf16le';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (enc === '') return 'utf8';
|
2016-06-07 16:03:27 -07:00
|
|
|
}
|
2017-02-15 13:00:21 -08:00
|
|
|
}
|
2016-06-08 08:18:26 -07:00
|
|
|
|
2017-10-25 12:11:10 -07:00
|
|
|
function emitExperimentalWarning(feature) {
|
|
|
|
if (experimentalWarnings.has(feature)) return;
|
|
|
|
const msg = `${feature} is an experimental feature. This feature could ` +
|
|
|
|
'change at any time';
|
|
|
|
experimentalWarnings.add(feature);
|
|
|
|
process.emitWarning(msg, 'ExperimentalWarning');
|
|
|
|
}
|
|
|
|
|
2017-02-15 13:00:21 -08:00
|
|
|
function filterDuplicateStrings(items, low) {
|
2016-06-08 08:18:26 -07:00
|
|
|
const map = new Map();
|
2017-01-07 20:12:08 -08:00
|
|
|
for (var i = 0; i < items.length; i++) {
|
2016-06-08 08:18:26 -07:00
|
|
|
const item = items[i];
|
|
|
|
const key = item.toLowerCase();
|
|
|
|
if (low) {
|
|
|
|
map.set(key, key);
|
|
|
|
} else {
|
2017-01-07 20:12:08 -08:00
|
|
|
map.set(key, item);
|
2016-06-08 08:18:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return Array.from(map.values()).sort();
|
2017-02-15 13:00:21 -08:00
|
|
|
}
|
2016-06-08 08:18:26 -07:00
|
|
|
|
2017-02-15 13:00:21 -08:00
|
|
|
function cachedResult(fn) {
|
2018-02-16 07:28:38 -05:00
|
|
|
let result;
|
2016-06-08 08:18:26 -07:00
|
|
|
return () => {
|
|
|
|
if (result === undefined)
|
|
|
|
result = fn();
|
2017-01-13 14:28:35 -08:00
|
|
|
return result.slice();
|
2016-06-08 08:18:26 -07:00
|
|
|
};
|
2017-02-15 13:00:21 -08:00
|
|
|
}
|
buffer: convert offset & length to int properly
As per ecma-262 2015's #sec-%typedarray%-buffer-byteoffset-length,
`offset` would be an integer, not a 32 bit unsigned integer. Also,
`length` would be an integer with the maximum value of 2^53 - 1, not a
32 bit unsigned integer.
This would be a problem because, if we create a buffer from an
arraybuffer, from an offset which is greater than 2^32, it would be
actually pointing to a different location in arraybuffer. For example,
if we use 2^40 as offset, then the actual value used will be 0,
because `byteOffset >>>= 0` will convert `byteOffset` to a 32 bit
unsigned int, which is based on 2^32 modulo.
This is a redo, as the ca37fa527f174b547893817fe8c67a3befa02317 broke
CI.
Refer: https://github.com/nodejs/node/pull/9814
Refer: https://github.com/nodejs/node/pull/9492
PR-URL: https://github.com/nodejs/node/pull/9815
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2016-11-27 15:08:17 +05:30
|
|
|
|
2017-02-15 07:43:22 -08:00
|
|
|
// Useful for Wrapping an ES6 Class with a constructor Function that
|
|
|
|
// does not require the new keyword. For instance:
|
|
|
|
// class A { constructor(x) {this.x = x;}}
|
|
|
|
// const B = createClassWrapper(A);
|
|
|
|
// B() instanceof A // true
|
|
|
|
// B() instanceof B // true
|
2017-02-15 13:00:21 -08:00
|
|
|
function createClassWrapper(type) {
|
2017-04-27 17:27:05 -07:00
|
|
|
function fn(...args) {
|
2017-02-15 07:43:22 -08:00
|
|
|
return Reflect.construct(type, args, new.target || type);
|
2017-04-27 17:27:05 -07:00
|
|
|
}
|
2017-02-15 07:43:22 -08:00
|
|
|
// Mask the wrapper function name and length values
|
|
|
|
Object.defineProperties(fn, {
|
2017-07-10 20:55:21 -04:00
|
|
|
name: { value: type.name },
|
|
|
|
length: { value: type.length }
|
2017-02-15 07:43:22 -08:00
|
|
|
});
|
|
|
|
Object.setPrototypeOf(fn, type);
|
|
|
|
fn.prototype = type.prototype;
|
|
|
|
return fn;
|
2017-02-15 13:00:21 -08:00
|
|
|
}
|
2016-12-23 14:36:20 +05:30
|
|
|
|
|
|
|
let signalsToNamesMapping;
|
|
|
|
function getSignalsToNamesMapping() {
|
|
|
|
if (signalsToNamesMapping !== undefined)
|
|
|
|
return signalsToNamesMapping;
|
|
|
|
|
|
|
|
signalsToNamesMapping = Object.create(null);
|
2019-03-26 05:21:27 +01:00
|
|
|
for (const key in signals) {
|
2016-12-23 14:36:20 +05:30
|
|
|
signalsToNamesMapping[signals[key]] = key;
|
|
|
|
}
|
|
|
|
|
|
|
|
return signalsToNamesMapping;
|
|
|
|
}
|
|
|
|
|
2017-02-15 13:00:21 -08:00
|
|
|
function convertToValidSignal(signal) {
|
2016-12-23 14:36:20 +05:30
|
|
|
if (typeof signal === 'number' && getSignalsToNamesMapping()[signal])
|
|
|
|
return signal;
|
|
|
|
|
|
|
|
if (typeof signal === 'string') {
|
|
|
|
const signalName = signals[signal.toUpperCase()];
|
|
|
|
if (signalName) return signalName;
|
|
|
|
}
|
|
|
|
|
2018-03-04 22:16:24 +01:00
|
|
|
throw new ERR_UNKNOWN_SIGNAL(signal);
|
2017-02-15 13:00:21 -08:00
|
|
|
}
|
|
|
|
|
2017-04-19 23:07:39 -07:00
|
|
|
function getConstructorOf(obj) {
|
|
|
|
while (obj) {
|
2018-02-16 07:28:38 -05:00
|
|
|
const descriptor = Object.getOwnPropertyDescriptor(obj, 'constructor');
|
2017-04-19 23:07:39 -07:00
|
|
|
if (descriptor !== undefined &&
|
|
|
|
typeof descriptor.value === 'function' &&
|
|
|
|
descriptor.value.name !== '') {
|
|
|
|
return descriptor.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj = Object.getPrototypeOf(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-12-20 05:33:10 +08:00
|
|
|
let uvBinding;
|
|
|
|
function lazyErrmapGet(name) {
|
|
|
|
if (!uvBinding) {
|
|
|
|
uvBinding = internalBinding('uv');
|
|
|
|
}
|
|
|
|
if (!uvBinding.errmap) {
|
|
|
|
uvBinding.errmap = uvBinding.getErrorMap();
|
|
|
|
}
|
|
|
|
return uvBinding.errmap.get(name);
|
|
|
|
}
|
|
|
|
|
2018-01-17 03:21:16 +08:00
|
|
|
function getSystemErrorName(err) {
|
2018-12-20 05:33:10 +08:00
|
|
|
const entry = lazyErrmapGet(err);
|
2018-01-17 03:21:16 +08:00
|
|
|
return entry ? entry[0] : `Unknown system error ${err}`;
|
|
|
|
}
|
|
|
|
|
2017-04-14 18:28:16 +02:00
|
|
|
const kCustomPromisifiedSymbol = Symbol('util.promisify.custom');
|
|
|
|
const kCustomPromisifyArgsSymbol = Symbol('customPromisifyArgs');
|
|
|
|
|
2017-06-20 23:20:10 +02:00
|
|
|
function promisify(original) {
|
|
|
|
if (typeof original !== 'function')
|
2018-03-19 13:33:46 +01:00
|
|
|
throw new ERR_INVALID_ARG_TYPE('original', 'Function', original);
|
2017-04-14 18:28:16 +02:00
|
|
|
|
2017-06-20 23:20:10 +02:00
|
|
|
if (original[kCustomPromisifiedSymbol]) {
|
|
|
|
const fn = original[kCustomPromisifiedSymbol];
|
2017-04-14 18:28:16 +02:00
|
|
|
if (typeof fn !== 'function') {
|
2018-03-04 22:16:24 +01:00
|
|
|
throw new ERR_INVALID_ARG_TYPE('util.promisify.custom', 'Function', fn);
|
2017-04-14 18:28:16 +02:00
|
|
|
}
|
2018-12-21 18:32:02 +09:00
|
|
|
return Object.defineProperty(fn, kCustomPromisifiedSymbol, {
|
2017-04-14 18:28:16 +02:00
|
|
|
value: fn, enumerable: false, writable: false, configurable: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Names to create an object from in case the callback receives multiple
|
2019-01-03 22:12:40 +09:00
|
|
|
// arguments, e.g. ['bytesRead', 'buffer'] for fs.read.
|
2017-06-20 23:20:10 +02:00
|
|
|
const argumentNames = original[kCustomPromisifyArgsSymbol];
|
2017-04-14 18:28:16 +02:00
|
|
|
|
|
|
|
function fn(...args) {
|
2018-05-19 00:25:07 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
2017-06-20 23:20:10 +02:00
|
|
|
original.call(this, ...args, (err, ...values) => {
|
2017-04-14 18:28:16 +02:00
|
|
|
if (err) {
|
2018-05-19 00:25:07 +02:00
|
|
|
return reject(err);
|
|
|
|
}
|
|
|
|
if (argumentNames !== undefined && values.length > 1) {
|
2017-04-14 18:28:16 +02:00
|
|
|
const obj = {};
|
|
|
|
for (var i = 0; i < argumentNames.length; i++)
|
|
|
|
obj[argumentNames[i]] = values[i];
|
2018-05-19 00:25:07 +02:00
|
|
|
resolve(obj);
|
2017-04-14 18:28:16 +02:00
|
|
|
} else {
|
2018-05-19 00:25:07 +02:00
|
|
|
resolve(values[0]);
|
2017-04-14 18:28:16 +02:00
|
|
|
}
|
|
|
|
});
|
2018-05-19 00:25:07 +02:00
|
|
|
});
|
2017-04-14 18:28:16 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 23:20:10 +02:00
|
|
|
Object.setPrototypeOf(fn, Object.getPrototypeOf(original));
|
2017-04-14 18:28:16 +02:00
|
|
|
|
|
|
|
Object.defineProperty(fn, kCustomPromisifiedSymbol, {
|
|
|
|
value: fn, enumerable: false, writable: false, configurable: true
|
|
|
|
});
|
2017-06-20 23:20:10 +02:00
|
|
|
return Object.defineProperties(
|
|
|
|
fn,
|
|
|
|
Object.getOwnPropertyDescriptors(original)
|
|
|
|
);
|
2017-04-14 18:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
promisify.custom = kCustomPromisifiedSymbol;
|
|
|
|
|
2017-08-21 23:20:59 -03:00
|
|
|
// The build-in Array#join is slower in v8 6.0
|
|
|
|
function join(output, separator) {
|
2018-02-16 07:28:38 -05:00
|
|
|
let str = '';
|
2017-08-21 23:20:59 -03:00
|
|
|
if (output.length !== 0) {
|
|
|
|
for (var i = 0; i < output.length - 1; i++) {
|
|
|
|
// It is faster not to use a template string here
|
|
|
|
str += output[i];
|
|
|
|
str += separator;
|
|
|
|
}
|
|
|
|
str += output[i];
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2018-05-01 14:22:39 +02:00
|
|
|
// As of V8 6.6, depending on the size of the array, this is anywhere
|
|
|
|
// between 1.5-10x faster than the two-arg version of Array#splice()
|
2017-10-15 23:59:53 +08:00
|
|
|
function spliceOne(list, index) {
|
2018-05-01 14:22:39 +02:00
|
|
|
for (; index + 1 < list.length; index++)
|
|
|
|
list[index] = list[index + 1];
|
2017-10-15 23:59:53 +08:00
|
|
|
list.pop();
|
|
|
|
}
|
|
|
|
|
2018-03-22 00:30:21 +01:00
|
|
|
const kNodeModulesRE = /^(.*)[\\/]node_modules[\\/]/;
|
|
|
|
|
|
|
|
let getStructuredStack;
|
|
|
|
|
|
|
|
function isInsideNodeModules() {
|
|
|
|
if (getStructuredStack === undefined) {
|
|
|
|
// Lazy-load to avoid a circular dependency.
|
|
|
|
const { runInNewContext } = require('vm');
|
|
|
|
// Use `runInNewContext()` to get something tamper-proof and
|
|
|
|
// side-effect-free. Since this is currently only used for a deprecated API,
|
|
|
|
// the perf implications should be okay.
|
2018-04-14 19:01:37 +02:00
|
|
|
getStructuredStack = runInNewContext(`(function() {
|
2018-03-22 00:30:21 +01:00
|
|
|
Error.prepareStackTrace = function(err, trace) {
|
2019-04-16 08:55:44 +02:00
|
|
|
return trace;
|
2018-03-22 00:30:21 +01:00
|
|
|
};
|
|
|
|
Error.stackTraceLimit = Infinity;
|
|
|
|
|
|
|
|
return function structuredStack() {
|
|
|
|
return new Error().stack;
|
|
|
|
};
|
2018-04-14 19:01:37 +02:00
|
|
|
})()`, {}, { filename: 'structured-stack' });
|
2018-03-22 00:30:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const stack = getStructuredStack();
|
|
|
|
|
|
|
|
// Iterate over all stack frames and look for the first one not coming
|
|
|
|
// from inside Node.js itself:
|
2018-04-25 00:56:35 +02:00
|
|
|
if (Array.isArray(stack)) {
|
|
|
|
for (const frame of stack) {
|
|
|
|
const filename = frame.getFileName();
|
|
|
|
// If a filename does not start with / or contain \,
|
|
|
|
// it's likely from Node.js core.
|
|
|
|
if (!/^\/|\\/.test(filename))
|
|
|
|
continue;
|
|
|
|
return kNodeModulesRE.test(filename);
|
|
|
|
}
|
2018-03-22 00:30:21 +01:00
|
|
|
}
|
2018-04-25 00:56:35 +02:00
|
|
|
return false;
|
2018-03-22 00:30:21 +01:00
|
|
|
}
|
|
|
|
|
2018-09-10 09:57:15 -04:00
|
|
|
function once(callback) {
|
|
|
|
let called = false;
|
|
|
|
return function(...args) {
|
|
|
|
if (called) return;
|
|
|
|
called = true;
|
2018-12-12 14:32:26 +01:00
|
|
|
callback.apply(this, args);
|
2018-09-10 09:57:15 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-05-12 08:37:32 -07:00
|
|
|
module.exports = {
|
|
|
|
assertCrypto,
|
|
|
|
cachedResult,
|
|
|
|
convertToValidSignal,
|
|
|
|
createClassWrapper,
|
|
|
|
decorateErrorStack,
|
|
|
|
deprecate,
|
2017-10-25 12:11:10 -07:00
|
|
|
emitExperimentalWarning,
|
2017-05-12 08:37:32 -07:00
|
|
|
filterDuplicateStrings,
|
|
|
|
getConstructorOf,
|
2018-01-17 03:21:16 +08:00
|
|
|
getSystemErrorName,
|
2017-05-12 08:37:32 -07:00
|
|
|
isError,
|
2018-03-22 00:30:21 +01:00
|
|
|
isInsideNodeModules,
|
2017-10-15 23:59:53 +08:00
|
|
|
join,
|
2017-05-12 08:37:32 -07:00
|
|
|
normalizeEncoding,
|
2018-09-10 09:57:15 -04:00
|
|
|
once,
|
2017-05-12 08:37:32 -07:00
|
|
|
promisify,
|
2017-10-15 23:59:53 +08:00
|
|
|
spliceOne,
|
2017-12-11 06:32:59 -02:00
|
|
|
removeColors,
|
2017-05-12 08:37:32 -07:00
|
|
|
|
|
|
|
// Symbol used to customize promisify conversion
|
|
|
|
customPromisifyArgs: kCustomPromisifyArgsSymbol,
|
|
|
|
|
|
|
|
// Symbol used to provide a custom inspect function for an object as an
|
|
|
|
// alternative to using 'inspect'
|
2018-05-20 21:27:34 +01:00
|
|
|
customInspectSymbol: Symbol.for('nodejs.util.inspect.custom'),
|
2017-05-12 08:37:32 -07:00
|
|
|
|
|
|
|
// Used by the buffer module to capture an internal reference to the
|
|
|
|
// default isEncoding implementation, just in case userland overrides it.
|
2018-02-26 15:46:50 +01:00
|
|
|
kIsEncodingSymbol: Symbol('kIsEncodingSymbol'),
|
2019-01-30 23:13:45 +01:00
|
|
|
kExpandStackSymbol: Symbol('kExpandStackSymbol'),
|
|
|
|
kVmBreakFirstLineSymbol: Symbol('kVmBreakFirstLineSymbol')
|
2017-05-12 08:37:32 -07:00
|
|
|
};
|