diff --git a/eslint.config.mjs b/eslint.config.mjs index a0c1610e7..b948b4562 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -299,6 +299,11 @@ export default [ "BinaryExpression[operator='instanceof'][right.name='Object']", message: "Use `typeof` rather than `instanceof Object`.", }, + { + selector: "MemberExpression[property.name='hasOwnProperty']", + message: + "Use `Object.hasOwn` rather than `Object.prototype.hasOwnProperty`.", + }, { selector: "CallExpression[callee.name='assert'][arguments.length!=2]", message: "`assert()` must always be invoked with two arguments.", diff --git a/src/core/catalog.js b/src/core/catalog.js index da4502b49..2cab5f961 100644 --- a/src/core/catalog.js +++ b/src/core/catalog.js @@ -718,7 +718,7 @@ class Catalog { getDestination(id) { // Avoid extra lookup/parsing when all destinations are already available. - if (this.hasOwnProperty("destinations")) { + if (Object.hasOwn(this, "destinations")) { return this.destinations[id] ?? null; } diff --git a/src/core/worker.js b/src/core/worker.js index 1d1f6f968..0544c93ef 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -127,7 +127,7 @@ class WorkerMessageHandler { // the `{Object, Array}.prototype` has been *incorrectly* extended. // // PLEASE NOTE: We do *not* want to slow down font parsing by adding - // `hasOwnProperty` checks all over the code-base. + // `Object.hasOwn` checks all over the code-base. const buildMsg = (type, prop) => `The \`${type}.prototype\` contains unexpected enumerable property ` + `"${prop}", thus breaking e.g. \`for...in\` iteration of ${type}s.`; diff --git a/src/core/xfa/bind.js b/src/core/xfa/bind.js index 4c6752160..bbe3ab1de 100644 --- a/src/core/xfa/bind.js +++ b/src/core/xfa/bind.js @@ -180,7 +180,7 @@ class Binder { // // - if (!formNode.hasOwnProperty("setProperty")) { + if (!Object.hasOwn(formNode, "setProperty")) { return; } @@ -265,7 +265,7 @@ class Binder { continue; } - if (!targetNode.hasOwnProperty($content)) { + if (!Object.hasOwn(targetNode, $content)) { warn(`XFA - Invalid node to use in setProperty`); continue; } @@ -285,8 +285,8 @@ class Binder { // if ( - !formNode.hasOwnProperty("items") || - !formNode.hasOwnProperty("bindItems") || + !Object.hasOwn(formNode, "items") || + !Object.hasOwn(formNode, "bindItems") || formNode.bindItems.isEmpty() ) { return; diff --git a/src/core/xfa/builder.js b/src/core/xfa/builder.js index 55660fe58..63af9b417 100644 --- a/src/core/xfa/builder.js +++ b/src/core/xfa/builder.js @@ -97,7 +97,7 @@ class Builder { this._addNamespacePrefix(prefixes); } - if (attributes.hasOwnProperty($nsAttributes)) { + if (Object.hasOwn(attributes, $nsAttributes)) { // Only support xfa-data namespace. const dataTemplate = NamespaceSetUp.datasets; const nsAttrs = attributes[$nsAttributes]; diff --git a/src/core/xfa/config.js b/src/core/xfa/config.js index 1a965720b..8e1dbc9d1 100644 --- a/src/core/xfa/config.js +++ b/src/core/xfa/config.js @@ -1355,7 +1355,7 @@ class Zpl extends XFAObject { class ConfigNamespace { static [$buildXFAObject](name, attributes) { - if (ConfigNamespace.hasOwnProperty(name)) { + if (Object.hasOwn(ConfigNamespace, name)) { return ConfigNamespace[name](attributes); } return undefined; diff --git a/src/core/xfa/connection_set.js b/src/core/xfa/connection_set.js index 7e14c5f61..f0ac9f3e5 100644 --- a/src/core/xfa/connection_set.js +++ b/src/core/xfa/connection_set.js @@ -144,7 +144,7 @@ class XsdConnection extends XFAObject { class ConnectionSetNamespace { static [$buildXFAObject](name, attributes) { - if (ConnectionSetNamespace.hasOwnProperty(name)) { + if (Object.hasOwn(ConnectionSetNamespace, name)) { return ConnectionSetNamespace[name](attributes); } return undefined; diff --git a/src/core/xfa/datasets.js b/src/core/xfa/datasets.js index 644c92ed5..5f4257f1a 100644 --- a/src/core/xfa/datasets.js +++ b/src/core/xfa/datasets.js @@ -57,7 +57,7 @@ class Datasets extends XFAObject { class DatasetsNamespace { static [$buildXFAObject](name, attributes) { - if (DatasetsNamespace.hasOwnProperty(name)) { + if (Object.hasOwn(DatasetsNamespace, name)) { return DatasetsNamespace[name](attributes); } return undefined; diff --git a/src/core/xfa/html_utils.js b/src/core/xfa/html_utils.js index 615505ec3..c345d3f7c 100644 --- a/src/core/xfa/html_utils.js +++ b/src/core/xfa/html_utils.js @@ -383,7 +383,7 @@ function toStyle(node, ...names) { if (value === null) { continue; } - if (converters.hasOwnProperty(name)) { + if (Object.hasOwn(converters, name)) { converters[name](node, style); continue; } diff --git a/src/core/xfa/locale_set.js b/src/core/xfa/locale_set.js index 82950161b..4465235ad 100644 --- a/src/core/xfa/locale_set.js +++ b/src/core/xfa/locale_set.js @@ -239,7 +239,7 @@ class TypeFaces extends XFAObject { class LocaleSetNamespace { static [$buildXFAObject](name, attributes) { - if (LocaleSetNamespace.hasOwnProperty(name)) { + if (Object.hasOwn(LocaleSetNamespace, name)) { return LocaleSetNamespace[name](attributes); } return undefined; diff --git a/src/core/xfa/signature.js b/src/core/xfa/signature.js index c13b78887..f2fc22ea7 100644 --- a/src/core/xfa/signature.js +++ b/src/core/xfa/signature.js @@ -26,7 +26,7 @@ class Signature extends XFAObject { class SignatureNamespace { static [$buildXFAObject](name, attributes) { - if (SignatureNamespace.hasOwnProperty(name)) { + if (Object.hasOwn(SignatureNamespace, name)) { return SignatureNamespace[name](attributes); } return undefined; diff --git a/src/core/xfa/stylesheet.js b/src/core/xfa/stylesheet.js index 175b58f4d..8b03c8b35 100644 --- a/src/core/xfa/stylesheet.js +++ b/src/core/xfa/stylesheet.js @@ -26,7 +26,7 @@ class Stylesheet extends XFAObject { class StylesheetNamespace { static [$buildXFAObject](name, attributes) { - if (StylesheetNamespace.hasOwnProperty(name)) { + if (Object.hasOwn(StylesheetNamespace, name)) { return StylesheetNamespace[name](attributes); } return undefined; diff --git a/src/core/xfa/template.js b/src/core/xfa/template.js index 4c643d517..dfcc9fd68 100644 --- a/src/core/xfa/template.js +++ b/src/core/xfa/template.js @@ -6132,7 +6132,7 @@ class Variables extends XFAObject { class TemplateNamespace { static [$buildXFAObject](name, attributes) { - if (TemplateNamespace.hasOwnProperty(name)) { + if (Object.hasOwn(TemplateNamespace, name)) { const node = TemplateNamespace[name](attributes); node[$setSetAttributes](attributes); return node; diff --git a/src/core/xfa/xdp.js b/src/core/xfa/xdp.js index f3968672b..1cb6e93f5 100644 --- a/src/core/xfa/xdp.js +++ b/src/core/xfa/xdp.js @@ -40,7 +40,7 @@ class Xdp extends XFAObject { class XdpNamespace { static [$buildXFAObject](name, attributes) { - if (XdpNamespace.hasOwnProperty(name)) { + if (Object.hasOwn(XdpNamespace, name)) { return XdpNamespace[name](attributes); } return undefined; diff --git a/src/core/xfa/xfa_object.js b/src/core/xfa/xfa_object.js index dc272a9ad..9938fceb3 100644 --- a/src/core/xfa/xfa_object.js +++ b/src/core/xfa/xfa_object.js @@ -171,7 +171,7 @@ class XFAObject { [$onChildCheck](child) { return ( - this.hasOwnProperty(child[$nodeName]) && + Object.hasOwn(this, child[$nodeName]) && child[$namespaceId] === this[$namespaceId] ); } @@ -240,7 +240,7 @@ class XFAObject { } [$hasSettableValue]() { - return this.hasOwnProperty("value"); + return Object.hasOwn(this, "value"); } [$setValue](_) {} @@ -817,7 +817,7 @@ class XmlObject extends XFAObject { for (const [attrName, value] of Object.entries(attributes)) { map.set(attrName, new XFAAttribute(this, attrName, value)); } - if (attributes.hasOwnProperty($nsAttributes)) { + if (Object.hasOwn(attributes, $nsAttributes)) { // XFA attributes. const dataNode = attributes[$nsAttributes].xfa.dataNode; if (dataNode !== undefined) { diff --git a/src/core/xfa/xhtml.js b/src/core/xfa/xhtml.js index c31fbcf09..47a0056d0 100644 --- a/src/core/xfa/xhtml.js +++ b/src/core/xfa/xhtml.js @@ -530,7 +530,7 @@ class Ul extends XhtmlObject { class XhtmlNamespace { static [$buildXFAObject](name, attributes) { - if (XhtmlNamespace.hasOwnProperty(name)) { + if (Object.hasOwn(XhtmlNamespace, name)) { return XhtmlNamespace[name](attributes); } return undefined; diff --git a/src/display/api.js b/src/display/api.js index 314206ac8..082e920ff 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -2575,7 +2575,7 @@ class WorkerTransport { this.#pagePromises.clear(); this.#pageRefCache.clear(); // Allow `AnnotationStorage`-related clean-up when destroying the document. - if (this.hasOwnProperty("annotationStorage")) { + if (Object.hasOwn(this, "annotationStorage")) { this.annotationStorage.resetModified(); } // We also need to wait for the worker to finish its long running tasks. diff --git a/src/display/xfa_layer.js b/src/display/xfa_layer.js index 2cd8452c3..a23ab1c20 100644 --- a/src/display/xfa_layer.js +++ b/src/display/xfa_layer.js @@ -86,7 +86,7 @@ class XfaLayer { for (const option of element.children) { if (option.attributes.value === storedData.value) { option.attributes.selected = true; - } else if (option.attributes.hasOwnProperty("selected")) { + } else if (Object.hasOwn(option.attributes, "selected")) { delete option.attributes.selected; } } diff --git a/src/scripting_api/field.js b/src/scripting_api/field.js index 5e355d924..0834bc6bb 100644 --- a/src/scripting_api/field.js +++ b/src/scripting_api/field.js @@ -77,7 +77,7 @@ class Field extends PDFObject { this._fillColor = data.fillColor || ["T"]; this._isChoice = Array.isArray(data.items); this._items = data.items || []; - this._hasValue = data.hasOwnProperty("value"); + this._hasValue = Object.hasOwn(data, "value"); this._page = data.page || 0; this._strokeColor = data.strokeColor || ["G", 0]; this._textColor = data.textColor || ["G", 0];