Skip to content

Commit

Permalink
Update all Object.fromEntries call-sites to ensure that a null pr…
Browse files Browse the repository at this point in the history
…ototype is used

Given that `Object.fromEntries` doesn't seem to *guarantee* that a `null` prototype is used, we thus hack around that by using `Object.assign` with `Object.create(null)`.
  • Loading branch information
Snuffleupagus committed Oct 28, 2020
1 parent 9fc7cdc commit 820fb7f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/display/annotation_storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* limitations under the License.
*/

import { objectFromEntries } from "../shared/util.js";

/**
* Key/value storage for annotation data in forms.
*/
Expand Down Expand Up @@ -67,7 +69,7 @@ class AnnotationStorage {
if (this._storage.size === 0) {
return null;
}
return Object.fromEntries(this._storage);
return objectFromEntries(this._storage);
}

get size() {
Expand Down
4 changes: 2 additions & 2 deletions src/display/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import { assert } from "../shared/util.js";
import { assert, objectFromEntries } from "../shared/util.js";
import { SimpleXMLParser } from "../shared/xml_parser.js";

class Metadata {
Expand Down Expand Up @@ -118,7 +118,7 @@ class Metadata {
}

getAll() {
return Object.fromEntries(this._metadataMap);
return objectFromEntries(this._metadataMap);
}

has(name) {
Expand Down
4 changes: 2 additions & 2 deletions src/display/optional_content_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { warn } from "../shared/util.js";
import { objectFromEntries, warn } from "../shared/util.js";

class OptionalContentGroup {
constructor(name, intent) {
Expand Down Expand Up @@ -145,7 +145,7 @@ class OptionalContentConfig {
if (!this._groups.size) {
return null;
}
return Object.fromEntries(this._groups);
return objectFromEntries(this._groups);
}

getGroup(id) {
Expand Down

0 comments on commit 820fb7f

Please sign in to comment.