From dcf1ea0a3fa3df1733c0e7c1f5cb23b870fb02eb Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 19 Dec 2021 20:03:58 -0800 Subject: [PATCH] benchmark,test: use Object.hasOwn() where applicable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Darshan Sen Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Tobias Nießen --- benchmark/common.js | 2 +- benchmark/es/map-bench.js | 2 +- test/parallel/test-http2-capture-rejection.js | 3 +-- test/parallel/test-http2-compat-serverrequest-host.js | 4 ++-- test/parallel/test-process-env.js | 3 +-- test/parallel/test-whatwg-url-properties.js | 6 +++--- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/benchmark/common.js b/benchmark/common.js index 28a317b9a1d7a4..dbe69e31ad58de 100644 --- a/benchmark/common.js +++ b/benchmark/common.js @@ -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( diff --git a/benchmark/es/map-bench.js b/benchmark/es/map-bench.js index d0b8534cf7c906..7e5e8824bfecb5 100644 --- a/benchmark/es/map-bench.js +++ b/benchmark/es/map-bench.js @@ -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}`); } }; } diff --git a/test/parallel/test-http2-capture-rejection.js b/test/parallel/test-http2-capture-rejection.js index 4469c6b7e64d20..6d8cb224ce7919 100644 --- a/test/parallel/test-http2-capture-rejection.js +++ b/test/parallel/test-http2-capture-rejection.js @@ -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(() => { diff --git a/test/parallel/test-http2-compat-serverrequest-host.js b/test/parallel/test-http2-compat-serverrequest-host.js index 36600f787ca2e3..e5593deb1ed2be 100644 --- a/test/parallel/test-http2-compat-serverrequest-host.js +++ b/test/parallel/test-http2-compat-serverrequest-host.js @@ -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(); diff --git a/test/parallel/test-process-env.js b/test/parallel/test-process-env.js index 2252ddea71675a..506e389d8848aa 100644 --- a/test/parallel/test-process-env.js +++ b/test/parallel/test-process-env.js @@ -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); } diff --git a/test/parallel/test-whatwg-url-properties.js b/test/parallel/test-whatwg-url-properties.js index a387b0eb753e1a..067a32919571ac 100644 --- a/test/parallel/test-whatwg-url-properties.js +++ b/test/parallel/test-whatwg-url-properties.js @@ -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, ); }