Skip to content

Commit dcf1ea0

Browse files
Trotttargos
authored andcommitted
benchmark,test: use Object.hasOwn() where applicable
Refs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn PR-URL: #41229 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent e457ec0 commit dcf1ea0

6 files changed

+9
-11
lines changed

benchmark/common.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class Benchmark {
9191
process.exit(1);
9292
}
9393
const [, key, value] = match;
94-
if (Object.prototype.hasOwnProperty.call(configs, key)) {
94+
if (Object.hasOwn(configs, key)) {
9595
if (!cliOptions[key])
9696
cliOptions[key] = [];
9797
cliOptions[key].push(

benchmark/es/map-bench.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function fakeMap() {
7272
get(key) { return m[`$${key}`]; },
7373
set(key, val) { m[`$${key}`] = val; },
7474
get size() { return Object.keys(m).length; },
75-
has(key) { return Object.prototype.hasOwnProperty.call(m, `$${key}`); }
75+
has(key) { return Object.hasOwn(m, `$${key}`); }
7676
};
7777
}
7878

test/parallel/test-http2-capture-rejection.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ events.captureRejections = true;
9090

9191
req.on('response', common.mustCall((headers) => {
9292
assert.strictEqual(headers[':status'], 500);
93-
assert.strictEqual(Object.hasOwnProperty.call(headers, 'content-type'),
94-
false);
93+
assert.strictEqual(Object.hasOwn(headers, 'content-type'), false);
9594
}));
9695

9796
req.on('close', common.mustCall(() => {

test/parallel/test-http2-compat-serverrequest-host.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ server.listen(0, common.mustCall(function() {
3636
assert.strictEqual(rawHeaders[position + 1], value);
3737
}
3838

39-
assert(!Object.hasOwnProperty.call(headers, ':authority'));
40-
assert(!Object.hasOwnProperty.call(rawHeaders, ':authority'));
39+
assert(!Object.hasOwn(headers, ':authority'));
40+
assert(!Object.hasOwn(rawHeaders, ':authority'));
4141

4242
response.on('finish', common.mustCall(function() {
4343
server.close();

test/parallel/test-process-env.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ if (process.argv[2] === 'you-are-the-child') {
2929
assert.strictEqual('NODE_PROCESS_ENV_DELETED' in process.env, false);
3030
assert.strictEqual(process.env.NODE_PROCESS_ENV, '42');
3131
assert.strictEqual(process.env.hasOwnProperty, 'asdf');
32-
const hasOwnProperty = Object.prototype.hasOwnProperty;
33-
const has = hasOwnProperty.call(process.env, 'hasOwnProperty');
32+
const has = Object.hasOwn(process.env, 'hasOwnProperty');
3433
assert.strictEqual(has, true);
3534
process.exit(0);
3635
}

test/parallel/test-whatwg-url-properties.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function testMethod(target, name, methodName = stringifyName(name)) {
6868
assert.strictEqual(typeof value, 'function');
6969
assert.strictEqual(value.name, methodName);
7070
assert.strictEqual(
71-
Object.prototype.hasOwnProperty.call(value, 'prototype'),
71+
Object.hasOwn(value, 'prototype'),
7272
false,
7373
);
7474
}
@@ -83,7 +83,7 @@ function testAccessor(target, name, readonly = false) {
8383
assert.strictEqual(typeof get, 'function');
8484
assert.strictEqual(get.name, `get ${methodName}`);
8585
assert.strictEqual(
86-
Object.prototype.hasOwnProperty.call(get, 'prototype'),
86+
Object.hasOwn(get, 'prototype'),
8787
false,
8888
);
8989

@@ -93,7 +93,7 @@ function testAccessor(target, name, readonly = false) {
9393
assert.strictEqual(typeof set, 'function');
9494
assert.strictEqual(set.name, `set ${methodName}`);
9595
assert.strictEqual(
96-
Object.prototype.hasOwnProperty.call(set, 'prototype'),
96+
Object.hasOwn(set, 'prototype'),
9797
false,
9898
);
9999
}

0 commit comments

Comments
 (0)