Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "nsHtml5Atom.h" |
michael@0 | 6 | #include "nsAutoPtr.h" |
michael@0 | 7 | #include "mozilla/unused.h" |
michael@0 | 8 | |
michael@0 | 9 | nsHtml5Atom::nsHtml5Atom(const nsAString& aString) |
michael@0 | 10 | { |
michael@0 | 11 | mLength = aString.Length(); |
michael@0 | 12 | nsRefPtr<nsStringBuffer> buf = nsStringBuffer::FromString(aString); |
michael@0 | 13 | if (buf) { |
michael@0 | 14 | mString = static_cast<char16_t*>(buf->Data()); |
michael@0 | 15 | } else { |
michael@0 | 16 | buf = nsStringBuffer::Alloc((mLength + 1) * sizeof(char16_t)); |
michael@0 | 17 | mString = static_cast<char16_t*>(buf->Data()); |
michael@0 | 18 | CopyUnicodeTo(aString, 0, mString, mLength); |
michael@0 | 19 | mString[mLength] = char16_t(0); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | NS_ASSERTION(mString[mLength] == char16_t(0), "null terminated"); |
michael@0 | 23 | NS_ASSERTION(buf && buf->StorageSize() >= (mLength+1) * sizeof(char16_t), |
michael@0 | 24 | "enough storage"); |
michael@0 | 25 | NS_ASSERTION(Equals(aString), "correct data"); |
michael@0 | 26 | |
michael@0 | 27 | // Take ownership of buffer |
michael@0 | 28 | mozilla::unused << buf.forget(); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | nsHtml5Atom::~nsHtml5Atom() |
michael@0 | 32 | { |
michael@0 | 33 | nsStringBuffer::FromData(mString)->Release(); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | NS_IMETHODIMP_(MozExternalRefCountType) |
michael@0 | 37 | nsHtml5Atom::AddRef() |
michael@0 | 38 | { |
michael@0 | 39 | NS_NOTREACHED("Attempt to AddRef an nsHtml5Atom."); |
michael@0 | 40 | return 2; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | NS_IMETHODIMP_(MozExternalRefCountType) |
michael@0 | 44 | nsHtml5Atom::Release() |
michael@0 | 45 | { |
michael@0 | 46 | NS_NOTREACHED("Attempt to Release an nsHtml5Atom."); |
michael@0 | 47 | return 1; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | NS_IMETHODIMP |
michael@0 | 51 | nsHtml5Atom::QueryInterface(REFNSIID aIID, void** aInstancePtr) |
michael@0 | 52 | { |
michael@0 | 53 | NS_NOTREACHED("Attempt to call QueryInterface an nsHtml5Atom."); |
michael@0 | 54 | return NS_ERROR_UNEXPECTED; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | NS_IMETHODIMP |
michael@0 | 58 | nsHtml5Atom::ScriptableToString(nsAString& aBuf) |
michael@0 | 59 | { |
michael@0 | 60 | NS_NOTREACHED("Should not call ScriptableToString."); |
michael@0 | 61 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | NS_IMETHODIMP |
michael@0 | 65 | nsHtml5Atom::ToUTF8String(nsACString& aReturn) |
michael@0 | 66 | { |
michael@0 | 67 | NS_NOTREACHED("Should not attempt to convert to an UTF-8 string."); |
michael@0 | 68 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | NS_IMETHODIMP_(bool) |
michael@0 | 72 | nsHtml5Atom::IsStaticAtom() |
michael@0 | 73 | { |
michael@0 | 74 | return false; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | NS_IMETHODIMP |
michael@0 | 78 | nsHtml5Atom::ScriptableEquals(const nsAString& aString, bool* aResult) |
michael@0 | 79 | { |
michael@0 | 80 | NS_NOTREACHED("Should not call ScriptableEquals."); |
michael@0 | 81 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | NS_IMETHODIMP_(bool) |
michael@0 | 85 | nsHtml5Atom::EqualsUTF8(const nsACString& aString) |
michael@0 | 86 | { |
michael@0 | 87 | NS_NOTREACHED("Should not attempt to compare with an UTF-8 string."); |
michael@0 | 88 | return false; |
michael@0 | 89 | } |