Issue #1442 - Part 6: binding codegen naming alignment for Streams. https://bugzilla.mozilla.org/show_bug.cgi?id=1128959

This commit is contained in:
Brian Smith 2023-09-27 19:04:02 -05:00 • committed by roytam1
commit 4c5775b621

View file

@ -5621,12 +5621,12 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
# otherwise. # otherwise.
if isOptional: if isOptional:
holderType = CGTemplatedType("SpiderMonkeyInterfaceRooter", interfaceType) holderType = CGTemplatedType("SpiderMonkeyInterfaceRooter", interfaceType)
# If our typed array is nullable, this will set the Nullable to # If our SpiderMonkey interface is nullable, this will set the
# be not-null, but that's ok because we make an explicit # Nullable to be not-null, but that's ok because we make an
# SetNull() call on it as needed if our JS value is actually # explicit SetNull() call on it as needed if our JS value is
# null. XXXbz Because "Maybe" takes const refs for constructor # actually null. XXXbz Because "Maybe" takes const refs for
# arguments, we can't pass a reference here; have to pass a # constructor arguments, we can't pass a reference here; have
# pointer. # to pass a pointer.
holderArgs = "cx, &%s" % objRef holderArgs = "cx, &%s" % objRef
declArgs = None declArgs = None
else: else:
@ -6401,7 +6401,8 @@ recordWrapLevel = 0
def getWrapTemplateForType(type, descriptorProvider, result, successCode, def getWrapTemplateForType(type, descriptorProvider, result, successCode,
returnsNewObject, exceptionCode, typedArraysAreStructs, returnsNewObject, exceptionCode,
spiderMonkeyInterfacesAreStructs,
isConstructorRetval=False): isConstructorRetval=False):
""" """
Reflect a C++ value stored in "result", of IDL type "type" into JS. The Reflect a C++ value stored in "result", of IDL type "type" into JS. The
@ -6411,8 +6412,9 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
doing a 'break' if the entire conversion template is inside a block that doing a 'break' if the entire conversion template is inside a block that
the 'break' will exit). the 'break' will exit).
If typedArraysAreStructs is true, then if the type is a typed array, If spiderMonkeyInterfacesAreStructs is true, then if the type is a
"result" is one of the dom::TypedArray subclasses, not a JSObject*. SpiderMonkey interface, "result" is one of the
dom::SpiderMonkeyInterfaceObjectStorage subclasses, not a JSObject*.
The resulting string should be used with string.Template. It The resulting string should be used with string.Template. It
needs the following keys when substituting: needs the following keys when substituting:
@ -6507,7 +6509,7 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
recTemplate, recInfall = getWrapTemplateForType(type.inner, descriptorProvider, recTemplate, recInfall = getWrapTemplateForType(type.inner, descriptorProvider,
"%s.Value()" % result, successCode, "%s.Value()" % result, successCode,
returnsNewObject, exceptionCode, returnsNewObject, exceptionCode,
typedArraysAreStructs) spiderMonkeyInterfacesAreStructs)
code = fill( code = fill(
""" """
@ -6539,7 +6541,7 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
'returnsNewObject': returnsNewObject, 'returnsNewObject': returnsNewObject,
'exceptionCode': exceptionCode, 'exceptionCode': exceptionCode,
'obj': "returnArray", 'obj': "returnArray",
'typedArraysAreStructs': typedArraysAreStructs 'spiderMonkeyInterfacesAreStructs': spiderMonkeyInterfacesAreStructs
}) })
sequenceWrapLevel -= 1 sequenceWrapLevel -= 1
code = fill( code = fill(
@ -6593,7 +6595,7 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
'returnsNewObject': returnsNewObject, 'returnsNewObject': returnsNewObject,
'exceptionCode': exceptionCode, 'exceptionCode': exceptionCode,
'obj': "returnObj", 'obj': "returnObj",
'typedArraysAreStructs': typedArraysAreStructs 'spiderMonkeyInterfacesAreStructs': spiderMonkeyInterfacesAreStructs
}) })
recordWrapLevel -= 1 recordWrapLevel -= 1
if type.keyType.isByteString(): if type.keyType.isByteString():
@ -6759,7 +6761,7 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
return (head + _setValue(result, wrapAsType=type), False) return (head + _setValue(result, wrapAsType=type), False)
if (type.isObject() or (type.isSpiderMonkeyInterface() and if (type.isObject() or (type.isSpiderMonkeyInterface() and
not typedArraysAreStructs)): not spiderMonkeyInterfacesAreStructs)):
# See comments in GetOrCreateDOMReflector explaining why we need # See comments in GetOrCreateDOMReflector explaining why we need
# to wrap here. # to wrap here.
if type.nullable(): if type.nullable():
@ -6778,21 +6780,21 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
if not (type.isUnion() or type.isPrimitive() or type.isDictionary() or if not (type.isUnion() or type.isPrimitive() or type.isDictionary() or
type.isDate() or type.isDate() or
(type.isSpiderMonkeyInterface() and typedArraysAreStructs)): (type.isSpiderMonkeyInterface() and spiderMonkeyInterfacesAreStructs)):
raise TypeError("Need to learn to wrap %s" % type) raise TypeError("Need to learn to wrap %s" % type)
if type.nullable(): if type.nullable():
recTemplate, recInfal = getWrapTemplateForType(type.inner, descriptorProvider, recTemplate, recInfal = getWrapTemplateForType(type.inner, descriptorProvider,
"%s.Value()" % result, successCode, "%s.Value()" % result, successCode,
returnsNewObject, exceptionCode, returnsNewObject, exceptionCode,
typedArraysAreStructs) spiderMonkeyInterfacesAreStructs)
return ("if (%s.IsNull()) {\n" % result + return ("if (%s.IsNull()) {\n" % result +
indent(setNull()) + indent(setNull()) +
"}\n" + "}\n" +
recTemplate, recInfal) recTemplate, recInfal)
if type.isSpiderMonkeyInterface(): if type.isSpiderMonkeyInterface():
assert typedArraysAreStructs assert spiderMonkeyInterfacesAreStructs
# See comments in GetOrCreateDOMReflector explaining why we need # See comments in GetOrCreateDOMReflector explaining why we need
# to wrap here. # to wrap here.
# NB: setObject(..., some-object-type) calls JS_WrapValue(), so is fallible # NB: setObject(..., some-object-type) calls JS_WrapValue(), so is fallible
@ -6874,7 +6876,7 @@ def wrapForType(type, descriptorProvider, templateValues):
templateValues.get('successCode', None), templateValues.get('successCode', None),
templateValues.get('returnsNewObject', False), templateValues.get('returnsNewObject', False),
templateValues.get('exceptionCode', "return false;\n"), templateValues.get('exceptionCode', "return false;\n"),
templateValues.get('typedArraysAreStructs', False), templateValues.get('spiderMonkeyInterfacesAreStructs', False),
isConstructorRetval=templateValues.get('isConstructorRetval', False))[0] isConstructorRetval=templateValues.get('isConstructorRetval', False))[0]
defaultValues = {'obj': 'obj'} defaultValues = {'obj': 'obj'}
@ -8203,10 +8205,10 @@ class CGMethodCall(CGThing):
# "object" arg. # "object" arg.
# First grab all the overloads that have a non-callback interface # First grab all the overloads that have a non-callback interface
# (which includes typed arrays and arraybuffers) at the # (which includes SpiderMonkey interfaces) at the distinguishing
# distinguishing index. We can also include the ones that have an # index. We can also include the ones that have an "object" here,
# "object" here, since if those are present no other object-typed # since if those are present no other object-typed argument will
# argument will be. # be.
objectSigs = [ objectSigs = [
s for s in possibleSignatures s for s in possibleSignatures
if (distinguishingType(s).isObject() or if (distinguishingType(s).isObject() or
@ -8237,16 +8239,17 @@ class CGMethodCall(CGThing):
# There might be more than one thing in objectSigs; we need to check # There might be more than one thing in objectSigs; we need to check
# which ones we unwrap to. # which ones we unwrap to.
if len(objectSigs) > 0: if len(objectSigs) > 0:
# Here it's enough to guard on our argument being an object. The # Here it's enough to guard on our argument being an object.
# code for unwrapping non-callback interfaces, typed arrays, # The code for unwrapping non-callback interfaces, spiderMonkey
# sequences, and Dates will just bail out and move on to # interfaces, sequences, and Dates will just bail out and move
# the next overload if the object fails to unwrap correctly, # on to the next overload if the object fails to unwrap
# while "object" accepts any object anyway. We could even not # correctly, while "object" accepts any object anyway. We
# do the isObject() check up front here, but in cases where we # could even not do the isObject() check up front here, but in
# have multiple object overloads it makes sense to do it only # cases where we have multiple object overloads it makes sense
# once instead of for each overload. That will also allow the # to do it only once instead of for each overload. That will
# unwrapping test to skip having to do codegen for the # also allow the unwrapping test to skip having to do codegen
# null-or-undefined case, which we already handled above. # for the null-or-undefined case, which we already handled
# above.
caseBody.append(CGGeneric("if (%s.isObject()) {\n" % caseBody.append(CGGeneric("if (%s.isObject()) {\n" %
distinguishingArg)) distinguishingArg))
for sig in objectSigs: for sig in objectSigs:
@ -10249,7 +10252,7 @@ class CGUnionStruct(CGThing):
"jsvalHandle": "rval", "jsvalHandle": "rval",
"obj": "scopeObj", "obj": "scopeObj",
"result": val, "result": val,
"typedArraysAreStructs": True "spiderMonkeyInterfacesAreStructs": True
}) })
return CGGeneric(wrapCode) return CGGeneric(wrapCode)
@ -13229,7 +13232,7 @@ class CGDictionary(CGThing):
# 'obj' can just be allowed to be the string "obj", since that # 'obj' can just be allowed to be the string "obj", since that
# will be our dictionary object, which is presumably itself in # will be our dictionary object, which is presumably itself in
# the right scope. # the right scope.
'typedArraysAreStructs': True 'spiderMonkeyInterfacesAreStructs': True
}) })
conversion = CGGeneric(innerTemplate) conversion = CGGeneric(innerTemplate)
conversion = CGWrapper(conversion, conversion = CGWrapper(conversion,
@ -13998,7 +14001,7 @@ class CGBindingRoot(CGThing):
return {desc.getDescriptor(desc.interface.parent.identifier.name)} return {desc.getDescriptor(desc.interface.parent.identifier.name)}
for x in dependencySortObjects(jsImplemented, getParentDescriptor, for x in dependencySortObjects(jsImplemented, getParentDescriptor,
lambda d: d.interface.identifier.name): lambda d: d.interface.identifier.name):
cgthings.append(CGCallbackInterface(x, typedArraysAreStructs=True)) cgthings.append(CGCallbackInterface(x, spiderMonkeyInterfacesAreStructs=True))
cgthings.append(CGJSImplClass(x)) cgthings.append(CGJSImplClass(x))
# And make sure we have the right number of newlines at the end # And make sure we have the right number of newlines at the end
@ -14060,14 +14063,13 @@ class CGBindingRoot(CGThing):
class CGNativeMember(ClassMethod): class CGNativeMember(ClassMethod):
def __init__(self, descriptorProvider, member, name, signature, extendedAttrs, def __init__(self, descriptorProvider, member, name, signature, extendedAttrs,
breakAfter=True, passJSBitsAsNeeded=True, visibility="public", breakAfter=True, passJSBitsAsNeeded=True, visibility="public",
typedArraysAreStructs=True, variadicIsSequence=False, spiderMonkeyInterfacesAreStructs=True,
resultNotAddRefed=False, variadicIsSequence=False, resultNotAddRefed=False,
virtual=False, virtual=False, override=False):
override=False):
""" """
If typedArraysAreStructs is false, typed arrays will be passed as If spiderMonkeyInterfacesAreStructs is false, SpiderMonkey interfaces
JS::Handle<JSObject*>. If it's true they will be passed as one of the will be passed as JS::Handle<JSObject*>. If it's true they will be
dom::TypedArray subclasses. passed as one of the dom::SpiderMonkeyInterfaceObjectStorage subclasses.
If passJSBitsAsNeeded is false, we don't automatically pass in a If passJSBitsAsNeeded is false, we don't automatically pass in a
JSContext* or a JSObject* based on the return and argument types. We JSContext* or a JSObject* based on the return and argument types. We
@ -14078,7 +14080,7 @@ class CGNativeMember(ClassMethod):
self.extendedAttrs = extendedAttrs self.extendedAttrs = extendedAttrs
self.resultAlreadyAddRefed = not resultNotAddRefed self.resultAlreadyAddRefed = not resultNotAddRefed
self.passJSBitsAsNeeded = passJSBitsAsNeeded self.passJSBitsAsNeeded = passJSBitsAsNeeded
self.typedArraysAreStructs = typedArraysAreStructs self.spiderMonkeyInterfacesAreStructs = spiderMonkeyInterfacesAreStructs
self.variadicIsSequence = variadicIsSequence self.variadicIsSequence = variadicIsSequence
breakAfterSelf = "\n" if breakAfter else "" breakAfterSelf = "\n" if breakAfter else ""
ClassMethod.__init__(self, name, ClassMethod.__init__(self, name,
@ -14385,7 +14387,7 @@ class CGNativeMember(ClassMethod):
False, False) False, False)
if type.isSpiderMonkeyInterface(): if type.isSpiderMonkeyInterface():
if not self.typedArraysAreStructs: if not self.spiderMonkeyInterfacesAreStructs:
return "JS::Handle<JSObject*>", False, False return "JS::Handle<JSObject*>", False, False
# Unroll for the name, in case we're nullable. # Unroll for the name, in case we're nullable.
@ -15557,16 +15559,16 @@ class CGFastCallback(CGClass):
class CGCallbackInterface(CGCallback): class CGCallbackInterface(CGCallback):
def __init__(self, descriptor, typedArraysAreStructs=False): def __init__(self, descriptor, spiderMonkeyInterfacesAreStructs=False):
iface = descriptor.interface iface = descriptor.interface
attrs = [m for m in iface.members if m.isAttr() and not m.isStatic()] attrs = [m for m in iface.members if m.isAttr() and not m.isStatic()]
getters = [CallbackGetter(a, descriptor, typedArraysAreStructs) getters = [CallbackGetter(a, descriptor, spiderMonkeyInterfacesAreStructs)
for a in attrs] for a in attrs]
setters = [CallbackSetter(a, descriptor, typedArraysAreStructs) setters = [CallbackSetter(a, descriptor, spiderMonkeyInterfacesAreStructs)
for a in attrs if not a.readonly] for a in attrs if not a.readonly]
methods = [m for m in iface.members methods = [m for m in iface.members
if m.isMethod() and not m.isStatic() and not m.isIdentifierLess()] if m.isMethod() and not m.isStatic() and not m.isIdentifierLess()]
methods = [CallbackOperation(m, sig, descriptor, typedArraysAreStructs) methods = [CallbackOperation(m, sig, descriptor, spiderMonkeyInterfacesAreStructs)
for m in methods for sig in m.signatures()] for m in methods for sig in m.signatures()]
if iface.isJSImplemented() and iface.ctor(): if iface.isJSImplemented() and iface.ctor():
sigs = descriptor.interface.ctor().signatures() sigs = descriptor.interface.ctor().signatures()
@ -15611,7 +15613,8 @@ class CallbackMember(CGNativeMember):
# CallSetup already handled the unmark-gray bits for us. we don't have # CallSetup already handled the unmark-gray bits for us. we don't have
# anything better to use for 'obj', really... # anything better to use for 'obj', really...
def __init__(self, sig, name, descriptorProvider, needThisHandling, def __init__(self, sig, name, descriptorProvider, needThisHandling,
rethrowContentException=False, typedArraysAreStructs=False, rethrowContentException=False,
spiderMonkeyInterfacesAreStructs=False,
wrapScope='CallbackKnownNotGray()'): wrapScope='CallbackKnownNotGray()'):
""" """
needThisHandling is True if we need to be able to accept a specified needThisHandling is True if we need to be able to accept a specified
@ -15646,7 +15649,7 @@ class CallbackMember(CGNativeMember):
extendedAttrs={}, extendedAttrs={},
passJSBitsAsNeeded=False, passJSBitsAsNeeded=False,
visibility=visibility, visibility=visibility,
typedArraysAreStructs=typedArraysAreStructs) spiderMonkeyInterfacesAreStructs=spiderMonkeyInterfacesAreStructs)
# We have to do all the generation of our body now, because # We have to do all the generation of our body now, because
# the caller relies on us throwing if we can't manage it. # the caller relies on us throwing if we can't manage it.
self.exceptionCode = ("aRv.Throw(NS_ERROR_UNEXPECTED);\n" self.exceptionCode = ("aRv.Throw(NS_ERROR_UNEXPECTED);\n"
@ -15763,7 +15766,7 @@ class CallbackMember(CGNativeMember):
'obj': self.wrapScope, 'obj': self.wrapScope,
'returnsNewObject': False, 'returnsNewObject': False,
'exceptionCode': self.exceptionCode, 'exceptionCode': self.exceptionCode,
'typedArraysAreStructs': self.typedArraysAreStructs 'spiderMonkeyInterfacesAreStructs': self.spiderMonkeyInterfacesAreStructs
}) })
except MethodNotNewObjectError as err: except MethodNotNewObjectError as err:
raise TypeError("%s being passed as an argument to %s but is not " raise TypeError("%s being passed as an argument to %s but is not "
@ -15867,10 +15870,11 @@ class CallbackMember(CGNativeMember):
class CallbackMethod(CallbackMember): class CallbackMethod(CallbackMember):
def __init__(self, sig, name, descriptorProvider, needThisHandling, def __init__(self, sig, name, descriptorProvider, needThisHandling,
rethrowContentException=False, typedArraysAreStructs=False): rethrowContentException=False,
spiderMonkeyInterfacesAreStructs=False):
CallbackMember.__init__(self, sig, name, descriptorProvider, CallbackMember.__init__(self, sig, name, descriptorProvider,
needThisHandling, rethrowContentException, needThisHandling, rethrowContentException,
typedArraysAreStructs=typedArraysAreStructs) spiderMonkeyInterfacesAreStructs=spiderMonkeyInterfacesAreStructs)
def getRvalDecl(self): def getRvalDecl(self):
return "JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());\n" return "JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());\n"
@ -15929,12 +15933,12 @@ class CallbackOperationBase(CallbackMethod):
""" """
def __init__(self, signature, jsName, nativeName, descriptor, def __init__(self, signature, jsName, nativeName, descriptor,
singleOperation, rethrowContentException=False, singleOperation, rethrowContentException=False,
typedArraysAreStructs=False): spiderMonkeyInterfacesAreStructs=False):
self.singleOperation = singleOperation self.singleOperation = singleOperation
self.methodName = descriptor.binaryNameFor(jsName) self.methodName = descriptor.binaryNameFor(jsName)
CallbackMethod.__init__(self, signature, nativeName, descriptor, CallbackMethod.__init__(self, signature, nativeName, descriptor,
singleOperation, rethrowContentException, singleOperation, rethrowContentException,
typedArraysAreStructs=typedArraysAreStructs) spiderMonkeyInterfacesAreStructs=spiderMonkeyInterfacesAreStructs)
def getThisDecl(self): def getThisDecl(self):
if not self.singleOperation: if not self.singleOperation:
@ -15985,7 +15989,8 @@ class CallbackOperation(CallbackOperationBase):
""" """
Codegen actual WebIDL operations on callback interfaces. Codegen actual WebIDL operations on callback interfaces.
""" """
def __init__(self, method, signature, descriptor, typedArraysAreStructs): def __init__(self, method, signature, descriptor,
spiderMonkeyInterfacesAreStructs):
self.ensureASCIIName(method) self.ensureASCIIName(method)
self.method = method self.method = method
jsName = method.identifier.name jsName = method.identifier.name
@ -15994,7 +15999,7 @@ class CallbackOperation(CallbackOperationBase):
MakeNativeName(descriptor.binaryNameFor(jsName)), MakeNativeName(descriptor.binaryNameFor(jsName)),
descriptor, descriptor.interface.isSingleOperationInterface(), descriptor, descriptor.interface.isSingleOperationInterface(),
rethrowContentException=descriptor.interface.isJSImplemented(), rethrowContentException=descriptor.interface.isJSImplemented(),
typedArraysAreStructs=typedArraysAreStructs) spiderMonkeyInterfacesAreStructs=spiderMonkeyInterfacesAreStructs)
def getPrettyName(self): def getPrettyName(self):
return "%s.%s" % (self.descriptorProvider.interface.identifier.name, return "%s.%s" % (self.descriptorProvider.interface.identifier.name,
@ -16005,13 +16010,14 @@ class CallbackAccessor(CallbackMember):
""" """
Shared superclass for CallbackGetter and CallbackSetter. Shared superclass for CallbackGetter and CallbackSetter.
""" """
def __init__(self, attr, sig, name, descriptor, typedArraysAreStructs): def __init__(self, attr, sig, name, descriptor,
spiderMonkeyInterfacesAreStructs):
self.ensureASCIIName(attr) self.ensureASCIIName(attr)
self.attrName = attr.identifier.name self.attrName = attr.identifier.name
CallbackMember.__init__(self, sig, name, descriptor, CallbackMember.__init__(self, sig, name, descriptor,
needThisHandling=False, needThisHandling=False,
rethrowContentException=descriptor.interface.isJSImplemented(), rethrowContentException=descriptor.interface.isJSImplemented(),
typedArraysAreStructs=typedArraysAreStructs) spiderMonkeyInterfacesAreStructs=spiderMonkeyInterfacesAreStructs)
def getPrettyName(self): def getPrettyName(self):
return "%s.%s" % (self.descriptorProvider.interface.identifier.name, return "%s.%s" % (self.descriptorProvider.interface.identifier.name,
@ -16019,12 +16025,12 @@ class CallbackAccessor(CallbackMember):
class CallbackGetter(CallbackAccessor): class CallbackGetter(CallbackAccessor):
def __init__(self, attr, descriptor, typedArraysAreStructs): def __init__(self, attr, descriptor, spiderMonkeyInterfacesAreStructs):
CallbackAccessor.__init__(self, attr, CallbackAccessor.__init__(self, attr,
(attr.type, []), (attr.type, []),
callbackGetterName(attr, descriptor), callbackGetterName(attr, descriptor),
descriptor, descriptor,
typedArraysAreStructs) spiderMonkeyInterfacesAreStructs)
def getRvalDecl(self): def getRvalDecl(self):
return "JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());\n" return "JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());\n"
@ -16046,12 +16052,12 @@ class CallbackGetter(CallbackAccessor):
class CallbackSetter(CallbackAccessor): class CallbackSetter(CallbackAccessor):
def __init__(self, attr, descriptor, typedArraysAreStructs): def __init__(self, attr, descriptor, spiderMonkeyInterfacesAreStructs):
CallbackAccessor.__init__(self, attr, CallbackAccessor.__init__(self, attr,
(BuiltinTypes[IDLBuiltinType.Types.void], (BuiltinTypes[IDLBuiltinType.Types.void],
[FakeArgument(attr.type, attr)]), [FakeArgument(attr.type, attr)]),
callbackSetterName(attr, descriptor), callbackSetterName(attr, descriptor),
descriptor, typedArraysAreStructs) descriptor, spiderMonkeyInterfacesAreStructs)
def getRvalDecl(self): def getRvalDecl(self):
# We don't need an rval # We don't need an rval
@ -16086,7 +16092,7 @@ class CGJSImplInitOperation(CallbackOperationBase):
"__init", "__Init", descriptor, "__init", "__Init", descriptor,
singleOperation=False, singleOperation=False,
rethrowContentException=True, rethrowContentException=True,
typedArraysAreStructs=True) spiderMonkeyInterfacesAreStructs=True)
def getPrettyName(self): def getPrettyName(self):
return "__init" return "__init"