Fix Codegen

This commit is contained in:
sagudev 2023-02-20 06:16:13 +01:00
parent 42d8269ac9
commit ee7c393773
3 changed files with 40 additions and 40 deletions

View file

@ -31,7 +31,7 @@ from WebIDL import (
from Configuration import ( from Configuration import (
MakeNativeName, MakeNativeName,
MemberIsUnforgeable, MemberIsLegacyUnforgeable,
getModuleFromObject, getModuleFromObject,
getTypesFromCallback, getTypesFromCallback,
getTypesFromDescriptor, getTypesFromDescriptor,
@ -587,7 +587,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
isEnforceRange = type.hasEnforceRange() isEnforceRange = type.hasEnforceRange()
isClamp = type.hasClamp() isClamp = type.hasClamp()
if type.treatNullAsEmpty: if type.legacyNullToEmptyString:
treatNullAs = "EmptyString" treatNullAs = "EmptyString"
else: else:
treatNullAs = "Default" treatNullAs = "Default"
@ -1702,7 +1702,7 @@ class MethodDefiner(PropertyDefiner):
m.isMethod() and m.isStatic() == static m.isMethod() and m.isStatic() == static
and (bool(m.getExtendedAttribute("CrossOriginCallable")) or not crossorigin) and (bool(m.getExtendedAttribute("CrossOriginCallable")) or not crossorigin)
and not m.isIdentifierLess() and not m.isIdentifierLess()
and (MemberIsUnforgeable(m, descriptor) == unforgeable or crossorigin)] and (MemberIsLegacyUnforgeable(m, descriptor) == unforgeable or crossorigin)]
else: else:
methods = [] methods = []
self.regular = [{"name": m.identifier.name, self.regular = [{"name": m.identifier.name,
@ -1787,8 +1787,8 @@ class MethodDefiner(PropertyDefiner):
descriptor) descriptor)
}) })
isUnforgeableInterface = bool(descriptor.interface.getExtendedAttribute("Unforgeable")) isLegacyUnforgeableInterface = bool(descriptor.interface.getExtendedAttribute("LegacyUnforgeable"))
if not static and unforgeable == isUnforgeableInterface and not crossorigin: if not static and unforgeable == isLegacyUnforgeableInterface and not crossorigin:
stringifier = descriptor.operations['Stringifier'] stringifier = descriptor.operations['Stringifier']
if stringifier: if stringifier:
self.regular.append({ self.regular.append({
@ -1890,7 +1890,7 @@ class AttrDefiner(PropertyDefiner):
} }
for m in descriptor.interface.members if for m in descriptor.interface.members if
m.isAttr() and m.isStatic() == static m.isAttr() and m.isStatic() == static
and (MemberIsUnforgeable(m, descriptor) == unforgeable or crossorigin) and (MemberIsLegacyUnforgeable(m, descriptor) == unforgeable or crossorigin)
and (not crossorigin and (not crossorigin
or m.getExtendedAttribute("CrossOriginReadable") or m.getExtendedAttribute("CrossOriginReadable")
or m.getExtendedAttribute("CrossOriginWritable")) or m.getExtendedAttribute("CrossOriginWritable"))
@ -1923,7 +1923,7 @@ class AttrDefiner(PropertyDefiner):
accessor = 'get_' + self.descriptor.internalNameFor(attr.identifier.name) accessor = 'get_' + self.descriptor.internalNameFor(attr.identifier.name)
jitinfo = "0 as *const JSJitInfo" jitinfo = "0 as *const JSJitInfo"
else: else:
if attr.hasLenientThis(): if attr.hasLegacyLenientThis():
accessor = "generic_lenient_getter" accessor = "generic_lenient_getter"
else: else:
accessor = "generic_getter" accessor = "generic_getter"
@ -1946,7 +1946,7 @@ class AttrDefiner(PropertyDefiner):
accessor = 'set_' + self.descriptor.internalNameFor(attr.identifier.name) accessor = 'set_' + self.descriptor.internalNameFor(attr.identifier.name)
jitinfo = "0 as *const JSJitInfo" jitinfo = "0 as *const JSJitInfo"
else: else:
if attr.hasLenientThis(): if attr.hasLegacyLenientThis():
accessor = "generic_lenient_setter" accessor = "generic_lenient_setter"
else: else:
accessor = "generic_setter" accessor = "generic_setter"
@ -2187,7 +2187,7 @@ class CGImports(CGWrapper):
if d.interface.isIteratorInterface(): if d.interface.isIteratorInterface():
types += [d.interface.iterableInterface] types += [d.interface.iterableInterface]
members = d.interface.members + d.interface.namedConstructors members = d.interface.members + d.interface.legacyFactoryFunctions
constructor = d.interface.ctor() constructor = d.interface.ctor()
if constructor: if constructor:
members += [constructor] members += [constructor]
@ -2436,7 +2436,7 @@ class CGPrototypeJSClass(CGThing):
def define(self): def define(self):
name = str_to_const_array(self.descriptor.interface.identifier.name + "Prototype") name = str_to_const_array(self.descriptor.interface.identifier.name + "Prototype")
slotCount = 0 slotCount = 0
if self.descriptor.hasUnforgeableMembers: if self.descriptor.hasLegacyUnforgeableMembers:
slotCount += 1 slotCount += 1
return """\ return """\
static PrototypeClass: JSClass = JSClass { static PrototypeClass: JSClass = JSClass {
@ -2814,7 +2814,7 @@ class CGConstructorEnabled(CGAbstractMethod):
return CGList((CGGeneric(cond) for cond in conditions), " &&\n") return CGList((CGGeneric(cond) for cond in conditions), " &&\n")
def InitUnforgeablePropertiesOnHolder(descriptor, properties): def InitLegacyUnforgeablePropertiesOnHolder(descriptor, properties):
""" """
Define the unforgeable properties on the unforgeable holder for Define the unforgeable properties on the unforgeable holder for
the interface represented by descriptor. the interface represented by descriptor.
@ -2823,12 +2823,12 @@ def InitUnforgeablePropertiesOnHolder(descriptor, properties):
""" """
unforgeables = [] unforgeables = []
defineUnforgeableAttrs = "define_guarded_properties(cx, unforgeable_holder.handle(), %s, global);" defineLegacyUnforgeableAttrs = "define_guarded_properties(cx, unforgeable_holder.handle(), %s, global);"
defineUnforgeableMethods = "define_guarded_methods(cx, unforgeable_holder.handle(), %s, global);" defineLegacyUnforgeableMethods = "define_guarded_methods(cx, unforgeable_holder.handle(), %s, global);"
unforgeableMembers = [ unforgeableMembers = [
(defineUnforgeableAttrs, properties.unforgeable_attrs), (defineLegacyUnforgeableAttrs, properties.unforgeable_attrs),
(defineUnforgeableMethods, properties.unforgeable_methods), (defineLegacyUnforgeableMethods, properties.unforgeable_methods),
] ]
for template, array in unforgeableMembers: for template, array in unforgeableMembers:
if array.length() > 0: if array.length() > 0:
@ -2836,12 +2836,12 @@ def InitUnforgeablePropertiesOnHolder(descriptor, properties):
return CGList(unforgeables, "\n") return CGList(unforgeables, "\n")
def CopyUnforgeablePropertiesToInstance(descriptor): def CopyLegacyUnforgeablePropertiesToInstance(descriptor):
""" """
Copy the unforgeable properties from the unforgeable holder for Copy the unforgeable properties from the unforgeable holder for
this interface to the instance object we have. this interface to the instance object we have.
""" """
if not descriptor.hasUnforgeableMembers: if not descriptor.hasLegacyUnforgeableMembers:
return "" return ""
copyCode = "" copyCode = ""
@ -2890,7 +2890,7 @@ class CGWrapMethod(CGAbstractMethod):
pub=True, unsafe=True) pub=True, unsafe=True)
def definition_body(self): def definition_body(self):
unforgeable = CopyUnforgeablePropertiesToInstance(self.descriptor) unforgeable = CopyLegacyUnforgeablePropertiesToInstance(self.descriptor)
if self.descriptor.proxy: if self.descriptor.proxy:
if self.descriptor.isMaybeCrossOriginObject(): if self.descriptor.isMaybeCrossOriginObject():
proto = "ptr::null_mut()" proto = "ptr::null_mut()"
@ -2958,10 +2958,10 @@ assert!(!proto.is_null());
%(createObject)s %(createObject)s
let root = raw.reflect_with(obj.get()); let root = raw.reflect_with(obj.get());
%(copyUnforgeable)s %(copyLegacyUnforgeable)s
DomRoot::from_ref(&*root)\ DomRoot::from_ref(&*root)\
""" % {'copyUnforgeable': unforgeable, 'createObject': create}) """ % {'copyLegacyUnforgeable': unforgeable, 'createObject': create})
class CGWrapGlobalMethod(CGAbstractMethod): class CGWrapGlobalMethod(CGAbstractMethod):
@ -2981,7 +2981,7 @@ class CGWrapGlobalMethod(CGAbstractMethod):
def definition_body(self): def definition_body(self):
values = { values = {
"concreteType": self.descriptor.concreteType, "concreteType": self.descriptor.concreteType,
"unforgeable": CopyUnforgeablePropertiesToInstance(self.descriptor) "unforgeable": CopyLegacyUnforgeablePropertiesToInstance(self.descriptor)
} }
pairs = [ pairs = [
@ -3121,10 +3121,10 @@ class PropertyArrays():
self.static_attrs = AttrDefiner(descriptor, "StaticAttributes", self.static_attrs = AttrDefiner(descriptor, "StaticAttributes",
static=True, unforgeable=False) static=True, unforgeable=False)
self.methods = MethodDefiner(descriptor, "Methods", static=False, unforgeable=False) self.methods = MethodDefiner(descriptor, "Methods", static=False, unforgeable=False)
self.unforgeable_methods = MethodDefiner(descriptor, "UnforgeableMethods", self.unforgeable_methods = MethodDefiner(descriptor, "LegacyUnforgeableMethods",
static=False, unforgeable=True) static=False, unforgeable=True)
self.attrs = AttrDefiner(descriptor, "Attributes", static=False, unforgeable=False) self.attrs = AttrDefiner(descriptor, "Attributes", static=False, unforgeable=False)
self.unforgeable_attrs = AttrDefiner(descriptor, "UnforgeableAttributes", self.unforgeable_attrs = AttrDefiner(descriptor, "LegacyUnforgeableAttributes",
static=False, unforgeable=True) static=False, unforgeable=True)
self.consts = ConstDefiner(descriptor, "Constants") self.consts = ConstDefiner(descriptor, "Constants")
pass pass
@ -3426,7 +3426,7 @@ assert!((*cache)[PrototypeList::Constructor::%(id)s as usize].is_null());
] + [defineAliasesFor(m) for m in sorted(aliasedMembers)]) ] + [defineAliasesFor(m) for m in sorted(aliasedMembers)])
code.append(defineAliases) code.append(defineAliases)
constructors = self.descriptor.interface.namedConstructors constructors = self.descriptor.interface.legacyFactoryFunctions
if constructors: if constructors:
decl = "let named_constructors: [(ConstructorClassHook, &'static [u8], u32); %d]" % len(constructors) decl = "let named_constructors: [(ConstructorClassHook, &'static [u8], u32); %d]" % len(constructors)
specs = [] specs = []
@ -3439,7 +3439,7 @@ assert!((*cache)[PrototypeList::Constructor::%(id)s as usize].is_null());
code.append(CGWrapper(values, pre="%s = [\n" % decl, post="\n];")) code.append(CGWrapper(values, pre="%s = [\n" % decl, post="\n];"))
code.append(CGGeneric("create_named_constructors(cx, global, &named_constructors, prototype.handle());")) code.append(CGGeneric("create_named_constructors(cx, global, &named_constructors, prototype.handle());"))
if self.descriptor.hasUnforgeableMembers: if self.descriptor.hasLegacyUnforgeableMembers:
# We want to use the same JSClass and prototype as the object we'll # We want to use the same JSClass and prototype as the object we'll
# end up defining the unforgeable properties on in the end, so that # end up defining the unforgeable properties on in the end, so that
# we can use JS_InitializePropertiesFromCompatibleNativeObject to do # we can use JS_InitializePropertiesFromCompatibleNativeObject to do
@ -3463,7 +3463,7 @@ unforgeable_holder.handle_mut().set(
JS_NewObjectWithoutMetadata(*cx, %(holderClass)s, %(holderProto)s)); JS_NewObjectWithoutMetadata(*cx, %(holderClass)s, %(holderProto)s));
assert!(!unforgeable_holder.is_null()); assert!(!unforgeable_holder.is_null());
""" % {'holderClass': holderClass, 'holderProto': holderProto})) """ % {'holderClass': holderClass, 'holderProto': holderProto}))
code.append(InitUnforgeablePropertiesOnHolder(self.descriptor, self.properties)) code.append(InitLegacyUnforgeablePropertiesOnHolder(self.descriptor, self.properties))
code.append(CGGeneric("""\ code.append(CGGeneric("""\
let val = ObjectValue(unforgeable_holder.get()); let val = ObjectValue(unforgeable_holder.get());
JS_SetReservedSlot(prototype.get(), DOM_PROTO_UNFORGEABLE_HOLDER_SLOT, &val)""")) JS_SetReservedSlot(prototype.get(), DOM_PROTO_UNFORGEABLE_HOLDER_SLOT, &val)"""))
@ -5631,7 +5631,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
namedSetter = self.descriptor.operations['NamedSetter'] namedSetter = self.descriptor.operations['NamedSetter']
if namedSetter: if namedSetter:
if self.descriptor.hasUnforgeableMembers: if self.descriptor.hasLegacyUnforgeableMembers:
raise TypeError("Can't handle a named setter on an interface that has " raise TypeError("Can't handle a named setter on an interface that has "
"unforgeables. Figure out how that should work!") "unforgeables. Figure out how that should work!")
set += ("if id.is_string() || id.is_int() {\n" set += ("if id.is_string() || id.is_int() {\n"
@ -5675,7 +5675,7 @@ class CGDOMJSProxyHandler_delete(CGAbstractExternMethod):
""") """)
if self.descriptor.operations['NamedDeleter']: if self.descriptor.operations['NamedDeleter']:
if self.descriptor.hasUnforgeableMembers: if self.descriptor.hasLegacyUnforgeableMembers:
raise TypeError("Can't handle a deleter on an interface that has " raise TypeError("Can't handle a deleter on an interface that has "
"unforgeables. Figure out how that should work!") "unforgeables. Figure out how that should work!")
set += CGProxyNamedDeleter(self.descriptor).define() set += CGProxyNamedDeleter(self.descriptor).define()
@ -6731,7 +6731,7 @@ class CGDescriptor(CGThing):
if descriptor.interface.hasInterfaceObject(): if descriptor.interface.hasInterfaceObject():
if descriptor.interface.ctor(): if descriptor.interface.ctor():
cgThings.append(CGClassConstructHook(descriptor)) cgThings.append(CGClassConstructHook(descriptor))
for ctor in descriptor.interface.namedConstructors: for ctor in descriptor.interface.legacyFactoryFunctions:
cgThings.append(CGClassConstructHook(descriptor, ctor)) cgThings.append(CGClassConstructHook(descriptor, ctor))
if not descriptor.interface.isCallback(): if not descriptor.interface.isCallback():
cgThings.append(CGInterfaceObjectJSClass(descriptor)) cgThings.append(CGInterfaceObjectJSClass(descriptor))
@ -7943,7 +7943,7 @@ class GlobalGenRoots():
pairs.append((d.name, binding, binding)) pairs.append((d.name, binding, binding))
for alias in d.interface.legacyWindowAliases: for alias in d.interface.legacyWindowAliases:
pairs.append((alias, binding, binding)) pairs.append((alias, binding, binding))
for ctor in d.interface.namedConstructors: for ctor in d.interface.legacyFactoryFunctions:
pairs.append((ctor.identifier.name, binding, binding)) pairs.append((ctor.identifier.name, binding, binding))
pairs.sort(key=operator.itemgetter(0)) pairs.sort(key=operator.itemgetter(0))
mappings = [ mappings = [

View file

@ -167,11 +167,11 @@ class DescriptorProvider:
return self.config.getDescriptor(interfaceName) return self.config.getDescriptor(interfaceName)
def MemberIsUnforgeable(member, descriptor): def MemberIsLegacyUnforgeable(member, descriptor):
return ((member.isAttr() or member.isMethod()) return ((member.isAttr() or member.isMethod())
and not member.isStatic() and not member.isStatic()
and (member.isUnforgeable() and (member.isLegacyUnforgeable()
or bool(descriptor.interface.getExtendedAttribute("Unforgeable")))) or bool(descriptor.interface.getExtendedAttribute("LegacyUnforgeable"))))
class Descriptor(DescriptorProvider): class Descriptor(DescriptorProvider):
@ -244,8 +244,8 @@ class Descriptor(DescriptorProvider):
and not self.interface.getExtendedAttribute("Abstract") and not self.interface.getExtendedAttribute("Abstract")
and not self.interface.getExtendedAttribute("Inline") and not self.interface.getExtendedAttribute("Inline")
and not spiderMonkeyInterface) and not spiderMonkeyInterface)
self.hasUnforgeableMembers = (self.concrete self.hasLegacyUnforgeableMembers = (self.concrete
and any(MemberIsUnforgeable(m, self) for m in and any(MemberIsLegacyUnforgeable(m, self) for m in
self.interface.members)) self.interface.members))
self.operations = { self.operations = {
@ -461,7 +461,7 @@ def getTypesFromDescriptor(descriptor):
members = [m for m in descriptor.interface.members] members = [m for m in descriptor.interface.members]
if descriptor.interface.ctor(): if descriptor.interface.ctor():
members.append(descriptor.interface.ctor()) members.append(descriptor.interface.ctor())
members.extend(descriptor.interface.namedConstructors) members.extend(descriptor.interface.legacyFactoryFunctions)
signatures = [s for m in members if m.isMethod() for s in m.signatures()] signatures = [s for m in members if m.isMethod() for s in m.signatures()]
types = [] types = []
for s in signatures: for s in signatures:

View file

@ -24,7 +24,7 @@ def main():
webidls = [name for name in os.listdir(webidls_dir) if name.endswith(".webidl")] webidls = [name for name in os.listdir(webidls_dir) if name.endswith(".webidl")]
for webidl in webidls: for webidl in webidls:
filename = os.path.join(webidls_dir, webidl) filename = os.path.join(webidls_dir, webidl)
with open(filename, "rb") as f: with open(filename, "r", encoding="utf-8") as f:
parser.parse(f.read(), filename) parser.parse(f.read(), filename)
add_css_properties_attributes(css_properties_json, parser) add_css_properties_attributes(css_properties_json, parser)
@ -72,7 +72,7 @@ def generate(config, name, filename):
def add_css_properties_attributes(css_properties_json, parser): def add_css_properties_attributes(css_properties_json, parser):
css_properties = json.load(open(css_properties_json, "rb")) css_properties = json.load(open(css_properties_json, "rb"))
idl = "partial interface CSSStyleDeclaration {\n%s\n};\n" % "\n".join( idl = "partial interface CSSStyleDeclaration {\n%s\n};\n" % "\n".join(
" [%sCEReactions, SetterThrows] attribute [TreatNullAs=EmptyString] DOMString %s;" % ( " [%sCEReactions, SetterThrows] attribute [LegacyNullToEmptyString] DOMString %s;" % (
('Pref="%s", ' % data["pref"] if data["pref"] else ""), ('Pref="%s", ' % data["pref"] if data["pref"] else ""),
attribute_name attribute_name
) )
@ -80,7 +80,7 @@ def add_css_properties_attributes(css_properties_json, parser):
for (property_name, data) in sorted(properties_list.items()) for (property_name, data) in sorted(properties_list.items())
for attribute_name in attribute_names(property_name) for attribute_name in attribute_names(property_name)
) )
parser.parse(idl.encode("utf-8"), "CSSStyleDeclaration_generated.webidl") parser.parse(idl, "CSSStyleDeclaration_generated.webidl")
def attribute_names(property_name): def attribute_names(property_name):