Replace the objectFromEntries helper function with an objectFromMap one instead

Given that it's only used with `Map`s, and that it's currently implemented in such a way that we (indirectly) must iterate through the data *twice*, some simplification cannot hurt here.
Note that the only reason that we're not using `Object.fromEntries(...)` directly, at each call-site, is that that one won't guarantee that a `null` prototype is being used.
This commit is contained in:
Jonas Jenwald 2021-03-11 16:20:53 +01:00
parent 3d4bb5e5c5
commit a0e584eeb2
4 changed files with 15 additions and 13 deletions

View file

@ -597,9 +597,14 @@ function objectSize(obj) {
return Object.keys(obj).length;
}
// Ensures that the returned Object has a `null` prototype.
function objectFromEntries(iterable) {
return Object.assign(Object.create(null), Object.fromEntries(iterable));
// Ensure that the returned Object has a `null` prototype; hence why
// `Object.fromEntries(...)` is not used.
function objectFromMap(map) {
const obj = Object.create(null);
for (const [key, value] of map) {
obj[key] = value;
}
return obj;
}
// Checks the endianness of the platform.
@ -1006,7 +1011,7 @@ export {
isSameOrigin,
isString,
MissingPDFException,
objectFromEntries,
objectFromMap,
objectSize,
OPS,
PageActionEventType,