mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-08-15 08:53:07 +09:00
Issue #80 - De-unify dom/xhr
This commit is contained in:
parent
3751ad3739
commit
e96e560f35
4 changed files with 98 additions and 92 deletions
|
|
@ -12,97 +12,6 @@
|
|||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class XMLHttpRequestStringBuffer final
|
||||
{
|
||||
friend class XMLHttpRequestStringWriterHelper;
|
||||
friend class XMLHttpRequestStringSnapshotReaderHelper;
|
||||
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(XMLHttpRequestStringBuffer)
|
||||
NS_DECL_OWNINGTHREAD
|
||||
|
||||
XMLHttpRequestStringBuffer()
|
||||
: mMutex("XMLHttpRequestStringBuffer::mMutex")
|
||||
{
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Length()
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
return mData.Length();
|
||||
}
|
||||
|
||||
uint32_t
|
||||
UnsafeLength() const
|
||||
{
|
||||
return mData.Length();
|
||||
}
|
||||
|
||||
void
|
||||
Append(const nsAString& aString)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestStringBuffer);
|
||||
|
||||
MutexAutoLock lock(mMutex);
|
||||
mData.Append(aString);
|
||||
}
|
||||
|
||||
MOZ_MUST_USE bool
|
||||
GetAsString(nsAString& aString)
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
return aString.Assign(mData, mozilla::fallible);
|
||||
}
|
||||
|
||||
size_t
|
||||
SizeOfThis(MallocSizeOf aMallocSizeOf) const
|
||||
{
|
||||
return mData.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
||||
}
|
||||
|
||||
MOZ_MUST_USE bool
|
||||
GetAsString(DOMString& aString, uint32_t aLength)
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
MOZ_ASSERT(aLength <= mData.Length());
|
||||
nsStringBuffer* buf = nsStringBuffer::FromString(mData);
|
||||
if (buf) {
|
||||
// We have to use SetEphemeralStringBuffer, because once we release our
|
||||
// mutex mData can get mutated from some other thread while the DOMString
|
||||
// is still alive.
|
||||
aString.SetEphemeralStringBuffer(buf, aLength);
|
||||
return true;
|
||||
}
|
||||
|
||||
// We can get here if mData is empty. In that case it won't have an
|
||||
// nsStringBuffer....
|
||||
MOZ_ASSERT(mData.IsEmpty());
|
||||
return aString.AsAString().Assign(mData.BeginReading(), aLength,
|
||||
mozilla::fallible);
|
||||
}
|
||||
|
||||
void
|
||||
CreateSnapshot(XMLHttpRequestStringSnapshot& aSnapshot)
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
aSnapshot.Set(this, mData.Length());
|
||||
}
|
||||
|
||||
private:
|
||||
~XMLHttpRequestStringBuffer()
|
||||
{}
|
||||
|
||||
nsString& UnsafeData()
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
|
||||
Mutex mMutex;
|
||||
|
||||
// The following member variable is protected by mutex.
|
||||
nsString mData;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLHttpRequestString
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue