Skip to content

Commit e8ca527

Browse files
committed
Bug 1359269 - Part 10: Make it a hard error to apply TreatNullAs on non-types; r=bzbarsky
Depends on D20060 Differential Revision: https://phabricator.services.mozilla.com/D20061 --HG-- extra : moz-landing-system : lando
1 parent 8f2ed90 commit e8ca527

20 files changed

+54
-103
lines changed

dom/bindings/Codegen.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4570,7 +4570,6 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
45704570
isOptional=False,
45714571
invalidEnumValueFatal=True,
45724572
defaultValue=None,
4573-
treatNullAs="Default",
45744573
isNullOrUndefined=False,
45754574
exceptionCode=None,
45764575
lenientFloatCode=None,
@@ -4650,8 +4649,6 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
46504649

46514650
isClamp = type.clamp
46524651
isEnforceRange = type.enforceRange
4653-
if type.treatNullAsEmpty:
4654-
treatNullAs = "EmptyString"
46554652

46564653
# If exceptionCode is not set, we'll just rethrow the exception we got.
46574654
# Note that we can't just set failureCode to exceptionCode, because setting
@@ -5791,6 +5788,10 @@ def handleNull(templateBody, setToNullVar, extraConditionForNull=""):
57915788
undefinedBehavior = "eNull"
57925789
else:
57935790
undefinedBehavior = "eStringify"
5791+
if type.treatNullAsEmpty:
5792+
treatNullAs = "EmptyString"
5793+
else:
5794+
treatNullAs = "Default"
57945795
nullBehavior = treatAs[treatNullAs]
57955796

57965797
def getConversionCode(varName):
@@ -6446,7 +6447,6 @@ def define(self):
64466447
not self.argument.variadic),
64476448
invalidEnumValueFatal=self.invalidEnumValueFatal,
64486449
defaultValue=self.argument.defaultValue,
6449-
treatNullAs=self.argument.treatNullAs,
64506450
lenientFloatCode=self.lenientFloatCode,
64516451
isMember="Variadic" if self.argument.variadic else False,
64526452
allowTreatNonCallableAsNull=self.argument.allowTreatNonCallableAsNull(),
@@ -8612,12 +8612,6 @@ def __init__(self, type, interfaceMember, name="arg", allowTreatNonCallableAsNul
86128612
self.variadic = False
86138613
self.defaultValue = None
86148614
self._allowTreatNonCallableAsNull = allowTreatNonCallableAsNull
8615-
# For FakeArguments generated by maplike/setlike convenience functions,
8616-
# we won't have an interfaceMember to pass in.
8617-
if interfaceMember:
8618-
self.treatNullAs = interfaceMember.treatNullAs
8619-
else:
8620-
self.treatNullAs = "Default"
86218615

86228616
self.identifier = FakeIdentifier(name)
86238617

@@ -11319,7 +11313,6 @@ def __init__(self, descriptor, operation, checkFound=True,
1131911313
argument = arguments[1]
1132011314
info = getJSToNativeConversionInfo(
1132111315
argument.type, descriptor,
11322-
treatNullAs=argument.treatNullAs,
1132311316
sourceDescription=("value being assigned to %s setter" %
1132411317
descriptor.interface.identifier.name))
1132511318
if argumentHandleValue is None:
@@ -16367,7 +16360,6 @@ def __init__(self, descriptor, spiderMonkeyInterfacesAreStructs=False):
1636716360

1636816361
class FakeMember():
1636916362
def __init__(self, name=None):
16370-
self.treatNullAs = "Default"
1637116363
if name is not None:
1637216364
self.identifier = FakeIdentifier(name)
1637316365

dom/bindings/GenerateCSS2PropertiesWebIDL.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# (whether camelCase, _underscorePrefixed, etc.) and the given array of
1212
# extended attributes.
1313
def generateLine(propName, extendedAttrs):
14-
return " [%s] attribute DOMString %s;\n" % (", ".join(extendedAttrs),
14+
return " [%s] attribute [TreatNullAs=EmptyString] DOMString %s;\n" % (", ".join(extendedAttrs),
1515
propName)
1616
def generate(output, idlFilename, dataFile):
1717
propList = runpy.run_path(dataFile)["data"]
@@ -21,7 +21,7 @@ def generate(output, idlFilename, dataFile):
2121
continue
2222
# Unfortunately, even some of the getters here are fallible
2323
# (e.g. on nsComputedDOMStyle).
24-
extendedAttrs = ["CEReactions", "Throws", "TreatNullAs=EmptyString",
24+
extendedAttrs = ["CEReactions", "Throws",
2525
"SetterNeedsSubjectPrincipal=NonSystem"]
2626
if p.pref is not "":
2727
extendedAttrs.append('Pref="%s"' % p.pref)

dom/bindings/parser/WebIDL.py

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -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

466429
class 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

dom/chrome-webidl/InspectorUtils.webidl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace InspectorUtils {
1515
sequence<StyleSheet> getAllStyleSheets(Document document, optional boolean documentOnly = false);
1616
sequence<CSSStyleRule> getCSSStyleRules(
1717
Element element,
18-
[TreatNullAs=EmptyString] optional DOMString pseudo = "");
18+
optional [TreatNullAs=EmptyString] DOMString pseudo = "");
1919
unsigned long getRuleLine(CSSRule rule);
2020
unsigned long getRuleColumn(CSSRule rule);
2121
unsigned long getRelativeRuleLine(CSSRule rule);
@@ -29,7 +29,7 @@ namespace InspectorUtils {
2929
Element element,
3030
CSSStyleRule rule,
3131
unsigned long selectorIndex,
32-
[TreatNullAs=EmptyString] optional DOMString pseudo = "");
32+
optional [TreatNullAs=EmptyString] DOMString pseudo = "");
3333
boolean isInheritedProperty(DOMString property);
3434
sequence<DOMString> getCSSPropertyNames(optional PropertyNamesOptions options);
3535
sequence<PropertyPref> getCSSPropertyPrefs();

dom/imptests/html/dom/test_interfaces.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ <h1>DOM IDL tests</h1>
277277
};
278278

279279
interface CharacterData : Node {
280-
[TreatNullAs=EmptyString] attribute DOMString data;
280+
attribute [TreatNullAs=EmptyString] DOMString data;
281281
readonly attribute unsigned long length;
282282
DOMString substringData(unsigned long offset, unsigned long count);
283283
void appendData(DOMString data);

dom/webidl/CSSStyleDeclaration.webidl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface CSSStyleDeclaration {
2424
DOMString getPropertyValue(DOMString property);
2525
DOMString getPropertyPriority(DOMString property);
2626
[CEReactions, NeedsSubjectPrincipal=NonSystem, Throws]
27-
void setProperty(DOMString property, [TreatNullAs=EmptyString] DOMString value, [TreatNullAs=EmptyString] optional DOMString priority = "");
27+
void setProperty(DOMString property, [TreatNullAs=EmptyString] DOMString value, optional [TreatNullAs=EmptyString] DOMString priority = "");
2828
[CEReactions, Throws]
2929
DOMString removeProperty(DOMString property);
3030

dom/webidl/CharacterData.webidl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
*/
1212

1313
interface CharacterData : Node {
14-
[TreatNullAs=EmptyString, Pure, SetterThrows]
15-
attribute DOMString data;
14+
[Pure, SetterThrows]
15+
attribute [TreatNullAs=EmptyString] DOMString data;
1616
[Pure]
1717
readonly attribute unsigned long length;
1818
[Throws]

dom/webidl/Element.webidl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@ partial interface Element {
204204

205205
// http://domparsing.spec.whatwg.org/#extensions-to-the-element-interface
206206
partial interface Element {
207-
[CEReactions, SetterNeedsSubjectPrincipal=NonSystem, Pure, SetterThrows, GetterCanOOM, TreatNullAs=EmptyString]
208-
attribute DOMString innerHTML;
209-
[CEReactions, Pure,SetterThrows,TreatNullAs=EmptyString]
210-
attribute DOMString outerHTML;
207+
[CEReactions, SetterNeedsSubjectPrincipal=NonSystem, Pure, SetterThrows, GetterCanOOM]
208+
attribute [TreatNullAs=EmptyString] DOMString innerHTML;
209+
[CEReactions, Pure, SetterThrows]
210+
attribute [TreatNullAs=EmptyString] DOMString outerHTML;
211211
[CEReactions, Throws]
212212
void insertAdjacentHTML(DOMString position, DOMString text);
213213
};

dom/webidl/HTMLDocument.webidl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ interface HTMLDocument : Document {
4242
[Throws]
4343
DOMString queryCommandValue(DOMString commandId);
4444

45-
[CEReactions, TreatNullAs=EmptyString] attribute DOMString fgColor;
46-
[CEReactions, TreatNullAs=EmptyString] attribute DOMString linkColor;
47-
[CEReactions, TreatNullAs=EmptyString] attribute DOMString vlinkColor;
48-
[CEReactions, TreatNullAs=EmptyString] attribute DOMString alinkColor;
49-
[CEReactions, TreatNullAs=EmptyString] attribute DOMString bgColor;
45+
[CEReactions] attribute [TreatNullAs=EmptyString] DOMString fgColor;
46+
[CEReactions] attribute [TreatNullAs=EmptyString] DOMString linkColor;
47+
[CEReactions] attribute [TreatNullAs=EmptyString] DOMString vlinkColor;
48+
[CEReactions] attribute [TreatNullAs=EmptyString] DOMString alinkColor;
49+
[CEReactions] attribute [TreatNullAs=EmptyString] DOMString bgColor;
5050

5151
void clear();
5252

dom/webidl/HTMLFontElement.webidl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
[HTMLConstructor]
1515
interface HTMLFontElement : HTMLElement {
16-
[CEReactions, TreatNullAs=EmptyString, SetterThrows] attribute DOMString color;
16+
[CEReactions, SetterThrows] attribute [TreatNullAs=EmptyString] DOMString color;
1717
[CEReactions, SetterThrows] attribute DOMString face;
1818
[CEReactions, SetterThrows] attribute DOMString size;
1919
};

0 commit comments

Comments
 (0)