From d2c4b0c2ac185862ba5c5ed813028e2df228c12d Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Mon, 1 Jan 2024 00:37:43 +0000 Subject: [PATCH] Bug 1869678 - Use more idiomatic code patterns for better type inference r=robwu These fall under 5 main categories: 1) Declare and/or initialize all class fiels in the constructor. (general good practise) 2) Use real getters and redefineGetter instead of defineLazyGetter. (also keeps related code closer together) 3) When subclassing, don't override class fields with getters (or vice versa). https://github.com/microsoft/TypeScript/pull/33509 4) Declare and assign object literals at the same time, not separatelly. (don't use `let foo;` at the top of the file, use `var foo = {`) 5) Don't re-use local variables unnecesarily with different types. (general good practise, local variables are "free") Differential Revision: https://phabricator.services.mozilla.com/D196386 UltraBlame original commit: 8e768446e17cc306729e3b0f705b0285c69321cf --- toolkit/components/extensions/.eslintrc.js | 109 +- .../extensions/ConduitsParent.sys.mjs | 11 +- .../components/extensions/Extension.sys.mjs | 224 ++- .../extensions/ExtensionActions.sys.mjs | 3 + .../extensions/ExtensionChild.sys.mjs | 53 +- .../extensions/ExtensionCommon.sys.mjs | 366 +++- .../extensions/ExtensionContent.sys.mjs | 167 +- .../extensions/ExtensionDNR.sys.mjs | 86 + .../extensions/ExtensionDNRStore.sys.mjs | 18 +- .../extensions/ExtensionPageChild.sys.mjs | 191 +- .../extensions/ExtensionParent.sys.mjs | 1574 ++++++++--------- .../extensions/ExtensionShortcuts.sys.mjs | 36 +- .../extensions/ExtensionStorageIDB.sys.mjs | 9 +- .../ExtensionStorageSyncKinto.sys.mjs | 6 + .../extensions/ExtensionTelemetry.sys.mjs | 3 + .../extensions/ExtensionTestCommon.sys.mjs | 8 +- .../extensions/ExtensionWorkerChild.sys.mjs | 109 +- .../extensions/ExtensionXPCShellUtils.sys.mjs | 223 ++- .../extensions/NativeMessaging.sys.mjs | 61 +- toolkit/components/extensions/Schemas.sys.mjs | 174 +- 20 files changed, 2015 insertions(+), 1416 deletions(-) diff --git a/toolkit/components/extensions/.eslintrc.js b/toolkit/components/extensions/.eslintrc.js index cd641b67610fa..5906ad26264ae 100644 --- a/toolkit/components/extensions/.eslintrc.js +++ b/toolkit/components/extensions/.eslintrc.js @@ -393,9 +393,13 @@ console / No using -variables +things before +they +' +re defined +. " no - @@ -406,9 +410,112 @@ before define " : +[ " error " +{ +allowNamedExports +: +true +classes +: +true +/ +/ +The +next +two +being +false +allows +idiomatic +patterns +which +are +more +/ +/ +type +- +inference +friendly +. +Functions +are +hoisted +so +this +is +safe +. +functions +: +false +/ +/ +This +flag +is +only +meaningful +for +var +declarations +. +/ +/ +When +false +it +still +disallows +use +- +before +- +define +in +the +same +scope +. +/ +/ +Since +we +only +allow +var +at +the +global +scope +this +is +no +worse +than +/ +/ +how +we +currently +declare +an +uninitialized +let +at +the +top +of +file +. +variables +: +false +} +] / / Disallow diff --git a/toolkit/components/extensions/ConduitsParent.sys.mjs b/toolkit/components/extensions/ConduitsParent.sys.mjs index 882fd71a589c3..ec40e91cfdf98 100644 --- a/toolkit/components/extensions/ConduitsParent.sys.mjs +++ b/toolkit/components/extensions/ConduitsParent.sys.mjs @@ -3114,7 +3114,8 @@ this ) ; } -sender +let +remote = Hub . @@ -3128,10 +3129,10 @@ sender if ( ! -sender +remote | | -sender +remote . actor ! @@ -3173,7 +3174,7 @@ Hub . recvConduitClosed ( -sender +remote ) ; } @@ -3224,6 +3225,8 @@ actor this query sender +: +remote } ) ; diff --git a/toolkit/components/extensions/Extension.sys.mjs b/toolkit/components/extensions/Extension.sys.mjs index b9a88f694ba8b..8c395936f64af 100644 --- a/toolkit/components/extensions/Extension.sys.mjs +++ b/toolkit/components/extensions/Extension.sys.mjs @@ -1384,6 +1384,7 @@ ExtensionUtils const { EventEmitter +redefineGetter updateAllowedOrigins } = @@ -6040,6 +6041,92 @@ export class ExtensionData { +/ +* +* +* +Note +: +These +fields +are +only +available +and +meant +to +be +used +on +Extension +* +instances +declared +here +because +methods +from +this +class +reference +them +. +* +/ +/ +* +* +type +{ +object +} +TODO +: +move +to +the +Extension +class +bug +1871094 +. +* +/ +addonData +; +/ +* +* +type +{ +nsIURI +} +* +/ +baseURI +; +/ +* +* +type +{ +nsIPrincipal +} +* +/ +principal +; +/ +* +* +type +{ +boolean +} +* +/ +temporarilyInstalled +; constructor ( rootURI @@ -17898,9 +17985,9 @@ this . updateReason = -this +BootstrapScope . -BOOTSTRAP_REASON_TO_STRING_MAP +BOOTSTRAP_REASON_MAP [ reason ] @@ -18051,9 +18138,9 @@ new Extension ( data -this +BootstrapScope . -BOOTSTRAP_REASON_TO_STRING_MAP +BOOTSTRAP_REASON_MAP [ reason ] @@ -18089,9 +18176,9 @@ extension . shutdown ( -this +BootstrapScope . -BOOTSTRAP_REASON_TO_STRING_MAP +BOOTSTRAP_REASON_MAP [ reason ] @@ -18107,39 +18194,31 @@ return result ; } -} -ChromeUtils -. -defineLazyGetter -( -BootstrapScope -. -prototype -" -BOOTSTRAP_REASON_TO_STRING_MAP -" +static +get +BOOTSTRAP_REASON_MAP ( ) -= -> { const -{ -BOOTSTRAP_REASONS -} +BR = lazy . AddonManagerPrivate +. +BOOTSTRAP_REASONS ; -return +const +value += Object . freeze ( { [ -BOOTSTRAP_REASONS +BR . APP_STARTUP ] @@ -18148,7 +18227,7 @@ APP_STARTUP APP_STARTUP " [ -BOOTSTRAP_REASONS +BR . APP_SHUTDOWN ] @@ -18157,7 +18236,7 @@ APP_SHUTDOWN APP_SHUTDOWN " [ -BOOTSTRAP_REASONS +BR . ADDON_ENABLE ] @@ -18166,7 +18245,7 @@ ADDON_ENABLE ADDON_ENABLE " [ -BOOTSTRAP_REASONS +BR . ADDON_DISABLE ] @@ -18175,7 +18254,7 @@ ADDON_DISABLE ADDON_DISABLE " [ -BOOTSTRAP_REASONS +BR . ADDON_INSTALL ] @@ -18184,7 +18263,7 @@ ADDON_INSTALL ADDON_INSTALL " [ -BOOTSTRAP_REASONS +BR . ADDON_UNINSTALL ] @@ -18193,7 +18272,7 @@ ADDON_UNINSTALL ADDON_UNINSTALL " [ -BOOTSTRAP_REASONS +BR . ADDON_UPGRADE ] @@ -18202,7 +18281,7 @@ ADDON_UPGRADE ADDON_UPGRADE " [ -BOOTSTRAP_REASONS +BR . ADDON_DOWNGRADE ] @@ -18213,9 +18292,18 @@ ADDON_DOWNGRADE } ) ; -} +return +redefineGetter +( +this +" +BOOTSTRAP_REASON_TO_STRING_MAP +" +value ) ; +} +} class DictionaryBootstrapScope extends @@ -18274,15 +18362,16 @@ dictionary . startup ( -this +BootstrapScope . -BOOTSTRAP_REASON_TO_STRING_MAP +BOOTSTRAP_REASON_MAP [ reason ] ) ; } +async shutdown ( data @@ -18295,9 +18384,9 @@ dictionary . shutdown ( -this +BootstrapScope . -BOOTSTRAP_REASON_TO_STRING_MAP +BOOTSTRAP_REASON_MAP [ reason ] @@ -18330,6 +18419,7 @@ reason ) { } +async update ( data @@ -18376,15 +18466,16 @@ langpack . startup ( -this +BootstrapScope . -BOOTSTRAP_REASON_TO_STRING_MAP +BOOTSTRAP_REASON_MAP [ reason ] ) ; } +async shutdown ( data @@ -18397,9 +18488,9 @@ langpack . shutdown ( -this +BootstrapScope . -BOOTSTRAP_REASON_TO_STRING_MAP +BOOTSTRAP_REASON_MAP [ reason ] @@ -18491,15 +18582,16 @@ sitepermission . startup ( -this +BootstrapScope . -BOOTSTRAP_REASON_TO_STRING_MAP +BOOTSTRAP_REASON_MAP [ reason ] ) ; } +async shutdown ( data @@ -18512,9 +18604,9 @@ sitepermission . shutdown ( -this +BootstrapScope . -BOOTSTRAP_REASON_TO_STRING_MAP +BOOTSTRAP_REASON_MAP [ reason ] @@ -18576,6 +18668,25 @@ Extension extends ExtensionData { +/ +* +* +type +{ +Map +< +string +Map +< +string +any +> +> +} +* +/ +persistentListeners +; constructor ( addonData @@ -18771,6 +18882,16 @@ updateReason = updateReason ; +this +. +temporarilyInstalled += +! +! +addonData +. +temporarilyInstalled +; if ( updateReason @@ -20219,21 +20340,6 @@ appLocaleAsBCP47 ] ; } -get -temporarilyInstalled -( -) -{ -return -! -! -this -. -addonData -. -temporarilyInstalled -; -} saveStartupData ( ) diff --git a/toolkit/components/extensions/ExtensionActions.sys.mjs b/toolkit/components/extensions/ExtensionActions.sys.mjs index 803973ee0f557..099752472377f 100644 --- a/toolkit/components/extensions/ExtensionActions.sys.mjs +++ b/toolkit/components/extensions/ExtensionActions.sys.mjs @@ -312,6 +312,9 @@ default_popup | " " +icon +: +null } ; this diff --git a/toolkit/components/extensions/ExtensionChild.sys.mjs b/toolkit/components/extensions/ExtensionChild.sys.mjs index f47959062f713..783af0bb61efb 100644 --- a/toolkit/components/extensions/ExtensionChild.sys.mjs +++ b/toolkit/components/extensions/ExtensionChild.sys.mjs @@ -366,7 +366,7 @@ ExtensionUtils ; const { -defineLazyGetter +redefineGetter EventEmitter EventManager LocalAPIImplementation @@ -1949,39 +1949,33 @@ port ) ; } -} -defineLazyGetter -( -Port -. -prototype -" +get api -" -function ( ) { -let -api +const +scope = this . -getAPI -( -) +context +. +cloneScope ; -return +const +value += Cu . cloneInto ( -api this . -context -. -cloneScope +getAPI +( +) +scope { cloneFunctions : @@ -1989,9 +1983,18 @@ true } ) ; -} +return +redefineGetter +( +this +" +api +" +value ) ; +} +} / * * @@ -3278,6 +3281,7 @@ args } ) ; +return super . emit @@ -5710,7 +5714,8 @@ getParentEvent path ) { -path +let +parts = path . @@ -5724,7 +5729,7 @@ split let name = -path +parts . pop ( @@ -5733,7 +5738,7 @@ pop let namespace = -path +parts . join ( diff --git a/toolkit/components/extensions/ExtensionCommon.sys.mjs b/toolkit/components/extensions/ExtensionCommon.sys.mjs index b0cb5d35d72d1..466ce2279374e 100644 --- a/toolkit/components/extensions/ExtensionCommon.sys.mjs +++ b/toolkit/components/extensions/ExtensionCommon.sys.mjs @@ -381,10 +381,6 @@ WebExtensions ) ; } -export -var -ExtensionCommon -; / / Run @@ -868,6 +864,20 @@ on . * * +Note +: +for +better +type +inference +prefer +redefineGetter +( +) +below +. +* +* param { object @@ -934,41 +944,6 @@ prop getter ) { -let -redefine -= -( -obj -value -) -= -> -{ -Object -. -defineProperty -( -obj -prop -{ -enumerable -: -true -configurable -: -true -writable -: -true -value -} -) -; -return -value -; -} -; Object . defineProperty @@ -987,15 +962,17 @@ get ) { return -redefine +redefineGetter ( this +prop getter . call ( this ) +true ) ; } @@ -1004,10 +981,12 @@ set value ) { -redefine +redefineGetter ( this +prop value +true ) ; } @@ -1015,6 +994,118 @@ value ) ; } +/ +* +* +* +A +more +type +- +inference +friendly +version +of +defineLazyGetter +( +) +above +. +* +Call +it +from +a +real +getter +( +and +setter +) +for +your +class +or +object +. +* +On +first +run +it +will +redefine +the +property +with +the +final +value +. +* +* +template +Value +* +param +{ +object +} +object +* +param +{ +string +| +symbol +} +key +* +param +{ +Value +} +value +* +returns +{ +Value +} +* +/ +function +redefineGetter +( +object +key +value +writable += +false +) +{ +Object +. +defineProperty +( +object +key +{ +enumerable +: +true +configurable +: +true +writable +value +} +) +; +return +value +; +} function checkLoadURI ( @@ -1808,6 +1899,7 @@ let wrapper = ( +event . . . @@ -1837,6 +1929,7 @@ listener return listener ( +event . . . @@ -2155,12 +2248,48 @@ destroy ) { } +/ +* +* +param +{ +string +} +entryName +* +/ onManifestEntry ( -entry +entryName +) +{ +} +/ +* +* +param +{ +boolean +} +isAppShutdown +* +/ +onShutdown +( +isAppShutdown ) { } +/ +* +* +param +{ +BaseContext +} +context +* +/ getAPI ( context @@ -2177,6 +2306,69 @@ Implemented ) ; } +/ +* +* +param +{ +string +} +id +* +/ +static +onDisable +( +id +) +{ +} +/ +* +* +param +{ +string +} +id +* +/ +static +onUninstall +( +id +) +{ +} +/ +* +* +* +param +{ +string +} +id +* +param +{ +Record +< +string +JSONValue +> +} +manifest +* +/ +static +onUpdate +( +id +manifest +) +{ +} } / * @@ -2226,6 +2418,21 @@ ExtensionAPI / * * +type +{ +Record +< +string +callback +> +} +* +/ +PERSISTENT_EVENTS +; +/ +* +* * Check for @@ -2685,6 +2892,28 @@ abstract class BaseContext { +/ +* +* +type +{ +boolean +} +* +/ +isTopContext +; +/ +* +* +type +{ +string +} +* +/ +viewType +; constructor ( envType @@ -11174,6 +11403,17 @@ super processType ) ; +/ +* +* +type +{ +Promise +| +boolean +} +* +/ this . initialized @@ -11607,6 +11847,7 @@ Map } ) ; +export function LocaleData ( @@ -13044,24 +13285,14 @@ locale appLocaleAsBCP47 ; } -} -; -defineLazyGetter -( -LocaleData -. -prototype -" +get availableLocales -" -function ( ) { -return -new -Set -( +const +locales += [ this . @@ -13073,6 +13304,14 @@ this . defaultLocale ] +; +const +value += +new +Set +( +locales . filter ( @@ -13090,9 +13329,19 @@ locale ) ) ; -} +return +redefineGetter +( +this +" +availableLocales +" +value ) ; +} +} +; / * * @@ -18706,6 +18955,8 @@ values ) ; } +export +var ExtensionCommon = { @@ -18724,6 +18975,7 @@ SpreadArgs checkLoadURI checkLoadURL defineLazyGetter +redefineGetter getConsole ignoreEvent instanceOf diff --git a/toolkit/components/extensions/ExtensionContent.sys.mjs b/toolkit/components/extensions/ExtensionContent.sys.mjs index e7987f7042b29..e1d35c0f936fb 100644 --- a/toolkit/components/extensions/ExtensionContent.sys.mjs +++ b/toolkit/components/extensions/ExtensionContent.sys.mjs @@ -403,6 +403,7 @@ BaseContext CanOfAPIs SchemaAPIManager defineLazyGetter +redefineGetter runSafeSyncWithoutClone } = @@ -824,6 +825,7 @@ cancel ) ; } +return super . delete @@ -954,21 +956,9 @@ extension super ( SCRIPT_EXPIRY_TIMEOUT_MS -null -extension -) -; -this -. -options -= -options -; -} -defaultConstructor -( url -) += +> { let promise @@ -978,8 +968,6 @@ ChromeUtils compileScript ( url -this -. options ) ; @@ -1004,6 +992,10 @@ return promise ; } +extension +) +; +} } / * @@ -1222,6 +1214,7 @@ return ; } } +return super . delete @@ -5273,44 +5266,6 @@ location . href ; -defineLazyGetter -( -this -" -chromeObj -" -( -) -= -> -{ -let -chromeObj -= -Cu -. -createObjectIn -( -this -. -sandbox -) -; -this -. -childManager -. -inject -( -chromeObj -) -; -return -chromeObj -; -} -) -; lazy . Schemas @@ -5790,38 +5745,8 @@ sandbox null ; } -} -defineLazyGetter -( -ContentScriptContextChild -. -prototype -" -messenger -" -function -( -) -{ -return -new -Messenger -( -this -) -; -} -) -; -defineLazyGetter -( -ContentScriptContextChild -. -prototype -" +get childManager -" -function ( ) { @@ -5832,12 +5757,6 @@ lazyInit ) ; let -localApis -= -{ -} -; -let can = new @@ -5845,7 +5764,8 @@ CanOfAPIs ( this apiManager -localApis +{ +} ) ; let @@ -5881,11 +5801,74 @@ childManager ) ; return +redefineGetter +( +this +" +childManager +" +childManager +) +; +} +get +chromeObj +( +) +{ +let +chromeObj += +Cu +. +createObjectIn +( +this +. +sandbox +) +; +this +. childManager +. +inject +( +chromeObj +) +; +return +redefineGetter +( +this +" +chromeObj +" +chromeObj +) ; } +get +messenger +( +) +{ +return +redefineGetter +( +this +" +messenger +" +new +Messenger +( +this +) ) ; +} +} / / Responsible diff --git a/toolkit/components/extensions/ExtensionDNR.sys.mjs b/toolkit/components/extensions/ExtensionDNR.sys.mjs index 664fca36338be..14741d4c6ef62 100644 --- a/toolkit/components/extensions/ExtensionDNR.sys.mjs +++ b/toolkit/components/extensions/ExtensionDNR.sys.mjs @@ -1206,6 +1206,7 @@ compiledRegexFilter ; } } +export class Rule { @@ -5150,6 +5151,90 @@ channel / * * +* +param +{ +MatchedRule +} +matchedRule +* +returns +{ +object +[ +] +} +* +/ +headerActionsFor +( +matchedRule +) +{ +throw +new +Error +( +" +Not +implemented +. +" +) +; +} +/ +* +* +* +param +{ +MatchedRule +} +matchedrule +* +param +{ +string +} +name +* +param +{ +string +} +value +* +param +{ +boolean +} +merge +* +/ +setHeaderImpl +( +matchedrule +name +value +merge +) +{ +throw +new +Error +( +" +Not +implemented +. +" +) +; +} +/ +* +* param { MatchedRule @@ -8708,6 +8793,7 @@ failures ; } } +export class RuleQuotaCounter { diff --git a/toolkit/components/extensions/ExtensionDNRStore.sys.mjs b/toolkit/components/extensions/ExtensionDNRStore.sys.mjs index 3b02c53692edf..e14e95fddfa2a 100644 --- a/toolkit/components/extensions/ExtensionDNRStore.sys.mjs +++ b/toolkit/components/extensions/ExtensionDNRStore.sys.mjs @@ -1143,9 +1143,7 @@ schemaVersion schemaVersion | | -this -. -constructor +StoreData . VERSION ; @@ -1663,7 +1661,11 @@ updateRulesets ( { staticRulesets += +null dynamicRuleset += +null lastUpdateTag = Services @@ -4579,21 +4581,11 @@ StoreData ( extension { -extUUID -: -extension -. -uuid extVersion : extension . version -temporarilyInstalled -: -extension -. -temporarilyInstalled } ) ; diff --git a/toolkit/components/extensions/ExtensionPageChild.sys.mjs b/toolkit/components/extensions/ExtensionPageChild.sys.mjs index 3d3680466e248..3794bd25b6f10 100644 --- a/toolkit/components/extensions/ExtensionPageChild.sys.mjs +++ b/toolkit/components/extensions/ExtensionPageChild.sys.mjs @@ -270,7 +270,7 @@ const BaseContext CanOfAPIs SchemaAPIManager -defineLazyGetter +redefineGetter } = ExtensionCommon @@ -283,10 +283,6 @@ Messenger = ExtensionChild ; -export -var -ExtensionPageChild -; const initializeBackgroundPage = @@ -992,6 +988,7 @@ childManager } ; } +export class ExtensionBaseContextChild extends @@ -1259,42 +1256,6 @@ true ) ; } -defineLazyGetter -( -this -" -browserObj -" -( -) -= -> -{ -let -browserObj -= -Cu -. -createObjectIn -( -contentWindow -) -; -this -. -childManager -. -inject -( -browserObj -) -; -return -browserObj -; -} -) -; lazy . Schemas @@ -1413,6 +1374,43 @@ chromeObj ) ; } +get +browserObj +( +) +{ +const +browserObj += +Cu +. +createObjectIn +( +this +. +contentWindow +) +; +this +. +childManager +. +inject +( +browserObj +) +; +return +redefineGetter +( +this +" +browserObj +" +browserObj +) +; +} logActivity ( type @@ -1589,29 +1587,61 @@ unload ) ; } -} -defineLazyGetter -( -ExtensionBaseContextChild -. -prototype -" +get messenger -" -function ( ) { return +redefineGetter +( +this +" +messenger +" new Messenger ( this ) +) ; } +/ +* +* +type +{ +ReturnType +< +ReturnType +< +getContextChildManagerGetter +> +> +} +* +/ +get +childManager +( +) +{ +throw +new +Error +( +" +childManager +getter +must +be +overridden +" ) ; +} +} class ExtensionPageContextChild extends @@ -1884,15 +1914,14 @@ this ) ; } -} -defineLazyGetter +get +childManager ( -ExtensionPageContextChild -. -prototype -" +) +{ +const childManager -" += getContextChildManagerGetter ( { @@ -1903,8 +1932,25 @@ addon_parent " } ) +. +call +( +this ) ; +return +redefineGetter +( +this +" +childManager +" +childManager +) +; +} +} +export class DevToolsContextChild extends @@ -2151,15 +2197,14 @@ this ) ; } -} -defineLazyGetter +get +childManager ( -DevToolsContextChild -. -prototype -" +) +{ +const childManager -" += getContextChildManagerGetter ( { @@ -2170,8 +2215,26 @@ devtools_parent " } ) +. +call +( +this ) ; +return +redefineGetter +( +this +" +childManager +" +childManager +) +; +} +} +export +var ExtensionPageChild = { diff --git a/toolkit/components/extensions/ExtensionParent.sys.mjs b/toolkit/components/extensions/ExtensionParent.sys.mjs index 0592dc3ff6ffe..ebb4373920878 100644 --- a/toolkit/components/extensions/ExtensionParent.sys.mjs +++ b/toolkit/components/extensions/ExtensionParent.sys.mjs @@ -524,7 +524,7 @@ BaseContext CanOfAPIs SchemaAPIManager SpreadArgs -defineLazyGetter +redefineGetter } = ExtensionCommon @@ -639,9 +639,6 @@ GlobalManager let ParentAPIManager ; -let -StartupCache -; function verifyActorForContext ( @@ -4463,27 +4460,13 @@ this ) ; } -} -defineLazyGetter -( -ProxyContextParent -. -prototype -" +get apiCan -" -function ( ) { -let -obj -= -{ -} -; -let -can +const +apiCan = new CanOfAPIs @@ -4494,55 +4477,50 @@ this extension . apiManager -obj -) -; -return -can -; +{ } ) ; -defineLazyGetter +return +redefineGetter ( -ProxyContextParent -. -prototype +this " -apiObj +apiCan " -function +apiCan +) +; +} +get +apiObj ( ) { return +redefineGetter +( +this +" +apiObj +" this . apiCan . root -; -} ) ; -defineLazyGetter -( -ProxyContextParent -. -prototype -" +} +get sandbox -" -function ( ) { / / -NOTE +Note : -the -required Blob and URL @@ -4550,27 +4528,15 @@ globals are used in -the ext - -registerContentScript +contentScripts . js -/ -/ -API -module -to -convert -JS -and -CSS -data -into -blob -URLs . -return +const +sandbox += Cu . Sandbox @@ -4599,9 +4565,18 @@ URL } ) ; -} +return +redefineGetter +( +this +" +sandbox +" +sandbox ) ; +} +} / * * @@ -4846,25 +4821,6 @@ tabId ; } } -onBrowserChange -( -browser -) -{ -super -. -onBrowserChange -( -browser -) -; -this -. -xulBrowser -= -browser -; -} unload ( ) @@ -8542,12 +8498,6 @@ value } let awaitFrameLoader -= -Promise -. -resolve -( -) ; if ( @@ -12651,1066 +12601,1078 @@ encodeURIComponent } } ; -/ -/ -A -cache -to -support -faster -initialization -of -extensions -at -browser -startup -. -/ -/ -All -cached -data -is -removed -when -the -browser -is -updated -. -/ -/ -Extension -- -specific -data -is -removed -when -the -add -- -on -is -updated -. -StartupCache -= +class +CacheStore { -STORE_NAMES -: -Object -. -freeze -( -[ -" -general -" -" -locales -" -" -manifests -" -" -other -" -" -permissions -" -" -schemas -" -" -menus -" -] -) -_ensureDirectoryPromise -: -null -_saveTask -: -null -_ensureDirectory +constructor ( +storeName ) { -if -( this . -_ensureDirectoryPromise -= +storeName = +storeName +; +} +async +getStore +( +path = null ) { -this -. -_ensureDirectoryPromise +let +data = -IOUtils +await +StartupCache . -makeDirectory -( -PathUtils +dataPromise +; +let +store += +data . -parent +get ( this . -file +storeName +) +; +if +( +! +store ) { -ignoreExisting -: -true -createAncestors -: -true -} +store += +new +Map +( ) ; -} -return +data +. +set +( this . -_ensureDirectoryPromise +storeName +store +) ; } -/ -/ -When -the -application -version -changes -this -file -is -removed -by -/ -/ -RemoveComponentRegistries -in -nsAppRunner -. -cpp -. -file -: -PathUtils -. -join +let +key += +path +; +if ( -Services -. -dirsvc +Array . -get +isArray ( -" -ProfLD -" -Ci -. -nsIFile +path ) -. +) +{ +for +( +let +elem +of path -" -startupCache -" -" -webext . -sc -. -lz4 -" -) -async -_saveNow +slice ( +0 +- +1 +) ) { let -data +next = -new -Uint8Array -( -lazy -. -aomStartup +store . -encodeBlob +get ( -this -. -_data -) +elem ) ; -await -this -. -_ensureDirectoryPromise -; -await -IOUtils -. -write +if ( -this -. -file -data -{ -tmpPath -: +! +next +) { -this -. -file -} -. -tmp -} +next += +new +Map +( ) ; -Glean -. -extensions -. -startupCacheWriteBytelength +store . set ( -data -. -byteLength +elem +next ) ; } -save -( -) -{ -this +store += +next +; +} +key += +path +[ +path . -_ensureDirectory -( -) +length +- +1 +] ; -if +} +return +[ +store +key +] +; +} +async +get ( -! -this -. -_saveTask +path +createFunc ) { -this -. -_saveTask +let +[ +store +key +] = -new -lazy +await +this . -DeferredTask -( +getStore ( +path ) +; +let +result = -> -this +store . -_saveNow +get ( -) -5000 +key ) ; -IOUtils -. -profileBeforeChange -. -addBlocker -( -" -Flush -WebExtension -StartupCache -" -async +if ( -) +result = -> += += +undefined +) { +result += await -this -. -_saveTask -. -finalize +createFunc ( +path ) ; -this +store . -_saveTask -= -null -; -} +set +( +key +result ) ; -} -return -this -. -_saveTask +StartupCache . -arm +save ( ) ; } -_data -: -null +return +result +; +} async -_readData +set ( +path +value ) { let -result +[ +store +key +] = -new -Map +await +this +. +getStore ( +path ) ; -try -{ -Glean -. -extensions +store . -startupCacheLoadTime +set +( +key +value +) +; +StartupCache . -start +save ( ) ; -let -{ -buffer } -= -await -IOUtils -. -read +async +getAll ( -this -. -file ) -; -result +{ +let +[ +store +] = -lazy -. -aomStartup +await +this . -decodeBlob +getStore ( -buffer ) ; -Glean -. -extensions -. -startupCacheLoadTime -. -stop +return +new +Map ( +store ) ; } -catch +async +delete ( -e +path ) { -Glean -. -extensions -. -startupCacheLoadTime +let +[ +store +key +] += +await +this . -cancel +getStore ( +path ) ; if ( -! -DOMException +store . -isInstance +delete ( -e +key ) -| -| -e -. -name -! -= -= -" -NotFoundError -" ) { -Cu +StartupCache . -reportError +save ( -e ) ; } -let -error -= -lazy -. -getErrorNameForTelemetry -( -e -) -; -Glean -. +} +} +/ +/ +A +cache +to +support +faster +initialization +of extensions +at +browser +startup . -startupCacheReadErrors -[ -error -] +/ +/ +All +cached +data +is +removed +when +the +browser +is +updated . +/ +/ +Extension +- +specific +data +is +removed +when +the add -( -1 -) -; -} -this +- +on +is +updated . -_data +var +StartupCache = -result -; -return -result -; -} -get -dataPromise +{ +_ensureDirectoryPromise +: +null +_saveTask +: +null +_ensureDirectory ( ) { if ( -! this . -_dataPromise +_ensureDirectoryPromise += += += +null ) { this . -_dataPromise +_ensureDirectoryPromise = -this +IOUtils . -_readData +makeDirectory +( +PathUtils +. +parent ( +this +. +file +) +{ +ignoreExisting +: +true +createAncestors +: +true +} ) ; } return this . -_dataPromise +_ensureDirectoryPromise ; } -clearAddonData +/ +/ +When +the +application +version +changes +this +file +is +removed +by +/ +/ +RemoveComponentRegistries +in +nsAppRunner +. +cpp +. +file +: +PathUtils +. +join +( +Services +. +dirsvc +. +get +( +" +ProfLD +" +Ci +. +nsIFile +) +. +path +" +startupCache +" +" +webext +. +sc +. +lz4 +" +) +async +_saveNow ( -id ) { -return -Promise -. -all +let +data += +new +Uint8Array ( -[ -this +lazy . -general +aomStartup . -delete +encodeBlob ( -id -) this . -locales -. -delete -( -id +_data ) +) +; +await this . -manifests +_ensureDirectoryPromise +; +await +IOUtils . -delete +write ( -id -) this . -permissions -. -delete -( -id -) +file +data +{ +tmpPath +: +{ this . -menus +file +} . -delete -( -id -) -] +tmp +} ) +; +Glean . -catch -( -e -= -> -{ -/ -/ -Ignore -the -error +extensions . -It -happens -when -we -try -to -flush -the -add -- -on -/ -/ +startupCacheWriteBytelength +. +set +( data -after -the -AddonManager -has -flushed -the -entire -startup -cache . -} +byteLength ) ; } -observe -( -subject -topic -data -) -{ -if +save ( -topic -= -= -= -" -startupcache -- -invalidate -" ) { this . -_data -= -new -Map +_ensureDirectory ( ) ; -this -. -_dataPromise -= -Promise -. -resolve +if ( +! this . -_data -) -; -} -} -get -( -extension -path -createFunc +_saveTask ) { -return this . -general +_saveTask += +new +lazy . -get +DeferredTask ( -[ -extension -. -id -extension -. -version -. -. -. -path -] -createFunc -) -; -} -delete ( -extension -path ) -{ -return += +> this . -general -. -delete +_saveNow ( -[ -extension -. -id -extension -. -version -. -. -. -path -] +) +5000 ) ; -} -} -; -Services +IOUtils . -obs +profileBeforeChange . -addObserver +addBlocker ( -StartupCache " -startupcache -- -invalidate +Flush +WebExtension +StartupCache " +async +( ) -; -class -CacheStore += +> { -constructor +await +this +. +_saveTask +. +finalize ( -storeName ) -{ +; this . -storeName +_saveTask = -storeName +null ; } -async -getStore -( -path -= -null ) -{ -let -data -= -await -StartupCache -. -dataPromise ; -let -store -= -data -. -get -( +} +return this . -storeName +_saveTask +. +arm +( ) ; -if +} +_data +: +null +async +_readData ( -! -store ) { -store +let +result = new Map ( ) ; -data +try +{ +Glean . -set -( -this +extensions . -storeName -store +startupCacheLoadTime +. +start +( ) ; -} let -key +{ +buffer +} = -path -; -if -( -Array +await +IOUtils . -isArray +read ( -path -) +this +. +file ) -{ -for +; +result += +lazy +. +aomStartup +. +decodeBlob ( -let -elem -of -path +buffer +) +; +Glean . -slice +extensions +. +startupCacheLoadTime +. +stop ( -0 -- -1 ) +; +} +catch +( +e ) { -let -next -= -store +Glean . -get +extensions +. +startupCacheLoadTime +. +cancel ( -elem ) ; if ( ! -next +DOMException +. +isInstance +( +e +) +| +| +e +. +name +! += += +" +NotFoundError +" ) { -next +Cu +. +reportError +( +e +) +; +} +let +error = -new -Map +lazy +. +getErrorNameForTelemetry ( +e ) ; -store +Glean . -set +extensions +. +startupCacheReadErrors +[ +error +] +. +add ( -elem -next +1 ) ; } -store +this +. +_data = -next +result +; +return +result ; } -key +get +dataPromise +( +) +{ +if +( +! +this +. +_dataPromise +) +{ +this +. +_dataPromise = -path -[ -path +this . -length -- -1 -] +_readData +( +) ; } return -[ -store -key -] +this +. +_dataPromise ; } -async -get +clearAddonData ( -path -createFunc +id ) { -let +return +Promise +. +all +( [ -store -key +this +. +general +. +delete +( +id +) +this +. +locales +. +delete +( +id +) +this +. +manifests +. +delete +( +id +) +this +. +permissions +. +delete +( +id +) +this +. +menus +. +delete +( +id +) ] +) +. +catch +( +e = -await -this +> +{ +/ +/ +Ignore +the +error +. +It +happens +when +we +try +to +flush +the +add +- +on +/ +/ +data +after +the +AddonManager +has +flushed +the +entire +startup +cache . -getStore -( -path +} ) ; -let -result -= -store -. -get +} +observe ( -key +subject +topic +data ) -; +{ if ( -result +topic = = = -undefined +" +startupcache +- +invalidate +" ) { -result +this +. +_data = -await -createFunc +new +Map ( -path ) ; -store +this . -set -( -key -result -) -; -StartupCache +_dataPromise += +Promise . -save +resolve ( +this +. +_data ) ; } -return -result -; } -async -set +get ( +extension path -value +createFunc ) { -let -[ -store -key -] -= -await +return this . -getStore -( -path -) -; -store +general . -set +get ( -key -value -) -; -StartupCache +[ +extension . -save -( +id +extension +. +version +. +. +. +path +] +createFunc ) ; } -async -getAll +delete ( +extension +path ) { -let -[ -store -] -= -await +return this . -getStore +general +. +delete ( +[ +extension +. +id +extension +. +version +. +. +. +path +] ) ; -return +} +general +: new -Map +CacheStore ( -store +" +general +" ) -; -} -async -delete +locales +: +new +CacheStore ( -path +" +locales +" ) -{ -let -[ -store -key -] -= -await -this -. -getStore +manifests +: +new +CacheStore ( -path +" +manifests +" ) -; -if -( -store -. -delete +other +: +new +CacheStore ( -key -) +" +other +" ) -{ -StartupCache -. -save +permissions +: +new +CacheStore ( +" +permissions +" ) -; -} -} -} -for +schemas +: +new +CacheStore ( -let -name -of -StartupCache -. -STORE_NAMES +" +schemas +" ) -{ -StartupCache -[ -name -] -= +menus +: new CacheStore ( -name +" +menus +" ) -; } +; +Services +. +obs +. +addObserver +( +StartupCache +" +startupcache +- +invalidate +" +) +; export var ExtensionParent diff --git a/toolkit/components/extensions/ExtensionShortcuts.sys.mjs b/toolkit/components/extensions/ExtensionShortcuts.sys.mjs index efd299e2571a2..65dc8411bc700 100644 --- a/toolkit/components/extensions/ExtensionShortcuts.sys.mjs +++ b/toolkit/components/extensions/ExtensionShortcuts.sys.mjs @@ -670,6 +670,14 @@ constructor { super ( +( +) += +> +new +Set +( +) ) ; / @@ -725,17 +733,6 @@ PlatformInfo os ; } -defaultConstructor -( -) -{ -return -new -Set -( -) -; -} getPlatformShortcutString ( shortcutString @@ -958,6 +955,7 @@ getPlatformShortcutString shortcutString ) ; +return super . delete @@ -2393,16 +2391,16 @@ remove let sidebarKey ; -commands -. -forEach -( +for ( -command +let +[ name +command +] +of +commands ) -= -> { if ( @@ -2539,8 +2537,6 @@ keyElement } } } -) -; doc . documentElement diff --git a/toolkit/components/extensions/ExtensionStorageIDB.sys.mjs b/toolkit/components/extensions/ExtensionStorageIDB.sys.mjs index 6e587dd42c4b5..63e6e6407485f 100644 --- a/toolkit/components/extensions/ExtensionStorageIDB.sys.mjs +++ b/toolkit/components/extensions/ExtensionStorageIDB.sys.mjs @@ -56,10 +56,6 @@ MPL . * / -export -let -ExtensionStorageIDB -; import { XPCOMUtils @@ -1446,9 +1442,6 @@ transaction objectStore ( IDB_DATA_STORENAME -" -readwrite -" ) ; const @@ -3531,6 +3524,8 @@ data . * / +export +var ExtensionStorageIDB = { diff --git a/toolkit/components/extensions/ExtensionStorageSyncKinto.sys.mjs b/toolkit/components/extensions/ExtensionStorageSyncKinto.sys.mjs index 4692003c2f17d..f1dedf0462170 100644 --- a/toolkit/components/extensions/ExtensionStorageSyncKinto.sys.mjs +++ b/toolkit/components/extensions/ExtensionStorageSyncKinto.sys.mjs @@ -2532,6 +2532,12 @@ storageSyncInit promise ; } +storageSyncInit +. +promise += +undefined +; / / Kinto diff --git a/toolkit/components/extensions/ExtensionTelemetry.sys.mjs b/toolkit/components/extensions/ExtensionTelemetry.sys.mjs index b61faa4b11704..0e95f6ff62383 100644 --- a/toolkit/components/extensions/ExtensionTelemetry.sys.mjs +++ b/toolkit/components/extensions/ExtensionTelemetry.sys.mjs @@ -2173,7 +2173,10 @@ Error Unknown metric { +String +( prop +) } ) ; diff --git a/toolkit/components/extensions/ExtensionTestCommon.sys.mjs b/toolkit/components/extensions/ExtensionTestCommon.sys.mjs index 9654f8bbaa905..8b6b0a595ab07 100644 --- a/toolkit/components/extensions/ExtensionTestCommon.sys.mjs +++ b/toolkit/components/extensions/ExtensionTestCommon.sys.mjs @@ -353,10 +353,6 @@ instanceOf = ExtensionCommon ; -export -var -ExtensionTestCommon -; / * * @@ -1509,8 +1505,6 @@ persistentListeners ? . size -> -0 | | ! @@ -1792,6 +1786,8 @@ primed } } ; +export +var ExtensionTestCommon = class diff --git a/toolkit/components/extensions/ExtensionWorkerChild.sys.mjs b/toolkit/components/extensions/ExtensionWorkerChild.sys.mjs index 3789769ace83c..bc403958d8a3e 100644 --- a/toolkit/components/extensions/ExtensionWorkerChild.sys.mjs +++ b/toolkit/components/extensions/ExtensionWorkerChild.sys.mjs @@ -212,7 +212,7 @@ mjs const { BaseContext -defineLazyGetter +redefineGetter } = ExtensionCommon @@ -827,16 +827,8 @@ return api ; } -} -defineLazyGetter -( -WorkerPort -. -prototype -" +get api -" -function ( ) { @@ -846,44 +838,34 @@ No need to clone -the -API -object +this for the worker -because it -runs -/ -/ +' +s on a -different +separate JSRuntime -and -doesn -' -t -have -direct -access -to -this -/ -/ -object . return +redefineGetter +( +this +" +api +" this . getAPI ( ) -; -} ) ; +} +} / * * @@ -4046,50 +4028,63 @@ unload ) ; } -} -defineLazyGetter +get +childManager ( -WorkerContextChild -. -prototype +) +{ +const +childManager += +getContextChildManagerGetter +( +{ +envType +: " -messenger +addon_parent " -function -( +} +WebIDLChildAPIManager ) -{ -return -new -WorkerMessenger +. +call ( this ) ; -} -) -; -defineLazyGetter +return +redefineGetter ( -WorkerContextChild -. -prototype +this " childManager " -getContextChildManagerGetter +childManager +) +; +} +get +messenger ( +) { -envType -: +return +redefineGetter +( +this " -addon_parent +messenger " -} -WebIDLChildAPIManager +new +WorkerMessenger +( +this ) ) ; +} +} export var ExtensionWorkerChild diff --git a/toolkit/components/extensions/ExtensionXPCShellUtils.sys.mjs b/toolkit/components/extensions/ExtensionXPCShellUtils.sys.mjs index e7e5dbe92b812..fd49762df303a 100644 --- a/toolkit/components/extensions/ExtensionXPCShellUtils.sys.mjs +++ b/toolkit/components/extensions/ExtensionXPCShellUtils.sys.mjs @@ -313,6 +313,44 @@ version class ExtensionWrapper { +/ +* +* +type +{ +AddonWrapper +} +* +/ +addon +; +/ +* +* +type +{ +Promise +< +AddonWrapper +> +} +* +/ +addonPromise +; +/ +* +* +type +{ +nsIFile +[ +] +} +* +/ +cleanupFiles +; constructor ( testScope @@ -2632,76 +2670,45 @@ unload ) ; } -async -upgrade -( -data -) -{ -this +/ +* +* +* +Override +for +subclasses +which +don +' +t +set +an +ID +in +the +constructor . -startupPromise -= -new -Promise -( -resolve -= -> +* +* +param { -this -. -resolveStartup -= -resolve -; +nsIURI } -) -; -this -. -state -= -" -restarting -" -; -await -this -. -_flushCache -( -) -; -let -xpiFile -= -lazy -. -ExtensionTestCommon -. -generateXPI -( -data -) -; -this -. -cleanupFiles -. -push -( -xpiFile -) -; -return -this -. -_install +uri +* +param +{ +string +} +id +* +/ +maybeSetID ( -xpiFile +uri +id ) -; +{ } } class @@ -3301,6 +3308,77 @@ file ) ; } +async +upgrade +( +data +) +{ +this +. +startupPromise += +new +Promise +( +resolve += +> +{ +this +. +resolveStartup += +resolve +; +} +) +; +this +. +state += +" +restarting +" +; +await +this +. +_flushCache +( +) +; +let +xpiFile += +lazy +. +ExtensionTestCommon +. +generateXPI +( +data +) +; +this +. +cleanupFiles +. +push +( +xpiFile +) +; +return +this +. +_install +( +xpiFile +) +; +} } class ExternallyInstalledWrapper @@ -3353,13 +3431,6 @@ restarting " ; } -maybeSetID -( -uri -id -) -{ -} } export var @@ -4257,10 +4328,6 @@ loadContentPage ( url options -. -. -. -args ) { return @@ -4270,10 +4337,6 @@ loadContentPage ( url options -. -. -. -args ) ; } diff --git a/toolkit/components/extensions/NativeMessaging.sys.mjs b/toolkit/components/extensions/NativeMessaging.sys.mjs index 21d0c580f38f2..c473d20ee4413 100644 --- a/toolkit/components/extensions/NativeMessaging.sys.mjs +++ b/toolkit/components/extensions/NativeMessaging.sys.mjs @@ -485,11 +485,33 @@ message bytes " ; +XPCOMUtils +. +defineLazyPreferenceGetter +( +lazy +" +maxRead +" +PREF_MAX_READ +MAX_READ +) +; +XPCOMUtils +. +defineLazyPreferenceGetter +( +lazy +" +maxWrite +" +PREF_MAX_WRITE +MAX_WRITE +) +; export -var -NativeApp -= class +NativeApp extends EventEmitter { @@ -1256,7 +1278,7 @@ buffer . byteLength > -NativeApp +lazy . maxWrite ) @@ -1407,7 +1429,7 @@ if ( len > -NativeApp +lazy . maxRead ) @@ -1434,7 +1456,7 @@ the limit of { -NativeApp +lazy . maxRead } @@ -1953,7 +1975,7 @@ buffer . byteLength > -NativeApp +lazy . maxWrite ) @@ -2723,28 +2745,3 @@ result ; } } -; -XPCOMUtils -. -defineLazyPreferenceGetter -( -NativeApp -" -maxRead -" -PREF_MAX_READ -MAX_READ -) -; -XPCOMUtils -. -defineLazyPreferenceGetter -( -NativeApp -" -maxWrite -" -PREF_MAX_WRITE -MAX_WRITE -) -; diff --git a/toolkit/components/extensions/Schemas.sys.mjs b/toolkit/components/extensions/Schemas.sys.mjs index 15e00bfbeda5c..ab66f187d8d28 100644 --- a/toolkit/components/extensions/Schemas.sys.mjs +++ b/toolkit/components/extensions/Schemas.sys.mjs @@ -305,10 +305,6 @@ errors false ) ; -export -let -Schemas -; const KEY_CONTENT_SCHEMAS = @@ -2339,6 +2335,12 @@ return value ; } +. +. +. +params +. +preprocessors } ; this @@ -2351,10 +2353,23 @@ this . isChromeCompat = +params +. +isChromeCompat +? +? false ; this . +manifestVersion += +params +. +manifestVersion +; +this +. currentChoices = new @@ -2400,85 +2415,6 @@ params ; } } -let -props -= -[ -" -isChromeCompat -" -" -manifestVersion -" -" -preprocessors -" -] -; -for -( -let -prop -of -props -) -{ -if -( -prop -in -params -) -{ -if -( -prop -in -this -& -& -typeof -this -[ -prop -] -= -= -" -object -" -) -{ -Object -. -assign -( -this -[ -prop -] -params -[ -prop -] -) -; -} -else -{ -this -[ -prop -] -= -params -[ -prop -] -; -} -} -} } get choicePath @@ -7201,8 +7137,9 @@ if ( isNaN ( -new Date +. +parse ( string ) @@ -14779,6 +14716,10 @@ TypeProperty extends Entry { +unsupported += +false +; constructor ( schema @@ -15623,6 +15564,10 @@ CallEntry extends Entry { +hasAsyncCallback += +false +; constructor ( schema @@ -17935,23 +17880,63 @@ _lazySchemas ) ; } -for +/ +/ +Keep +in +sync +with +LOADERS +above +. +this +. +types += +new +DefaultMap ( -let -type -of -Object +( +) += +> +[ +] +) +; +this . -keys +properties += +new +DefaultMap +( ( -LOADERS ) += +> +[ +] ) -{ +; this +. +functions += +new +DefaultMap +( +( +) += +> [ -type ] +) +; +this +. +events = new DefaultMap @@ -17964,7 +17949,6 @@ DefaultMap ] ) ; -} for ( let @@ -21075,6 +21059,8 @@ result ; } } +export +var Schemas = {