From: Jérôme Benoit Date: Tue, 25 Oct 2022 22:22:27 +0000 (+0200) Subject: Fix empty object implementation X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=baef08960965e3735ae6edddcf6c148fa534564a;p=benchmarks-js.git Fix empty object implementation Signed-off-by: Jérôme Benoit --- diff --git a/is-empty-object.js b/is-empty-object.js index 909a7d7..2b3be46 100644 --- a/is-empty-object.js +++ b/is-empty-object.js @@ -10,7 +10,7 @@ for (let i = 0; i < size; i++) { Benchmark.suite( `Is empty object with ${size} keys`, Benchmark.add('Reflect keys', (obj = testObject) => { - return Reflect.ownKeys(obj).length === 0 && obj.constructor === Object + return Reflect.ownKeys(obj).length === 0 && obj?.constructor === Object }), Benchmark.add('Keys iteration ', (obj = testObject) => { if (obj?.constructor !== Object) return false @@ -21,7 +21,7 @@ Benchmark.suite( return true }), Benchmark.add('Object keys', (obj = testObject) => { - return obj.constructor === Object && !Object.keys(obj).length + return obj?.constructor === Object && !Object.keys(obj).length }), Benchmark.cycle(), Benchmark.complete(),