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