Skip to content

util: prefer `Reflect.ownKeys(…)` in `util.inspect(…)`

Using Reflect.ownKeys(obj) instead of:

const keys = Object.getOwnPropertyNames(obj);
const symbols = Object.getOwnPropertySymbols(obj);
if (symbols.length !== 0) {
	keys.push(...symbols);
}

is more efficient, as it only has to call obj.[[OwnPropertyKeys]]() once and return the resulting List as an Array, instead of calling it twice and returning two separate arrays, which have the string and symbol keys filtered: https://tc39.es/ecma262/#sec-getownpropertykeys, which are then joined back using %Array.prototype.push%.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

Merge request reports

Loading