Skip to content

Commit

Permalink
benchmark,test: use Object.hasOwn() where applicable
Browse files Browse the repository at this point in the history
Refs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn

PR-URL: #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>
  • Loading branch information
Trott authored and targos committed Jan 14, 2022
1 parent e457ec0 commit dcf1ea0
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion benchmark/es/map-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`); }
};
}

Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-http2-capture-rejection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http2-compat-serverrequest-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-process-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-whatwg-url-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
Expand All @@ -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,
);

Expand All @@ -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,
);
}
Expand Down

0 comments on commit dcf1ea0

Please sign in to comment.