Skip to content

Commit

Permalink
Merge pull request #950 from nodejs/main
Browse files Browse the repository at this point in the history
Create a new pull request by comparing changes across two branches
  • Loading branch information
GulajavaMinistudio authored Dec 12, 2023
2 parents a0b4e90 + 1b60054 commit a9e393d
Show file tree
Hide file tree
Showing 35 changed files with 1,862 additions and 415 deletions.
2 changes: 1 addition & 1 deletion benchmark/crypto/aes-gcm-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const common = require('../common.js');
const crypto = require('crypto');
const keylen = { 'aes-128-gcm': 16, 'aes-192-gcm': 24, 'aes-256-gcm': 32 };
const bench = common.createBenchmark(main, {
n: [500],
n: [2500],
cipher: ['aes-128-gcm', 'aes-192-gcm', 'aes-256-gcm'],
len: [1024, 4 * 1024, 16 * 1024, 64 * 1024, 256 * 1024, 1024 * 1024],
});
Expand Down
13 changes: 10 additions & 3 deletions benchmark/crypto/randomBytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
const common = require('../common.js');
const { randomBytes } = require('crypto');

// Add together with imports
const assert = require('assert');

let _cryptoResult;

const bench = common.createBenchmark(main, {
size: [64, 1024, 8192, 512 * 1024],
n: [1e3],
size: [64, 1024, 8 * 1024, 16 * 1024],
n: [1e5],
});

function main({ n, size }) {
bench.start();
for (let i = 0; i < n; ++i)
randomBytes(size);
_cryptoResult = randomBytes(size);
bench.end(n);
// Avoid V8 deadcode (elimination)
assert.ok(_cryptoResult);
}
2 changes: 1 addition & 1 deletion benchmark/perf_hooks/performance-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function randomFn() {
}

const bench = common.createBenchmark(main, {
n: [1e5],
n: [1e6],
pending: [1, 10],
}, {
options: ['--expose-internals'],
Expand Down
2 changes: 1 addition & 1 deletion benchmark/perf_hooks/resourcetiming.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function createTimingInfo({
}

const bench = common.createBenchmark(main, {
n: [1e5],
n: [1e6],
observe: ['resource'],
});

Expand Down
2 changes: 1 addition & 1 deletion benchmark/perf_hooks/timerfied.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function randomFn() {
}

const bench = common.createBenchmark(main, {
n: [1e5],
n: [1e6],
observe: ['function'],
});

Expand Down
2 changes: 1 addition & 1 deletion benchmark/perf_hooks/usertiming.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
} = require('perf_hooks');

const bench = common.createBenchmark(main, {
n: [1e5],
n: [1e6],
observe: ['all', 'measure'],
});

Expand Down
16 changes: 16 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -3545,6 +3545,21 @@ Type: Documentation-only
The [`dirent.path`][] is deprecated due to its lack of consistency across
release lines. Please use [`dirent.parentPath`][] instead.

### DEP0179: `Hash` constructor

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/51077
description: Documentation-only deprecation.
-->

Type: Documentation-only

Calling `Hash` class directly with `Hash()` or `new Hash()` is
deprecated due to being internals, not intended for public use.
Please use the [`crypto.createHash()`][] method to create Hash instances.

[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
[RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3
[RFC 8247 Section 2.4]: https://www.rfc-editor.org/rfc/rfc8247#section-2.4
Expand Down Expand Up @@ -3583,6 +3598,7 @@ release lines. Please use [`dirent.parentPath`][] instead.
[`crypto.createCipheriv()`]: crypto.md#cryptocreatecipherivalgorithm-key-iv-options
[`crypto.createDecipher()`]: crypto.md#cryptocreatedecipheralgorithm-password-options
[`crypto.createDecipheriv()`]: crypto.md#cryptocreatedecipherivalgorithm-key-iv-options
[`crypto.createHash()`]: crypto.md#cryptocreatehashalgorithm-options
[`crypto.fips`]: crypto.md#cryptofips
[`crypto.pbkdf2()`]: crypto.md#cryptopbkdf2password-salt-iterations-keylen-digest-callback
[`crypto.randomBytes()`]: crypto.md#cryptorandombytessize-callback
Expand Down
18 changes: 9 additions & 9 deletions doc/api/diagnostics_channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ channels.tracePromise(async () => {
});
```

#### `tracingChannel.traceCallback(fn[, position[, context[, thisArg[, ...args]]]])`
#### `tracingChannel.traceCallback(fn, position, context, thisArg, ...args)`

<!-- YAML
added:
Expand All @@ -874,23 +874,23 @@ added:
* `fn` {Function} callback using function to wrap a trace around
* `position` {number} Zero-indexed argument position of expected callback
* `context` {Object} Shared object to correlate trace events through
(defaults to last argument if `undefined` is passed)
* `context` {Object} Shared object to correlate trace events through (defaults
to `{}` if `undefined` is passed)
* `thisArg` {any} The receiver to be used for the function call
* `...args` {any} Optional arguments to pass to the function
* `...args` {any} arguments to pass to the function (must include the callback)
* Returns: {any} The return value of the given function

Trace a callback-receiving function call. This will always produce a
Trace a callback-receiving function call. The callback is expected to follow
the error as first arg convention typically used. This will always produce a
[`start` event][] and [`end` event][] around the synchronous portion of the
function execution, and will produce a [`asyncStart` event][] and
[`asyncEnd` event][] around the callback execution. It may also produce an
[`error` event][] if the given function throws an error or the returned
promise rejects. This will run the given function using
[`error` event][] if the given function throws or the first argument passed to
the callback is set. This will run the given function using
[`channel.runStores(context, ...)`][] on the `start` channel which ensures all
events should have any bound stores set to match this trace context.

The `position` will be -1 by default to indicate the final argument should
be used as the callback.

```mjs
import diagnostics_channel from 'node:diagnostics_channel';

Expand Down
16 changes: 9 additions & 7 deletions doc/api/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ expressions:
* Strings passed in as an argument to `--eval`, or piped to `node` via `STDIN`,
with the flag `--input-type=module`.

* Code that contains syntax that only parses successfully as [ES modules][],
such as `import` or `export` statements or `import.meta`, when the code has no
explicit marker of how it should be interpreted. Explicit markers are `.mjs`
or `.cjs` extensions, `package.json` `"type"` fields with either `"module"` or
`"commonjs"` values, or `--input-type` or `--experimental-default-type` flags.
Dynamic `import()` expressions are supported in either CommonJS or ES modules
and would not cause a file to be treated as an ES module.
* When using [`--experimental-detect-module`][], code containing syntax only
successfully parsed as [ES modules][], such as `import` or `export`
statements or `import.meta`, having no explicit marker of how it should be
interpreted. Explicit markers are `.mjs` or `.cjs` extensions, `package.json`
`"type"` fields with either `"module"` or `"commonjs"` values, or
`--input-type` or `--experimental-default-type` flags. Dynamic `import()`
expressions are supported in either CommonJS or ES modules and would not
cause a file to be treated as an ES module.

Node.js will treat the following as [CommonJS][] when passed to `node` as the
initial input, or when referenced by `import` statements or `import()`
Expand Down Expand Up @@ -1362,6 +1363,7 @@ This field defines [subpath imports][] for the current package.
[`"type"`]: #type
[`--conditions` / `-C` flag]: #resolving-user-conditions
[`--experimental-default-type`]: cli.md#--experimental-default-typetype
[`--experimental-detect-module`]: cli.md#--experimental-detect-module
[`--no-addons` flag]: cli.md#--no-addons
[`ERR_PACKAGE_PATH_NOT_EXPORTED`]: errors.md#err_package_path_not_exported
[`esm`]: https://github.com/standard-things/esm#readme
Expand Down
9 changes: 8 additions & 1 deletion lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,14 @@ function processHeader(self, state, key, value, validate) {
// https://www.rfc-editor.org/rfc/rfc6266#section-4.3
// Refs: https://github.com/nodejs/node/pull/46528
if (isContentDispositionField(key) && self._contentLength) {
value = Buffer.from(value, 'latin1');
// The value could be an array here
if (ArrayIsArray(value)) {
for (let i = 0; i < value.length; i++) {
value[i] = Buffer.from(value[i], 'latin1');
}
} else {
value = Buffer.from(value, 'latin1');
}
}

if (ArrayIsArray(value)) {
Expand Down
4 changes: 1 addition & 3 deletions lib/diagnostics_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,7 @@ class TracingChannel {
// Using runStores here enables manual context failure recovery
asyncStart.runStores(context, () => {
try {
if (callback) {
return ReflectApply(callback, this, arguments);
}
return ReflectApply(callback, this, arguments);
} finally {
asyncEnd.publish(context);
}
Expand Down
4 changes: 1 addition & 3 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2051,9 +2051,7 @@ function fchownSync(fd, uid, gid) {
validateInteger(uid, 'uid', -1, kMaxUserId);
validateInteger(gid, 'gid', -1, kMaxUserId);

const ctx = {};
binding.fchown(fd, uid, gid, undefined, ctx);
handleErrorFromBinding(ctx);
binding.fchown(fd, uid, gid);
}

/**
Expand Down
17 changes: 13 additions & 4 deletions lib/internal/main/mksnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const {
const { isExperimentalSeaWarningNeeded } = internalBinding('sea');

const { emitExperimentalWarning } = require('internal/util');

const { emitWarningSync } = require('internal/process/warning');
const {
getOptionValue,
} = require('internal/options');
Expand All @@ -29,6 +29,7 @@ const {
namespace: {
addSerializeCallback,
addDeserializeCallback,
isBuildingSnapshot,
},
} = require('internal/v8/startup_snapshot');

Expand Down Expand Up @@ -119,10 +120,18 @@ function requireForUserSnapshot(id) {
err.code = 'MODULE_NOT_FOUND';
throw err;
}
if (!supportedInUserSnapshot(normalizedId)) {
if (isBuildingSnapshot() && !supportedInUserSnapshot(normalizedId)) {
if (!warnedModules.has(normalizedId)) {
process.emitWarning(
`built-in module ${id} is not yet supported in user snapshots`);
// Emit the warning synchronously in case we don't get to process
// the tick and print it before the unsupported built-in causes a
// crash.
emitWarningSync(
`It's not yet fully verified whether built-in module "${id}" ` +
'works in user snapshot builder scripts.\n' +
'It may still work in some cases, but in other cases certain ' +
'run-time states may be out-of-sync after snapshot deserialization.\n' +
'To request support for the module, use the Node.js issue tracker: ' +
'https://github.com/nodejs/node/issues');
warnedModules.add(normalizedId);
}
}
Expand Down
38 changes: 20 additions & 18 deletions lib/internal/test_runner/reporter/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,11 @@ const {
const assert = require('assert');
const Transform = require('internal/streams/transform');
const { inspectWithNoCustomRetry } = require('internal/errors');
const { green, blue, red, white, gray, shouldColorize } = require('internal/util/colors');
const colors = require('internal/util/colors');
const { kSubtestsFailed } = require('internal/test_runner/test');
const { getCoverageReport } = require('internal/test_runner/utils');
const { relative } = require('path');

const inspectOptions = { __proto__: null, colors: shouldColorize(process.stdout), breakLength: Infinity };

const colors = {
'__proto__': null,
'test:fail': red,
'test:pass': green,
'test:diagnostic': blue,
};
const symbols = {
'__proto__': null,
'test:fail': '\u2716 ',
Expand All @@ -42,9 +34,19 @@ class SpecReporter extends Transform {
#indentMemo = new SafeMap();
#failedTests = [];
#cwd = process.cwd();
#inspectOptions;
#colors;

constructor() {
super({ __proto__: null, writableObjectMode: true });
colors.refresh();
this.#inspectOptions = { __proto__: null, colors: colors.shouldColorize(process.stdout), breakLength: Infinity };
this.#colors = {
'__proto__': null,
'test:fail': colors.red,
'test:pass': colors.green,
'test:diagnostic': colors.blue,
};
}

#indent(nesting) {
Expand All @@ -62,15 +64,15 @@ class SpecReporter extends Transform {
const message = ArrayPrototypeJoin(
RegExpPrototypeSymbolSplit(
hardenRegExp(/\r?\n/),
inspectWithNoCustomRetry(err, inspectOptions),
inspectWithNoCustomRetry(err, this.#inspectOptions),
), `\n${indent} `);
return `\n${indent} ${message}\n`;
}
#formatTestReport(type, data, prefix = '', indent = '', hasChildren = false) {
let color = colors[type] ?? white;
let color = this.#colors[type] ?? colors.white;
let symbol = symbols[type] ?? ' ';
const { skip, todo } = data;
const duration_ms = data.details?.duration_ms ? ` ${gray}(${data.details.duration_ms}ms)${white}` : '';
const duration_ms = data.details?.duration_ms ? ` ${colors.gray}(${data.details.duration_ms}ms)${colors.white}` : '';
let title = `${data.name}${duration_ms}`;

if (skip !== undefined) {
Expand All @@ -82,13 +84,13 @@ class SpecReporter extends Transform {
if (hasChildren) {
// If this test has had children - it was already reported, so slightly modify the output
const err = data.details?.error?.failureType === 'subtestsFailed' ? '' : error;
return `${prefix}${indent}${color}${symbols['arrow:right']}${white}${title}\n${err}`;
return `${prefix}${indent}${color}${symbols['arrow:right']}${colors.white}${title}\n${err}`;
}
if (skip !== undefined) {
color = gray;
color = colors.gray;
symbol = symbols['hyphen:minus'];
}
return `${prefix}${indent}${color}${symbol}${title}${white}${error}`;
return `${prefix}${indent}${color}${symbol}${title}${colors.white}${error}`;
}
#handleTestReportEvent(type, data) {
const subtest = ArrayPrototypeShift(this.#stack); // This is the matching `test:start` event
Expand Down Expand Up @@ -130,9 +132,9 @@ class SpecReporter extends Transform {
case 'test:stdout':
return data.message;
case 'test:diagnostic':
return `${colors[type]}${this.#indent(data.nesting)}${symbols[type]}${data.message}${white}\n`;
return `${this.#colors[type]}${this.#indent(data.nesting)}${symbols[type]}${data.message}${colors.white}\n`;
case 'test:coverage':
return getCoverageReport(this.#indent(data.nesting), data.summary, symbols['test:coverage'], blue, true);
return getCoverageReport(this.#indent(data.nesting), data.summary, symbols['test:coverage'], colors.blue, true);
}
}
_transform({ type, data }, encoding, callback) {
Expand All @@ -143,7 +145,7 @@ class SpecReporter extends Transform {
callback(null, '');
return;
}
const results = [`\n${colors['test:fail']}${symbols['test:fail']}failing tests:${white}\n`];
const results = [`\n${this.#colors['test:fail']}${symbols['test:fail']}failing tests:${colors.white}\n`];
for (let i = 0; i < this.#failedTests.length; i++) {
const test = this.#failedTests[i];
const relPath = relative(this.#cwd, test.file);
Expand Down
3 changes: 3 additions & 0 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,9 @@ function run(options = kEmptyObject) {
}

const root = createTestTree({ __proto__: null, concurrency, timeout, signal });
if (process.env.NODE_TEST_CONTEXT !== undefined) {
return root.reporter;
}
let testFiles = files ?? createTestFileList();

if (shard) {
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/util/comparisons.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const {
StringPrototypeValueOf,
SymbolPrototypeValueOf,
TypedArrayPrototypeGetSymbolToStringTag,
TypedArrayPrototypeGetByteLength,
Uint8Array,
} = primordials;

Expand Down Expand Up @@ -71,7 +72,8 @@ function areSimilarFloatArrays(a, b) {
if (a.byteLength !== b.byteLength) {
return false;
}
for (let offset = 0; offset < a.byteLength; offset++) {
const len = TypedArrayPrototypeGetByteLength(a);
for (let offset = 0; offset < len; offset++) {
if (a[offset] !== b[offset]) {
return false;
}
Expand Down
Loading

0 comments on commit a9e393d

Please sign in to comment.