зеркало из https://github.com/mozilla/pjs.git
Bug 755636 part 2. Add some tests (not exhaustive!) for sequence codegen and fix the bugs they uncover. r=peterv
This commit is contained in:
Родитель
b5f8f8c87f
Коммит
44d2171a91
|
@ -95,9 +95,10 @@ UnwrapDOMObject(JSObject* obj, const js::Class* clasp)
|
|||
// Some callers don't want to set an exception when unwrappin fails
|
||||
// (for example, overload resolution uses unwrapping to tell what sort
|
||||
// of thing it's looking at).
|
||||
template <prototypes::ID PrototypeID, class T>
|
||||
// U must be something that a T* can be assigned to (e.g. T* or an nsRefPtr<T>).
|
||||
template <prototypes::ID PrototypeID, class T, typename U>
|
||||
inline nsresult
|
||||
UnwrapObject(JSContext* cx, JSObject* obj, T** value)
|
||||
UnwrapObject(JSContext* cx, JSObject* obj, U& value)
|
||||
{
|
||||
/* First check to see whether we have a DOM object */
|
||||
JSClass* clasp = js::GetObjectJSClass(obj);
|
||||
|
@ -128,7 +129,7 @@ UnwrapObject(JSContext* cx, JSObject* obj, T** value)
|
|||
DOMJSClass* domClass = DOMJSClass::FromJSClass(clasp);
|
||||
if (domClass->mInterfaceChain[PrototypeTraits<PrototypeID>::Depth] ==
|
||||
PrototypeID) {
|
||||
*value = UnwrapDOMObject<T>(obj, clasp);
|
||||
value = UnwrapDOMObject<T>(obj, clasp);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -188,9 +189,10 @@ IsPlatformObject(JSContext* cx, JSObject* obj)
|
|||
JS_IsArrayBufferObject(obj, cx);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
// U must be something that a T* can be assigned to (e.g. T* or an nsRefPtr<T>).
|
||||
template <class T, typename U>
|
||||
inline nsresult
|
||||
UnwrapObject(JSContext* cx, JSObject* obj, T* *value)
|
||||
UnwrapObject(JSContext* cx, JSObject* obj, U& value)
|
||||
{
|
||||
return UnwrapObject<static_cast<prototypes::ID>(
|
||||
PrototypeIDMap<T>::PrototypeID)>(cx, obj, value);
|
||||
|
|
|
@ -246,6 +246,10 @@ DOMInterfaces = {
|
|||
'nativeType': 'mozilla::dom::TestInterface',
|
||||
'headerFile': 'TestBindingHeader.h',
|
||||
'register': False,
|
||||
'resultNotAddRefed': [ 'receiveWeakSelf', 'receiveWeakNullableSelf' ]
|
||||
'resultNotAddRefed': [ 'receiveWeakSelf', 'receiveWeakNullableSelf',
|
||||
'receiveWeakCastableObjectSequence',
|
||||
'receiveWeakNullableCastableObjectSequence',
|
||||
'receiveWeakCastableObjectNullableSequence',
|
||||
'receiveWeakNullableCastableObjectNullableSequence' ]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1237,7 +1237,7 @@ class CastableObjectUnwrapper():
|
|||
def __str__(self):
|
||||
return string.Template(
|
||||
"""{
|
||||
nsresult rv = UnwrapObject<${protoID}>(cx, ${source}, ${target});
|
||||
nsresult rv = UnwrapObject<${protoID}, ${type}>(cx, ${source}, ${target});
|
||||
if (NS_FAILED(rv)) {
|
||||
${codeOnFailure}
|
||||
}
|
||||
|
@ -1459,7 +1459,6 @@ for (uint32_t i = 0; i < length; ++i) {
|
|||
# tuple.
|
||||
# - holderType is the type we want to return as the third element
|
||||
# of our tuple.
|
||||
# - target is where a pointer to the object is being stored
|
||||
|
||||
# Set up some sensible defaults for these things insofar as we can.
|
||||
holderType = None
|
||||
|
@ -1468,13 +1467,11 @@ for (uint32_t i = 0; i < length; ++i) {
|
|||
declType = "nsRefPtr<" + typeName + ">"
|
||||
else:
|
||||
declType = typePtr
|
||||
target = "&${declName}"
|
||||
else:
|
||||
if forceOwningType:
|
||||
declType = "OwningNonNull<" + typeName + ">"
|
||||
else:
|
||||
declType = "NonNull<" + typeName + ">"
|
||||
target = "${declName}.Slot()"
|
||||
|
||||
templateBody = ""
|
||||
if descriptor.castable:
|
||||
|
@ -1482,13 +1479,13 @@ for (uint32_t i = 0; i < length; ++i) {
|
|||
templateBody += str(CastableObjectUnwrapper(
|
||||
descriptor,
|
||||
"&${val}.toObject()",
|
||||
target,
|
||||
"${declName}",
|
||||
failureCode))
|
||||
else:
|
||||
templateBody += str(FailureFatalCastableObjectUnwrapper(
|
||||
descriptor,
|
||||
"&${val}.toObject()",
|
||||
target))
|
||||
"${declName}"))
|
||||
elif descriptor.interface.isCallback():
|
||||
templateBody += str(CallbackObjectUnwrapper(
|
||||
descriptor,
|
||||
|
@ -2006,10 +2003,11 @@ def getRetvalDeclarationForType(returnType, descriptorProvider,
|
|||
nullable = returnType.nullable()
|
||||
if nullable:
|
||||
returnType = returnType.inner
|
||||
# Assume no need to addref for now
|
||||
# If our result is already addrefed, use the right type in the
|
||||
# sequence argument here.
|
||||
(result, needsCx) = getRetvalDeclarationForType(returnType.inner,
|
||||
descriptorProvider,
|
||||
False)
|
||||
resultAlreadyAddRefed)
|
||||
result = CGWrapper(result, pre="nsTArray< ", post=" >")
|
||||
if nullable:
|
||||
result = CGWrapper(result, pre="Nullable< ", post=" >")
|
||||
|
@ -2561,7 +2559,7 @@ class CGAbstractBindingMethod(CGAbstractStaticMethod):
|
|||
def definition_body(self):
|
||||
unwrapThis = CGIndenter(CGGeneric(
|
||||
str(FailureFatalCastableObjectUnwrapper(self.descriptor,
|
||||
"obj", "&self"))))
|
||||
"obj", "self"))))
|
||||
return CGList([ self.getThis(), unwrapThis,
|
||||
self.generate_code() ], "\n").define()
|
||||
|
||||
|
|
|
@ -84,7 +84,39 @@ public:
|
|||
void SetNonNullSelf(TestInterface&, ErrorResult&);
|
||||
already_AddRefed<TestInterface> GetNullableSelf(ErrorResult&);
|
||||
void SetNullableSelf(TestInterface*, ErrorResult&);
|
||||
|
||||
|
||||
void ReceiveSequence(nsTArray<int32_t>&, ErrorResult&);
|
||||
void ReceiveNullableSequence(Nullable< nsTArray<int32_t> >&, ErrorResult&);
|
||||
void PassSequence(const Sequence<int32_t> &, ErrorResult&);
|
||||
void PassNullableSequence(const Nullable< Sequence<int32_t> >&, ErrorResult&);
|
||||
// XXXbz is this the right signature???? For all the sequence
|
||||
// "receive" methods here! Shouldn't we take strong refs?
|
||||
void ReceiveCastableObjectSequence(nsTArray< nsRefPtr<TestInterface> > &,
|
||||
ErrorResult&);
|
||||
void ReceiveNullableCastableObjectSequence(nsTArray< nsRefPtr<TestInterface> > &,
|
||||
ErrorResult&);
|
||||
void ReceiveCastableObjectNullableSequence(Nullable< nsTArray< nsRefPtr<TestInterface> > >&,
|
||||
ErrorResult&);
|
||||
void ReceiveWeakNullableCastableObjectNullableSequence(Nullable< nsTArray< nsRefPtr<TestInterface> > >&,
|
||||
ErrorResult&);
|
||||
void ReceiveNullableCastableObjectNullableSequence(Nullable< nsTArray< nsRefPtr<TestInterface> > >&,
|
||||
ErrorResult&);
|
||||
void ReceiveWeakCastableObjectSequence(nsTArray<TestInterface*> &,
|
||||
ErrorResult&);
|
||||
void ReceiveWeakNullableCastableObjectSequence(nsTArray<TestInterface*> &,
|
||||
ErrorResult&);
|
||||
void ReceiveWeakCastableObjectNullableSequence(Nullable< nsTArray<TestInterface*> >&,
|
||||
ErrorResult&);
|
||||
void ReceiveWeakNullableCastableObjectNullableSequence(Nullable< nsTArray<TestInterface*> >&,
|
||||
ErrorResult&);
|
||||
void PassCastableObjectSequence(const Sequence< OwningNonNull<TestInterface> >&,
|
||||
ErrorResult&);
|
||||
void PassNullableCastableObjectSequence(const Sequence< nsRefPtr<TestInterface> > &,
|
||||
ErrorResult&);
|
||||
void PassCastableObjectNullableSequence(const Nullable< Sequence< OwningNonNull<TestInterface> > >&,
|
||||
ErrorResult&);
|
||||
void PassNullableCastableObjectNullableSequence(const Nullable< Sequence< nsRefPtr<TestInterface> > >&,
|
||||
ErrorResult&);
|
||||
private:
|
||||
// We add signatures here that _could_ start matching if the codegen
|
||||
// got data types wrong. That way if it ever does we'll have a call
|
||||
|
@ -136,6 +168,9 @@ private:
|
|||
void SetWritableUnsignedLongLong(T, ErrorResult&) MOZ_DELETE;
|
||||
template<typename T>
|
||||
void PassUnsignedLongLong(T, ErrorResult&) MOZ_DELETE;
|
||||
|
||||
void PassSequence(Sequence<int32_t> &, ErrorResult&) MOZ_DELETE;
|
||||
void PassNullableSequence(Nullable< Sequence<int32_t> >&, ErrorResult&) MOZ_DELETE;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -58,7 +58,24 @@ interface TestInterface {
|
|||
// A version we can use to test for the exact type passed in
|
||||
void passSelf2(TestInterface arg);
|
||||
void passNullableSelf(TestInterface? arg);
|
||||
|
||||
attribute TestInterface nonNullSelf;
|
||||
attribute TestInterface? nullableSelf;
|
||||
|
||||
// Sequence types
|
||||
sequence<long> receiveSequence();
|
||||
sequence<long>? receiveNullableSequence();
|
||||
void passSequence(sequence<long> arg);
|
||||
void passNullableSequence(sequence<long>? arg);
|
||||
sequence<TestInterface> receiveCastableObjectSequence();
|
||||
sequence<TestInterface?> receiveNullableCastableObjectSequence();
|
||||
sequence<TestInterface>? receiveCastableObjectNullableSequence();
|
||||
sequence<TestInterface?>? receiveNullableCastableObjectNullableSequence();
|
||||
sequence<TestInterface> receiveWeakCastableObjectSequence();
|
||||
sequence<TestInterface?> receiveWeakNullableCastableObjectSequence();
|
||||
sequence<TestInterface>? receiveWeakCastableObjectNullableSequence();
|
||||
sequence<TestInterface?>? receiveWeakNullableCastableObjectNullableSequence();
|
||||
void passCastableObjectSequence(sequence<TestInterface> arg);
|
||||
void passNullableCastableObjectSequence(sequence<TestInterface?> arg);
|
||||
void passCastableObjectNullableSequence(sequence<TestInterface>? arg);
|
||||
void passNullableCastableObjectNullableSequence(sequence<TestInterface?>? arg);
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче