Backed out 2 changesets (bug 1803752) for causing python mbu failures in dom/bindings/mozwebidlcodegen/test/test_mozwebidlcodegen.py CLOSED TREE

Backed out changeset 0a06638b1f49 (bug 1803752)
Backed out changeset 3e1599493e2e (bug 1803752)
This commit is contained in:
Sandor Molnar 2023-06-20 21:35:33 +03:00
Родитель b3cea24dfd
Коммит 53e2e84520
8 изменённых файлов: 132 добавлений и 765 удалений

Просмотреть файл

@ -2125,31 +2125,3 @@ addExternalIface('nsISessionStoreRestoreData',
headerFile='nsISessionStoreRestoreData.h', notflattened=True)
addExternalIface('nsIScreen', nativeType='nsIScreen',
headerFile='nsIScreen.h', notflattened=True)
# The TemplatedAttributes dictionary has the interface name where the template
# should be generated as the key. The values are lists of dictionaries, where
# each dictionary corresponds to one template. The dictionary contains:
#
# template the template's name
# getter the name for the native getter to call
# setter the name for the native setter to call
# argument a tuple for the additional argument that should be passed to the
# native getter and setter, containing the type for the argument
# and a name for the argument. The value will be supplied by the
# [BindingTemplate] extended attribute.
# attrName a string which in the generated C++ code would yield a
# |const char*| that contains the attribute's name
TemplatedAttributes = {
'CSS2Properties': [
{
'template': 'CSS2Property',
'getter': 'GetPropertyValue',
'setter': 'SetPropertyValue',
'argument': ('nsCSSPropertyID', 'id'),
'attrName': 'nsCSSProps::PropertyIDLName(id)',
},
],
}

Просмотреть файл

@ -1927,7 +1927,7 @@ class CGAbstractMethod(CGThing):
prologue += indent(
fill(
"""
BindingCallContext ${cxname}(cx_, ${label});
BindingCallContext ${cxname}(cx_, "${label}");
""",
cxname=cxname,
label=error_reporting_label,
@ -8989,14 +8989,6 @@ class CGPerSignatureCall(CGThing):
dontSetSlot should be set to True if the value should not be cached in a
slot (even if the attribute is marked as StoreInSlot or Cached in the
WebIDL).
errorReportingLabel can contain a custom label to use for error reporting.
It will be inserted as is in the code, so if it needs to be a literal
string in C++ it should be quoted.
additionalArgsPre contains additional arguments that are added after the
arguments that CGPerSignatureCall itself adds (JSContext, global, ), and
before the actual arguments.
"""
# XXXbz For now each entry in the argument list is either an
@ -9021,8 +9013,6 @@ class CGPerSignatureCall(CGThing):
objectName="obj",
dontSetSlot=False,
extendedAttributes=None,
errorReportingLabel=None,
additionalArgsPre=[],
):
assert idlNode.isMethod() == (not getter and not setter)
assert idlNode.isAttr() == (getter or setter)
@ -9332,17 +9322,14 @@ class CGPerSignatureCall(CGThing):
assert setter
cgThings.append(CGObservableArraySetterGenerator(descriptor, idlNode))
else:
if errorReportingLabel is None:
context = GetLabelForErrorReporting(descriptor, idlNode, isConstructor)
if getter:
context = context + " getter"
elif setter:
context = context + " setter"
# Callee expects a quoted string for the context if
# there's a context.
context = '"%s"' % context
else:
context = errorReportingLabel
context = GetLabelForErrorReporting(descriptor, idlNode, isConstructor)
if getter:
context = context + " getter"
elif setter:
context = context + " setter"
# Callee expects a quoted string for the context if
# there's a context.
context = '"%s"' % context
if idlNode.isMethod() and idlNode.getExtendedAttribute("WebExtensionStub"):
[
@ -9359,7 +9346,7 @@ class CGPerSignatureCall(CGThing):
needsCallerType(idlNode),
isChromeOnly(idlNode),
args,
argsPre + additionalArgsPre,
argsPre,
returnType,
self.extendedAttributes,
descriptor,
@ -10238,8 +10225,6 @@ class CGGetterCall(CGPerSignatureCall):
nativeMethodName,
descriptor,
attr,
errorReportingLabel=None,
argsPre=[],
dontSetSlot=False,
extendedAttributes=None,
):
@ -10264,8 +10249,6 @@ class CGGetterCall(CGPerSignatureCall):
useCounterName=useCounterName,
dontSetSlot=dontSetSlot,
extendedAttributes=extendedAttributes,
errorReportingLabel=errorReportingLabel,
additionalArgsPre=argsPre,
)
@ -10302,15 +10285,7 @@ class CGSetterCall(CGPerSignatureCall):
setter.
"""
def __init__(
self,
argType,
nativeMethodName,
descriptor,
attr,
errorReportingLabel=None,
argsPre=[],
):
def __init__(self, argType, nativeMethodName, descriptor, attr):
if attr.getExtendedAttribute("UseCounter"):
useCounterName = "%s_%s_setter" % (
descriptor.interface.identifier.name,
@ -10330,8 +10305,6 @@ class CGSetterCall(CGPerSignatureCall):
attr,
setter=True,
useCounterName=useCounterName,
errorReportingLabel=errorReportingLabel,
additionalArgsPre=argsPre,
)
def wrap_return_value(self):
@ -10613,7 +10586,7 @@ class CGSpecializedMethod(CGAbstractStaticMethod):
descriptor, idlMethod
):
return None
return '"%s"' % GetLabelForErrorReporting(descriptor, idlMethod, isConstructor)
return GetLabelForErrorReporting(descriptor, idlMethod, isConstructor)
def error_reporting_label(self):
return CGSpecializedMethod.error_reporting_label_helper(
@ -10623,9 +10596,7 @@ class CGSpecializedMethod(CGAbstractStaticMethod):
@staticmethod
def makeNativeName(descriptor, method):
if method.underlyingAttr:
return CGSpecializedGetterCommon.makeNativeName(
descriptor, method.underlyingAttr
)
return CGSpecializedGetter.makeNativeName(descriptor, method.underlyingAttr)
name = method.identifier.name
return MakeNativeName(descriptor.binaryNameFor(name, method.isStatic()))
@ -11018,25 +10989,21 @@ class CGStaticMethod(CGAbstractStaticBindingMethod):
)
class CGSpecializedGetterCommon(CGAbstractStaticMethod):
class CGSpecializedGetter(CGAbstractStaticMethod):
"""
A class for generating the code for a specialized attribute getter
that the JIT can call with lower overhead.
"""
def __init__(
self,
descriptor,
name,
nativeName,
attr,
args,
errorReportingLabel=None,
additionalArg=None,
):
self.nativeName = nativeName
self.errorReportingLabel = errorReportingLabel
self.additionalArgs = [] if additionalArg is None else [additionalArg]
def __init__(self, descriptor, attr):
self.attr = attr
name = "get_" + IDLToCIdentifier(attr.identifier.name)
args = [
Argument("JSContext*", "cx"),
Argument("JS::Handle<JSObject*>", "obj"),
Argument("void*", "void_self"),
Argument("JSJitGetterCallArgs", "args"),
]
# StoreInSlot attributes have their getters called from Wrap(). We
# really hope they can't run script, and don't want to annotate Wrap()
# methods as doing that anyway, so let's not annotate them as
@ -11046,7 +11013,7 @@ class CGSpecializedGetterCommon(CGAbstractStaticMethod):
descriptor,
name,
"bool",
args + self.additionalArgs,
args,
canRunScript=not attr.getExtendedAttribute("StoreInSlot"),
)
@ -11074,13 +11041,7 @@ class CGSpecializedGetterCommon(CGAbstractStaticMethod):
# backing object from the slot, this requires its own generator.
return prefix + getObservableArrayGetterBody(self.descriptor, self.attr)
if self.nativeName is None:
nativeName = CGSpecializedGetterCommon.makeNativeName(
self.descriptor, self.attr
)
else:
nativeName = self.nativeName
nativeName = CGSpecializedGetter.makeNativeName(self.descriptor, self.attr)
type = self.attr.type
if self.attr.getExtendedAttribute("CrossOriginReadable"):
remoteType = type
@ -11113,8 +11074,6 @@ class CGSpecializedGetterCommon(CGAbstractStaticMethod):
nativeName,
self.descriptor,
self.attr,
self.errorReportingLabel,
argsPre=[a.name for a in self.additionalArgs],
dontSetSlot=True,
extendedAttributes=extendedAttributes,
).define(),
@ -11185,30 +11144,21 @@ class CGSpecializedGetterCommon(CGAbstractStaticMethod):
)
return (
prefix
+ CGGetterCall(
type,
nativeName,
self.descriptor,
self.attr,
self.errorReportingLabel,
argsPre=[a.name for a in self.additionalArgs],
).define()
prefix + CGGetterCall(type, nativeName, self.descriptor, self.attr).define()
)
def auto_profiler_label(self, profilerLabel=None):
if profilerLabel is None:
profilerLabel = '"' + self.attr.identifier.name + '"'
def auto_profiler_label(self):
interface_name = self.descriptor.interface.identifier.name
attr_name = self.attr.identifier.name
return fill(
"""
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"${interface_name}", ${attr_name}, DOM, cx,
"${interface_name}", "${attr_name}", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
""",
interface_name=interface_name,
attr_name=profilerLabel,
attr_name=attr_name,
)
def error_reporting_label(self):
@ -11227,112 +11177,6 @@ class CGSpecializedGetterCommon(CGAbstractStaticMethod):
return nativeName
class CGSpecializedGetter(CGSpecializedGetterCommon):
"""
A class for generating the code for a specialized attribute getter
that the JIT can call with lower overhead.
"""
def __init__(self, descriptor, attr):
self.attr = attr
name = "get_" + IDLToCIdentifier(attr.identifier.name)
args = [
Argument("JSContext*", "cx"),
Argument("JS::Handle<JSObject*>", "obj"),
Argument("void*", "void_self"),
Argument("JSJitGetterCallArgs", "args"),
]
CGSpecializedGetterCommon.__init__(self, descriptor, name, None, attr, args)
class CGTemplateForSpecializedGetter(CGSpecializedGetterCommon):
"""
A class for generating the code for a specialized attribute getter
that can be used as the common getter that templated attribute
getters can forward to.
"""
def __init__(self, descriptor, template):
self.attr = template.attr
self.attrNameString = template.attrNameString
args = [
Argument("JSContext*", "cx"),
Argument("JS::Handle<JSObject*>", "obj"),
Argument("void*", "void_self"),
Argument("JSJitGetterCallArgs", "args"),
]
errorDescription = (
'ErrorDescriptionFor<ErrorFor::getter>{ "%s", attrName }'
% descriptor.interface.identifier.name
)
CGSpecializedGetterCommon.__init__(
self,
descriptor,
template.getter,
template.getter,
self.attr,
args,
errorReportingLabel=errorDescription,
additionalArg=Argument(template.argument.type, template.argument.name),
)
def auto_profiler_label(self):
return (
fill(
"""
const char* attrName = ${attrNameString};
""",
attrNameString=self.attrNameString,
)
+ CGSpecializedGetterCommon.auto_profiler_label(self, "attrName")
)
class CGSpecializedTemplatedGetter(CGAbstractStaticMethod):
"""
A class for generating the code for a specialized templated attribute
getter that forwards to a common template getter.
"""
def __init__(self, descriptor, attr, template, additionalArg):
self.attr = attr
self.template = template
self.additionalArg = additionalArg
name = "get_" + IDLToCIdentifier(attr.identifier.name)
args = [
Argument("JSContext*", "cx"),
Argument("JS::Handle<JSObject*>", "obj"),
Argument("void*", "void_self"),
Argument("JSJitGetterCallArgs", "args"),
]
assert not attr.getExtendedAttribute("StoreInSlot")
CGAbstractStaticMethod.__init__(
self,
descriptor,
name,
"bool",
args,
canRunScript=True,
)
def definition_body(self):
if self.additionalArg is None:
additionalArg = self.attr.identifier.name
else:
additionalArg = self.additionalArg
return fill(
"""
return ${namespace}::${getter}(cx, obj, void_self, args, ${additionalArg});
""",
namespace=toBindingNamespace(
self.template.descriptor.interface.identifier.name
),
getter=self.template.getter,
additionalArg=additionalArg,
)
class CGGetterPromiseWrapper(CGAbstractStaticMethod):
"""
A class for generating a wrapper around another getter that will
@ -11376,9 +11220,7 @@ class CGStaticGetter(CGAbstractStaticBindingMethod):
CGAbstractStaticBindingMethod.__init__(self, descriptor, name)
def generate_code(self):
nativeName = CGSpecializedGetterCommon.makeNativeName(
self.descriptor, self.attr
)
nativeName = CGSpecializedGetter.makeNativeName(self.descriptor, self.attr)
return CGGetterCall(self.attr.type, nativeName, self.descriptor, self.attr)
def auto_profiler_label(self):
@ -11400,44 +11242,29 @@ class CGStaticGetter(CGAbstractStaticBindingMethod):
return None
class CGSpecializedSetterCommon(CGAbstractStaticMethod):
class CGSpecializedSetter(CGAbstractStaticMethod):
"""
A class for generating the code for a specialized attribute setter
that the JIT can call with lower overhead.
"""
def __init__(
self,
descriptor,
name,
nativeName,
attr,
args,
errorReportingLabel=None,
additionalArg=None,
):
self.nativeName = nativeName
self.errorReportingLabel = errorReportingLabel
self.additionalArgs = [] if additionalArg is None else [additionalArg]
def __init__(self, descriptor, attr):
self.attr = attr
name = "set_" + IDLToCIdentifier(attr.identifier.name)
args = [
Argument("JSContext*", "cx"),
Argument("JS::Handle<JSObject*>", "obj"),
Argument("void*", "void_self"),
Argument("JSJitSetterCallArgs", "args"),
]
CGAbstractStaticMethod.__init__(
self,
descriptor,
name,
"bool",
args + self.additionalArgs,
canRunScript=True,
self, descriptor, name, "bool", args, canRunScript=True
)
def definition_body(self):
nativeName = CGSpecializedSetter.makeNativeName(self.descriptor, self.attr)
type = self.attr.type
call = CGSetterCall(
type,
self.nativeName,
self.descriptor,
self.attr,
self.errorReportingLabel,
[a.name for a in self.additionalArgs],
).define()
call = CGSetterCall(type, nativeName, self.descriptor, self.attr).define()
prefix = ""
if self.attr.getExtendedAttribute("CrossOriginWritable"):
if type.isGeckoInterface() and not type.unroll().inner.isExternal():
@ -11471,19 +11298,18 @@ class CGSpecializedSetterCommon(CGAbstractStaticMethod):
call=call,
)
def auto_profiler_label(self, profilerLabel=None):
def auto_profiler_label(self):
interface_name = self.descriptor.interface.identifier.name
if profilerLabel is None:
profilerLabel = '"' + self.attr.identifier.name + '"'
attr_name = self.attr.identifier.name
return fill(
"""
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"${interface_name}", ${attr_name}, DOM, cx,
"${interface_name}", "${attr_name}", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_SETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
""",
interface_name=interface_name,
attr_name=profilerLabel,
attr_name=attr_name,
)
@staticmethod
@ -11494,19 +11320,14 @@ class CGSpecializedSetterCommon(CGAbstractStaticMethod):
attr.type, descriptor, allowTreatNonCallableAsNull=True
):
return None
return '"%s"' % (
return (
GetLabelForErrorReporting(descriptor, attr, isConstructor=False) + " setter"
)
def error_reporting_label(self):
errorReportingLabel = CGSpecializedSetterCommon.error_reporting_label_helper(
return CGSpecializedSetter.error_reporting_label_helper(
self.descriptor, self.attr
)
if errorReportingLabel is None:
return None
if self.errorReportingLabel:
return self.errorReportingLabel
return errorReportingLabel
@staticmethod
def makeNativeName(descriptor, attr):
@ -11514,114 +11335,6 @@ class CGSpecializedSetterCommon(CGAbstractStaticMethod):
return "Set" + MakeNativeName(descriptor.binaryNameFor(name, attr.isStatic()))
class CGSpecializedSetter(CGSpecializedSetterCommon):
"""
A class for generating the code for a specialized attribute setter
that the JIT can call with lower overhead.
"""
def __init__(self, descriptor, attr):
self.attr = attr
name = "set_" + IDLToCIdentifier(attr.identifier.name)
args = [
Argument("JSContext*", "cx"),
Argument("JS::Handle<JSObject*>", "obj"),
Argument("void*", "void_self"),
Argument("JSJitSetterCallArgs", "args"),
]
CGSpecializedSetterCommon.__init__(
self,
descriptor,
name,
CGSpecializedSetterCommon.makeNativeName(descriptor, attr),
attr,
args,
)
class CGTemplateForSpecializedSetter(CGSpecializedSetterCommon):
"""
A class for generating the code for a specialized attribute setter
that can be used as the common setter that templated attribute
setters can forward to.
"""
def __init__(self, descriptor, template):
self.attr = template.attr
self.attrNameString = template.attrNameString
args = [
Argument("JSContext*", "cx"),
Argument("JS::Handle<JSObject*>", "obj"),
Argument("void*", "void_self"),
Argument("JSJitSetterCallArgs", "args"),
]
errorDescription = (
'ErrorDescriptionFor<ErrorFor::setter>{ "%s", attrName }'
% descriptor.interface.identifier.name
)
CGSpecializedSetterCommon.__init__(
self,
descriptor,
template.setter,
template.setter,
self.attr,
args,
errorReportingLabel=errorDescription,
additionalArg=Argument(template.argument.type, template.argument.name),
)
def auto_profiler_label(self):
return (
fill(
"""
const char* attrName = ${attrNameString};
""",
attrNameString=self.attrNameString,
)
+ CGSpecializedSetterCommon.auto_profiler_label(self, "attrName")
)
class CGSpecializedTemplatedSetter(CGAbstractStaticMethod):
"""
A class for generating the code for a specialized templated attribute
setter that forwards to a common template setter.
"""
def __init__(self, descriptor, attr, template, additionalArg):
self.attr = attr
self.template = template
self.additionalArg = additionalArg
name = "set_" + IDLToCIdentifier(attr.identifier.name)
args = [
Argument("JSContext*", "cx"),
Argument("JS::Handle<JSObject*>", "obj"),
Argument("void*", "void_self"),
Argument("JSJitSetterCallArgs", "args"),
]
CGAbstractStaticMethod.__init__(
self, descriptor, name, "bool", args, canRunScript=True
)
def definition_body(self):
additionalArgs = []
if self.additionalArg is None:
additionalArgs.append(self.attr.identifier.name)
else:
additionalArgs.append(self.additionalArg)
return fill(
"""
return ${namespace}::${setter}(cx, obj, void_self, args, ${additionalArgs});
""",
namespace=toBindingNamespace(
self.template.descriptor.interface.identifier.name
),
setter=self.template.setter,
additionalArgs=", ".join(additionalArgs),
)
class CGStaticSetter(CGAbstractStaticBindingMethod):
"""
A class for generating the C++ code for an IDL static attribute setter.
@ -11633,9 +11346,7 @@ class CGStaticSetter(CGAbstractStaticBindingMethod):
CGAbstractStaticBindingMethod.__init__(self, descriptor, name)
def generate_code(self):
nativeName = CGSpecializedSetterCommon.makeNativeName(
self.descriptor, self.attr
)
nativeName = CGSpecializedSetter.makeNativeName(self.descriptor, self.attr)
checkForArg = CGGeneric(
fill(
"""
@ -11664,7 +11375,7 @@ class CGStaticSetter(CGAbstractStaticBindingMethod):
)
def error_reporting_label(self):
return CGSpecializedSetterCommon.error_reporting_label_helper(
return CGSpecializedSetter.error_reporting_label_helper(
self.descriptor, self.attr
)
@ -11705,7 +11416,7 @@ class CGSpecializedForwardingSetter(CGSpecializedSetter):
def error_reporting_label(self):
# We always need to be able to throw.
return '"%s"' % (
return (
GetLabelForErrorReporting(self.descriptor, self.attr, isConstructor=False)
+ " setter"
)
@ -15114,7 +14825,7 @@ class CGDOMJSProxyHandler_defineProperty(ClassMethod):
if error_label:
cxDecl = fill(
"""
BindingCallContext cx(cx_, ${error_label});
BindingCallContext cx(cx_, "${error_label}");
""",
error_label=error_label,
)
@ -15166,7 +14877,7 @@ class CGDOMJSProxyHandler_defineProperty(ClassMethod):
if error_label:
set += fill(
"""
BindingCallContext cx(cx_, ${error_label});
BindingCallContext cx(cx_, "${error_label}");
""",
error_label=error_label,
)
@ -15927,7 +15638,7 @@ class CGDOMJSProxyHandler_setCustom(ClassMethod):
if error_label:
cxDecl = fill(
"""
BindingCallContext cx(cx_, ${error_label});
BindingCallContext cx(cx_, "${error_label}");
""",
error_label=error_label,
)
@ -15960,7 +15671,7 @@ class CGDOMJSProxyHandler_setCustom(ClassMethod):
if error_label:
cxDecl = fill(
"""
BindingCallContext cx(cx_, ${error_label});
BindingCallContext cx(cx_, "${error_label}");
""",
error_label=error_label,
)
@ -16594,7 +16305,7 @@ def memberProperties(m, descriptor):
class CGDescriptor(CGThing):
def __init__(self, descriptor, attributeTemplates):
def __init__(self, descriptor):
CGThing.__init__(self)
assert (
@ -16654,23 +16365,10 @@ class CGDescriptor(CGThing):
defaultToJSONMethod = None
needCrossOriginPropertyArrays = False
unscopableNames = list()
for n in descriptor.interface.legacyFactoryFunctions:
cgThings.append(
CGClassConstructor(descriptor, n, LegacyFactoryFunctionName(n))
)
if descriptor.attributeTemplates is not None:
for template in descriptor.attributeTemplates:
if template.getter is not None:
cgThings.append(
CGTemplateForSpecializedGetter(descriptor, template)
)
if template.setter is not None:
cgThings.append(
CGTemplateForSpecializedSetter(descriptor, template)
)
for m in descriptor.interface.members:
if m.isMethod() and m.identifier.name == "QueryInterface":
continue
@ -16719,28 +16417,7 @@ class CGDescriptor(CGThing):
assert descriptor.interface.hasInterfaceObject()
cgThings.append(CGStaticGetter(descriptor, m))
elif descriptor.interface.hasInterfacePrototypeObject():
template = m.getExtendedAttribute("BindingTemplate")
if template is not None:
templateName = template[0][0]
additionalArg = template[0][1]
if not (m.type.isPrimitive() or m.type.isString()):
raise TypeError(
"We only support primitives or strings on templated attributes. "
"Attribute '%s' on interface '%s' has type '%s' but tries to "
"use template '%s'"
% (
m.identifier.name,
descriptor.interface.identifier.name,
m.type,
templateName,
)
)
template = attributeTemplates.get(templateName)
specializedGetter = CGSpecializedTemplatedGetter(
descriptor, m, template, additionalArg
)
else:
specializedGetter = CGSpecializedGetter(descriptor, m)
specializedGetter = CGSpecializedGetter(descriptor, m)
cgThings.append(specializedGetter)
if m.type.isPromise():
cgThings.append(
@ -16753,21 +16430,7 @@ class CGDescriptor(CGThing):
assert descriptor.interface.hasInterfaceObject()
cgThings.append(CGStaticSetter(descriptor, m))
elif descriptor.interface.hasInterfacePrototypeObject():
template = m.getExtendedAttribute("BindingTemplate")
if template is not None:
if isinstance(template[0], list):
templateName = template[0][0]
additionalArg = template[0][1]
else:
templateName = template[0]
additionalArg = None
template = attributeTemplates.get(templateName)
specializedSetter = CGSpecializedTemplatedSetter(
descriptor, m, template, additionalArg
)
else:
specializedSetter = CGSpecializedSetter(descriptor, m)
cgThings.append(specializedSetter)
cgThings.append(CGSpecializedSetter(descriptor, m))
if props.isCrossOriginSetter:
needCrossOriginPropertyArrays = True
elif m.getExtendedAttribute("PutForwards"):
@ -19045,9 +18708,7 @@ class CGBindingRoot(CGThing):
cgthings.append(CGNamespace("binding_detail", CGFastCallback(t)))
# Do codegen for all the descriptors
cgthings.extend(
[CGDescriptor(x, config.attributeTemplates) for x in descriptors]
)
cgthings.extend([CGDescriptor(x) for x in descriptors])
# Do codegen for all the callback interfaces.
cgthings.extend([CGCallbackInterface(x) for x in callbackDescriptors])
@ -19663,7 +19324,7 @@ class CGExampleGetter(CGNativeMember):
self,
descriptor,
attr,
CGSpecializedGetterCommon.makeNativeName(descriptor, attr),
CGSpecializedGetter.makeNativeName(descriptor, attr),
(attr.type, []),
descriptor.getExtendedAttributes(attr, getter=True),
)
@ -19688,7 +19349,7 @@ class CGExampleSetter(CGNativeMember):
self,
descriptor,
attr,
CGSpecializedSetterCommon.makeNativeName(descriptor, attr),
CGSpecializedSetter.makeNativeName(descriptor, attr),
(
BuiltinTypes[IDLBuiltinType.Types.undefined],
[FakeArgument(attr.type)],
@ -19811,7 +19472,7 @@ class CGBindingImplClass(CGClass):
m
for m in iface.members
if m.isAttr()
and CGSpecializedGetterCommon.makeNativeName(descriptor, m) == "Length"
and CGSpecializedGetter.makeNativeName(descriptor, m) == "Length"
)
if not haveLengthAttr:
self.methodDecls.append(
@ -20362,7 +20023,7 @@ class CGJSImplGetter(CGJSImplMember):
self,
descriptor,
attr,
CGSpecializedGetterCommon.makeNativeName(descriptor, attr),
CGSpecializedGetter.makeNativeName(descriptor, attr),
(attr.type, []),
descriptor.getExtendedAttributes(attr, getter=True),
passJSBitsAsNeeded=False,
@ -20387,7 +20048,7 @@ class CGJSImplSetter(CGJSImplMember):
self,
descriptor,
attr,
CGSpecializedSetterCommon.makeNativeName(descriptor, attr),
CGSpecializedSetter.makeNativeName(descriptor, attr),
(
BuiltinTypes[IDLBuiltinType.Types.undefined],
[FakeArgument(attr.type)],
@ -23931,7 +23592,7 @@ class CGEventGetter(CGNativeMember):
self,
descriptor,
attr,
CGSpecializedGetterCommon.makeNativeName(descriptor, attr),
CGSpecializedGetter.makeNativeName(descriptor, attr),
(attr.type, []),
ea,
resultNotAddRefed=not attr.type.isSequence(),
@ -24271,7 +23932,7 @@ class CGEventClass(CGBindingImplClass):
# either.
extraMethods.append(
ClassMethod(
CGSpecializedGetterCommon.makeNativeName(descriptor, m),
CGSpecializedGetter.makeNativeName(descriptor, m),
"void",
[Argument("JS::MutableHandle<JS::Value>", "aRetVal")],
const=True,

Просмотреть файл

@ -52,31 +52,6 @@ class Configuration(DescriptorProvider):
exec(io.open(filename, encoding="utf-8").read(), glbl)
config = glbl["DOMInterfaces"]
class IDLAttrGetterOrSetterTemplate:
def __init__(self, template, getter, setter, argument, attrName):
class TemplateAdditionalArg:
def __init__(self, type, name, value=None):
self.type = type
self.name = name
self.value = value
self.descriptor = None
self.usedInOtherInterfaces = False
self.getter = getter
self.setter = setter
self.argument = TemplateAdditionalArg(*argument)
self.attrNameString = attrName
self.attr = None
self.attributeTemplates = dict()
attributeTemplatesByInterface = dict()
for interface, templates in glbl["TemplatedAttributes"].items():
for template in templates:
name = template.get("template")
t = IDLAttrGetterOrSetterTemplate(**template)
self.attributeTemplates[name] = t
attributeTemplatesByInterface.setdefault(interface, list()).append(t)
webRoots = tuple(map(os.path.normpath, webRoots))
def isInWebIDLRoot(path):
@ -162,12 +137,7 @@ class Configuration(DescriptorProvider):
entry = config.get(iface.identifier.name, {})
assert not isinstance(entry, list)
desc = Descriptor(
self,
iface,
entry,
attributeTemplatesByInterface.get(iface.identifier.name),
)
desc = Descriptor(self, iface, entry)
self.descriptors.append(desc)
# Setting up descriptorsByName while iterating through interfaces
# means we can get the nativeType of iterable interfaces without
@ -304,183 +274,6 @@ class Configuration(DescriptorProvider):
offsets = accumulate(map(lambda n: len(n) + 1, names), initial=0)
self.namesStringOffsets = list(zip(names, offsets))
allTemplatedAttributes = (
(m, d)
for d in self.descriptors
if not d.interface.isExternal()
for m in d.interface.members
if m.isAttr() and m.getExtendedAttribute("BindingTemplate") is not None
)
# attributesPerTemplate will have the template names as keys, and a
# list of tuples as values. Every tuple contains an IDLAttribute and a
# descriptor.
attributesPerTemplate = dict()
for m, d in allTemplatedAttributes:
t = m.getExtendedAttribute("BindingTemplate")
if isinstance(t[0], list):
t = t[0]
l = attributesPerTemplate.setdefault(t[0], list())
# We want the readonly attributes last, because we use the first
# attribute in the list as the canonical attribute for the
# template, and if there are any writable attributes the
# template should have support for that.
if not m.readonly:
l.insert(0, (m, d))
else:
l.append((m, d))
for name, attributes in attributesPerTemplate.items():
# We use the first attribute to generate a canonical implementation
# of getter and setter.
firstAttribute, firstDescriptor = attributes[0]
template = self.attributeTemplates.get(name)
if template is None:
raise TypeError(
"Unknown BindingTemplate with name %s for %s on %s"
% (
name,
firstAttribute.identifier.name,
firstDescriptor.interface.identifier.name,
)
)
# This mimics a real IDL attribute for templated bindings.
class TemplateIDLAttribute:
def __init__(self, attr):
assert attr.isAttr()
assert not attr.isMaplikeOrSetlikeAttr()
assert not attr.slotIndices
self.identifier = attr.identifier
self.type = attr.type
self.extendedAttributes = attr.getExtendedAttributes()
self.slotIndices = None
def getExtendedAttribute(self, name):
return self.extendedAttributes.get(name)
def isAttr(self):
return True
def isMaplikeOrSetlikeAttr(self):
return False
def isMethod(self):
return False
def isStatic(self):
return False
template.attr = TemplateIDLAttribute(firstAttribute)
def filterExtendedAttributes(extendedAttributes):
# These are the extended attributes that we allow to have
# different values among all atributes that use the same
# template.
ignoredAttributes = {
"BindingTemplate",
"BindingAlias",
"Pure",
"Pref",
"Func",
"Throws",
"GetterThrows",
"SetterThrows",
}
return dict(
filter(
lambda i: i[0] not in ignoredAttributes,
extendedAttributes.items(),
)
)
firstExtAttrs = filterExtendedAttributes(
firstAttribute.getExtendedAttributes()
)
for a, d in attributes:
# We want to make sure all getters or setters grouped by a
# template have the same WebIDL signatures, so make sure
# their types are the same.
if template.attr.type != a.type:
raise TypeError(
"%s on %s and %s on %s have different type, but they're using the same template %s."
% (
firstAttribute.identifier.name,
firstDescriptor.interface.identifier.name,
a.identifier.name,
d.interface.identifier.name,
name,
)
)
extAttrs = filterExtendedAttributes(a.getExtendedAttributes())
if template.attr.extendedAttributes != extAttrs:
for k in extAttrs.keys() - firstExtAttrs.keys():
raise TypeError(
"%s on %s has extended attribute %s and %s on %s does not, but they're using the same template %s."
% (
a.identifier.name,
d.interface.identifier.name,
k,
firstAttribute.identifier.name,
firstDescriptor.interface.identifier.name,
name,
)
)
for k in firstExtAttrs.keys() - extAttrs.keys():
raise TypeError(
"%s on %s has extended attribute %s and %s on %s does not, but they're using the same template %s."
% (
firstAttribute.identifier.name,
firstDescriptor.interface.identifier.name,
k,
a.identifier.name,
d.interface.identifier.name,
name,
)
)
for (k, v) in firstExtAttrs.items():
if extAttrs[k] != v:
raise TypeError(
"%s on %s and %s on %s have different values for extended attribute %s, but they're using the same template %s."
% (
firstAttribute.identifier.name,
firstDescriptor.interface.identifier.name,
a.identifier.name,
d.interface.identifier.name,
k,
name,
)
)
def sameThrows(getter=False, setter=False):
extAttrs1 = firstDescriptor.getExtendedAttributes(
firstAttribute, getter=getter, setter=setter
)
extAttrs2 = d.getExtendedAttributes(a, getter=getter, setter=setter)
return ("needsErrorResult" in extAttrs1) == (
"needsErrorResult" in extAttrs2
)
if not sameThrows(getter=True) or (
not a.readonly and not sameThrows(setter=True)
):
raise TypeError(
"%s on %s and %s on %s have different annotations about throwing, but they're using the same template %s."
% (
firstAttribute.identifier.name,
firstDescriptor.interface.identifier.name,
a.identifier.name,
d.interface.identifier.name,
name,
)
)
for name, template in self.attributeTemplates.items():
if template.attr is None:
raise TypeError("Template %s is unused, please remove it." % name)
def getInterface(self, ifname):
return self.interfaces[ifname]
@ -634,14 +427,10 @@ class Descriptor(DescriptorProvider):
Represents a single descriptor for an interface. See Bindings.conf.
"""
def __init__(self, config, interface, desc, attributeTemplates):
def __init__(self, config, interface, desc):
DescriptorProvider.__init__(self)
self.config = config
self.interface = interface
self.attributeTemplates = attributeTemplates
if self.attributeTemplates is not None:
for t in self.attributeTemplates:
t.descriptor = self
self.wantsXrays = not interface.isExternal() and interface.isExposedInWindow()

Просмотреть файл

@ -464,11 +464,6 @@ class TErrorResult {
// hopefully it's all temporary until we sort out the EME bits.
friend class dom::Promise;
// Implementation of MaybeSetPendingException for the case when we're a
// failure result. See documentation of MaybeSetPendingException for the
// "context" argument.
void SetPendingException(JSContext* cx, const char* context);
private:
#ifdef DEBUG
enum UnionState {
@ -572,6 +567,11 @@ class TErrorResult {
// touching the union anymore.
void ClearUnionData();
// Implementation of MaybeSetPendingException for the case when we're a
// failure result. See documentation of MaybeSetPendingException for the
// "context" argument.
void SetPendingException(JSContext* cx, const char* context);
// Methods for setting various specific kinds of pending exceptions. See
// documentation of MaybeSetPendingException for the "context" argument.
void SetPendingExceptionWithMessage(JSContext* cx, const char* context);
@ -828,47 +828,13 @@ class CopyableErrorResult
inline ErrorResult::ErrorResult(CopyableErrorResult&& aRHS)
: ErrorResult(reinterpret_cast<ErrorResult&&>(aRHS)) {}
namespace dom::binding_detail {
enum class ErrorFor {
getter,
setter,
};
template <ErrorFor ErrorType>
struct ErrorDescriptionFor {
const char* mInterface;
const char* mMember;
};
namespace dom {
namespace binding_detail {
class FastErrorResult : public mozilla::binding_danger::TErrorResult<
mozilla::binding_danger::JustAssertCleanupPolicy> {
public:
using TErrorResult::MaybeSetPendingException;
template <ErrorFor ErrorType>
[[nodiscard]] bool MaybeSetPendingException(
JSContext* aCx, const ErrorDescriptionFor<ErrorType>& aDescription) {
WouldReportJSException();
if (!Failed()) {
return false;
}
nsAutoCString description(aDescription.mInterface);
description.Append('.');
description.Append(aDescription.mMember);
if constexpr (ErrorType == ErrorFor::getter) {
description.AppendLiteral(" getter");
} else {
static_assert(ErrorType == ErrorFor::setter);
description.AppendLiteral(" setter");
}
SetPendingException(aCx, description.get());
return true;
}
};
} // namespace dom::binding_detail
} // namespace binding_detail
} // namespace dom
// We want an OOMReporter class that has the following properties:
//

Просмотреть файл

@ -30,18 +30,9 @@ def generate(output, idlFilename, dataFile):
if "Style" not in p.rules:
continue
if p.type() == "alias":
if p.pref == propsData[p.prop_id].pref:
# We already added this as a BindingAlias for the original prop.
continue
propId = p.prop_id
else:
propId = p.id
# Unfortunately, even some of the getters here are fallible
# (e.g. on nsComputedDOMStyle).
extendedAttrs = [
"BindingTemplate=(CSS2Property, eCSSProperty_%s)" % propId,
"CEReactions",
"Throws",
"SetterNeedsSubjectPrincipal=NonSystem",
@ -55,47 +46,36 @@ def generate(output, idlFilename, dataFile):
else:
extendedAttrs.append('Pref="%s"' % p.pref)
def add_extra_accessors(p):
prop = p.method
prop = p.method
# webkit properties get a camelcase "webkitFoo" accessor
# as well as a capitalized "WebkitFoo" alias (added here).
if prop.startswith("Webkit"):
extendedAttrs.append('BindingAlias="%s"' % prop)
# webkit properties get a camelcase "webkitFoo" accessor
# as well as a capitalized "WebkitFoo" alias (added here).
if prop.startswith("Webkit"):
extendedAttrs.append('BindingAlias="%s"' % prop)
# Generate a name with camelCase spelling of property-name (or capitalized,
# for Moz-prefixed properties):
if not prop.startswith("Moz"):
prop = prop[0].lower() + prop[1:]
# Generate a name with camelCase spelling of property-name (or capitalized,
# for Moz-prefixed properties):
if not prop.startswith("Moz"):
prop = prop[0].lower() + prop[1:]
# Per spec, what's actually supposed to happen here is that we're supposed
# to have properties for:
#
# 1) Each supported CSS property name, camelCased.
# 2) Each supported name that contains or starts with dashes,
# without any changes to the name.
# 3) cssFloat
#
# Note that "float" will cause a property called "float" to exist due to (1)
# in that list.
#
# In practice, cssFloat is the only case in which "name" doesn't contain
# "-" but also doesn't match "prop". So the generateLine() call will
# cover (3) and all of (1) except "float". If we now add an alias
# for all the cases where "name" doesn't match "prop", that will cover
# "float" and (2).
if prop != p.name:
extendedAttrs.append('BindingAlias="%s"' % p.name)
return prop
prop = add_extra_accessors(p)
if p.type() != "alias":
for a in p.aliases:
if p.pref == propsData[a].pref:
newProp = add_extra_accessors(propsData[a])
extendedAttrs.append('BindingAlias="%s"' % newProp)
# Per spec, what's actually supposed to happen here is that we're supposed
# to have properties for:
#
# 1) Each supported CSS property name, camelCased.
# 2) Each supported name that contains or starts with dashes,
# without any changes to the name.
# 3) cssFloat
#
# Note that "float" will cause a property called "float" to exist due to (1)
# in that list.
#
# In practice, cssFloat is the only case in which "name" doesn't contain
# "-" but also doesn't match "prop". So the generateLine() call will
# cover (3) and all of (1) except "float". If we now add an alias
# for all the cases where "name" doesn't match "prop", that will cover
# "float" and (2).
if prop != p.name:
extendedAttrs.append('BindingAlias="%s"' % p.name)
props += generateLine(prop, extendedAttrs)

Просмотреть файл

@ -5725,7 +5725,6 @@ class IDLAttribute(IDLInterfaceMember):
or identifier == "ReturnValueNeedsContainsHack"
or identifier == "BinaryName"
or identifier == "NonEnumerable"
or identifier == "BindingTemplate"
):
# Known attributes that we don't need to do anything with here
pass
@ -5736,9 +5735,6 @@ class IDLAttribute(IDLInterfaceMember):
)
IDLInterfaceMember.handleExtendedAttribute(self, attr)
def getExtendedAttributes(self):
return self._extendedAttrDict
def resolve(self, parentScope):
assert isinstance(parentScope, IDLScope)
self.type.resolveType(parentScope)

Просмотреть файл

@ -1390,25 +1390,6 @@ implementing `MyInterface`.
Multiple `[BindingAlias]` extended attributes can be used on a single
attribute.
### `[BindingTemplate=(name, value)]`
This extended attribute can be specified on an attribute, and causes the getter
and setter for this attribute to forward to a common generated implementation,
shared with all other attributes that have a `[BindingTemplate]` with the same
value for the `name` argument. The `TemplatedAttributes` dictionary in
Bindings.conf needs to contain a definition for the template with the name
`name`. The `value` will be passed as an argument when calling the common
generated implementation.
This is aimed at very specialized use cases where an interface has a
large number of attributes that all have the same type, and for which we have a
native implementation that's common to all these attributes, and typically uses
some id based on the attribute's name in the implementation. All the attributes
that use the same template need to mostly have the same extended attributes,
except form a small number that are allowed to differ (`[BindingTemplate]`,
`[BindingAlias]`, `[Pure]`, [`Pref`] and [`Func`], and the annotations for
whether the getter and setter throws exceptions).
### `[ChromeOnly]`
This extended attribute can be specified on any method, attribute, or

Просмотреть файл

@ -65,10 +65,6 @@ class nsDOMCSSDeclaration : public nsICSSDeclaration {
*/
virtual nsresult GetPropertyValue(const nsCSSPropertyID aPropID,
nsACString& aValue);
void GetPropertyValue(const nsCSSPropertyID aPropID, nsACString& aValue,
mozilla::ErrorResult& aRv) {
aRv = GetPropertyValue(aPropID, aValue);
}
/**
* Method analogous to CSSStyleDeclaration::SetProperty. This
@ -97,6 +93,32 @@ class nsDOMCSSDeclaration : public nsICSSDeclaration {
uint32_t Length() override;
// WebIDL interface for CSS2Properties
#define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_
#define CSS_PROP(id_, method_) \
void Get##method_(nsACString& aValue, mozilla::ErrorResult& rv) { \
rv = GetPropertyValue(eCSSProperty_##id_, aValue); \
} \
\
void Set##method_(const nsACString& aValue, nsIPrincipal* aSubjectPrincipal, \
mozilla::ErrorResult& aRv) { \
SetPropertyValue(eCSSProperty_##id_, aValue, aSubjectPrincipal, aRv); \
}
#define CSS_PROP_LIST_EXCLUDE_INTERNAL
#define CSS_PROP_LIST_EXCLUDE_NOT_IN_STYLE
#define CSS_PROP_LONGHAND(name_, id_, method_, ...) CSS_PROP(id_, method_)
#define CSS_PROP_SHORTHAND(name_, id_, method_, ...) CSS_PROP(id_, method_)
#define CSS_PROP_ALIAS(name_, aliasid_, id_, method_, ...) \
CSS_PROP(id_, method_)
#include "mozilla/ServoCSSPropList.h"
#undef CSS_PROP_ALIAS
#undef CSS_PROP_SHORTHAND
#undef CSS_PROP_LONGHAND
#undef CSS_PROP_LIST_EXCLUDE_INTERNAL
#undef CSS_PROP_LIST_EXCLUDE_NOT_IN_STYLE
#undef CSS_PROP
#undef CSS_PROP_PUBLIC_OR_PRIVATE
virtual void IndexedGetter(uint32_t aIndex, bool& aFound,
nsACString& aPropName) override;