Skip to content

Commit

Permalink
Merge branch 'main' into fix-49848
Browse files Browse the repository at this point in the history
  • Loading branch information
MrJithil authored Sep 28, 2023
2 parents 7f12e59 + cc725a6 commit 4c7229c
Show file tree
Hide file tree
Showing 42 changed files with 731 additions and 339 deletions.
File renamed without changes.
66 changes: 66 additions & 0 deletions benchmark/error/node-error-instantiation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
'use strict';

const common = require('../common');
const assert = require('assert');

const bench = common.createBenchmark(main, {
n: [1e6],
code: [
'built-in',
'ERR_HTTP2_STREAM_SELF_DEPENDENCY',
'ERR_INVALID_STATE',
'ERR_INVALID_URL',
],
stackTraceLimit: [0, 10],
}, {
flags: ['--expose-internals'],
});

function getErrorFactory(code) {
const {
ERR_HTTP2_STREAM_SELF_DEPENDENCY,
ERR_INVALID_STATE,
ERR_INVALID_URL,
} = require('internal/errors').codes;

switch (code) {
case 'built-in':
return (n) => new Error();
case 'ERR_HTTP2_STREAM_SELF_DEPENDENCY':
return (n) => new ERR_HTTP2_STREAM_SELF_DEPENDENCY();
case 'ERR_INVALID_STATE':
return (n) => new ERR_INVALID_STATE(n + '');
case 'ERR_INVALID_URL':
return (n) => new ERR_INVALID_URL({ input: n + '' });
default:
throw new Error(`${code} not supported`);
}
}

function main({ n, code, stackTraceLimit }) {
const getError = getErrorFactory(code);

Error.stackTraceLimit = stackTraceLimit;

// Warm up.
const length = 1024;
const array = [];
for (let i = 0; i < length; ++i) {
array.push(getError(i));
}

bench.start();

for (let i = 0; i < n; ++i) {
const index = i % length;
array[index] = getError(index);
}

bench.end(n);

// Verify the entries to prevent dead code elimination from making
// the benchmark invalid.
for (let i = 0; i < length; ++i) {
assert.strictEqual(typeof array[i], 'object');
}
}
62 changes: 62 additions & 0 deletions benchmark/error/node-error-stack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict';

const common = require('../common');
const assert = require('assert');

const bench = common.createBenchmark(main, {
n: [1e6],
code: [
'built-in',
'ERR_HTTP2_STREAM_SELF_DEPENDENCY',
'ERR_INVALID_STATE',
],
stackTraceLimit: [0, 10],
}, {
flags: ['--expose-internals'],
});

function getErrorStackFactory(code) {
const {
ERR_INVALID_STATE,
ERR_HTTP2_STREAM_SELF_DEPENDENCY,
} = require('internal/errors').codes;

switch (code) {
case 'built-in':
return (n) => new Error().stack;
case 'ERR_HTTP2_STREAM_SELF_DEPENDENCY':
return (n) => new ERR_HTTP2_STREAM_SELF_DEPENDENCY().stack;
case 'ERR_INVALID_STATE':
return (n) => new ERR_INVALID_STATE(n + '').stack;
default:
throw new Error(`${code} not supported`);
}
}

function main({ n, code, stackTraceLimit }) {
const getStack = getErrorStackFactory(code);

Error.stackTraceLimit = stackTraceLimit;

// Warm up.
const length = 1024;
const array = [];
for (let i = 0; i < length; ++i) {
array.push(getStack(i));
}

bench.start();

for (let i = 0; i < n; ++i) {
const index = i % length;
array[index] = getStack(index);
}

bench.end(n);

// Verify the entries to prevent dead code elimination from making
// the benchmark invalid.
for (let i = 0; i < length; ++i) {
assert.strictEqual(typeof array[i], 'string');
}
}
21 changes: 0 additions & 21 deletions benchmark/error/node-error.js

This file was deleted.

43 changes: 43 additions & 0 deletions benchmark/fs/bench-unlinkSync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

const common = require('../common');
const fs = require('fs');
const tmpdir = require('../../test/common/tmpdir');
tmpdir.refresh();

const bench = common.createBenchmark(main, {
type: ['existing', 'non-existing'],
n: [1e3],
});

function main({ n, type }) {
let files;

switch (type) {
case 'existing':
files = [];

// Populate tmpdir with mock files
for (let i = 0; i < n; i++) {
const path = tmpdir.resolve(`unlinksync-bench-file-${i}`);
fs.writeFileSync(path, 'bench');
files.push(path);
}
break;
case 'non-existing':
files = new Array(n).fill(tmpdir.resolve(`.non-existing-file-${Date.now()}`));
break;
default:
new Error('Invalid type');
}

bench.start();
for (let i = 0; i < n; i++) {
try {
fs.unlinkSync(files[i]);
} catch {
// do nothing
}
}
bench.end(n);
}
36 changes: 36 additions & 0 deletions benchmark/perf_hooks/timerfied.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

const assert = require('assert');
const common = require('../common.js');

const {
PerformanceObserver,
performance,
} = require('perf_hooks');

function randomFn() {
return Math.random();
}

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

let _result;

function main({ n, observe }) {
const obs = new PerformanceObserver(() => {
bench.end(n);
});
obs.observe({ entryTypes: [observe], buffered: true });

const timerfied = performance.timerify(randomFn);

bench.start();
for (let i = 0; i < n; i++)
_result = timerfied();

// Avoid V8 deadcode (elimination)
assert.ok(_result);
}
23 changes: 23 additions & 0 deletions benchmark/url/whatwg-url-validity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
const common = require('../common.js');
const url = require('url');
const URL = url.URL;

const bench = common.createBenchmark(main, {
type: ['valid', 'invalid'],
e: [1e5],
});

// This benchmark is used to compare the `Invalid URL` path of the URL parser
function main({ type, e }) {
const url = type === 'valid' ? 'https://www.nodejs.org' : 'www.nodejs.org';
bench.start();
for (let i = 0; i < e; i++) {
try {
new URL(url);
} catch {
// do nothing
}
}
bench.end(e);
}
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.18',
'v8_embedder_string': '-node.19',

##### V8 defaults for Node.js #####

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ EmbeddedTargetOs ToEmbeddedTargetOs(const char* s) {
}

std::string string(s);
if (string == "aix") {
// Python 3.9+ on IBM i returns os400 as sys.platform instead of aix
if (string == "aix" || string == "os400") {
return EmbeddedTargetOs::kAIX;
} else if (string == "chromeos") {
return EmbeddedTargetOs::kChromeOS;
Expand Down
5 changes: 1 addition & 4 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1850,10 +1850,7 @@ function unlink(path, callback) {
* @returns {void}
*/
function unlinkSync(path) {
path = getValidatedPath(path);
const ctx = { path };
binding.unlink(pathModule.toNamespacedPath(path), undefined, ctx);
handleErrorFromBinding(ctx);
return syncFs.unlink(path);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/crypto/hkdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const validateParameters = hideStackFrames((hash, key, salt, info, length) => {
validateInteger(length, 'length', 0, kMaxLength);

if (info.byteLength > 1024) {
throw ERR_OUT_OF_RANGE(
throw new ERR_OUT_OF_RANGE(
'info',
'must not contain more than 1024 bytes',
info.byteLength);
Expand Down
Loading

0 comments on commit 4c7229c

Please sign in to comment.