Bug 915971. Rename FooReturnValue unions to OwningFoo, because we use them for more than just return values. r=dzbarsky

This commit is contained in:
Boris Zbarsky 2013-09-17 11:16:02 -04:00
Родитель 343e97071a
Коммит 7f755053b4
12 изменённых файлов: 70 добавлений и 70 удалений

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

@ -638,7 +638,7 @@ CanvasRenderingContext2D::SetStyleFromString(const nsAString& str,
}
void
CanvasRenderingContext2D::GetStyleAsUnion(StringOrCanvasGradientOrCanvasPatternReturnValue& aValue,
CanvasRenderingContext2D::GetStyleAsUnion(OwningStringOrCanvasGradientOrCanvasPattern& aValue,
Style aWhichStyle)
{
const ContextState &state = CurrentState();

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

@ -32,7 +32,7 @@ namespace dom {
class HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement;
class ImageData;
class StringOrCanvasGradientOrCanvasPattern;
class StringOrCanvasGradientOrCanvasPatternReturnValue;
class OwningStringOrCanvasGradientOrCanvasPattern;
class TextMetrics;
extern const mozilla::gfx::Float SIGMA_MAX;
@ -94,7 +94,7 @@ public:
void SetGlobalCompositeOperation(const nsAString& op,
mozilla::ErrorResult& error);
void GetStrokeStyle(StringOrCanvasGradientOrCanvasPatternReturnValue& value)
void GetStrokeStyle(OwningStringOrCanvasGradientOrCanvasPattern& value)
{
GetStyleAsUnion(value, STYLE_STROKE);
}
@ -104,7 +104,7 @@ public:
SetStyleFromUnion(value, STYLE_STROKE);
}
void GetFillStyle(StringOrCanvasGradientOrCanvasPatternReturnValue& value)
void GetFillStyle(OwningStringOrCanvasGradientOrCanvasPattern& value)
{
GetStyleAsUnion(value, STYLE_FILL);
}
@ -499,7 +499,7 @@ protected:
CurrentState().SetPatternStyle(whichStyle, &pattern);
}
void GetStyleAsUnion(StringOrCanvasGradientOrCanvasPatternReturnValue& aValue,
void GetStyleAsUnion(OwningStringOrCanvasGradientOrCanvasPattern& aValue,
Style aWhichStyle);
// Returns whether a color was successfully parsed.

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

@ -95,7 +95,7 @@ nsDOMMessageEvent::GetSource(nsIDOMWindow** aSource)
}
void
nsDOMMessageEvent::GetSource(Nullable<mozilla::dom::WindowProxyOrMessagePortReturnValue>& aValue) const
nsDOMMessageEvent::GetSource(Nullable<mozilla::dom::OwningWindowProxyOrMessagePort>& aValue) const
{
if (mWindowSource) {
aValue.SetValue().SetAsWindowProxy() = mWindowSource;

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

@ -14,7 +14,7 @@
namespace mozilla {
namespace dom {
class MessagePortList;
class WindowProxyOrMessagePortReturnValue;
class OwningWindowProxyOrMessagePort;
}
}
@ -50,7 +50,7 @@ public:
JS::Value GetData(JSContext* aCx, mozilla::ErrorResult& aRv);
void GetSource(Nullable<mozilla::dom::WindowProxyOrMessagePortReturnValue>& aValue) const;
void GetSource(Nullable<mozilla::dom::OwningWindowProxyOrMessagePort>& aValue) const;
mozilla::dom::MessagePortList* GetPorts()
{

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

@ -795,7 +795,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, config):
implheaders = set(["UnionTypes.h"])
declarations = set()
unionStructs = dict()
unionReturnValues = dict()
owningUnionStructs = dict()
def addInfoForType((t, descriptor, dictionary)):
"""
@ -812,8 +812,8 @@ def UnionTypes(descriptors, dictionaries, callbacks, config):
config)
# FIXME: Unions are broken in workers. See bug 809899.
unionStructs[name] = CGUnionStruct(t, providers[0])
unionReturnValues[name] = CGUnionStruct(t, providers[0],
isReturnValue=True)
owningUnionStructs[name] = CGUnionStruct(t, providers[0],
ownsMembers=True)
for f in t.flatMemberTypes:
f = f.unroll()
@ -841,7 +841,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, config):
return (headers, implheaders, declarations,
CGList(itertools.chain(SortedDictValues(unionStructs),
SortedDictValues(unionReturnValues)), "\n"))
SortedDictValues(owningUnionStructs)), "\n"))
def UnionConversions(descriptors, dictionaries, callbacks, config):
"""
@ -2575,7 +2575,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
lenientFloatCode=None,
allowTreatNonCallableAsNull=False,
isCallbackReturnValue=False,
isInUnionReturnValue=False,
isInOwningUnion=False,
sourceDescription="value"):
"""
Get a template for converting a JS value to a native object based on the
@ -2741,9 +2741,8 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
return templateBody
# A helper function for converting things that look like a JSObject*.
def handleJSObjectType(type, isMember, isInUnionReturnValue,
failureCode):
if not isMember and not isInUnionReturnValue:
def handleJSObjectType(type, isMember, isInOwningUnion, failureCode):
if not isMember and not isInOwningUnion:
if isOptional:
# We have a specialization of Optional that will use a
# Rooted for the storage here.
@ -2752,7 +2751,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
declType = CGGeneric("JS::Rooted<JSObject*>")
else:
assert (isMember == "Sequence" or isMember == "Variadic" or
isMember == "Dictionary" or isInUnionReturnValue)
isMember == "Dictionary" or isInOwningUnion)
# We'll get traced by the sequence or dictionary or union tracer
declType = CGGeneric("JSObject*")
templateBody = "${declName} = &${val}.toObject();"
@ -3054,7 +3053,7 @@ for (uint32_t i = 0; i < length; ++i) {
exceptionCodeIndented.define()))
templateBody = CGWrapper(CGIndenter(CGList([templateBody, throw], "\n")), pre="{\n", post="\n}")
typeName = type.name + ("ReturnValue" if isMember else "")
typeName = ("Owning" if isMember else "") + type.name
argumentTypeName = typeName + "Argument"
if nullable:
typeName = "Nullable<" + typeName + " >"
@ -3141,7 +3140,7 @@ for (uint32_t i = 0; i < length; ++i) {
if descriptor.nativeType == 'JSObject':
# XXXbz Workers code does this sometimes
assert descriptor.workers
return handleJSObjectType(type, isMember, isInUnionReturnValue,
return handleJSObjectType(type, isMember, isInOwningUnion,
failureCode)
if (descriptor.interface.isCallback() and
@ -3180,7 +3179,7 @@ for (uint32_t i = 0; i < length; ++i) {
forceOwningType = ((descriptor.interface.isCallback() and
not descriptor.workers) or
isMember or
isInUnionReturnValue or
isInOwningUnion or
isCallbackReturnValue)
typeName = descriptor.nativeType
@ -3304,7 +3303,7 @@ for (uint32_t i = 0; i < length; ++i) {
CGIndenter(onFailureBadType(failureCode, type.name)).define()))
template = wrapObjectTemplate(template, type, "${declName}.SetNull()",
failureCode)
if not isMember and not isInUnionReturnValue:
if not isMember and not isInOwningUnion:
# This is a bit annoying. In a union we don't want to have a
# holder, since unions don't support that. But if we're optional we
# want to have a holder, so that the callee doesn't see
@ -3396,22 +3395,22 @@ for (uint32_t i = 0; i < length; ++i) {
if isOptional:
declType = "Optional<nsAString>"
elif isInUnionReturnValue:
elif isInOwningUnion:
declType = "nsString"
else:
declType = "NonNull<nsAString>"
# No need to deal with optional here; we handled it already
decl = ""
if isInUnionReturnValue:
if isInOwningUnion:
decl += "FakeDependentString str;\n"
return JSToNativeConversionInfo(
"%s"
"%s\n"
"${declName} = %s" %
(decl,
getConversionCode("str" if isInUnionReturnValue else "${holderName}"),
("str;" if isInUnionReturnValue else "&${holderName};")),
getConversionCode("str" if isInOwningUnion else "${holderName}"),
("str;" if isInOwningUnion else "&${holderName};")),
declType=CGGeneric(declType),
holderType=CGGeneric("FakeDependentString"))
@ -3575,8 +3574,7 @@ for (uint32_t i = 0; i < length; ++i) {
if type.isObject():
assert not isEnforceRange and not isClamp
return handleJSObjectType(type, isMember, isInUnionReturnValue,
failureCode)
return handleJSObjectType(type, isMember, isInOwningUnion, failureCode)
if type.isDictionary():
if failureCode is not None and not isDefinitelyObject:
@ -4496,7 +4494,7 @@ def getRetvalDeclarationForType(returnType, descriptorProvider,
resultArgs = None
return result, True, None, resultArgs
if returnType.isUnion():
result = CGGeneric(returnType.unroll().name + "ReturnValue")
result = CGGeneric("Owning" + returnType.unroll().name)
if not isMember and typeNeedsRooting(returnType, descriptorProvider):
if returnType.nullable():
result = CGTemplatedType("NullableRootedUnion", result)
@ -6138,7 +6136,8 @@ def getUnionAccessorSignatureType(type, descriptorProvider):
typeName = CGTemplatedType("Nullable", typeName, isReference=True)
return typeName
def getUnionTypeTemplateVars(unionType, type, descriptorProvider, isReturnValue=False):
def getUnionTypeTemplateVars(unionType, type, descriptorProvider,
ownsMembers=False):
# For dictionaries and sequences we need to pass None as the failureCode
# for getJSToNativeConversionInfo.
# Also, for dictionaries we would need to handle conversion of
@ -6148,19 +6147,19 @@ def getUnionTypeTemplateVars(unionType, type, descriptorProvider, isReturnValue=
name = getUnionMemberName(type)
ctorNeedsCx = type.isSpiderMonkeyInterface() and not isReturnValue
ctorNeedsCx = type.isSpiderMonkeyInterface() and not ownsMembers
ctorArgs = "cx" if ctorNeedsCx else ""
tryNextCode = ("tryNext = true;\n"
"return true;")
if type.isGeckoInterface():
prefix = "" if isReturnValue else "mUnion."
prefix = "" if ownsMembers else "mUnion."
tryNextCode = ("if (%smType != %seUninitialized) {"
" %sDestroy%s();"
"}") % (prefix, prefix, prefix, name) + tryNextCode
conversionInfo = getJSToNativeConversionInfo(
type, descriptorProvider, failureCode=tryNextCode,
isDefinitelyObject=True, isInUnionReturnValue=isReturnValue,
isDefinitelyObject=True, isInOwningUnion=ownsMembers,
sourceDescription="member of %s" % unionType)
# This is ugly, but UnionMember needs to call a constructor with no
@ -6171,7 +6170,7 @@ def getUnionTypeTemplateVars(unionType, type, descriptorProvider, isReturnValue=
externalType = getUnionAccessorSignatureType(type, descriptorProvider).define()
if type.isObject():
if isReturnValue:
if ownsMembers:
body = ("mValue.mObject.SetValue(obj);\n"
"mType = eObject;")
else:
@ -6201,8 +6200,8 @@ def getUnionTypeTemplateVars(unionType, type, descriptorProvider, isReturnValue=
Argument("JS::Handle<JS::Value>", "value"),
Argument("JS::MutableHandle<JS::Value>", "pvalue"),
Argument("bool&", "tryNext")],
inline=not isReturnValue,
bodyInHeader=not isReturnValue,
inline=not ownsMembers,
bodyInHeader=not ownsMembers,
body=jsConversion.define())
return {
@ -6220,11 +6219,11 @@ def mapTemplate(template, templateVarArray):
templateVarArray)
class CGUnionStruct(CGThing):
def __init__(self, type, descriptorProvider, isReturnValue=False):
def __init__(self, type, descriptorProvider, ownsMembers=False):
CGThing.__init__(self)
self.type = type.unroll()
self.descriptorProvider = descriptorProvider
self.isReturnValue = isReturnValue
self.ownsMembers = ownsMembers
self.struct = self.getStruct()
def declare(self):
@ -6261,8 +6260,8 @@ class CGUnionStruct(CGThing):
for t in self.type.flatMemberTypes:
vars = getUnionTypeTemplateVars(self.type,
t, self.descriptorProvider,
isReturnValue=self.isReturnValue)
if vars["name"] != "Object" or self.isReturnValue:
ownsMembers=self.ownsMembers)
if vars["name"] != "Object" or self.ownsMembers:
body=string.Template("mType = e${name};\n"
"return mValue.m${name}.SetValue(${ctorArgs});").substitute(vars)
# bodyInHeader must be false for return values because they own
@ -6271,9 +6270,9 @@ class CGUnionStruct(CGThing):
methods.append(ClassMethod("SetAs" + vars["name"],
vars["structType"] + "&",
vars["ctorArgList"],
bodyInHeader=not self.isReturnValue,
bodyInHeader=not self.ownsMembers,
body=body))
if self.isReturnValue:
if self.ownsMembers:
methods.append(vars["setter"])
if t.isString():
methods.append(
@ -6290,7 +6289,7 @@ class CGUnionStruct(CGThing):
"void",
[],
visibility="private",
bodyInHeader=not self.isReturnValue,
bodyInHeader=not self.ownsMembers,
body=body))
body = string.Template("return mType == e${name};").substitute(vars)
methods.append(ClassMethod("Is" + vars["name"],
@ -6302,7 +6301,7 @@ class CGUnionStruct(CGThing):
body = string.Template('MOZ_ASSERT(Is${name}(), "Wrong type!");\n'
'return const_cast<${structType}&>(mValue.m${name}.Value());').substitute(vars)
if self.isReturnValue:
if self.ownsMembers:
getterReturnType = "%s&" % vars["structType"]
else:
getterReturnType = vars["externalType"]
@ -6322,7 +6321,7 @@ class CGUnionStruct(CGThing):
destructorCases.append(CGCase("e" + vars["name"],
CGGeneric("Destroy%s();"
% vars["name"])))
if self.isReturnValue and typeNeedsRooting(t, self.descriptorProvider):
if self.ownsMembers and typeNeedsRooting(t, self.descriptorProvider):
if t.isObject():
traceCases.append(
CGCase("e" + vars["name"],
@ -6345,7 +6344,7 @@ class CGUnionStruct(CGThing):
], body=CGSwitch("mType", toJSValCases,
default=CGGeneric("return false;")).define(), const=True))
if self.isReturnValue:
if self.ownsMembers:
if len(traceCases):
traceBody = CGSwitch("mType", traceCases,
default=CGGeneric("")).define()
@ -6355,8 +6354,8 @@ class CGUnionStruct(CGThing):
[Argument("JSTracer*", "trc")],
body=traceBody))
friend=" friend class %sArgument;\n" % str(self.type) if not self.isReturnValue else ""
return CGClass(str(self.type) + ("ReturnValue" if self.isReturnValue else ""),
friend=" friend class %sArgument;\n" % str(self.type) if not self.ownsMembers else ""
return CGClass(("Owning" if self.ownsMembers else "") + str(self.type),
members=members,
constructors=[ctor],
methods=methods,
@ -6364,7 +6363,7 @@ class CGUnionStruct(CGThing):
extradeclarations=friend,
destructor=ClassDestructor(visibility="public",
body=dtor,
bodyInHeader=not self.isReturnValue),
bodyInHeader=not self.ownsMembers),
enums=[ClassEnum("Type", enumValues, visibility="private")],
unions=[ClassUnion("Value", unionValues, visibility="private")])
@ -8180,7 +8179,7 @@ class CGDictionary(CGThing):
isMember="Dictionary",
isOptional=(not member.defaultValue),
# Set this to true so that we get an owning union.
isInUnionReturnValue=True,
isInOwningUnion=True,
defaultValue=member.defaultValue,
sourceDescription=("'%s' member of %s" %
(member.identifier.name,

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

@ -490,15 +490,16 @@ public:
void PassUnion(JSContext*, const ObjectOrLong& arg);
void PassUnionWithNullable(JSContext* cx, const ObjectOrNullOrLong& arg)
{
ObjectOrLong returnValue;
OwningObjectOrLong returnValue;
if (arg.IsNull()) {
} else if (arg.IsObject()) {
JS::Rooted<JSObject*> obj(cx, arg.GetAsObject());
JS_GetClass(obj);
//returnValue.SetAsObject(&obj);
returnValue.SetAsObject() = obj;
} else {
int32_t i = arg.GetAsLong();
i += 1;
returnValue.SetAsLong() = i;
}
}
void PassNullableUnion(JSContext*, const Nullable<ObjectOrLong>&);
@ -541,16 +542,16 @@ public:
void PassNullableUnionWithDefaultValue11(const Nullable<UnrestrictedFloatOrString>& arg);
void PassNullableUnionWithDefaultValue12(const Nullable<UnrestrictedFloatOrString>& arg);
void ReceiveUnion(CanvasPatternOrCanvasGradientReturnValue&);
void ReceiveUnion2(JSContext*, ObjectOrLongReturnValue&);
void ReceiveUnionContainingNull(CanvasPatternOrNullOrCanvasGradientReturnValue&);
void ReceiveNullableUnion(Nullable<CanvasPatternOrCanvasGradientReturnValue>&);
void ReceiveNullableUnion2(JSContext*, Nullable<ObjectOrLongReturnValue>&);
void GetWritableUnion(CanvasPatternOrCanvasGradientReturnValue&);
void ReceiveUnion(OwningCanvasPatternOrCanvasGradient&);
void ReceiveUnion2(JSContext*, OwningObjectOrLong&);
void ReceiveUnionContainingNull(OwningCanvasPatternOrNullOrCanvasGradient&);
void ReceiveNullableUnion(Nullable<OwningCanvasPatternOrCanvasGradient>&);
void ReceiveNullableUnion2(JSContext*, Nullable<OwningObjectOrLong>&);
void GetWritableUnion(OwningCanvasPatternOrCanvasGradient&);
void SetWritableUnion(const CanvasPatternOrCanvasGradient&);
void GetWritableUnionContainingNull(CanvasPatternOrNullOrCanvasGradientReturnValue&);
void GetWritableUnionContainingNull(OwningCanvasPatternOrNullOrCanvasGradient&);
void SetWritableUnionContainingNull(const CanvasPatternOrNullOrCanvasGradient&);
void GetWritableNullableUnion(Nullable<CanvasPatternOrCanvasGradientReturnValue>&);
void GetWritableNullableUnion(Nullable<OwningCanvasPatternOrCanvasGradient>&);
void SetWritableNullableUnion(const Nullable<CanvasPatternOrCanvasGradient>&);
// Date types

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

@ -32,7 +32,7 @@
USING_INDEXEDDB_NAMESPACE
using namespace mozilla::dom::indexedDB::ipc;
using mozilla::dom::Optional;
using mozilla::dom::IDBObjectStoreOrIDBIndexReturnValue;
using mozilla::dom::OwningIDBObjectStoreOrIDBIndex;
using mozilla::ErrorResult;
static_assert(sizeof(size_t) >= sizeof(IDBCursor::Direction),
@ -521,7 +521,7 @@ IDBCursor::GetDirection() const
void
IDBCursor::GetSource(IDBObjectStoreOrIDBIndexReturnValue& aSource) const
IDBCursor::GetSource(OwningIDBObjectStoreOrIDBIndex& aSource) const
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");

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

@ -24,7 +24,7 @@ class nsPIDOMWindow;
namespace mozilla {
namespace dom {
class IDBObjectStoreOrIDBIndexReturnValue;
class OwningIDBObjectStoreOrIDBIndex;
}
}
@ -166,7 +166,7 @@ public:
}
void
GetSource(IDBObjectStoreOrIDBIndexReturnValue& aSource) const;
GetSource(OwningIDBObjectStoreOrIDBIndex& aSource) const;
IDBCursorDirection
GetDirection() const;

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

@ -39,7 +39,7 @@ uint64_t gNextSerialNumber = 1;
} // anonymous namespace
USING_INDEXEDDB_NAMESPACE
using mozilla::dom::IDBObjectStoreOrIDBIndexOrIDBCursorReturnValue;
using mozilla::dom::OwningIDBObjectStoreOrIDBIndexOrIDBCursor;
IDBRequest::IDBRequest()
: mResultVal(JSVAL_VOID),
@ -130,7 +130,7 @@ IDBRequest::AssertSourceIsCorrect() const
#endif
void
IDBRequest::GetSource(Nullable<IDBObjectStoreOrIDBIndexOrIDBCursorReturnValue>& aSource) const
IDBRequest::GetSource(Nullable<OwningIDBObjectStoreOrIDBIndexOrIDBCursor>& aSource) const
{
MOZ_ASSERT(NS_IsMainThread());

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

@ -23,7 +23,7 @@ class nsPIDOMWindow;
namespace mozilla {
namespace dom {
class IDBObjectStoreOrIDBIndexOrIDBCursorReturnValue;
class OwningIDBObjectStoreOrIDBIndexOrIDBCursor;
}
}
@ -65,7 +65,7 @@ public:
// nsIDOMEventTarget
virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
void GetSource(Nullable<IDBObjectStoreOrIDBIndexOrIDBCursorReturnValue>& aSource) const;
void GetSource(Nullable<OwningIDBObjectStoreOrIDBIndexOrIDBCursor>& aSource) const;
void Reset();

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

@ -375,7 +375,7 @@ Telephony::SetSpeakerEnabled(bool aEnabled, ErrorResult& aRv)
}
void
Telephony::GetActive(Nullable<TelephonyCallOrTelephonyCallGroupReturnValue>& aValue)
Telephony::GetActive(Nullable<OwningTelephonyCallOrTelephonyCallGroup>& aValue)
{
if (mActiveCall) {
aValue.SetValue().SetAsTelephonyCall() = mActiveCall;

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

@ -20,7 +20,7 @@ class nsPIDOMWindow;
namespace mozilla {
namespace dom {
class TelephonyCallOrTelephonyCallGroupReturnValue;
class OwningTelephonyCallOrTelephonyCallGroup;
class Telephony MOZ_FINAL : public nsDOMEventTargetHelper
{
@ -84,7 +84,7 @@ public:
SetSpeakerEnabled(bool aEnabled, ErrorResult& aRv);
void
GetActive(Nullable<TelephonyCallOrTelephonyCallGroupReturnValue>& aValue);
GetActive(Nullable<OwningTelephonyCallOrTelephonyCallGroup>& aValue);
already_AddRefed<CallsList>
Calls() const;