2012-05-29 19:52:43 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-09-18 19:13:10 +04:00
|
|
|
|
|
|
|
#include "nsHtml5Atom.h"
|
2013-04-22 15:13:22 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2014-03-15 23:00:16 +04:00
|
|
|
#include "mozilla/unused.h"
|
2009-09-18 19:13:10 +04:00
|
|
|
|
|
|
|
nsHtml5Atom::nsHtml5Atom(const nsAString& aString)
|
|
|
|
{
|
2010-03-08 18:45:00 +03:00
|
|
|
mLength = aString.Length();
|
2013-04-22 15:13:22 +04:00
|
|
|
nsRefPtr<nsStringBuffer> buf = nsStringBuffer::FromString(aString);
|
2010-03-08 18:45:00 +03:00
|
|
|
if (buf) {
|
2014-01-04 19:02:17 +04:00
|
|
|
mString = static_cast<char16_t*>(buf->Data());
|
2013-04-22 15:13:22 +04:00
|
|
|
} else {
|
2014-01-04 19:02:17 +04:00
|
|
|
buf = nsStringBuffer::Alloc((mLength + 1) * sizeof(char16_t));
|
|
|
|
mString = static_cast<char16_t*>(buf->Data());
|
2010-03-08 18:45:00 +03:00
|
|
|
CopyUnicodeTo(aString, 0, mString, mLength);
|
2014-01-04 19:02:17 +04:00
|
|
|
mString[mLength] = char16_t(0);
|
2010-03-08 18:45:00 +03:00
|
|
|
}
|
2010-03-08 19:03:55 +03:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
NS_ASSERTION(mString[mLength] == char16_t(0), "null terminated");
|
|
|
|
NS_ASSERTION(buf && buf->StorageSize() >= (mLength+1) * sizeof(char16_t),
|
2010-03-08 19:03:55 +03:00
|
|
|
"enough storage");
|
|
|
|
NS_ASSERTION(Equals(aString), "correct data");
|
2013-04-22 15:13:22 +04:00
|
|
|
|
|
|
|
// Take ownership of buffer
|
2014-03-15 23:00:16 +04:00
|
|
|
mozilla::unused << buf.forget();
|
2009-09-18 19:13:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsHtml5Atom::~nsHtml5Atom()
|
|
|
|
{
|
2010-03-08 18:45:00 +03:00
|
|
|
nsStringBuffer::FromData(mString)->Release();
|
2009-09-18 19:13:10 +04:00
|
|
|
}
|
|
|
|
|
2014-03-28 00:38:33 +04:00
|
|
|
NS_IMETHODIMP_(MozExternalRefCountType)
|
2009-09-18 19:13:10 +04:00
|
|
|
nsHtml5Atom::AddRef()
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Attempt to AddRef an nsHtml5Atom.");
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2014-03-28 00:38:33 +04:00
|
|
|
NS_IMETHODIMP_(MozExternalRefCountType)
|
2009-09-18 19:13:10 +04:00
|
|
|
nsHtml5Atom::Release()
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Attempt to Release an nsHtml5Atom.");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHtml5Atom::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Attempt to call QueryInterface an nsHtml5Atom.");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2010-03-08 18:45:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHtml5Atom::ScriptableToString(nsAString& aBuf)
|
2009-09-18 19:13:10 +04:00
|
|
|
{
|
2010-03-08 18:45:00 +03:00
|
|
|
NS_NOTREACHED("Should not call ScriptableToString.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2009-09-18 19:13:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHtml5Atom::ToUTF8String(nsACString& aReturn)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Should not attempt to convert to an UTF-8 string.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2009-09-18 19:13:10 +04:00
|
|
|
nsHtml5Atom::IsStaticAtom()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-09-18 19:13:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsHtml5Atom::ScriptableEquals(const nsAString& aString, bool* aResult)
|
2009-09-18 19:13:10 +04:00
|
|
|
{
|
2010-03-08 18:45:00 +03:00
|
|
|
NS_NOTREACHED("Should not call ScriptableEquals.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2009-09-18 19:13:10 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2010-03-08 18:45:00 +03:00
|
|
|
nsHtml5Atom::EqualsUTF8(const nsACString& aString)
|
2009-09-18 19:13:10 +04:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("Should not attempt to compare with an UTF-8 string.");
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-09-18 19:13:10 +04:00
|
|
|
}
|