Skip to content

Commit

Permalink
Merge branch 'main' into dev-48730
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcanaltin authored Sep 27, 2023
2 parents 557f2b9 + a6ad048 commit f5f6397
Show file tree
Hide file tree
Showing 20 changed files with 340 additions and 191 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ on:
- corepack
- doc
- eslint
- github_reporter
- googletest
- histogram
- icu
Expand Down
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);
}
7 changes: 6 additions & 1 deletion lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1370,8 +1370,13 @@ E('ERR_INVALID_SYNC_FORK_INPUT',
E('ERR_INVALID_THIS', 'Value of "this" must be of type %s', TypeError);
E('ERR_INVALID_TUPLE', '%s must be an iterable %s tuple', TypeError);
E('ERR_INVALID_URI', 'URI malformed', URIError);
E('ERR_INVALID_URL', function(input) {
E('ERR_INVALID_URL', function(input, base = null) {
this.input = input;

if (base != null) {
this.base = base;
}

// Don't include URL in message.
// (See https://github.com/nodejs/node/pull/38614)
return 'Invalid URL';
Expand Down
26 changes: 16 additions & 10 deletions lib/internal/perf/performance_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const {
ObjectDefineProperties,
ReflectConstruct,
Symbol,
} = primordials;

Expand All @@ -25,14 +24,17 @@ const kEntryType = Symbol('PerformanceEntry.EntryType');
const kStartTime = Symbol('PerformanceEntry.StartTime');
const kDuration = Symbol('PerformanceEntry.Duration');
const kDetail = Symbol('NodePerformanceEntry.Detail');
const kSkipThrow = Symbol('kSkipThrow');

function isPerformanceEntry(obj) {
return obj?.[kName] !== undefined;
}

class PerformanceEntry {
constructor() {
throw new ERR_ILLEGAL_CONSTRUCTOR();
constructor(skipThrowSymbol = undefined) {
if (skipThrowSymbol !== kSkipThrow) {
throw new ERR_ILLEGAL_CONSTRUCTOR();
}
}

get name() {
Expand Down Expand Up @@ -92,9 +94,11 @@ function initPerformanceEntry(entry, name, type, start, duration) {
}

function createPerformanceEntry(name, type, start, duration) {
return ReflectConstruct(function PerformanceEntry() {
initPerformanceEntry(this, name, type, start, duration);
}, [], PerformanceEntry);
const entry = new PerformanceEntry(kSkipThrow);

initPerformanceEntry(entry, name, type, start, duration);

return entry;
}

/**
Expand All @@ -119,10 +123,12 @@ class PerformanceNodeEntry extends PerformanceEntry {
}

function createPerformanceNodeEntry(name, type, start, duration, detail) {
return ReflectConstruct(function PerformanceNodeEntry() {
initPerformanceEntry(this, name, type, start, duration);
this[kDetail] = detail;
}, [], PerformanceNodeEntry);
const entry = new PerformanceNodeEntry(kSkipThrow);

initPerformanceEntry(entry, name, type, start, duration);
entry[kDetail] = detail;

return entry;
}

module.exports = {
Expand Down
Loading

0 comments on commit f5f6397

Please sign in to comment.