Skip to content

Commit

Permalink
Update to node 21.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
hildjj committed Feb 1, 2024
1 parent cfd913d commit 3723510
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 59 deletions.
28 changes: 23 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const hacks = [
'eslint-plugin-jsdoc',
'eslint-plugin-markdown',
'@babel/eslint-parser',
'@babel/plugin-syntax-import-assertions',
'@babel/plugin-syntax-import-attributes',
];
Module._findPath = (request, paths, isMain) => {
const r = ModuleFindPath(request, paths, isMain);
Expand All @@ -46,7 +46,7 @@ module.exports = {
parserOptions: {
babelOptions: {
plugins: [
Module._findPath('@babel/plugin-syntax-import-assertions'),
Module._findPath('@babel/plugin-syntax-import-attributes'),
],
},
requireConfigFile: false,
Expand All @@ -55,10 +55,10 @@ module.exports = {
overrides: [
{
files: [
'test/es-module/test-esm-type-flag.js',
'test/es-module/test-esm-type-flag-alias.js',
'*.mjs',
'test/es-module/test-esm-example-loader.js',
'test/es-module/test-esm-type-flag.js',
'test/es-module/test-esm-type-flag-alias.js',
],
parserOptions: { sourceType: 'module' },
},
Expand Down Expand Up @@ -113,6 +113,22 @@ module.exports = {
},
] },
},
{
files: [
'lib/internal/modules/**/*.js',
],
rules: {
'curly': 'error',
},
},
{
files: [
'lib/internal/test_runner/**/*.js',
],
rules: {
'node-core/set-proto-to-null-in-object': 'error',
},
},
],
rules: {
// ESLint built-in rules
Expand Down Expand Up @@ -242,7 +258,6 @@ module.exports = {
message: 'Use `globalThis.crypto`.',
},
],
'no-return-await': 'error',
'no-self-compare': 'error',
'no-tabs': 'error',
'no-template-curly-in-string': 'error',
Expand Down Expand Up @@ -308,6 +323,7 @@ module.exports = {
'jsdoc/newline-after-description': 'off',
'jsdoc/require-returns-description': 'off',
'jsdoc/valid-types': 'off',
'jsdoc/no-defaults': 'off',
'jsdoc/no-undefined-types': 'off',
'jsdoc/require-param': 'off',
'jsdoc/check-tag-names': 'off',
Expand All @@ -329,6 +345,7 @@ module.exports = {
DecompressionStream: 'readable',
fetch: 'readable',
FormData: 'readable',
navigator: 'readable',
ReadableStream: 'readable',
ReadableStreamDefaultReader: 'readable',
ReadableStreamBYOBReader: 'readable',
Expand All @@ -345,5 +362,6 @@ module.exports = {
WritableStream: 'readable',
WritableStreamDefaultWriter: 'readable',
WritableStreamDefaultController: 'readable',
WebSocket: 'readable',
},
};
6 changes: 3 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
node-version: [16.x, 18.x, 20.x, 21.x]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install test run dependencies
Expand Down
2 changes: 1 addition & 1 deletion dist/inspect.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
],
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.22.5",
"@babel/preset-env": "^7.22.5",
"babel-loader": "^9.1.2",
"c8": "^8.0.0",
"eslint": "^8.43.0",
"semver": "7.5.3",
"webpack": "^5.88.1",
"@babel/core": "^7.23.9",
"@babel/preset-env": "^7.23.9",
"babel-loader": "^9.1.3",
"c8": "^9.1.0",
"eslint": "^8.56.0",
"semver": "7.5.4",
"webpack": "^5.90.0",
"webpack-cli": "^5.1.4"
},
"pnpm": {
Expand Down
5 changes: 3 additions & 2 deletions src/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const { BuiltinModule } = require('./internal/bootstrap/realm');
const {
validateObject,
validateString,
kValidateObjectAllowArray,
} = require('./internal/validators');

let hexSlice;
Expand Down Expand Up @@ -1264,7 +1265,7 @@ function getFunctionBase(value, constructor, tag) {
function identicalSequenceRange(a, b) {
for (let i = 0; i < a.length - 3; i++) {
// Find the first entry of b that matches the current entry of a.
const pos = b.indexOf(a[i]);
const pos = ArrayPrototypeIndexOf(b, a[i]);
if (pos !== -1) {
const rest = b.length - pos;
if (rest > 3) {
Expand Down Expand Up @@ -2206,7 +2207,7 @@ function format(...args) {
}

function formatWithOptions(inspectOptions, ...args) {
validateObject(inspectOptions, 'inspectOptions', { allowArray: true });
validateObject(inspectOptions, 'inspectOptions', kValidateObjectAllowArray);
return formatWithOptionsInternal(inspectOptions, args);
}

Expand Down
59 changes: 42 additions & 17 deletions src/internal/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,48 @@ const {
},
} = require('./errors');

const kValidateObjectNone = 0;
const kValidateObjectAllowNullable = 1 << 0;
const kValidateObjectAllowArray = 1 << 1;
const kValidateObjectAllowFunction = 1 << 2;

/**
* @param {unknown} value
* @callback validateObject
* @param {*} value
* @param {string} name
* @param {{
* allowArray?: boolean,
* allowFunction?: boolean,
* nullable?: boolean
* }} [options]
* @param {number} [options]
*/

/** @type {validateObject} */
const validateObject = hideStackFrames(
(value, name, options) => {
const useDefaultOptions = options == null;
const allowArray = useDefaultOptions ? false : options.allowArray;
const allowFunction = useDefaultOptions ? false : options.allowFunction;
const nullable = useDefaultOptions ? false : options.nullable;
if ((!nullable && value === null) ||
(!allowArray && ArrayIsArray(value)) ||
(typeof value !== 'object' && (
!allowFunction || typeof value !== 'function'
))) {
throw new ERR_INVALID_ARG_TYPE(name, 'Object', value);
(value, name, options = kValidateObjectNone) => {
if (options === kValidateObjectNone) {
if (value === null || ArrayIsArray(value)) {
throw new ERR_INVALID_ARG_TYPE(name, 'Object', value);
}

if (typeof value !== 'object') {
throw new ERR_INVALID_ARG_TYPE(name, 'Object', value);
}
} else {
const throwOnNullable = (kValidateObjectAllowNullable & options) === 0;

if (throwOnNullable && value === null) {
throw new ERR_INVALID_ARG_TYPE(name, 'Object', value);
}

const throwOnArray = (kValidateObjectAllowArray & options) === 0;

if (throwOnArray && ArrayIsArray(value)) {
throw new ERR_INVALID_ARG_TYPE(name, 'Object', value);
}

const throwOnFunction = (kValidateObjectAllowFunction & options) === 0;
const typeofValue = typeof value;

if (typeofValue !== 'object' && (throwOnFunction || typeofValue !== 'function')) {
throw new ERR_INVALID_ARG_TYPE(name, 'Object', value);
}
}
});

Expand All @@ -41,6 +62,10 @@ function validateString(value, name) {
}

module.exports = {
kValidateObjectNone,
kValidateObjectAllowNullable,
kValidateObjectAllowArray,
kValidateObjectAllowFunction,
validateObject,
validateString,
};
4 changes: 3 additions & 1 deletion test/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ rules:
message: Use Number.isNaN() instead of the global isNaN() function.
- selector: VariableDeclarator > CallExpression:matches([callee.name='debuglog'], [callee.property.name='debuglog']):not([arguments.0.value='test'])
message: Use 'test' as debuglog value in tests.
- selector: CallExpression:matches([callee.object.name="common"][callee.property.name=/^mustCall/],[callee.name="mustCall"],[callee.name="mustCallAtLeast"])>:first-child[type=/FunctionExpression$/][body.body.length=0]
- selector: CallExpression:matches([callee.object.name="common"][callee.property.name=/^must(Not)?Call/],[callee.name="mustCall"],[callee.name="mustCallAtLeast"],[callee.name="mustNotCall"])>:first-child[type=/FunctionExpression$/][body.body.length=0]
message: Do not use an empty function, omit the parameter altogether.
- selector: ExpressionStatement>CallExpression:matches([callee.name='rejects'], [callee.object.name='assert'][callee.property.name='rejects'])
message: Calling `assert.rejects` without `await` or `.then(common.mustCall())` will not detect never-settling promises.
- selector: Identifier[name='webcrypto']
message: Use `globalThis.crypto`.

Expand Down
65 changes: 59 additions & 6 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ if (process.argv.length === 2 &&
}

const isWindows = process.platform === 'win32';
const isAIX = process.platform === 'aix';
const isSunOS = process.platform === 'sunos';
const isFreeBSD = process.platform === 'freebsd';
const isOpenBSD = process.platform === 'openbsd';
Expand Down Expand Up @@ -274,7 +273,7 @@ function platformTimeout(ms) {
if (process.features.debug)
ms = multipliers.two * ms;

if (isAIX)
if (exports.isAIX || exports.isIBMi)
return multipliers.two * ms; // Default localhost speed is slower on AIX

if (isPi)
Expand Down Expand Up @@ -309,6 +308,14 @@ if (global.gc) {
knownGlobals.push(global.gc);
}

if (global.navigator) {
knownGlobals.push(global.navigator);
}

if (global.Navigator) {
knownGlobals.push(global.Navigator);
}

if (global.Performance) {
knownGlobals.push(global.Performance);
}
Expand Down Expand Up @@ -362,6 +369,9 @@ if (global.ReadableStream) {
global.DecompressionStream,
);
}
if (global.WebSocket) {
knownGlobals.push(WebSocket);
}

function allowGlobals(...allowlist) {
knownGlobals = knownGlobals.concat(allowlist);
Expand Down Expand Up @@ -712,9 +722,8 @@ function expectsError(validator, exact) {
assert.fail(`Expected one argument, got ${inspect(args)}`);
}
const error = args.pop();
const descriptor = Object.getOwnPropertyDescriptor(error, 'message');
// The error message should be non-enumerable
assert.strictEqual(descriptor.enumerable, false);
assert.strictEqual(Object.prototype.propertyIsEnumerable.call(error, 'message'), false);

assert.throws(() => { throw error; }, validator);
return true;
Expand Down Expand Up @@ -807,7 +816,7 @@ function invalidArgTypeHelper(input) {
if (input == null) {
return ` Received ${input}`;
}
if (typeof input === 'function' && input.name) {
if (typeof input === 'function') {
return ` Received function ${input.name}`;
}
if (typeof input === 'object') {
Expand Down Expand Up @@ -897,6 +906,45 @@ function spawnPromisified(...args) {
});
}

function getPrintedStackTrace(stderr) {
const lines = stderr.split('\n');

let state = 'initial';
const result = {
message: [],
nativeStack: [],
jsStack: [],
};
for (let i = 0; i < lines.length; ++i) {
const line = lines[i].trim();
if (line.length === 0) {
continue; // Skip empty lines.
}

switch (state) {
case 'initial':
result.message.push(line);
if (line.includes('Native stack trace')) {
state = 'native-stack';
} else {
result.message.push(line);
}
break;
case 'native-stack':
if (line.includes('JavaScript stack trace')) {
state = 'js-stack';
} else {
result.nativeStack.push(line);
}
break;
case 'js-stack':
result.jsStack.push(line);
break;
}
}
return result;
}

const common = {
allowGlobals,
buildType,
Expand All @@ -910,6 +958,7 @@ const common = {
getArrayBufferViews,
getBufferSources,
getCallSite,
getPrintedStackTrace,
getTTYfd,
hasIntl,
hasCrypto,
Expand All @@ -918,7 +967,6 @@ const common = {
hasQuic,
hasMultiLocalhost,
invalidArgTypeHelper,
isAIX,
isAlive,
isAsan,
isDumbTerminal,
Expand Down Expand Up @@ -989,7 +1037,12 @@ const common = {
},

// On IBMi, process.platform and os.platform() both return 'aix',
// when built with Python versions earlier than 3.9
// It is not enough to differentiate between IBMi and real AIX system.
get isAIX() {
return require('os').type() === 'AIX';
},

get isIBMi() {
return require('os').type() === 'OS400';
},
Expand Down
Loading

0 comments on commit 3723510

Please sign in to comment.