mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Add support for BinaryName attribute to servo's codegen (fixes #4435) r=jdm
This commit is contained in:
parent
26567ef2e6
commit
c81f1cc541
5 changed files with 47 additions and 20 deletions
|
@ -68,13 +68,6 @@ def stripTrailingWhitespace(text):
|
|||
return '\n'.join(lines) + tail
|
||||
|
||||
def MakeNativeName(name):
|
||||
# The gecko counterpart to this file uses the BinaryName machinery
|
||||
# for this purpose (#4435 is the servo issue for BinaryName).
|
||||
replacements = {
|
||||
"__stringifier": "Stringify",
|
||||
}
|
||||
if name in replacements:
|
||||
return replacements[name]
|
||||
return name[0].upper() + name[1:]
|
||||
|
||||
builtinNames = {
|
||||
|
@ -2569,7 +2562,8 @@ class CGSpecializedMethod(CGAbstractExternMethod):
|
|||
|
||||
@staticmethod
|
||||
def makeNativeName(descriptor, method):
|
||||
return MakeNativeName(method.identifier.name)
|
||||
name = method.identifier.name
|
||||
return MakeNativeName(descriptor.binaryNameFor(name))
|
||||
|
||||
class CGStaticMethod(CGAbstractStaticBindingMethod):
|
||||
"""
|
||||
|
@ -2635,7 +2629,8 @@ class CGSpecializedGetter(CGAbstractExternMethod):
|
|||
|
||||
@staticmethod
|
||||
def makeNativeName(descriptor, attr):
|
||||
nativeName = MakeNativeName(attr.identifier.name)
|
||||
name = attr.identifier.name
|
||||
nativeName = MakeNativeName(descriptor.binaryNameFor(name))
|
||||
infallible = ('infallible' in
|
||||
descriptor.getExtendedAttributes(attr, getter=True))
|
||||
if attr.type.nullable() or not infallible:
|
||||
|
@ -2713,7 +2708,8 @@ class CGSpecializedSetter(CGAbstractExternMethod):
|
|||
|
||||
@staticmethod
|
||||
def makeNativeName(descriptor, attr):
|
||||
return "Set" + MakeNativeName(attr.identifier.name)
|
||||
name = attr.identifier.name
|
||||
return "Set" + MakeNativeName(descriptor.binaryNameFor(name))
|
||||
|
||||
|
||||
class CGStaticSetter(CGAbstractStaticBindingMethod):
|
||||
|
@ -3569,7 +3565,7 @@ class CGProxySpecialOperation(CGPerSignatureCall):
|
|||
(don't use this directly, use the derived classes below).
|
||||
"""
|
||||
def __init__(self, descriptor, operation):
|
||||
nativeName = MakeNativeName(operation)
|
||||
nativeName = MakeNativeName(descriptor.binaryNameFor(operation))
|
||||
operation = descriptor.operations[operation]
|
||||
assert len(operation.signatures()) == 1
|
||||
signature = operation.signatures()[0]
|
||||
|
@ -3993,7 +3989,8 @@ class CGDOMJSProxyHandler_obj_toString(CGAbstractExternMethod):
|
|||
def getBody(self):
|
||||
stringifier = self.descriptor.operations['Stringifier']
|
||||
if stringifier:
|
||||
nativeName = MakeNativeName(stringifier.identifier.name)
|
||||
name = self.descriptor.binaryNameFor(stringifier.identifier.name)
|
||||
nativeName = MakeNativeName(name)
|
||||
signature = stringifier.signatures()[0]
|
||||
returnType = signature[0]
|
||||
extendedAttributes = self.descriptor.getExtendedAttributes(stringifier)
|
||||
|
@ -4077,7 +4074,8 @@ class CGClassConstructHook(CGAbstractExternMethod):
|
|||
let global = global_object_for_js_object(JS_CALLEE(cx, vp).to_object());
|
||||
let global = global.root();
|
||||
""")
|
||||
nativeName = MakeNativeName(self._ctor.identifier.name)
|
||||
name = self._ctor.identifier.name
|
||||
nativeName = MakeNativeName(self.descriptor.binaryNameFor(name))
|
||||
callGenerator = CGMethodCall(["global.r()"], nativeName, True,
|
||||
self.descriptor, self._ctor)
|
||||
return CGList([preamble, callGenerator])
|
||||
|
@ -4848,11 +4846,15 @@ class CGCallback(CGClass):
|
|||
return self._deps
|
||||
|
||||
# We're always fallible
|
||||
def callbackGetterName(attr):
|
||||
return "Get" + MakeNativeName(attr.identifier.name)
|
||||
def callbackGetterName(attr, descriptor):
|
||||
return "Get" + MakeNativeName(
|
||||
descriptor.binaryNameFor(attr.identifier.name))
|
||||
|
||||
|
||||
def callbackSetterName(attr, descriptor):
|
||||
return "Set" + MakeNativeName(
|
||||
descriptor.binaryNameFor(attr.identifier.name))
|
||||
|
||||
def callbackSetterName(attr):
|
||||
return "Set" + MakeNativeName(attr.identifier.name)
|
||||
|
||||
class CGCallbackFunction(CGCallback):
|
||||
def __init__(self, callback, descriptorProvider):
|
||||
|
@ -5179,7 +5181,8 @@ class CallbackOperation(CallbackOperationBase):
|
|||
self.ensureASCIIName(method)
|
||||
jsName = method.identifier.name
|
||||
CallbackOperationBase.__init__(self, signature,
|
||||
jsName, MakeNativeName(jsName),
|
||||
jsName,
|
||||
MakeNativeName(descriptor.binaryNameFor(jsName)),
|
||||
descriptor, descriptor.interface.isSingleOperationInterface())
|
||||
|
||||
class CallbackGetter(CallbackMember):
|
||||
|
|
|
@ -251,6 +251,20 @@ class Descriptor(DescriptorProvider):
|
|||
else:
|
||||
add('all', [config], attribute)
|
||||
|
||||
self._binaryNames = desc.get('binaryNames', {})
|
||||
self._binaryNames.setdefault('__legacycaller', 'LegacyCall')
|
||||
self._binaryNames.setdefault('__stringifier', 'Stringify')
|
||||
|
||||
for member in self.interface.members:
|
||||
if not member.isAttr() and not member.isMethod():
|
||||
continue
|
||||
binaryName = member.getExtendedAttribute("BinaryName")
|
||||
if binaryName:
|
||||
assert isinstance(binaryName, list)
|
||||
assert len(binaryName) == 1
|
||||
self._binaryNames.setdefault(member.identifier.name,
|
||||
binaryName[0])
|
||||
|
||||
# Build the prototype chain.
|
||||
self.prototypeChain = []
|
||||
parent = interface
|
||||
|
@ -260,6 +274,9 @@ class Descriptor(DescriptorProvider):
|
|||
config.maxProtoChainLength = max(config.maxProtoChainLength,
|
||||
len(self.prototypeChain))
|
||||
|
||||
def binaryNameFor(self, name):
|
||||
return self._binaryNames.get(name, name)
|
||||
|
||||
def getExtendedAttributes(self, member, getter=False, setter=False):
|
||||
def maybeAppendInfallibleToAttrs(attrs, throws):
|
||||
if throws is None:
|
||||
|
|
|
@ -3262,7 +3262,8 @@ class IDLAttribute(IDLInterfaceMember):
|
|||
identifier == "Frozen" or
|
||||
identifier == "AvailableIn" or
|
||||
identifier == "NewObject" or
|
||||
identifier == "CheckPermissions"):
|
||||
identifier == "CheckPermissions" or
|
||||
identifier == "BinaryName"):
|
||||
# Known attributes that we don't need to do anything with here
|
||||
pass
|
||||
else:
|
||||
|
@ -3861,7 +3862,8 @@ class IDLMethod(IDLInterfaceMember, IDLScope):
|
|||
identifier == "Pref" or
|
||||
identifier == "Func" or
|
||||
identifier == "AvailableIn" or
|
||||
identifier == "CheckPermissions"):
|
||||
identifier == "CheckPermissions" or
|
||||
identifier == "BinaryName"):
|
||||
# Known attributes that we don't need to do anything with here
|
||||
pass
|
||||
else:
|
||||
|
|
|
@ -98,6 +98,8 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
|||
fn SetByteStringAttributeNullable(self, _: Option<ByteString>) {}
|
||||
fn GetStringAttributeNullable(self) -> Option<DOMString> { Some("".to_owned()) }
|
||||
fn SetStringAttributeNullable(self, _: Option<DOMString>) {}
|
||||
fn SetBinaryRenamedAttribute(self, _: DOMString) {}
|
||||
fn BinaryRenamedAttribute(self) -> DOMString { "".to_owned() }
|
||||
fn GetEnumAttributeNullable(self) -> Option<TestEnum> { Some(_empty) }
|
||||
fn GetInterfaceAttributeNullable(self) -> Option<Temporary<Blob>> {
|
||||
let global = self.global.root();
|
||||
|
@ -108,6 +110,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
|||
fn SetUnionAttributeNullable(self, _: Option<HTMLElementOrLong>) {}
|
||||
fn GetUnion2AttributeNullable(self) -> Option<EventOrString> { Some(eString("".to_owned())) }
|
||||
fn SetUnion2AttributeNullable(self, _: Option<EventOrString>) {}
|
||||
fn BinaryRenamedMethod(self) -> () {}
|
||||
fn ReceiveVoid(self) -> () {}
|
||||
fn ReceiveBoolean(self) -> bool { false }
|
||||
fn ReceiveByte(self) -> i8 { 0 }
|
||||
|
|
|
@ -91,7 +91,9 @@ interface TestBinding {
|
|||
attribute Blob? interfaceAttributeNullable;
|
||||
attribute (HTMLElement or long)? unionAttributeNullable;
|
||||
attribute (Event or DOMString)? union2AttributeNullable;
|
||||
[BinaryName="BinaryRenamedAttribute"] attribute DOMString attrToBinaryRename;
|
||||
|
||||
[BinaryName="BinaryRenamedMethod"] void methToBinaryRename();
|
||||
void receiveVoid();
|
||||
boolean receiveBoolean();
|
||||
byte receiveByte();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue