From 0fce659bb07d4d04f8f2c2da8a717f26263ad1b8 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 24 Mar 2025 08:15:09 -0400 Subject: [PATCH] Use `Object.hasOwn` instead of `Object.prototype.hasOwnProperty` Reference: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn --- platform/common/vapi-background.js | 7 ++---- src/js/3p-filters.js | 8 ++----- src/js/advanced-settings.js | 2 +- src/js/assets.js | 5 +--- src/js/cachestorage.js | 12 ++++------ src/js/document-blocked.js | 2 +- src/js/dyna-rules.js | 2 +- src/js/dynamic-net-filtering.js | 2 +- src/js/hnswitches.js | 2 +- src/js/i18n.js | 2 +- src/js/logger-ui.js | 13 ++++------ src/js/messaging.js | 9 +++---- src/js/popup-fenix.js | 9 +++---- src/js/resources/run-at.js | 2 +- src/js/reverselookup.js | 2 +- src/js/s14e-serializer.js | 5 +--- src/js/start.js | 6 ++--- src/js/storage.js | 38 +++++++++++++----------------- src/js/text-encode.js | 2 +- src/js/ublock.js | 2 +- src/js/utils.js | 4 ++-- 21 files changed, 52 insertions(+), 84 deletions(-) diff --git a/platform/common/vapi-background.js b/platform/common/vapi-background.js index 5fcff01f8..d292341ec 100644 --- a/platform/common/vapi-background.js +++ b/platform/common/vapi-background.js @@ -43,9 +43,6 @@ if ( vAPI.canWASM === false ) { vAPI.supportsUserStylesheets = vAPI.webextFlavor.soup.has('user_stylesheet'); -const hasOwnProperty = (o, p) => - Object.prototype.hasOwnProperty.call(o, p); - /******************************************************************************/ vAPI.app = { @@ -190,7 +187,7 @@ vAPI.browserSettings = (( ) => { set: function(details) { for ( const setting in details ) { - if ( hasOwnProperty(details, setting) === false ) { continue; } + if ( Object.hasOwn(details, setting) === false ) { continue; } switch ( setting ) { case 'prefetching': { const enabled = !!details[setting]; @@ -1220,7 +1217,7 @@ vAPI.Net = class { { const wrrt = browser.webRequest.ResourceType; for ( const typeKey in wrrt ) { - if ( hasOwnProperty(wrrt, typeKey) ) { + if ( Object.hasOwn(wrrt, typeKey) ) { this.validTypes.add(wrrt[typeKey]); } } diff --git a/src/js/3p-filters.js b/src/js/3p-filters.js index e551dcfd0..fed315421 100644 --- a/src/js/3p-filters.js +++ b/src/js/3p-filters.js @@ -30,10 +30,6 @@ const obsoleteTemplateString = i18n$('3pExternalListObsolete'); const reValidExternalList = /^[a-z-]+:\/\/(?:\S+\/\S*|\/\S+)/m; const recentlyUpdated = 1 * 60 * 60 * 1000; // 1 hour -// https://eslint.org/docs/latest/rules/no-prototype-builtins -const hasOwnProperty = (o, p) => - Object.prototype.hasOwnProperty.call(o, p); - let listsetDetails = {}; /******************************************************************************/ @@ -246,7 +242,7 @@ const renderFilterLists = ( ) => { } for ( const [ listkey, listDetails ] of Object.entries(response.available) ) { let groupkey = listDetails.group2 || listDetails.group; - if ( hasOwnProperty(listTree, groupkey) === false ) { + if ( Object.hasOwn(listTree, groupkey) === false ) { groupkey = 'unknown'; } const groupDetails = listTree[groupkey]; @@ -603,7 +599,7 @@ const selectFilterLists = async ( ) => { const toRemove = []; for ( const liEntry of qsa$('#lists .listEntry[data-role="leaf"]') ) { const listkey = liEntry.dataset.key; - if ( hasOwnProperty(listsetDetails.available, listkey) === false ) { + if ( Object.hasOwn(listsetDetails.available, listkey) === false ) { continue; } const listDetails = listsetDetails.available[listkey]; diff --git a/src/js/advanced-settings.js b/src/js/advanced-settings.js index de7da56b2..d40ab7630 100644 --- a/src/js/advanced-settings.js +++ b/src/js/advanced-settings.js @@ -88,7 +88,7 @@ const hashFromAdvancedSettings = function(raw) { const arrayFromObject = function(o) { const out = []; for ( const k in o ) { - if ( o.hasOwnProperty(k) === false ) { continue; } + if ( Object.hasOwn(o, k) === false ) { continue; } out.push([ k, `${o[k]}` ]); } return out; diff --git a/src/js/assets.js b/src/js/assets.js index ba7c4cf70..a9d07cf0a 100644 --- a/src/js/assets.js +++ b/src/js/assets.js @@ -47,9 +47,6 @@ let remoteServerFriendly = false; /******************************************************************************/ -const hasOwnProperty = (o, p) => - Object.prototype.hasOwnProperty.call(o, p); - const stringIsNotEmpty = s => typeof s === 'string' && s !== ''; const parseExpires = s => { @@ -735,7 +732,7 @@ async function assetCacheRead(assetKey, updateReadTime = false) { } if ( bin instanceof Object === false ) { return reportBack(''); } - if ( hasOwnProperty(bin, internalKey) === false ) { return reportBack(''); } + if ( Object.hasOwn(bin, internalKey) === false ) { return reportBack(''); } const entry = assetCacheRegistry[assetKey]; if ( entry === undefined ) { return reportBack(''); } diff --git a/src/js/cachestorage.js b/src/js/cachestorage.js index 97b8b6f05..91578f667 100644 --- a/src/js/cachestorage.js +++ b/src/js/cachestorage.js @@ -44,10 +44,6 @@ const keysFromGetArg = arg => { let fastCache = 'indexedDB'; -// https://eslint.org/docs/latest/rules/no-prototype-builtins -const hasOwnProperty = (o, p) => - Object.prototype.hasOwnProperty.call(o, p); - /******************************************************************************* * * Extension storage @@ -76,7 +72,7 @@ const cacheStorage = (( ) => { if ( found.length === wanted.length ) { return; } const missing = []; for ( const key of wanted ) { - if ( hasOwnProperty(outbin, key) ) { continue; } + if ( Object.hasOwn(outbin, key) ) { continue; } missing.push(key); } return missing; @@ -118,7 +114,7 @@ const cacheStorage = (( ) => { if ( argbin instanceof Object === false ) { return; } if ( Array.isArray(argbin) ) { return; } for ( const key of wanted ) { - if ( hasOwnProperty(argbin, key) === false ) { continue; } + if ( Object.hasOwn(argbin, key) === false ) { continue; } outbin[key] = argbin[key]; } }).then(( ) => { @@ -187,7 +183,7 @@ const cacheStorage = (( ) => { }, select(api) { - if ( hasOwnProperty(cacheAPIs, api) === false ) { return fastCache; } + if ( Object.hasOwn(cacheAPIs, api) === false ) { return fastCache; } fastCache = api; for ( const k of Object.keys(cacheAPIs) ) { if ( k === api ) { continue; } @@ -672,7 +668,7 @@ const idbStorage = (( ) => { } if ( argbin instanceof Object && Array.isArray(argbin) === false ) { for ( const key of keys ) { - if ( hasOwnProperty(outbin, key) ) { continue; } + if ( Object.hasOwn(outbin, key) ) { continue; } outbin[key] = argbin[key]; } } diff --git a/src/js/document-blocked.js b/src/js/document-blocked.js index 2d7f28a7a..aabcf2eb3 100644 --- a/src/js/document-blocked.js +++ b/src/js/document-blocked.js @@ -45,7 +45,7 @@ let details = {}; let lists; for ( const rawFilter in response ) { - if ( Object.prototype.hasOwnProperty.call(response, rawFilter) ) { + if ( Object.hasOwn(response, rawFilter) ) { lists = response[rawFilter]; break; } diff --git a/src/js/dyna-rules.js b/src/js/dyna-rules.js index 1bb1d097b..6d6e77842 100644 --- a/src/js/dyna-rules.js +++ b/src/js/dyna-rules.js @@ -177,7 +177,7 @@ function rulesToDoc(clearHistory) { edit.startOperation(); for ( const key in thePanes ) { - if ( thePanes.hasOwnProperty(key) === false ) { continue; } + if ( Object.hasOwn(thePanes, key) === false ) { continue; } const doc = thePanes[key].doc; const rules = filterRules(key); if ( diff --git a/src/js/dynamic-net-filtering.js b/src/js/dynamic-net-filtering.js index 4bc53e1a7..f921d93c2 100644 --- a/src/js/dynamic-net-filtering.js +++ b/src/js/dynamic-net-filtering.js @@ -30,7 +30,7 @@ import punycode from '../lib/punycode.js'; // Object.create(null) is used below to eliminate worries about unexpected // property names in prototype chain -- and this way we don't have to use -// hasOwnProperty() to avoid this. +// Object.hasOwn() to avoid this. const supportedDynamicTypes = Object.create(null); Object.assign(supportedDynamicTypes, { diff --git a/src/js/hnswitches.js b/src/js/hnswitches.js index 126b7e4a6..4e531cf30 100644 --- a/src/js/hnswitches.js +++ b/src/js/hnswitches.js @@ -29,7 +29,7 @@ const decomposedSource = []; // Object.create(null) is used below to eliminate worries about unexpected // property names in prototype chain -- and this way we don't have to use -// hasOwnProperty() to avoid this. +// Object.hasOwn() to avoid this. const switchBitOffsets = Object.create(null); Object.assign(switchBitOffsets, { diff --git a/src/js/i18n.js b/src/js/i18n.js index 6ce3b5f96..2f6f7dc01 100644 --- a/src/js/i18n.js +++ b/src/js/i18n.js @@ -173,7 +173,7 @@ if ( isBackgroundProcess !== true ) { } textout += textin.slice(0, match.index); let prop = match[0].slice(2, -2); - if ( Object.prototype.hasOwnProperty.call(dict, prop) ) { + if ( Object.hasOwn(dict, prop) ) { textout += dict[prop].replace(//g, '>'); } else { diff --git a/src/js/logger-ui.js b/src/js/logger-ui.js index 19270a2be..4a62b92ad 100644 --- a/src/js/logger-ui.js +++ b/src/js/logger-ui.js @@ -70,9 +70,6 @@ const tabIdFromAttribute = function(elem) { return isNaN(tabId) ? 0 : tabId; }; -const hasOwnProperty = (o, p) => - Object.prototype.hasOwnProperty.call(o, p); - const dispatchTabidChange = vAPI.defer.create(( ) => { document.dispatchEvent(new Event('tabIdChanged')); }); @@ -253,7 +250,7 @@ class LogEntry { this.voided = false; if ( details instanceof Object === false ) { return; } for ( const prop in this ) { - if ( hasOwnProperty(details, prop) === false ) { continue; } + if ( Object.hasOwn(details, prop) === false ) { continue; } this[prop] = details[prop]; } if ( details.aliasURL !== undefined ) { @@ -1224,7 +1221,7 @@ dom.on(document, 'keydown', ev => { const onColorsReady = function(response) { dom.cl.toggle(dom.body, 'dirty', response.dirty); for ( const url in response.colors ) { - if ( hasOwnProperty(response.colors, url) === false ) { continue; } + if ( Object.hasOwn(response.colors, url) === false ) { continue; } const colorEntry = response.colors[url]; const node = qs$(dialog, `.dynamic .entry .action[data-url="${url}"]`); if ( node === null ) { continue; } @@ -1291,7 +1288,7 @@ dom.on(document, 'keydown', ev => { dom.cl.toggle( qs$(dialog, '#createStaticFilter'), 'disabled', - hasOwnProperty(createdStaticFilters, value) || value === '' + Object.hasOwn(createdStaticFilters, value) || value === '' ); }; @@ -1332,7 +1329,7 @@ dom.on(document, 'keydown', ev => { const value = staticFilterNode().value .replace(/^((?:@@)?\/.+\/)(\$|$)/, '$1*$2'); // Avoid duplicates - if ( hasOwnProperty(createdStaticFilters, value) ) { return; } + if ( Object.hasOwn(createdStaticFilters, value) ) { return; } createdStaticFilters[value] = true; // https://github.com/uBlockOrigin/uBlock-issues/issues/1281#issuecomment-704217175 // TODO: @@ -2835,7 +2832,7 @@ const loggerStats = (( ) => { }; const setRadioButton = function(group, value) { - if ( hasOwnProperty(options, group) === false ) { return; } + if ( Object.hasOwn(options, group) === false ) { return; } const groupEl = qs$(dialog, `[data-radio="${group}"]`); const buttonEls = qsa$(groupEl, '[data-radio-item]'); for ( const buttonEl of buttonEls ) { diff --git a/src/js/messaging.js b/src/js/messaging.js index 668138c3b..d7c862d10 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -58,9 +58,6 @@ import µb from './background.js'; /******************************************************************************/ -const hasOwnProperty = (o, p) => - Object.prototype.hasOwnProperty.call(o, p); - // https://github.com/uBlockOrigin/uBlock-issues/issues/710 // Listeners have a name and a "privileged" status. // The nameless default handler is always deemed "privileged". @@ -1095,7 +1092,7 @@ const restoreUserData = async function(request) { // Discard unknown setting or setting with default value. for ( const key in hiddenSettings ) { if ( - hasOwnProperty(µb.hiddenSettingsDefault, key) === false || + Object.hasOwn(µb.hiddenSettingsDefault, key) === false || hiddenSettings[key] === µb.hiddenSettingsDefault[key] ) { delete hiddenSettings[key]; @@ -1147,7 +1144,7 @@ const resetUserData = async function() { // Filter lists const prepListEntries = function(entries) { for ( const k in entries ) { - if ( hasOwnProperty(entries, k) === false ) { continue; } + if ( Object.hasOwn(entries, k) === false ) { continue; } const entry = entries[k]; if ( typeof entry.supportURL === 'string' && entry.supportURL !== '' ) { entry.supportName = hostnameFromURI(entry.supportURL); @@ -1335,7 +1332,7 @@ const getSupportData = async function() { let addedListset = {}; let removedListset = {}; for ( const listKey in lists ) { - if ( hasOwnProperty(lists, listKey) === false ) { continue; } + if ( Object.hasOwn(lists, listKey) === false ) { continue; } const list = lists[listKey]; if ( list.content !== 'filters' ) { continue; } const used = µb.selectedFilterLists.includes(listKey); diff --git a/src/js/popup-fenix.js b/src/js/popup-fenix.js index c4ffc7fd7..298afe28f 100644 --- a/src/js/popup-fenix.js +++ b/src/js/popup-fenix.js @@ -68,9 +68,6 @@ let cachedPopupHash = ''; const reCyrillicNonAmbiguous = /[\u0400-\u042b\u042d-\u042f\u0431\u0432\u0434\u0436-\u043d\u0442\u0444\u0446-\u0449\u044b-\u0454\u0457\u0459-\u0460\u0462-\u0474\u0476-\u04ba\u04bc\u04be-\u04ce\u04d0-\u0500\u0502-\u051a\u051c\u051e-\u052f]/; const reCyrillicAmbiguous = /[\u042c\u0430\u0433\u0435\u043e\u043f\u0440\u0441\u0443\u0445\u044a\u0455\u0456\u0458\u0461\u0475\u04bb\u04bd\u04cf\u0501\u051b\u051d]/; -const hasOwnProperty = (o, p) => - Object.prototype.hasOwnProperty.call(o, p); - /******************************************************************************/ const cachePopupData = function(data) { @@ -89,7 +86,7 @@ const cachePopupData = function(data) { return popupData; } for ( const hostname in hostnameDict ) { - if ( hasOwnProperty(hostnameDict, hostname) === false ) { continue; } + if ( Object.hasOwn(hostnameDict, hostname) === false ) { continue; } let domain = hostnameDict[hostname].domain; let prefix = hostname.slice(0, 0 - domain.length - 1); // Prefix with space char for 1st-party hostnames: this ensure these @@ -161,7 +158,7 @@ const formatNumber = function(count) { }); if ( intl.resolvedOptions instanceof Function && - hasOwnProperty(intl.resolvedOptions(), 'notation') + Object.hasOwn(intl.resolvedOptions(), 'notation') ) { intlNumberFormat = intl; } @@ -546,7 +543,7 @@ const renderPrivacyExposure = function() { if ( des === '*' || desHostnameDone.has(des) ) { continue; } const hnDetails = hostnameDict[des]; const { domain, counts } = hnDetails; - if ( hasOwnProperty(allDomains, domain) === false ) { + if ( Object.hasOwn(allDomains, domain) === false ) { allDomains[domain] = false; allDomainCount += 1; } diff --git a/src/js/resources/run-at.js b/src/js/resources/run-at.js index 545324dcf..35036d2ba 100644 --- a/src/js/resources/run-at.js +++ b/src/js/resources/run-at.js @@ -53,7 +53,7 @@ export function runAt(fn, when) { const tokens = Array.isArray(state) ? state : [ state ]; for ( const token of tokens ) { const prop = `${token}`; - if ( targets.hasOwnProperty(prop) === false ) { continue; } + if ( Object.hasOwn(targets, prop) === false ) { continue; } return targets[prop]; } return 0; diff --git a/src/js/reverselookup.js b/src/js/reverselookup.js index 7a0bfb04c..2d2709c1e 100644 --- a/src/js/reverselookup.js +++ b/src/js/reverselookup.js @@ -93,7 +93,7 @@ const initWorker = function() { }; for ( const listKey in µb.availableFilterLists ) { - if ( Object.prototype.hasOwnProperty.call(µb.availableFilterLists, listKey) === false ) { + if ( Object.hasOwn(µb.availableFilterLists, listKey) === false ) { continue; } const entry = µb.availableFilterLists[listKey]; diff --git a/src/js/s14e-serializer.js b/src/js/s14e-serializer.js index db40388e9..c74a4f2e3 100644 --- a/src/js/s14e-serializer.js +++ b/src/js/s14e-serializer.js @@ -306,9 +306,6 @@ const shouldCompress = (s, options) => options.compressThreshold <= s.length ); -const hasOwnProperty = (o, p) => - Object.prototype.hasOwnProperty.call(o, p); - /******************************************************************************* * * A large Uint is always a positive integer (can be zero), assumed to be @@ -1155,7 +1152,7 @@ export const getConfig = ( ) => Object.assign({}, currentConfig); export const setConfig = config => { for ( const key in Object.keys(config) ) { - if ( hasOwnProperty(defaultConfig, key) === false ) { continue; } + if ( Object.hasOwn(defaultConfig, key) === false ) { continue; } const val = config[key]; if ( typeof val !== typeof defaultConfig[key] ) { continue; } if ( (validateConfig[key])(val) === false ) { continue; } diff --git a/src/js/start.js b/src/js/start.js index df7ce0528..bb6b1850e 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -357,15 +357,15 @@ const onFirstFetchReady = (fetched, adminExtra) => { const toFetch = (from, fetched) => { for ( const k in from ) { - if ( from.hasOwnProperty(k) === false ) { continue; } + if ( Object.hasOwn(from, k) === false ) { continue; } fetched[k] = from[k]; } }; const fromFetch = (to, fetched) => { for ( const k in to ) { - if ( to.hasOwnProperty(k) === false ) { continue; } - if ( fetched.hasOwnProperty(k) === false ) { continue; } + if ( Object.hasOwn(to, k) === false ) { continue; } + if ( Object.hasOwn(fetched, k) === false ) { continue; } to[k] = fetched[k]; } }; diff --git a/src/js/storage.js b/src/js/storage.js index 8d1696515..7dc6e8638 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -48,12 +48,6 @@ import µb from './background.js'; /******************************************************************************/ -// https://eslint.org/docs/latest/rules/no-prototype-builtins -const hasOwnProperty = (o, p) => - Object.prototype.hasOwnProperty.call(o, p); - -/******************************************************************************/ - µb.getBytesInUse = async function() { const promises = []; let bytesInUse; @@ -186,7 +180,7 @@ const hasOwnProperty = (o, p) => for ( const entry of adminSettings ) { if ( entry.length < 1 ) { continue; } const name = entry[0]; - if ( hasOwnProperty(usDefault, name) === false ) { continue; } + if ( Object.hasOwn(usDefault, name) === false ) { continue; } const value = entry.length < 2 ? usDefault[name] : this.settingValueFromString(usDefault, name, entry[1]); @@ -215,8 +209,8 @@ const hasOwnProperty = (o, p) => const toRemove = []; for ( const key in this.userSettings ) { - if ( hasOwnProperty(this.userSettings, key) === false ) { continue; } - if ( hasOwnProperty(toSave, key) ) { continue; } + if ( Object.hasOwn(this.userSettings, key) === false ) { continue; } + if ( Object.hasOwn(toSave, key) ) { continue; } toRemove.push(key); } if ( toRemove.length !== 0 ) { @@ -253,7 +247,7 @@ const hasOwnProperty = (o, p) => for ( const entry of advancedSettings ) { if ( entry.length < 1 ) { continue; } const name = entry[0]; - if ( hasOwnProperty(hsDefault, name) === false ) { continue; } + if ( Object.hasOwn(hsDefault, name) === false ) { continue; } const value = entry.length < 2 ? hsDefault[name] : this.hiddenSettingValueFromString(name, entry[1]); @@ -287,8 +281,8 @@ const hasOwnProperty = (o, p) => } for ( const key in hsDefault ) { - if ( hasOwnProperty(hsDefault, key) === false ) { continue; } - if ( hasOwnProperty(hsAdmin, name) ) { continue; } + if ( Object.hasOwn(hsDefault, key) === false ) { continue; } + if ( Object.hasOwn(hsAdmin, name) ) { continue; } if ( typeof hs[key] !== typeof hsDefault[key] ) { continue; } this.hiddenSettings[key] = hs[key]; } @@ -334,8 +328,8 @@ onBroadcast(msg => { const matches = /^\s*(\S+)\s+(.+)$/.exec(line); if ( matches === null || matches.length !== 3 ) { continue; } const name = matches[1]; - if ( hasOwnProperty(out, name) === false ) { continue; } - if ( hasOwnProperty(this.hiddenSettingsAdmin, name) ) { continue; } + if ( Object.hasOwn(out, name) === false ) { continue; } + if ( Object.hasOwn(this.hiddenSettingsAdmin, name) ) { continue; } const value = this.hiddenSettingValueFromString(name, matches[2]); if ( value !== undefined ) { out[name] = value; @@ -347,7 +341,7 @@ onBroadcast(msg => { µb.hiddenSettingValueFromString = function(name, value) { if ( typeof name !== 'string' || typeof value !== 'string' ) { return; } const hsDefault = this.hiddenSettingsDefault; - if ( hasOwnProperty(hsDefault, name) === false ) { return; } + if ( Object.hasOwn(hsDefault, name) === false ) { return; } let r; switch ( typeof hsDefault[name] ) { case 'boolean': @@ -688,7 +682,7 @@ onBroadcast(msg => { µb.autoSelectRegionalFilterLists = function(lists) { const selectedListKeys = [ this.userFiltersPath ]; for ( const key in lists ) { - if ( hasOwnProperty(lists, key) === false ) { continue; } + if ( Object.hasOwn(lists, key) === false ) { continue; } const list = lists[key]; if ( list.content !== 'filters' ) { continue; } if ( list.off !== true ) { @@ -941,7 +935,7 @@ onBroadcast(msg => { let acceptedCount = snfe.acceptedCount + sxfe.acceptedCount; let discardedCount = snfe.discardedCount + sxfe.discardedCount; µb.applyCompiledFilters(compiled, assetKey === µb.userFiltersPath); - if ( hasOwnProperty(µb.availableFilterLists, assetKey) ) { + if ( Object.hasOwn(µb.availableFilterLists, assetKey) ) { const entry = µb.availableFilterLists[assetKey]; entry.entryCount = snfe.acceptedCount + sxfe.acceptedCount - acceptedCount; @@ -977,7 +971,7 @@ onBroadcast(msg => { // content. const toLoad = []; for ( const assetKey in lists ) { - if ( hasOwnProperty(lists, assetKey) === false ) { continue; } + if ( Object.hasOwn(lists, assetKey) === false ) { continue; } if ( lists[assetKey].off ) { continue; } toLoad.push( µb.getCompiledFilterList(assetKey).then(details => { @@ -1428,8 +1422,8 @@ onBroadcast(msg => { const µbus = this.userSettings; const adminus = data.userSettings; for ( const name in µbus ) { - if ( hasOwnProperty(µbus, name) === false ) { continue; } - if ( hasOwnProperty(adminus, name) === false ) { continue; } + if ( Object.hasOwn(µbus, name) === false ) { continue; } + if ( Object.hasOwn(adminus, name) === false ) { continue; } bin[name] = adminus[name]; binNotEmpty = true; } @@ -1600,7 +1594,7 @@ onBroadcast(msg => { if ( topic === 'before-asset-updated' ) { if ( details.type === 'filters' ) { if ( - hasOwnProperty(this.availableFilterLists, details.assetKey) === false || + Object.hasOwn(this.availableFilterLists, details.assetKey) === false || this.selectedFilterLists.indexOf(details.assetKey) === -1 || this.badLists.get(details.assetKey) ) { @@ -1615,7 +1609,7 @@ onBroadcast(msg => { // Skip selfie-related content. if ( details.assetKey.startsWith('selfie/') ) { return; } const cached = typeof details.content === 'string' && details.content !== ''; - if ( hasOwnProperty(this.availableFilterLists, details.assetKey) ) { + if ( Object.hasOwn(this.availableFilterLists, details.assetKey) ) { if ( cached ) { if ( this.selectedFilterLists.indexOf(details.assetKey) !== -1 ) { this.extractFilterListMetadata( diff --git a/src/js/text-encode.js b/src/js/text-encode.js index 8e5ad81ae..b1e850b29 100644 --- a/src/js/text-encode.js +++ b/src/js/text-encode.js @@ -251,7 +251,7 @@ const textEncode = (( ) => { return { encode: function(charset, buf) { - return encoders.hasOwnProperty(charset) ? + return Object.hasOwn(encoders, charset) ? encoders[charset](buf) : buf; }, diff --git a/src/js/ublock.js b/src/js/ublock.js index 0ac05d08d..b3a453c81 100644 --- a/src/js/ublock.js +++ b/src/js/ublock.js @@ -333,7 +333,7 @@ const matchBucket = function(url, hostname, bucket, start) { } // Change -- but only if the user setting actually exists. - const mustSave = us.hasOwnProperty(name) && value !== us[name]; + const mustSave = Object.hasOwn(us, name) && value !== us[name]; if ( mustSave ) { us[name] = value; } diff --git a/src/js/utils.js b/src/js/utils.js index 8b12244fd..da7e15995 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -93,7 +93,7 @@ import µb from './background.js'; µb.getModifiedSettings = function(edit, orig = {}) { const out = {}; for ( const prop in edit ) { - if ( orig.hasOwnProperty(prop) && edit[prop] !== orig[prop] ) { + if ( Object.hasOwn(orig, prop) && edit[prop] !== orig[prop] ) { out[prop] = edit[prop]; } } @@ -102,7 +102,7 @@ import µb from './background.js'; µb.settingValueFromString = function(orig, name, s) { if ( typeof name !== 'string' || typeof s !== 'string' ) { return; } - if ( orig.hasOwnProperty(name) === false ) { return; } + if ( Object.hasOwn(orig, name) === false ) { return; } let r; switch ( typeof orig[name] ) { case 'boolean':