michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsHtml5Atom.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "mozilla/unused.h" michael@0: michael@0: nsHtml5Atom::nsHtml5Atom(const nsAString& aString) michael@0: { michael@0: mLength = aString.Length(); michael@0: nsRefPtr buf = nsStringBuffer::FromString(aString); michael@0: if (buf) { michael@0: mString = static_cast(buf->Data()); michael@0: } else { michael@0: buf = nsStringBuffer::Alloc((mLength + 1) * sizeof(char16_t)); michael@0: mString = static_cast(buf->Data()); michael@0: CopyUnicodeTo(aString, 0, mString, mLength); michael@0: mString[mLength] = char16_t(0); michael@0: } michael@0: michael@0: NS_ASSERTION(mString[mLength] == char16_t(0), "null terminated"); michael@0: NS_ASSERTION(buf && buf->StorageSize() >= (mLength+1) * sizeof(char16_t), michael@0: "enough storage"); michael@0: NS_ASSERTION(Equals(aString), "correct data"); michael@0: michael@0: // Take ownership of buffer michael@0: mozilla::unused << buf.forget(); michael@0: } michael@0: michael@0: nsHtml5Atom::~nsHtml5Atom() michael@0: { michael@0: nsStringBuffer::FromData(mString)->Release(); michael@0: } michael@0: michael@0: NS_IMETHODIMP_(MozExternalRefCountType) michael@0: nsHtml5Atom::AddRef() michael@0: { michael@0: NS_NOTREACHED("Attempt to AddRef an nsHtml5Atom."); michael@0: return 2; michael@0: } michael@0: michael@0: NS_IMETHODIMP_(MozExternalRefCountType) michael@0: nsHtml5Atom::Release() michael@0: { michael@0: NS_NOTREACHED("Attempt to Release an nsHtml5Atom."); michael@0: return 1; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsHtml5Atom::QueryInterface(REFNSIID aIID, void** aInstancePtr) michael@0: { michael@0: NS_NOTREACHED("Attempt to call QueryInterface an nsHtml5Atom."); michael@0: return NS_ERROR_UNEXPECTED; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsHtml5Atom::ScriptableToString(nsAString& aBuf) michael@0: { michael@0: NS_NOTREACHED("Should not call ScriptableToString."); michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsHtml5Atom::ToUTF8String(nsACString& aReturn) michael@0: { michael@0: NS_NOTREACHED("Should not attempt to convert to an UTF-8 string."); michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: NS_IMETHODIMP_(bool) michael@0: nsHtml5Atom::IsStaticAtom() michael@0: { michael@0: return false; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsHtml5Atom::ScriptableEquals(const nsAString& aString, bool* aResult) michael@0: { michael@0: NS_NOTREACHED("Should not call ScriptableEquals."); michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: NS_IMETHODIMP_(bool) michael@0: nsHtml5Atom::EqualsUTF8(const nsACString& aString) michael@0: { michael@0: NS_NOTREACHED("Should not attempt to compare with an UTF-8 string."); michael@0: return false; michael@0: }