Bug 836920. Move dom::Optional<> and dom::Sequence to BindingDeclarations.h so using dictionaries in interfaces whose name comes before 'PrimitiveConversions' alphabetically does not break. r=peterv

All the code is just moving except the Optional<nsAString>::operator=
that takes a FakeDependentString.  That had to be changed so it has no
dependency on the actual definition of FakeDependentString.
This commit is contained in:
Boris Zbarsky 2013-02-06 09:56:15 +00:00
Родитель 82c6f6b490
Коммит 30eb9315d6
2 изменённых файлов: 116 добавлений и 91 удалений

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

@ -19,6 +19,7 @@
#include "nsCOMPtr.h"
#include "nsDOMString.h"
#include "nsStringBuffer.h"
#include "nsTArray.h"
namespace mozilla {
namespace dom {
@ -212,6 +213,119 @@ private:
bool mIsNull;
};
// Class for representing optional arguments.
template<typename T>
class Optional
{
public:
Optional()
{}
bool WasPassed() const
{
return !mImpl.empty();
}
void Construct()
{
mImpl.construct();
}
template <class T1>
void Construct(const T1 &t1)
{
mImpl.construct(t1);
}
template <class T1, class T2>
void Construct(const T1 &t1, const T2 &t2)
{
mImpl.construct(t1, t2);
}
const T& Value() const
{
return mImpl.ref();
}
T& Value()
{
return mImpl.ref();
}
// If we ever decide to add conversion operators for optional arrays
// like the ones Nullable has, we'll need to ensure that Maybe<> has
// the boolean before the actual data.
private:
// Forbid copy-construction and assignment
Optional(const Optional& other) MOZ_DELETE;
const Optional &operator=(const Optional &other) MOZ_DELETE;
Maybe<T> mImpl;
};
// Specialization for strings.
// XXXbz we can't pull in FakeDependentString here, because it depends on
// internal strings. So we just have to forward-declare it and reimplement its
// ToAStringPtr.
class FakeDependentString;
template<>
class Optional<nsAString>
{
public:
Optional() : mPassed(false) {}
bool WasPassed() const
{
return mPassed;
}
void operator=(const nsAString* str)
{
MOZ_ASSERT(str);
mStr = str;
mPassed = true;
}
// If this code ever goes away, remove the comment pointing to it in the
// FakeDependentString class in BindingUtils.h.
void operator=(const FakeDependentString* str)
{
MOZ_ASSERT(str);
mStr = reinterpret_cast<const nsDependentString*>(str);
mPassed = true;
}
const nsAString& Value() const
{
MOZ_ASSERT(WasPassed());
return *mStr;
}
private:
// Forbid copy-construction and assignment
Optional(const Optional& other) MOZ_DELETE;
const Optional &operator=(const Optional &other) MOZ_DELETE;
bool mPassed;
const nsAString* mStr;
};
// Class for representing sequences in arguments. We use an auto array that can
// hold 16 elements, to avoid having to allocate in common cases. This needs to
// be fallible because web content controls the length of the array, and can
// easily try to create very large lengths.
template<typename T>
class Sequence : public AutoFallibleTArray<T, 16>
{
public:
Sequence() : AutoFallibleTArray<T, 16>()
{}
};
} // namespace dom
} // namespace mozilla

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

@ -1434,6 +1434,8 @@ struct FakeDependentString {
mFlags |= nsDependentString::F_VOIDED;
}
// If this ever changes, change the corresponding code in the
// Optional<nsAString> specialization as well.
const nsAString* ToAStringPtr() const {
return reinterpret_cast<const nsDependentString*>(this);
}
@ -1526,97 +1528,6 @@ ConvertJSValueToString(JSContext* cx, const JS::Value& v, JS::Value* pval,
return true;
}
// Class for representing optional arguments.
template<typename T>
class Optional {
public:
Optional() {}
bool WasPassed() const {
return !mImpl.empty();
}
void Construct() {
mImpl.construct();
}
template <class T1>
void Construct(const T1 &t1) {
mImpl.construct(t1);
}
template <class T1, class T2>
void Construct(const T1 &t1, const T2 &t2) {
mImpl.construct(t1, t2);
}
const T& Value() const {
return mImpl.ref();
}
T& Value() {
return mImpl.ref();
}
// If we ever decide to add conversion operators for optional arrays
// like the ones Nullable has, we'll need to ensure that Maybe<> has
// the boolean before the actual data.
private:
// Forbid copy-construction and assignment
Optional(const Optional& other) MOZ_DELETE;
const Optional &operator=(const Optional &other) MOZ_DELETE;
Maybe<T> mImpl;
};
// Specialization for strings.
template<>
class Optional<nsAString> {
public:
Optional() : mPassed(false) {}
bool WasPassed() const {
return mPassed;
}
void operator=(const nsAString* str) {
MOZ_ASSERT(str);
mStr = str;
mPassed = true;
}
void operator=(const FakeDependentString* str) {
MOZ_ASSERT(str);
mStr = str->ToAStringPtr();
mPassed = true;
}
const nsAString& Value() const {
MOZ_ASSERT(WasPassed());
return *mStr;
}
private:
// Forbid copy-construction and assignment
Optional(const Optional& other) MOZ_DELETE;
const Optional &operator=(const Optional &other) MOZ_DELETE;
bool mPassed;
const nsAString* mStr;
};
// Class for representing sequences in arguments. We use an auto array that can
// hold 16 elements, to avoid having to allocate in common cases. This needs to
// be fallible because web content controls the length of the array, and can
// easily try to create very large lengths.
template<typename T>
class Sequence : public AutoFallibleTArray<T, 16>
{
public:
Sequence() : AutoFallibleTArray<T, 16>() {}
};
// Class for holding the type of members of a union. The union type has an enum
// to keep track of which of its UnionMembers has been constructed.
template<class T>