2015-05-28 17:01:56 +03:00
|
|
|
'use strict';
|
|
|
|
|
2019-11-22 18:04:46 +01:00
|
|
|
const {
|
2022-11-26 22:14:57 -05:00
|
|
|
ArrayBufferPrototypeGetByteLength,
|
2019-11-23 10:09:05 +01:00
|
|
|
ArrayFrom,
|
|
|
|
ArrayIsArray,
|
2020-11-16 16:39:28 +01:00
|
|
|
ArrayPrototypePush,
|
|
|
|
ArrayPrototypeSlice,
|
|
|
|
ArrayPrototypeSort,
|
2020-01-02 19:19:02 +01:00
|
|
|
Error,
|
2022-08-05 10:01:32 +02:00
|
|
|
FunctionPrototypeCall,
|
2019-11-22 18:04:46 +01:00
|
|
|
ObjectDefineProperties,
|
|
|
|
ObjectDefineProperty,
|
|
|
|
ObjectGetOwnPropertyDescriptor,
|
|
|
|
ObjectGetOwnPropertyDescriptors,
|
|
|
|
ObjectGetPrototypeOf,
|
2022-05-21 17:48:37 +08:00
|
|
|
ObjectFreeze,
|
2022-08-05 00:41:48 +02:00
|
|
|
ObjectPrototypeHasOwnProperty,
|
2019-11-22 18:04:46 +01:00
|
|
|
ObjectSetPrototypeOf,
|
2022-08-17 20:36:33 +02:00
|
|
|
ObjectValues,
|
2019-12-13 16:46:35 +01:00
|
|
|
Promise,
|
2020-11-16 16:39:28 +01:00
|
|
|
ReflectApply,
|
2019-11-22 18:04:46 +01:00
|
|
|
ReflectConstruct,
|
2021-08-19 21:40:18 +02:00
|
|
|
RegExpPrototypeExec,
|
2022-12-14 15:48:50 +01:00
|
|
|
RegExpPrototypeGetDotAll,
|
|
|
|
RegExpPrototypeGetGlobal,
|
|
|
|
RegExpPrototypeGetHasIndices,
|
|
|
|
RegExpPrototypeGetIgnoreCase,
|
|
|
|
RegExpPrototypeGetMultiline,
|
|
|
|
RegExpPrototypeGetSticky,
|
|
|
|
RegExpPrototypeGetUnicode,
|
|
|
|
RegExpPrototypeGetSource,
|
2020-11-16 16:39:28 +01:00
|
|
|
SafeMap,
|
|
|
|
SafeSet,
|
2022-12-14 15:48:50 +01:00
|
|
|
SafeWeakMap,
|
2020-11-16 16:39:28 +01:00
|
|
|
StringPrototypeReplace,
|
|
|
|
StringPrototypeToLowerCase,
|
|
|
|
StringPrototypeToUpperCase,
|
2019-11-30 16:55:29 +01:00
|
|
|
Symbol,
|
2019-12-08 18:33:33 +01:00
|
|
|
SymbolFor,
|
2022-12-14 15:48:50 +01:00
|
|
|
SymbolReplace,
|
|
|
|
SymbolSplit,
|
2019-11-22 18:04:46 +01:00
|
|
|
} = primordials;
|
2019-11-30 16:55:29 +01:00
|
|
|
|
2018-03-04 22:16:24 +01:00
|
|
|
const {
|
2021-06-21 11:34:48 +08:00
|
|
|
hideStackFrames,
|
2019-08-23 15:47:40 -04:00
|
|
|
codes: {
|
|
|
|
ERR_NO_CRYPTO,
|
2023-02-26 11:34:02 +01:00
|
|
|
ERR_UNKNOWN_SIGNAL,
|
2019-08-23 15:47:40 -04:00
|
|
|
},
|
2019-09-16 15:32:15 -05:00
|
|
|
uvErrmapGet,
|
|
|
|
overrideStackTrace,
|
2019-08-23 15:47:40 -04:00
|
|
|
} = require('internal/errors');
|
2018-10-15 01:41:32 +02:00
|
|
|
const { signals } = internalBinding('constants').os;
|
2017-10-26 21:34:15 -07:00
|
|
|
const {
|
2022-11-26 22:14:57 -05:00
|
|
|
isArrayBufferDetached: _isArrayBufferDetached,
|
2022-11-04 18:33:03 +01:00
|
|
|
privateSymbols: {
|
|
|
|
arrow_message_private_symbol,
|
|
|
|
decorated_private_symbol,
|
|
|
|
},
|
2021-09-24 13:59:45 +08:00
|
|
|
sleep: _sleep,
|
|
|
|
toUSVString: _toUSVString,
|
2018-09-03 11:16:48 -04:00
|
|
|
} = internalBinding('util');
|
2019-03-19 13:09:42 +08:00
|
|
|
const { isNativeError } = internalBinding('types');
|
2023-04-05 13:13:23 +02:00
|
|
|
const { getOptionValue } = require('internal/options');
|
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
|
|
|
|
2020-11-16 16:39:28 +01:00
|
|
|
const experimentalWarnings = new SafeSet();
|
2017-10-25 12:11:10 -07:00
|
|
|
|
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
|
|
|
|
2023-04-01 06:29:16 -04:00
|
|
|
const unpairedSurrogateRe =
|
|
|
|
/(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])/;
|
2021-08-19 21:40:18 +02:00
|
|
|
function toUSVString(val) {
|
2023-04-01 06:29:16 -04:00
|
|
|
const str = `${val}`;
|
|
|
|
// As of V8 5.5, `str.search()` (and `unpairedSurrogateRe[@@search]()`) are
|
|
|
|
// slower than `unpairedSurrogateRe.exec()`.
|
|
|
|
const match = RegExpPrototypeExec(unpairedSurrogateRe, str);
|
|
|
|
if (!match)
|
|
|
|
return str;
|
|
|
|
return _toUSVString(str, match.index);
|
2021-08-19 21:40:18 +02:00
|
|
|
}
|
|
|
|
|
2021-04-06 00:18:34 +03:00
|
|
|
let uvBinding;
|
|
|
|
|
|
|
|
function lazyUv() {
|
|
|
|
uvBinding ??= internalBinding('uv');
|
|
|
|
return uvBinding;
|
|
|
|
}
|
|
|
|
|
2017-12-11 06:32:59 -02:00
|
|
|
function removeColors(str) {
|
2020-11-16 16:39:28 +01:00
|
|
|
return StringPrototypeReplace(str, colorRegExp, '');
|
2017-12-11 06:32:59 -02:00
|
|
|
}
|
|
|
|
|
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.
|
2020-11-16 16:39:28 +01:00
|
|
|
const codesWarned = new SafeSet();
|
2017-10-22 12:26:32 -07:00
|
|
|
|
2021-08-05 18:12:21 +04:30
|
|
|
let validateString;
|
|
|
|
|
2023-04-05 13:13:23 +02:00
|
|
|
function getDeprecationWarningEmitter(
|
|
|
|
code, msg, deprecated, useEmitSync,
|
|
|
|
shouldEmitWarning = () => true,
|
|
|
|
) {
|
|
|
|
let warned = false;
|
|
|
|
return function() {
|
|
|
|
if (!warned && shouldEmitWarning()) {
|
|
|
|
warned = true;
|
|
|
|
if (code !== undefined) {
|
|
|
|
if (!codesWarned.has(code)) {
|
|
|
|
const emitWarning = useEmitSync ?
|
|
|
|
require('internal/process/warning').emitWarningSync :
|
|
|
|
process.emitWarning;
|
|
|
|
emitWarning(msg, 'DeprecationWarning', code, deprecated);
|
|
|
|
codesWarned.add(code);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
process.emitWarning(msg, 'DeprecationWarning', deprecated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function isPendingDeprecation() {
|
|
|
|
return getOptionValue('--pending-deprecation') &&
|
|
|
|
!getOptionValue('--no-deprecation');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Internal deprecator for pending --pending-deprecation. This can be invoked
|
|
|
|
// at snapshot building time as the warning permission is only queried at
|
|
|
|
// run time.
|
|
|
|
function pendingDeprecate(fn, msg, code) {
|
|
|
|
const emitDeprecationWarning = getDeprecationWarningEmitter(
|
|
|
|
code, msg, deprecated, false, isPendingDeprecation,
|
|
|
|
);
|
|
|
|
function deprecated(...args) {
|
|
|
|
emitDeprecationWarning();
|
|
|
|
return ReflectApply(fn, this, args);
|
|
|
|
}
|
|
|
|
return deprecated;
|
|
|
|
}
|
|
|
|
|
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.
|
2022-10-07 22:26:12 +09:00
|
|
|
function deprecate(fn, msg, code, useEmitSync) {
|
2015-06-15 21:51:41 -07:00
|
|
|
if (process.noDeprecation === true) {
|
|
|
|
return fn;
|
|
|
|
}
|
|
|
|
|
2021-08-05 18:12:21 +04:30
|
|
|
// Lazy-load to avoid a circular dependency.
|
|
|
|
if (validateString === undefined)
|
|
|
|
({ validateString } = require('internal/validators'));
|
|
|
|
|
|
|
|
if (code !== undefined)
|
|
|
|
validateString(code, 'code');
|
2016-12-04 12:47:01 -08:00
|
|
|
|
2023-04-05 13:13:23 +02:00
|
|
|
const emitDeprecationWarning = getDeprecationWarningEmitter(
|
|
|
|
code, msg, deprecated, useEmitSync,
|
|
|
|
);
|
|
|
|
|
2017-02-15 13:00:21 -08:00
|
|
|
function deprecated(...args) {
|
2023-04-05 13:13:23 +02:00
|
|
|
emitDeprecationWarning();
|
2016-07-12 23:09:12 +02:00
|
|
|
if (new.target) {
|
2019-11-22 18:04:46 +01:00
|
|
|
return ReflectConstruct(fn, args, new.target);
|
2016-07-12 23:09:12 +02:00
|
|
|
}
|
2020-11-16 16:39:28 +01:00
|
|
|
return ReflectApply(fn, 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
|
2019-11-22 18:04:46 +01:00
|
|
|
ObjectSetPrototypeOf(deprecated, fn);
|
2016-07-12 23:09:12 +02:00
|
|
|
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) {
|
2022-11-04 18:33:03 +01:00
|
|
|
if (!(isError(err) && err.stack) || err[decorated_private_symbol])
|
2015-11-25 22:37:43 +01:00
|
|
|
return;
|
|
|
|
|
2022-11-04 18:33:03 +01:00
|
|
|
const arrow = err[arrow_message_private_symbol];
|
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;
|
2022-11-04 18:33:03 +01:00
|
|
|
err[decorated_private_symbol] = 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';
|
2021-04-15 15:05:42 +02:00
|
|
|
enc = `${enc}`.toLowerCase();
|
2018-02-14 23:48:35 +01:00
|
|
|
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:
|
2020-11-16 16:39:28 +01:00
|
|
|
if (enc === 'hex' || enc === 'HEX' ||
|
2021-04-15 15:05:42 +02:00
|
|
|
`${enc}`.toLowerCase() === 'hex')
|
2018-02-14 23:48:35 +01:00
|
|
|
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';
|
2021-04-15 15:05:42 +02:00
|
|
|
enc = `${enc}`.toLowerCase();
|
2018-02-14 23:48:35 +01:00
|
|
|
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';
|
2021-04-15 15:05:42 +02:00
|
|
|
enc = `${enc}`.toLowerCase();
|
2018-02-14 23:48:35 +01:00
|
|
|
if (enc === 'base64') return 'base64';
|
|
|
|
if (enc === 'latin1' || enc === 'binary') return 'latin1';
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
if (enc === 'utf16le' || enc === 'UTF16LE' ||
|
2021-04-15 15:05:42 +02:00
|
|
|
`${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' ||
|
2021-04-15 15:05:42 +02:00
|
|
|
`${enc}`.toLowerCase() === 'utf-16le')
|
2018-02-14 23:48:35 +01:00
|
|
|
return 'utf16le';
|
|
|
|
break;
|
2021-01-15 21:01:28 +01:00
|
|
|
case 9:
|
|
|
|
if (enc === 'base64url' || enc === 'BASE64URL' ||
|
2021-04-15 15:05:42 +02:00
|
|
|
`${enc}`.toLowerCase() === 'base64url')
|
2021-01-15 21:01:28 +01:00
|
|
|
return 'base64url';
|
|
|
|
break;
|
2018-02-14 23:48:35 +01:00
|
|
|
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;
|
2022-11-12 20:11:13 -08:00
|
|
|
const msg = `${feature} is an experimental feature and might change at any time`;
|
2017-10-25 12:11:10 -07:00
|
|
|
experimentalWarnings.add(feature);
|
|
|
|
process.emitWarning(msg, 'ExperimentalWarning');
|
|
|
|
}
|
|
|
|
|
2017-02-15 13:00:21 -08:00
|
|
|
function filterDuplicateStrings(items, low) {
|
2020-11-16 16:39:28 +01:00
|
|
|
const map = new SafeMap();
|
2019-11-12 14:47:03 +00:00
|
|
|
for (let i = 0; i < items.length; i++) {
|
2016-06-08 08:18:26 -07:00
|
|
|
const item = items[i];
|
2020-11-16 16:39:28 +01:00
|
|
|
const key = StringPrototypeToLowerCase(item);
|
2016-06-08 08:18:26 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2020-11-16 16:39:28 +01:00
|
|
|
return ArrayPrototypeSort(ArrayFrom(map.values()));
|
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();
|
2020-11-16 16:39:28 +01:00
|
|
|
return ArrayPrototypeSlice(result);
|
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) {
|
2019-11-22 18:04:46 +01:00
|
|
|
return ReflectConstruct(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
|
2019-11-22 18:04:46 +01:00
|
|
|
ObjectDefineProperties(fn, {
|
2022-06-03 10:23:58 +02:00
|
|
|
name: { __proto__: null, value: type.name },
|
|
|
|
length: { __proto__: null, value: type.length },
|
2017-02-15 07:43:22 -08:00
|
|
|
});
|
2019-11-22 18:04:46 +01:00
|
|
|
ObjectSetPrototypeOf(fn, type);
|
2017-02-15 07:43:22 -08:00
|
|
|
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;
|
|
|
|
|
2023-01-09 21:38:36 -08:00
|
|
|
signalsToNamesMapping = { __proto__: 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') {
|
2020-11-16 16:39:28 +01:00
|
|
|
const signalName = signals[StringPrototypeToUpperCase(signal)];
|
2016-12-23 14:36:20 +05:30
|
|
|
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) {
|
2019-11-22 18:04:46 +01:00
|
|
|
const descriptor = ObjectGetOwnPropertyDescriptor(obj, 'constructor');
|
2017-04-19 23:07:39 -07:00
|
|
|
if (descriptor !== undefined &&
|
|
|
|
typeof descriptor.value === 'function' &&
|
|
|
|
descriptor.value.name !== '') {
|
|
|
|
return descriptor.value;
|
|
|
|
}
|
|
|
|
|
2019-11-22 18:04:46 +01:00
|
|
|
obj = ObjectGetPrototypeOf(obj);
|
2017-04-19 23:07:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-01-17 03:21:16 +08:00
|
|
|
function getSystemErrorName(err) {
|
2019-08-23 15:47:40 -04:00
|
|
|
const entry = uvErrmapGet(err);
|
2018-01-17 03:21:16 +08:00
|
|
|
return entry ? entry[0] : `Unknown system error ${err}`;
|
|
|
|
}
|
|
|
|
|
2021-04-06 00:18:34 +03:00
|
|
|
function getSystemErrorMap() {
|
|
|
|
return lazyUv().getErrorMap();
|
|
|
|
}
|
|
|
|
|
2020-02-07 11:40:00 +01:00
|
|
|
const kCustomPromisifiedSymbol = SymbolFor('nodejs.util.promisify.custom');
|
2017-04-14 18:28:16 +02:00
|
|
|
const kCustomPromisifyArgsSymbol = Symbol('customPromisifyArgs');
|
|
|
|
|
2021-08-05 18:12:21 +04:30
|
|
|
let validateFunction;
|
|
|
|
|
2017-06-20 23:20:10 +02:00
|
|
|
function promisify(original) {
|
2021-08-05 18:12:21 +04:30
|
|
|
// Lazy-load to avoid a circular dependency.
|
|
|
|
if (validateFunction === undefined)
|
|
|
|
({ validateFunction } = require('internal/validators'));
|
|
|
|
|
|
|
|
validateFunction(original, 'original');
|
2017-04-14 18:28:16 +02:00
|
|
|
|
2017-06-20 23:20:10 +02:00
|
|
|
if (original[kCustomPromisifiedSymbol]) {
|
|
|
|
const fn = original[kCustomPromisifiedSymbol];
|
2021-08-05 18:12:21 +04:30
|
|
|
|
|
|
|
validateFunction(fn, 'util.promisify.custom');
|
|
|
|
|
2019-11-22 18:04:46 +01:00
|
|
|
return ObjectDefineProperty(fn, kCustomPromisifiedSymbol, {
|
2022-06-03 10:23:58 +02:00
|
|
|
__proto__: null,
|
2023-02-26 11:34:02 +01:00
|
|
|
value: fn, enumerable: false, writable: false, configurable: true,
|
2017-04-14 18:28:16 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) => {
|
2020-11-16 16:39:28 +01:00
|
|
|
ArrayPrototypePush(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 = {};
|
2019-11-12 14:47:03 +00:00
|
|
|
for (let i = 0; i < argumentNames.length; i++)
|
2017-04-14 18:28:16 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
});
|
2020-11-16 16:39:28 +01:00
|
|
|
ReflectApply(original, this, args);
|
2018-05-19 00:25:07 +02:00
|
|
|
});
|
2017-04-14 18:28:16 +02:00
|
|
|
}
|
|
|
|
|
2019-11-22 18:04:46 +01:00
|
|
|
ObjectSetPrototypeOf(fn, ObjectGetPrototypeOf(original));
|
2017-04-14 18:28:16 +02:00
|
|
|
|
2019-11-22 18:04:46 +01:00
|
|
|
ObjectDefineProperty(fn, kCustomPromisifiedSymbol, {
|
2022-06-03 10:23:58 +02:00
|
|
|
__proto__: null,
|
2023-02-26 11:34:02 +01:00
|
|
|
value: fn, enumerable: false, writable: false, configurable: true,
|
2017-04-14 18:28:16 +02:00
|
|
|
});
|
2022-08-17 20:36:33 +02:00
|
|
|
|
|
|
|
const descriptors = ObjectGetOwnPropertyDescriptors(original);
|
|
|
|
const propertiesValues = ObjectValues(descriptors);
|
|
|
|
for (let i = 0; i < propertiesValues.length; i++) {
|
|
|
|
// We want to use null-prototype objects to not rely on globally mutable
|
|
|
|
// %Object.prototype%.
|
|
|
|
ObjectSetPrototypeOf(propertiesValues[i], null);
|
|
|
|
}
|
|
|
|
return ObjectDefineProperties(fn, descriptors);
|
2017-04-14 18:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
promisify.custom = kCustomPromisifiedSymbol;
|
|
|
|
|
2021-05-31 08:50:41 -04:00
|
|
|
// The built-in Array#join is slower in v8 6.0
|
2017-08-21 23:20:59 -03:00
|
|
|
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) {
|
2019-05-08 20:45:10 +02:00
|
|
|
const lastIndex = output.length - 1;
|
|
|
|
for (let i = 0; i < lastIndex; i++) {
|
2017-08-21 23:20:59 -03:00
|
|
|
// It is faster not to use a template string here
|
|
|
|
str += output[i];
|
|
|
|
str += separator;
|
|
|
|
}
|
2019-05-08 20:45:10 +02:00
|
|
|
str += output[lastIndex];
|
2017-08-21 23:20:59 -03:00
|
|
|
}
|
|
|
|
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];
|
2021-04-15 15:05:42 +02:00
|
|
|
list.pop();
|
2017-10-15 23:59:53 +08:00
|
|
|
}
|
|
|
|
|
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() {
|
2021-04-12 17:48:57 +02:00
|
|
|
try { Error.stackTraceLimit = Infinity; } catch {}
|
2018-03-22 00:30:21 +01:00
|
|
|
return function structuredStack() {
|
2019-09-16 15:32:15 -05:00
|
|
|
const e = new Error();
|
|
|
|
overrideStackTrace.set(e, (err, trace) => trace);
|
|
|
|
return e.stack;
|
2018-03-22 00:30:21 +01:00
|
|
|
};
|
2019-09-16 15:32:15 -05:00
|
|
|
})()`, { overrideStackTrace }, { 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:
|
2019-11-23 10:09:05 +01:00
|
|
|
if (ArrayIsArray(stack)) {
|
2018-04-25 00:56:35 +02:00
|
|
|
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.
|
2022-06-27 17:16:06 +02:00
|
|
|
if (RegExpPrototypeExec(/^\/|\\/, filename) === null)
|
2018-04-25 00:56:35 +02:00
|
|
|
continue;
|
2022-06-27 17:16:06 +02:00
|
|
|
return RegExpPrototypeExec(kNodeModulesRE, filename) !== null;
|
2018-04-25 00:56:35 +02:00
|
|
|
}
|
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;
|
2022-11-07 16:58:39 +11:00
|
|
|
return ReflectApply(callback, this, args);
|
2018-09-10 09:57:15 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-12-03 23:02:49 -05:00
|
|
|
let validateUint32;
|
|
|
|
|
|
|
|
function sleep(msec) {
|
|
|
|
// Lazy-load to avoid a circular dependency.
|
|
|
|
if (validateUint32 === undefined)
|
|
|
|
({ validateUint32 } = require('internal/validators'));
|
|
|
|
|
|
|
|
validateUint32(msec, 'msec');
|
|
|
|
_sleep(msec);
|
|
|
|
}
|
|
|
|
|
2021-01-26 23:15:56 -05:00
|
|
|
function createDeferredPromise() {
|
|
|
|
let resolve;
|
|
|
|
let reject;
|
|
|
|
const promise = new Promise((res, rej) => {
|
|
|
|
resolve = res;
|
|
|
|
reject = rej;
|
|
|
|
});
|
|
|
|
|
|
|
|
return { promise, resolve, reject };
|
|
|
|
}
|
|
|
|
|
2022-01-05 20:01:49 +09:00
|
|
|
// https://heycam.github.io/webidl/#define-the-operations
|
|
|
|
function defineOperation(target, name, method) {
|
|
|
|
ObjectDefineProperty(target, name, {
|
2022-06-03 10:23:58 +02:00
|
|
|
__proto__: null,
|
2022-01-05 20:01:49 +09:00
|
|
|
writable: true,
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true,
|
2023-02-26 11:34:02 +01:00
|
|
|
value: method,
|
2022-01-05 20:01:49 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://heycam.github.io/webidl/#es-interfaces
|
|
|
|
function exposeInterface(target, name, interfaceObject) {
|
|
|
|
ObjectDefineProperty(target, name, {
|
2022-06-03 10:23:58 +02:00
|
|
|
__proto__: null,
|
2022-01-05 20:01:49 +09:00
|
|
|
writable: true,
|
|
|
|
enumerable: false,
|
|
|
|
configurable: true,
|
2023-02-26 11:34:02 +01:00
|
|
|
value: interfaceObject,
|
2022-01-05 20:01:49 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-16 00:21:53 +08:00
|
|
|
// https://heycam.github.io/webidl/#es-namespaces
|
|
|
|
function exposeNamespace(target, name, namespaceObject) {
|
|
|
|
ObjectDefineProperty(target, name, {
|
|
|
|
__proto__: null,
|
|
|
|
writable: true,
|
|
|
|
enumerable: false,
|
|
|
|
configurable: true,
|
|
|
|
value: namespaceObject,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function exposeGetterAndSetter(target, name, getter, setter = undefined) {
|
|
|
|
ObjectDefineProperty(target, name, {
|
|
|
|
__proto__: null,
|
|
|
|
enumerable: false,
|
|
|
|
configurable: true,
|
|
|
|
get: getter,
|
|
|
|
set: setter,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-09 23:37:35 +01:00
|
|
|
function defineLazyProperties(target, id, keys, enumerable = true) {
|
|
|
|
const descriptors = { __proto__: null };
|
|
|
|
let mod;
|
|
|
|
for (let i = 0; i < keys.length; i++) {
|
|
|
|
const key = keys[i];
|
|
|
|
let lazyLoadedValue;
|
|
|
|
function set(value) {
|
|
|
|
ObjectDefineProperty(target, key, {
|
|
|
|
__proto__: null,
|
|
|
|
writable: true,
|
|
|
|
value,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
ObjectDefineProperty(set, 'name', {
|
|
|
|
__proto__: null,
|
|
|
|
value: `set ${key}`,
|
|
|
|
});
|
|
|
|
function get() {
|
|
|
|
mod ??= require(id);
|
|
|
|
if (lazyLoadedValue === undefined) {
|
|
|
|
lazyLoadedValue = mod[key];
|
|
|
|
set(lazyLoadedValue);
|
|
|
|
}
|
|
|
|
return lazyLoadedValue;
|
|
|
|
}
|
|
|
|
ObjectDefineProperty(get, 'name', {
|
|
|
|
__proto__: null,
|
|
|
|
value: `get ${key}`,
|
|
|
|
});
|
|
|
|
descriptors[key] = {
|
|
|
|
__proto__: null,
|
|
|
|
configurable: true,
|
|
|
|
enumerable,
|
|
|
|
get,
|
|
|
|
set,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
ObjectDefineProperties(target, descriptors);
|
|
|
|
}
|
|
|
|
|
2022-12-16 13:32:22 +01:00
|
|
|
function defineReplaceableLazyAttribute(target, id, keys, writable = true, check) {
|
2022-12-09 23:37:35 +01:00
|
|
|
let mod;
|
|
|
|
for (let i = 0; i < keys.length; i++) {
|
|
|
|
const key = keys[i];
|
|
|
|
let value;
|
|
|
|
let setterCalled = false;
|
|
|
|
|
|
|
|
function get() {
|
2022-12-16 13:32:22 +01:00
|
|
|
if (check !== undefined) {
|
|
|
|
FunctionPrototypeCall(check, this);
|
|
|
|
}
|
2022-12-09 23:37:35 +01:00
|
|
|
if (setterCalled) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
mod ??= require(id);
|
|
|
|
value ??= mod[key];
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectDefineProperty(get, 'name', {
|
|
|
|
__proto__: null,
|
|
|
|
value: `get ${key}`,
|
|
|
|
});
|
|
|
|
|
|
|
|
function set(val) {
|
|
|
|
setterCalled = true;
|
|
|
|
value = val;
|
|
|
|
}
|
|
|
|
ObjectDefineProperty(set, 'name', {
|
|
|
|
__proto__: null,
|
|
|
|
value: `set ${key}`,
|
|
|
|
});
|
|
|
|
|
|
|
|
ObjectDefineProperty(target, key, {
|
|
|
|
__proto__: null,
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true,
|
|
|
|
get,
|
|
|
|
set: writable ? set : undefined,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function exposeLazyInterfaces(target, id, keys) {
|
|
|
|
defineLazyProperties(target, id, keys, false);
|
|
|
|
}
|
|
|
|
|
2021-06-28 16:29:54 +08:00
|
|
|
let _DOMException;
|
|
|
|
const lazyDOMExceptionClass = () => {
|
|
|
|
_DOMException ??= internalBinding('messaging').DOMException;
|
|
|
|
return _DOMException;
|
|
|
|
};
|
|
|
|
|
2021-06-21 11:34:48 +08:00
|
|
|
const lazyDOMException = hideStackFrames((message, name) => {
|
2021-06-28 16:29:54 +08:00
|
|
|
_DOMException ??= internalBinding('messaging').DOMException;
|
|
|
|
return new _DOMException(message, name);
|
2021-06-21 11:34:48 +08:00
|
|
|
});
|
|
|
|
|
2023-01-09 21:38:36 -08:00
|
|
|
const kEnumerableProperty = { __proto__: null };
|
2022-02-11 18:30:47 +01:00
|
|
|
kEnumerableProperty.enumerable = true;
|
2022-05-26 08:00:35 +08:00
|
|
|
ObjectFreeze(kEnumerableProperty);
|
2022-02-11 18:30:47 +01:00
|
|
|
|
2023-01-09 21:38:36 -08:00
|
|
|
const kEmptyObject = ObjectFreeze({ __proto__: null });
|
2022-05-21 17:48:37 +08:00
|
|
|
|
2022-08-05 00:41:48 +02:00
|
|
|
function filterOwnProperties(source, keys) {
|
2023-01-09 21:38:36 -08:00
|
|
|
const filtered = { __proto__: null };
|
2022-08-05 00:41:48 +02:00
|
|
|
for (let i = 0; i < keys.length; i++) {
|
|
|
|
const key = keys[i];
|
|
|
|
if (ObjectPrototypeHasOwnProperty(source, key)) {
|
|
|
|
filtered[key] = source[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return filtered;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mimics `obj[key] = value` but ignoring potential prototype inheritance.
|
|
|
|
* @param {any} obj
|
|
|
|
* @param {string} key
|
|
|
|
* @param {any} value
|
|
|
|
* @returns {any}
|
|
|
|
*/
|
|
|
|
function setOwnProperty(obj, key, value) {
|
|
|
|
return ObjectDefineProperty(obj, key, {
|
|
|
|
__proto__: null,
|
|
|
|
configurable: true,
|
|
|
|
enumerable: true,
|
|
|
|
value,
|
|
|
|
writable: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-08-05 10:01:32 +02:00
|
|
|
let internalGlobal;
|
|
|
|
function getInternalGlobal() {
|
|
|
|
if (internalGlobal == null) {
|
|
|
|
// Lazy-load to avoid a circular dependency.
|
|
|
|
const { runInNewContext } = require('vm');
|
|
|
|
internalGlobal = runInNewContext('this', undefined, { contextName: 'internal' });
|
|
|
|
}
|
|
|
|
return internalGlobal;
|
|
|
|
}
|
|
|
|
|
|
|
|
function SideEffectFreeRegExpPrototypeExec(regex, string) {
|
|
|
|
const { RegExp: RegExpFromAnotherRealm } = getInternalGlobal();
|
|
|
|
return FunctionPrototypeCall(RegExpFromAnotherRealm.prototype.exec, regex, string);
|
|
|
|
}
|
|
|
|
|
2022-12-14 15:48:50 +01:00
|
|
|
const crossRelmRegexes = new SafeWeakMap();
|
|
|
|
function getCrossRelmRegex(regex) {
|
|
|
|
const cached = crossRelmRegexes.get(regex);
|
|
|
|
if (cached) return cached;
|
|
|
|
|
|
|
|
let flagString = '';
|
|
|
|
if (RegExpPrototypeGetHasIndices(regex)) flagString += 'd';
|
|
|
|
if (RegExpPrototypeGetGlobal(regex)) flagString += 'g';
|
|
|
|
if (RegExpPrototypeGetIgnoreCase(regex)) flagString += 'i';
|
|
|
|
if (RegExpPrototypeGetMultiline(regex)) flagString += 'm';
|
|
|
|
if (RegExpPrototypeGetDotAll(regex)) flagString += 's';
|
|
|
|
if (RegExpPrototypeGetUnicode(regex)) flagString += 'u';
|
|
|
|
if (RegExpPrototypeGetSticky(regex)) flagString += 'y';
|
|
|
|
|
|
|
|
const { RegExp: RegExpFromAnotherRealm } = getInternalGlobal();
|
|
|
|
const crossRelmRegex = new RegExpFromAnotherRealm(RegExpPrototypeGetSource(regex), flagString);
|
|
|
|
crossRelmRegexes.set(regex, crossRelmRegex);
|
|
|
|
return crossRelmRegex;
|
|
|
|
}
|
|
|
|
|
|
|
|
function SideEffectFreeRegExpPrototypeSymbolReplace(regex, string, replacement) {
|
|
|
|
return getCrossRelmRegex(regex)[SymbolReplace](string, replacement);
|
|
|
|
}
|
|
|
|
|
|
|
|
function SideEffectFreeRegExpPrototypeSymbolSplit(regex, string, limit = undefined) {
|
|
|
|
return getCrossRelmRegex(regex)[SymbolSplit](string, limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-26 22:14:57 -05:00
|
|
|
function isArrayBufferDetached(value) {
|
|
|
|
if (ArrayBufferPrototypeGetByteLength(value) === 0) {
|
|
|
|
return _isArrayBufferDetached(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-14 00:02:51 +01:00
|
|
|
/**
|
|
|
|
* Helper function to lazy-load an initialize-once value.
|
|
|
|
* @template T Return value of initializer
|
|
|
|
* @param {()=>T} initializer Initializer of the lazily loaded value.
|
|
|
|
* @returns {()=>T}
|
|
|
|
*/
|
|
|
|
function getLazy(initializer) {
|
|
|
|
let value;
|
|
|
|
let initialized = false;
|
|
|
|
return function() {
|
|
|
|
if (initialized === false) {
|
|
|
|
value = initializer();
|
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-21 13:26:16 -05:00
|
|
|
// Setup user-facing NODE_V8_COVERAGE environment variable that writes
|
|
|
|
// ScriptCoverage objects to a specified directory.
|
|
|
|
function setupCoverageHooks(dir) {
|
|
|
|
const cwd = require('internal/process/execution').tryGetCwd();
|
|
|
|
const { resolve } = require('path');
|
|
|
|
const coverageDirectory = resolve(cwd, dir);
|
|
|
|
const { sourceMapCacheToObject } =
|
|
|
|
require('internal/source_map/source_map_cache');
|
|
|
|
|
|
|
|
if (process.features.inspector) {
|
|
|
|
internalBinding('profiler').setCoverageDirectory(coverageDirectory);
|
|
|
|
internalBinding('profiler').setSourceMapCacheGetter(sourceMapCacheToObject);
|
|
|
|
} else {
|
|
|
|
process.emitWarning('The inspector is disabled, ' +
|
|
|
|
'coverage could not be collected',
|
|
|
|
'Warning');
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return coverageDirectory;
|
|
|
|
}
|
|
|
|
|
2017-05-12 08:37:32 -07:00
|
|
|
module.exports = {
|
2022-12-14 00:02:51 +01:00
|
|
|
getLazy,
|
2017-05-12 08:37:32 -07:00
|
|
|
assertCrypto,
|
|
|
|
cachedResult,
|
|
|
|
convertToValidSignal,
|
|
|
|
createClassWrapper,
|
2021-01-26 23:15:56 -05:00
|
|
|
createDeferredPromise,
|
2017-05-12 08:37:32 -07:00
|
|
|
decorateErrorStack,
|
2022-01-05 20:01:49 +09:00
|
|
|
defineOperation,
|
2022-12-09 23:37:35 +01:00
|
|
|
defineLazyProperties,
|
|
|
|
defineReplaceableLazyAttribute,
|
2017-05-12 08:37:32 -07:00
|
|
|
deprecate,
|
2017-10-25 12:11:10 -07:00
|
|
|
emitExperimentalWarning,
|
2022-01-05 20:01:49 +09:00
|
|
|
exposeInterface,
|
2022-12-09 23:37:35 +01:00
|
|
|
exposeLazyInterfaces,
|
2023-03-16 00:21:53 +08:00
|
|
|
exposeNamespace,
|
|
|
|
exposeGetterAndSetter,
|
2017-05-12 08:37:32 -07:00
|
|
|
filterDuplicateStrings,
|
2022-08-05 00:41:48 +02:00
|
|
|
filterOwnProperties,
|
2017-05-12 08:37:32 -07:00
|
|
|
getConstructorOf,
|
2022-08-05 10:01:32 +02:00
|
|
|
getInternalGlobal,
|
2021-04-06 00:18:34 +03:00
|
|
|
getSystemErrorMap,
|
2018-01-17 03:21:16 +08:00
|
|
|
getSystemErrorName,
|
2022-11-26 22:14:57 -05:00
|
|
|
isArrayBufferDetached,
|
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,
|
2021-06-21 11:34:48 +08:00
|
|
|
lazyDOMException,
|
2021-06-28 16:29:54 +08:00
|
|
|
lazyDOMExceptionClass,
|
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,
|
2022-08-05 10:01:32 +02:00
|
|
|
SideEffectFreeRegExpPrototypeExec,
|
2022-12-14 15:48:50 +01:00
|
|
|
SideEffectFreeRegExpPrototypeSymbolReplace,
|
|
|
|
SideEffectFreeRegExpPrototypeSymbolSplit,
|
2019-12-03 23:02:49 -05:00
|
|
|
sleep,
|
2017-10-15 23:59:53 +08:00
|
|
|
spliceOne,
|
2022-12-21 13:26:16 -05:00
|
|
|
setupCoverageHooks,
|
2021-08-19 21:40:18 +02:00
|
|
|
toUSVString,
|
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'
|
2019-12-08 18:33:33 +01:00
|
|
|
customInspectSymbol: SymbolFor('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'),
|
2022-02-11 18:30:47 +01:00
|
|
|
kVmBreakFirstLineSymbol: Symbol('kVmBreakFirstLineSymbol'),
|
|
|
|
|
2022-05-21 17:48:37 +08:00
|
|
|
kEmptyObject,
|
2022-02-11 18:30:47 +01:00
|
|
|
kEnumerableProperty,
|
2022-08-05 00:41:48 +02:00
|
|
|
setOwnProperty,
|
2023-04-05 13:13:23 +02:00
|
|
|
pendingDeprecate,
|
2017-05-12 08:37:32 -07:00
|
|
|
};
|