@@ -327,13 +327,6 @@ def lookupIdentifier(self, identifier):
327327 assert identifier .scope == self
328328 return self ._lookupIdentifier (identifier )
329329
330- def addIfaceGlobalNames (self , interfaceName , globalNames ):
331- """Record the global names (from |globalNames|) that can be used in
332- [Exposed] to expose things in a global named |interfaceName|"""
333- self .globalNames .update (globalNames )
334- for name in globalNames :
335- self .globalNameMapping [name ].add (interfaceName )
336-
337330
338331class IDLIdentifier (IDLObject ):
339332 def __init__ (self , location , scope , name ):
@@ -511,10 +504,8 @@ def isExposedInWindow(self):
511504 return 'Window' in self .exposureSet
512505
513506 def isExposedOnMainThread (self ):
514- return self .isExposedInWindow ()
515-
516- def isExposedOffMainThread (self ):
517- return len (self .exposureSet - {'Window' }) > 0
507+ return (self .isExposedInWindow () or
508+ self .isExposedInSystemGlobals ())
518509
519510 def isExposedInAnyWorker (self ):
520511 return len (self .getWorkerExposureSet ()) > 0
@@ -525,6 +516,9 @@ def isExposedInWorkerDebugger(self):
525516 def isExposedInAnyWorklet (self ):
526517 return len (self .getWorkletExposureSet ()) > 0
527518
519+ def isExposedInSystemGlobals (self ):
520+ return 'BackstagePass' in self .exposureSet
521+
528522 def isExposedInSomeButNotAllWorkers (self ):
529523 """
530524 Returns true if the Exposed extended attribute for this interface
@@ -1329,9 +1323,10 @@ def checkDuplicateNames(member, name, attributeName):
13291323 checkDuplicateNames (member , bindingAlias , "BindingAlias" )
13301324
13311325
1332- if self .getExtendedAttribute ("Pref" ) and self .isExposedOffMainThread ():
1333- raise WebIDLError ("[Pref] used on an interface that is not "
1334- "main-thread-only" ,
1326+ if (self .getExtendedAttribute ("Pref" ) and
1327+ self ._exposureGlobalNames != set ([self .parentScope .primaryGlobalName ])):
1328+ raise WebIDLError ("[Pref] used on an interface that is not %s-only" %
1329+ self .parentScope .primaryGlobalName ,
13351330 [self .location ])
13361331
13371332 # Conditional exposure makes no sense for interfaces with no
@@ -1715,8 +1710,9 @@ def addExtendedAttributes(self, attrs):
17151710 self .globalNames = attr .args ()
17161711 else :
17171712 self .globalNames = [self .identifier .name ]
1718- self .parentScope .addIfaceGlobalNames (self .identifier .name ,
1719- self .globalNames )
1713+ self .parentScope .globalNames .update (self .globalNames )
1714+ for globalName in self .globalNames :
1715+ self .parentScope .globalNameMapping [globalName ].add (self .identifier .name )
17201716 self ._isOnGlobalProtoChain = True
17211717 elif identifier == "PrimaryGlobal" :
17221718 if not attr .noArguments ():
@@ -1729,8 +1725,8 @@ def addExtendedAttributes(self, attrs):
17291725 self .parentScope .primaryGlobalAttr .location ])
17301726 self .parentScope .primaryGlobalAttr = attr
17311727 self .parentScope .primaryGlobalName = self .identifier .name
1732- self .parentScope .addIfaceGlobalNames (self .identifier .name ,
1733- [self .identifier .name ])
1728+ self .parentScope .globalNames . add (self .identifier .name )
1729+ self . parentScope . globalNameMapping [self .identifier .name ]. add ( self . identifier . name )
17341730 self ._isOnGlobalProtoChain = True
17351731 elif identifier == "SecureContext" :
17361732 if not attr .noArguments ():
@@ -3576,9 +3572,10 @@ def finish(self, scope):
35763572 IDLExposureMixins .finish (self , scope )
35773573
35783574 def validate (self ):
3579- if self .getExtendedAttribute ("Pref" ) and self .isExposedOffMainThread ():
3575+ if (self .getExtendedAttribute ("Pref" ) and
3576+ self .exposureSet != set ([self ._globalScope .primaryGlobalName ])):
35803577 raise WebIDLError ("[Pref] used on an interface member that is not "
3581- "main-thread- only" ,
3578+ "%s- only" % self . _globalScope . primaryGlobalName ,
35823579 [self .location ])
35833580
35843581 if self .isAttr () or self .isMethod ():
@@ -6899,13 +6896,16 @@ def __init__(self, outputdir='', lexer=None):
68996896 logger .reportGrammarErrors ()
69006897
69016898 self ._globalScope = IDLScope (BuiltinLocation ("<Global Scope>" ), None , None )
6902-
69036899 # To make our test harness work, pretend like we have a primary global already.
69046900 # Note that we _don't_ set _globalScope.primaryGlobalAttr,
69056901 # so we'll still be able to detect multiple PrimaryGlobal extended attributes.
69066902 self ._globalScope .primaryGlobalName = "FakeTestPrimaryGlobal"
6907- self ._globalScope .addIfaceGlobalNames ("FakeTestPrimaryGlobal" , ["FakeTestPrimaryGlobal" ])
6908-
6903+ self ._globalScope .globalNames .add ("FakeTestPrimaryGlobal" )
6904+ self ._globalScope .globalNameMapping ["FakeTestPrimaryGlobal" ].add ("FakeTestPrimaryGlobal" )
6905+ # And we add the special-cased "System" global name, which
6906+ # doesn't have any corresponding interfaces.
6907+ self ._globalScope .globalNames .add ("System" )
6908+ self ._globalScope .globalNameMapping ["System" ].add ("BackstagePass" )
69096909 self ._installBuiltins (self ._globalScope )
69106910 self ._productions = []
69116911
0 commit comments