parser/html/nsHtml5Atom.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/parser/html/nsHtml5Atom.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,89 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#include "nsHtml5Atom.h"
     1.9 +#include "nsAutoPtr.h"
    1.10 +#include "mozilla/unused.h"
    1.11 +
    1.12 +nsHtml5Atom::nsHtml5Atom(const nsAString& aString)
    1.13 +{
    1.14 +  mLength = aString.Length();
    1.15 +  nsRefPtr<nsStringBuffer> buf = nsStringBuffer::FromString(aString);
    1.16 +  if (buf) {
    1.17 +    mString = static_cast<char16_t*>(buf->Data());
    1.18 +  } else {
    1.19 +    buf = nsStringBuffer::Alloc((mLength + 1) * sizeof(char16_t));
    1.20 +    mString = static_cast<char16_t*>(buf->Data());
    1.21 +    CopyUnicodeTo(aString, 0, mString, mLength);
    1.22 +    mString[mLength] = char16_t(0);
    1.23 +  }
    1.24 +
    1.25 +  NS_ASSERTION(mString[mLength] == char16_t(0), "null terminated");
    1.26 +  NS_ASSERTION(buf && buf->StorageSize() >= (mLength+1) * sizeof(char16_t),
    1.27 +               "enough storage");
    1.28 +  NS_ASSERTION(Equals(aString), "correct data");
    1.29 +
    1.30 +  // Take ownership of buffer
    1.31 +  mozilla::unused << buf.forget();
    1.32 +}
    1.33 +
    1.34 +nsHtml5Atom::~nsHtml5Atom()
    1.35 +{
    1.36 +  nsStringBuffer::FromData(mString)->Release();
    1.37 +}
    1.38 +
    1.39 +NS_IMETHODIMP_(MozExternalRefCountType)
    1.40 +nsHtml5Atom::AddRef()
    1.41 +{
    1.42 +  NS_NOTREACHED("Attempt to AddRef an nsHtml5Atom.");
    1.43 +  return 2;
    1.44 +}
    1.45 +
    1.46 +NS_IMETHODIMP_(MozExternalRefCountType)
    1.47 +nsHtml5Atom::Release()
    1.48 +{
    1.49 +  NS_NOTREACHED("Attempt to Release an nsHtml5Atom.");
    1.50 +  return 1;
    1.51 +}
    1.52 +
    1.53 +NS_IMETHODIMP
    1.54 +nsHtml5Atom::QueryInterface(REFNSIID aIID, void** aInstancePtr)
    1.55 +{
    1.56 +  NS_NOTREACHED("Attempt to call QueryInterface an nsHtml5Atom.");
    1.57 +  return NS_ERROR_UNEXPECTED;
    1.58 +}
    1.59 +
    1.60 +NS_IMETHODIMP 
    1.61 +nsHtml5Atom::ScriptableToString(nsAString& aBuf)
    1.62 +{
    1.63 +  NS_NOTREACHED("Should not call ScriptableToString.");
    1.64 +  return NS_ERROR_NOT_IMPLEMENTED;
    1.65 +}
    1.66 +
    1.67 +NS_IMETHODIMP
    1.68 +nsHtml5Atom::ToUTF8String(nsACString& aReturn)
    1.69 +{
    1.70 +  NS_NOTREACHED("Should not attempt to convert to an UTF-8 string.");
    1.71 +  return NS_ERROR_NOT_IMPLEMENTED;
    1.72 +}
    1.73 +
    1.74 +NS_IMETHODIMP_(bool)
    1.75 +nsHtml5Atom::IsStaticAtom()
    1.76 +{
    1.77 +  return false;
    1.78 +}
    1.79 +
    1.80 +NS_IMETHODIMP
    1.81 +nsHtml5Atom::ScriptableEquals(const nsAString& aString, bool* aResult)
    1.82 +{
    1.83 +  NS_NOTREACHED("Should not call ScriptableEquals.");
    1.84 +  return NS_ERROR_NOT_IMPLEMENTED;
    1.85 +}
    1.86 +
    1.87 +NS_IMETHODIMP_(bool)
    1.88 +nsHtml5Atom::EqualsUTF8(const nsACString& aString)
    1.89 +{
    1.90 +  NS_NOTREACHED("Should not attempt to compare with an UTF-8 string.");
    1.91 +  return false;
    1.92 +}

mercurial