Skip to content

Commit 639130e

Browse files
Trottdanielleadams
authored andcommitted
test: use Object.hasOwn() where applicable
Replace Object.prototpye.hasOwnProperty() with Object.hasOwn() where applicable. PR-URL: #41664 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Mestery <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Tierney Cyren <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent cb362a3 commit 639130e

21 files changed

+40
-40
lines changed

test/common/report.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function _validateContent(report, fields = []) {
6969

7070
checkForUnknownFields(report, sections);
7171
sections.forEach((section) => {
72-
assert(report.hasOwnProperty(section));
72+
assert(Object.hasOwn(report, section));
7373
assert(typeof report[section] === 'object' && report[section] !== null);
7474
});
7575

test/doctool/test-doctool-versions.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ for (const version of versions) {
5151
assert.strictEqual(parts[parts.length - 1], 'x',
5252
`'num' from ${tested} doesn't end in '.x'.`);
5353
const isEvenRelease = Number.parseInt(parts[expectedLength - 2]) % 2 === 0;
54-
const hasLtsProperty = version.hasOwnProperty('lts');
54+
const hasLtsProperty = Object.hasOwn(version, 'lts');
5555
if (hasLtsProperty) {
5656
// Odd-numbered versions of Node.js are never LTS.
5757
assert.ok(isEvenRelease, `${tested} should not be an 'lts' release.`);

test/parallel/test-child-process-constructor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ child.spawn({
7878
stdio: 'pipe'
7979
});
8080

81-
assert.strictEqual(child.hasOwnProperty('pid'), true);
81+
assert.strictEqual(Object.hasOwn(child, 'pid'), true);
8282
assert(Number.isInteger(child.pid));
8383

8484
// Try killing with invalid signal

test/parallel/test-child-process-validate-stdio.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ assert.throws(() => getValidStdio(600), expectedError);
1818
const stdio1 = [];
1919
const result = getValidStdio(stdio1, false);
2020
assert.strictEqual(stdio1.length, 3);
21-
assert.strictEqual(result.hasOwnProperty('stdio'), true);
22-
assert.strictEqual(result.hasOwnProperty('ipc'), true);
23-
assert.strictEqual(result.hasOwnProperty('ipcFd'), true);
21+
assert.strictEqual(Object.hasOwn(result, 'stdio'), true);
22+
assert.strictEqual(Object.hasOwn(result, 'ipc'), true);
23+
assert.strictEqual(Object.hasOwn(result, 'ipcFd'), true);
2424
}
2525

2626
// Should throw if stdio has ipc and sync is true

test/parallel/test-cluster-basic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ if (cluster.isWorker) {
131131
assert.strictEqual(Object.keys(arguments[0]).length, 4);
132132
assert.strictEqual(arguments[0].address, '127.0.0.1');
133133
assert.strictEqual(arguments[0].addressType, 4);
134-
assert(arguments[0].hasOwnProperty('fd'));
134+
assert(Object.hasOwn(arguments[0], 'fd'));
135135
assert.strictEqual(arguments[0].fd, undefined);
136136
const port = arguments[0].port;
137137
assert(Number.isInteger(port));

test/parallel/test-cluster-dgram-1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function primary() {
7272
// Set up event handlers for every worker. Each worker sends a message when
7373
// it has received the expected number of packets. After that it disconnects.
7474
for (const key in cluster.workers) {
75-
if (cluster.workers.hasOwnProperty(key))
75+
if (Object.hasOwn(cluster.workers, key))
7676
setupWorker(cluster.workers[key]);
7777
}
7878

test/parallel/test-cluster-dgram-bind-fd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function primary() {
6363
// Set up event handlers for every worker. Each worker sends a message when
6464
// it has received the expected number of packets. After that it disconnects.
6565
for (const key in cluster.workers) {
66-
if (cluster.workers.hasOwnProperty(key))
66+
if (Object.hasOwn(cluster.workers, key))
6767
setupWorker(cluster.workers[key]);
6868
}
6969

test/parallel/test-disable-proto-delete.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ const { Worker, isMainThread } = require('worker_threads');
99

1010
// eslint-disable-next-line no-proto
1111
assert.strictEqual(Object.prototype.__proto__, undefined);
12-
assert(!Object.prototype.hasOwnProperty('__proto__'));
12+
assert(!Object.hasOwn(Object.prototype, '__proto__'));
1313

1414
const ctx = vm.createContext();
1515
const ctxGlobal = vm.runInContext('this', ctx);
1616

1717
// eslint-disable-next-line no-proto
1818
assert.strictEqual(ctxGlobal.Object.prototype.__proto__, undefined);
19-
assert(!ctxGlobal.Object.prototype.hasOwnProperty('__proto__'));
19+
assert(!Object.hasOwn(ctxGlobal.Object.prototype, '__proto__'));
2020

2121
if (isMainThread) {
2222
new Worker(__filename);

test/parallel/test-disable-proto-throw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const assert = require('assert');
77
const vm = require('vm');
88
const { Worker, isMainThread } = require('worker_threads');
99

10-
assert(Object.prototype.hasOwnProperty('__proto__'));
10+
assert(Object.hasOwn(Object.prototype, '__proto__'));
1111

1212
assert.throws(() => {
1313
// eslint-disable-next-line no-proto,no-unused-expressions

test/parallel/test-event-emitter-check-listener-leaks.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,40 +32,40 @@ const events = require('events');
3232
for (let i = 0; i < 10; i++) {
3333
e.on('default', common.mustNotCall());
3434
}
35-
assert.ok(!e._events.default.hasOwnProperty('warned'));
35+
assert.ok(!Object.hasOwn(e._events.default, 'warned'));
3636
e.on('default', common.mustNotCall());
3737
assert.ok(e._events.default.warned);
3838

3939
// symbol
4040
const symbol = Symbol('symbol');
4141
e.setMaxListeners(1);
4242
e.on(symbol, common.mustNotCall());
43-
assert.ok(!e._events[symbol].hasOwnProperty('warned'));
43+
assert.ok(!Object.hasOwn(e._events[symbol], 'warned'));
4444
e.on(symbol, common.mustNotCall());
45-
assert.ok(e._events[symbol].hasOwnProperty('warned'));
45+
assert.ok(Object.hasOwn(e._events[symbol], 'warned'));
4646

4747
// specific
4848
e.setMaxListeners(5);
4949
for (let i = 0; i < 5; i++) {
5050
e.on('specific', common.mustNotCall());
5151
}
52-
assert.ok(!e._events.specific.hasOwnProperty('warned'));
52+
assert.ok(!Object.hasOwn(e._events.specific, 'warned'));
5353
e.on('specific', common.mustNotCall());
5454
assert.ok(e._events.specific.warned);
5555

5656
// only one
5757
e.setMaxListeners(1);
5858
e.on('only one', common.mustNotCall());
59-
assert.ok(!e._events['only one'].hasOwnProperty('warned'));
59+
assert.ok(!Object.hasOwn(e._events['only one'], 'warned'));
6060
e.on('only one', common.mustNotCall());
61-
assert.ok(e._events['only one'].hasOwnProperty('warned'));
61+
assert.ok(Object.hasOwn(e._events['only one'], 'warned'));
6262

6363
// unlimited
6464
e.setMaxListeners(0);
6565
for (let i = 0; i < 1000; i++) {
6666
e.on('unlimited', common.mustNotCall());
6767
}
68-
assert.ok(!e._events.unlimited.hasOwnProperty('warned'));
68+
assert.ok(!Object.hasOwn(e._events.unlimited, 'warned'));
6969
}
7070

7171
// process-wide
@@ -76,16 +76,16 @@ const events = require('events');
7676
for (let i = 0; i < 42; ++i) {
7777
e.on('fortytwo', common.mustNotCall());
7878
}
79-
assert.ok(!e._events.fortytwo.hasOwnProperty('warned'));
79+
assert.ok(!Object.hasOwn(e._events.fortytwo, 'warned'));
8080
e.on('fortytwo', common.mustNotCall());
81-
assert.ok(e._events.fortytwo.hasOwnProperty('warned'));
81+
assert.ok(Object.hasOwn(e._events.fortytwo, 'warned'));
8282
delete e._events.fortytwo.warned;
8383

8484
events.EventEmitter.defaultMaxListeners = 44;
8585
e.on('fortytwo', common.mustNotCall());
86-
assert.ok(!e._events.fortytwo.hasOwnProperty('warned'));
86+
assert.ok(!Object.hasOwn(e._events.fortytwo, 'warned'));
8787
e.on('fortytwo', common.mustNotCall());
88-
assert.ok(e._events.fortytwo.hasOwnProperty('warned'));
88+
assert.ok(Object.hasOwn(e._events.fortytwo, 'warned'));
8989
}
9090

9191
// But _maxListeners still has precedence over defaultMaxListeners
@@ -94,9 +94,9 @@ const events = require('events');
9494
const e = new events.EventEmitter();
9595
e.setMaxListeners(1);
9696
e.on('uno', common.mustNotCall());
97-
assert.ok(!e._events.uno.hasOwnProperty('warned'));
97+
assert.ok(!Object.hasOwn(e._events.uno, 'warned'));
9898
e.on('uno', common.mustNotCall());
99-
assert.ok(e._events.uno.hasOwnProperty('warned'));
99+
assert.ok(Object.hasOwn(e._events.uno, 'warned'));
100100

101101
// chainable
102102
assert.strictEqual(e, e.setMaxListeners(1));

0 commit comments

Comments
 (0)