benchmark,test: use Object.hasOwn() where applicable

Refs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn

PR-URL: https://github.com/nodejs/node/pull/41229
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
Rich Trott authored and Michaël Zasso committed 2022-01-14 16:19:31 +01:00
1 parent e457ec05d6
commit dcf1ea0a3f
6 files changed
+9 -11

No files matched your search

+1 -1
View File
@@ -91,7 +91,7 @@ class Benchmark {
process.exit(1);
}
const [, key, value] = match;
if (Object.prototype.hasOwnProperty.call(configs, key)) {
if (Object.hasOwn(configs, key)) {
if (!cliOptions[key])
cliOptions[key] = [];
cliOptions[key].push(
+1 -1
View File
@@ -72,7 +72,7 @@ function fakeMap() {
get(key) { return m[`$${key}`]; },
set(key, val) { m[`$${key}`] = val; },
get size() { return Object.keys(m).length; },
has(key) { return Object.prototype.hasOwnProperty.call(m, `$${key}`); }
has(key) { return Object.hasOwn(m, `$${key}`); }
};
}
@@ -90,8 +90,7 @@ events.captureRejections = true;
req.on('response', common.mustCall((headers) => {
assert.strictEqual(headers[':status'], 500);
assert.strictEqual(Object.hasOwnProperty.call(headers, 'content-type'),
false);
assert.strictEqual(Object.hasOwn(headers, 'content-type'), false);
}));
req.on('close', common.mustCall(() => {
@@ -36,8 +36,8 @@ server.listen(0, common.mustCall(function() {
assert.strictEqual(rawHeaders[position + 1], value);
}
assert(!Object.hasOwnProperty.call(headers, ':authority'));
assert(!Object.hasOwnProperty.call(rawHeaders, ':authority'));
assert(!Object.hasOwn(headers, ':authority'));
assert(!Object.hasOwn(rawHeaders, ':authority'));
response.on('finish', common.mustCall(function() {
server.close();
+1 -2
View File
@@ -29,8 +29,7 @@ if (process.argv[2] === 'you-are-the-child') {
assert.strictEqual('NODE_PROCESS_ENV_DELETED' in process.env, false);
assert.strictEqual(process.env.NODE_PROCESS_ENV, '42');
assert.strictEqual(process.env.hasOwnProperty, 'asdf');
const hasOwnProperty = Object.prototype.hasOwnProperty;
const has = hasOwnProperty.call(process.env, 'hasOwnProperty');
const has = Object.hasOwn(process.env, 'hasOwnProperty');
assert.strictEqual(has, true);
process.exit(0);
}
+3 -3
View File
@@ -68,7 +68,7 @@ function testMethod(target, name, methodName = stringifyName(name)) {
assert.strictEqual(typeof value, 'function');
assert.strictEqual(value.name, methodName);
assert.strictEqual(
Object.prototype.hasOwnProperty.call(value, 'prototype'),
Object.hasOwn(value, 'prototype'),
false,
);
}
@@ -83,7 +83,7 @@ function testAccessor(target, name, readonly = false) {
assert.strictEqual(typeof get, 'function');
assert.strictEqual(get.name, `get ${methodName}`);
assert.strictEqual(
Object.prototype.hasOwnProperty.call(get, 'prototype'),
Object.hasOwn(get, 'prototype'),
false,
);
@@ -93,7 +93,7 @@ function testAccessor(target, name, readonly = false) {
assert.strictEqual(typeof set, 'function');
assert.strictEqual(set.name, `set ${methodName}`);
assert.strictEqual(
Object.prototype.hasOwnProperty.call(set, 'prototype'),
Object.hasOwn(set, 'prototype'),
false,
);
}