@@ -420,48 +420,11 @@ def __init__(self, location, parentScope, identifier):
420420 if parentScope :
421421 self .resolve (parentScope )
422422
423- self .treatNullAs = "Default"
424-
425423 def resolve (self , parentScope ):
426424 assert isinstance (parentScope , IDLScope )
427425 assert isinstance (self .identifier , IDLUnresolvedIdentifier )
428426 self .identifier .resolve (parentScope , self )
429427
430- def checkForStringHandlingExtendedAttributes (self , attrs ,
431- isDictionaryMember = False ,
432- isOptional = False ):
433- """
434- A helper function to deal with TreatNullAs. Returns the list
435- of attrs it didn't handle itself.
436- """
437- assert isinstance (self , IDLArgument ) or isinstance (self , IDLAttribute )
438- unhandledAttrs = list ()
439- for attr in attrs :
440- if not attr .hasValue ():
441- unhandledAttrs .append (attr )
442- continue
443-
444- identifier = attr .identifier ()
445- value = attr .value ()
446- if identifier == "TreatNullAs" :
447- if not self .type .isDOMString () or self .type .nullable ():
448- raise WebIDLError ("[TreatNullAs] is only allowed on "
449- "arguments or attributes whose type is "
450- "DOMString" ,
451- [self .location ])
452- if isDictionaryMember :
453- raise WebIDLError ("[TreatNullAs] is not allowed for "
454- "dictionary members" , [self .location ])
455- if value != 'EmptyString' :
456- raise WebIDLError ("[TreatNullAs] must take the identifier "
457- "'EmptyString', not '%s'" % value ,
458- [self .location ])
459- self .treatNullAs = value
460- else :
461- unhandledAttrs .append (attr )
462-
463- return unhandledAttrs
464-
465428
466429class IDLObjectWithScope (IDLObjectWithIdentifier , IDLScope ):
467430 def __init__ (self , location , parentScope , identifier ):
@@ -3561,6 +3524,10 @@ def coerceToType(self, type, location):
35613524 # extra normalization step.
35623525 assert self .type .isDOMString ()
35633526 return self
3527+ elif self .type .isDOMString () and type .treatNullAsEmpty :
3528+ # TreatNullAsEmpty is a different type for resolution reasons,
3529+ # however once you have a value it doesn't matter
3530+ return self
35643531 elif self .type .isString () and type .isByteString ():
35653532 # Allow ByteStrings to use a default value like DOMString.
35663533 # No coercion is required as Codegen.py will handle the
@@ -4238,7 +4205,7 @@ def finish(self, scope):
42384205 assert not isinstance (t .name , IDLUnresolvedIdentifier )
42394206 self .type = t
42404207
4241- if self .readonly and (self .type .clamp or self .type .enforceRange ):
4208+ if self .readonly and (self .type .clamp or self .type .enforceRange or self . type . treatNullAsEmpty ):
42424209 raise WebIDLError ("A readonly attribute cannot be [Clamp] or [EnforceRange]" ,
42434210 [self .location ])
42444211 if self .type .isDictionary () and not self .getExtendedAttribute ("Cached" ):
@@ -4565,10 +4532,6 @@ def resolve(self, parentScope):
45654532 self .type .resolveType (parentScope )
45664533 IDLObjectWithIdentifier .resolve (self , parentScope )
45674534
4568- def addExtendedAttributes (self , attrs ):
4569- attrs = self .checkForStringHandlingExtendedAttributes (attrs )
4570- IDLInterfaceMember .addExtendedAttributes (self , attrs )
4571-
45724535 def hasLenientThis (self ):
45734536 return self .lenientThis
45744537
@@ -4607,13 +4570,10 @@ def __init__(self, location, identifier, type, optional=False, defaultValue=None
46074570 assert not variadic or not defaultValue
46084571
46094572 def addExtendedAttributes (self , attrs ):
4610- attrs = self .checkForStringHandlingExtendedAttributes (
4611- attrs ,
4612- isDictionaryMember = self .dictionaryMember ,
4613- isOptional = self .optional )
46144573 for attribute in attrs :
46154574 identifier = attribute .identifier ()
4616- if self .allowTypeAttributes and (identifier == "EnforceRange" or identifier == "Clamp" ):
4575+ if self .allowTypeAttributes and (identifier == "EnforceRange" or identifier == "Clamp" or
4576+ identifier == "TreatNullAs" ):
46174577 self .type = self .type .withExtendedAttributes ([attribute ])
46184578 elif identifier == "TreatNonCallableAsNull" :
46194579 self ._allowTreatNonCallableAsNull = True
0 commit comments