From dbc95f00f4348cf4e425f1ecb3a0aeebcffbaedf Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Fri, 11 Oct 2013 13:38:28 -0400 Subject: [PATCH] Backed out changesets 46029c9fbfe4 and 6114164c3d1b (bug 925495) for OSX (at least) crashes. --- content/base/public/nsINode.h | 17 +-- dom/bindings/BindingDeclarations.h | 132 +++++++++++++++++- dom/bindings/DOMString.h | 149 --------------------- dom/bindings/moz.build | 1 - editor/libeditor/base/InsertElementTxn.cpp | 3 +- 5 files changed, 138 insertions(+), 164 deletions(-) delete mode 100644 dom/bindings/DOMString.h diff --git a/content/base/public/nsINode.h b/content/base/public/nsINode.h index b18db1bb0edd..cd97babda3f2 100644 --- a/content/base/public/nsINode.h +++ b/content/base/public/nsINode.h @@ -20,7 +20,6 @@ #include "mozilla/MemoryReporting.h" #include "mozilla/dom/EventTarget.h" // for base class #include "js/TypeDecls.h" // for Handle, Value, JSObject, JSContext -#include "mozilla/dom/DOMString.h" // Including 'windows.h' will #define GetClassInfo to something else. #ifdef XP_WIN @@ -1484,11 +1483,9 @@ public: */ uint32_t Length() const; - void GetNodeName(mozilla::dom::DOMString& aNodeName) + void GetNodeName(nsAString& aNodeName) const { - const nsString& nodeName = NodeName(); - aNodeName.SetStringBuffer(nsStringBuffer::FromString(nodeName), - nodeName.Length()); + aNodeName = NodeName(); } void GetBaseURI(nsAString& aBaseURI) const; bool HasChildNodes() const @@ -1539,11 +1536,9 @@ public: mNodeInfo->GetPrefix(aPrefix); } #endif - void GetLocalName(mozilla::dom::DOMString& aLocalName) + void GetLocalName(nsAString& aLocalName) { - const nsString& localName = LocalName(); - aLocalName.SetStringBuffer(nsStringBuffer::FromString(localName), - localName.Length()); + aLocalName = mNodeInfo->LocalName(); } // HasAttributes is defined inline in Element.h. bool HasAttributes() const; @@ -1761,7 +1756,7 @@ ToCanonicalSupports(nsINode* aPointer) #define NS_FORWARD_NSIDOMNODE_TO_NSINODE_HELPER(...) \ NS_IMETHOD GetNodeName(nsAString& aNodeName) __VA_ARGS__ \ { \ - aNodeName = nsINode::NodeName(); \ + nsINode::GetNodeName(aNodeName); \ return NS_OK; \ } \ NS_IMETHOD GetNodeValue(nsAString& aNodeValue) __VA_ARGS__ \ @@ -1863,7 +1858,7 @@ ToCanonicalSupports(nsINode* aPointer) } \ NS_IMETHOD GetLocalName(nsAString& aLocalName) __VA_ARGS__ \ { \ - aLocalName = nsINode::LocalName(); \ + nsINode::GetLocalName(aLocalName); \ return NS_OK; \ } \ using nsINode::HasAttributes; \ diff --git a/dom/bindings/BindingDeclarations.h b/dom/bindings/BindingDeclarations.h index 5c25c96c99db..835070fe9d41 100644 --- a/dom/bindings/BindingDeclarations.h +++ b/dom/bindings/BindingDeclarations.h @@ -18,9 +18,10 @@ #include "js/RootingAPI.h" #include "mozilla/Maybe.h" #include "nsCOMPtr.h" +#include "nsDOMString.h" +#include "nsStringBuffer.h" #include "nsTArray.h" #include "nsAutoPtr.h" // for nsRefPtr member variables -#include "mozilla/dom/DOMString.h" #include "mozilla/dom/OwningNonNull.h" class nsWrapperCache; @@ -89,6 +90,133 @@ protected: mutable nsCOMPtr mGlobalObjectRef; }; +/** + * A class for representing string return values. This can be either passed to + * callees that have an nsString or nsAString out param or passed to a callee + * that actually knows about this class and can work with it. Such a callee may + * call SetStringBuffer on this object, but only if it plans to keep holding a + * strong ref to the stringbuffer! + * + * The proper way to store a value in this class is to either to do nothing + * (which leaves this as an empty string), to call SetStringBuffer with a + * non-null stringbuffer, to call SetNull(), or to call AsAString() and set the + * value in the resulting nsString. These options are mutually exclusive! + * Don't do more than one of them. + * + * The proper way to extract a value is to check IsNull(). If not null, then + * check HasStringBuffer(). If that's true, check for a zero length, and if the + * length is nonzero call StringBuffer(). If the length is zero this is the + * empty string. If HasStringBuffer() returns false, call AsAString() and get + * the value from that. + */ +class MOZ_STACK_CLASS DOMString { +public: + DOMString() + : mStringBuffer(nullptr) + , mLength(0) + , mIsNull(false) + {} + ~DOMString() + { + MOZ_ASSERT(mString.empty() || !mStringBuffer, + "Shouldn't have both present!"); + } + + operator nsString&() + { + return AsAString(); + } + + nsString& AsAString() + { + MOZ_ASSERT(!mStringBuffer, "We already have a stringbuffer?"); + MOZ_ASSERT(!mIsNull, "We're already set as null"); + if (mString.empty()) { + mString.construct(); + } + return mString.ref(); + } + + bool HasStringBuffer() const + { + MOZ_ASSERT(mString.empty() || !mStringBuffer, + "Shouldn't have both present!"); + MOZ_ASSERT(!mIsNull, "Caller should have checked IsNull() first"); + return mString.empty(); + } + + // Get the stringbuffer. This can only be called if HasStringBuffer() + // returned true and StringBufferLength() is nonzero. If that's true, it will + // never return null. + nsStringBuffer* StringBuffer() const + { + MOZ_ASSERT(!mIsNull, "Caller should have checked IsNull() first"); + MOZ_ASSERT(HasStringBuffer(), + "Don't ask for the stringbuffer if we don't have it"); + MOZ_ASSERT(StringBufferLength() != 0, "Why are you asking for this?"); + MOZ_ASSERT(mStringBuffer, + "If our length is nonzero, we better have a stringbuffer."); + return mStringBuffer; + } + + // Get the length of the stringbuffer. Can only be called if + // HasStringBuffer(). + uint32_t StringBufferLength() const + { + MOZ_ASSERT(HasStringBuffer(), "Don't call this if there is no stringbuffer"); + return mLength; + } + + void SetStringBuffer(nsStringBuffer* aStringBuffer, uint32_t aLength) + { + MOZ_ASSERT(mString.empty(), "We already have a string?"); + MOZ_ASSERT(!mIsNull, "We're already set as null"); + MOZ_ASSERT(!mStringBuffer, "Setting stringbuffer twice?"); + MOZ_ASSERT(aStringBuffer, "Why are we getting null?"); + mStringBuffer = aStringBuffer; + mLength = aLength; + } + + void SetNull() + { + MOZ_ASSERT(!mStringBuffer, "Should have no stringbuffer if null"); + MOZ_ASSERT(mString.empty(), "Should have no string if null"); + mIsNull = true; + } + + bool IsNull() const + { + MOZ_ASSERT(!mStringBuffer || mString.empty(), + "How could we have a stringbuffer and a nonempty string?"); + return mIsNull || (!mString.empty() && mString.ref().IsVoid()); + } + + void ToString(nsAString& aString) + { + if (IsNull()) { + SetDOMStringToNull(aString); + } else if (HasStringBuffer()) { + if (StringBufferLength() == 0) { + aString.Truncate(); + } else { + StringBuffer()->ToString(StringBufferLength(), aString); + } + } else { + aString = AsAString(); + } + } + +private: + // We need to be able to act like a string as needed + Maybe mString; + + // For callees that know we exist, we can be a stringbuffer/length/null-flag + // triple. + nsStringBuffer* mStringBuffer; + uint32_t mLength; + bool mIsNull; +}; + // Class for representing optional arguments. template class Optional_base @@ -493,4 +621,4 @@ struct ParentObject { } // namespace dom } // namespace mozilla -#endif // mozilla_dom_BindingDeclarations_h__ +#endif // mozilla_dom_BindingDeclarations_h__ \ No newline at end of file diff --git a/dom/bindings/DOMString.h b/dom/bindings/DOMString.h deleted file mode 100644 index 7ba3f6a8f039..000000000000 --- a/dom/bindings/DOMString.h +++ /dev/null @@ -1,149 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* 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/. */ - -#ifndef mozilla_dom_DOMString_h -#define mozilla_dom_DOMString_h - -#include "nsStringGlue.h" -#include "nsStringBuffer.h" -#include "mozilla/Assertions.h" -#include "mozilla/Attributes.h" -#include "mozilla/Maybe.h" -#include "nsDOMString.h" - -namespace mozilla { -namespace dom { - -/** - * A class for representing string return values. This can be either passed to - * callees that have an nsString or nsAString out param or passed to a callee - * that actually knows about this class and can work with it. Such a callee may - * call SetStringBuffer on this object, but only if it plans to keep holding a - * strong ref to the stringbuffer! - * - * The proper way to store a value in this class is to either to do nothing - * (which leaves this as an empty string), to call SetStringBuffer with a - * non-null stringbuffer, to call SetNull(), or to call AsAString() and set the - * value in the resulting nsString. These options are mutually exclusive! - * Don't do more than one of them. - * - * The proper way to extract a value is to check IsNull(). If not null, then - * check HasStringBuffer(). If that's true, check for a zero length, and if the - * length is nonzero call StringBuffer(). If the length is zero this is the - * empty string. If HasStringBuffer() returns false, call AsAString() and get - * the value from that. - */ -class MOZ_STACK_CLASS DOMString { -public: - DOMString() - : mStringBuffer(nullptr) - , mLength(0) - , mIsNull(false) - {} - ~DOMString() - { - MOZ_ASSERT(mString.empty() || !mStringBuffer, - "Shouldn't have both present!"); - } - - operator nsString&() - { - return AsAString(); - } - - nsString& AsAString() - { - MOZ_ASSERT(!mStringBuffer, "We already have a stringbuffer?"); - MOZ_ASSERT(!mIsNull, "We're already set as null"); - if (mString.empty()) { - mString.construct(); - } - return mString.ref(); - } - - bool HasStringBuffer() const - { - MOZ_ASSERT(mString.empty() || !mStringBuffer, - "Shouldn't have both present!"); - MOZ_ASSERT(!mIsNull, "Caller should have checked IsNull() first"); - return mString.empty(); - } - - // Get the stringbuffer. This can only be called if HasStringBuffer() - // returned true and StringBufferLength() is nonzero. If that's true, it will - // never return null. - nsStringBuffer* StringBuffer() const - { - MOZ_ASSERT(!mIsNull, "Caller should have checked IsNull() first"); - MOZ_ASSERT(HasStringBuffer(), - "Don't ask for the stringbuffer if we don't have it"); - MOZ_ASSERT(StringBufferLength() != 0, "Why are you asking for this?"); - MOZ_ASSERT(mStringBuffer, - "If our length is nonzero, we better have a stringbuffer."); - return mStringBuffer; - } - - // Get the length of the stringbuffer. Can only be called if - // HasStringBuffer(). - uint32_t StringBufferLength() const - { - MOZ_ASSERT(HasStringBuffer(), "Don't call this if there is no stringbuffer"); - return mLength; - } - - void SetStringBuffer(nsStringBuffer* aStringBuffer, uint32_t aLength) - { - MOZ_ASSERT(mString.empty(), "We already have a string?"); - MOZ_ASSERT(!mIsNull, "We're already set as null"); - MOZ_ASSERT(!mStringBuffer, "Setting stringbuffer twice?"); - MOZ_ASSERT(aStringBuffer, "Why are we getting null?"); - mStringBuffer = aStringBuffer; - mLength = aLength; - } - - void SetNull() - { - MOZ_ASSERT(!mStringBuffer, "Should have no stringbuffer if null"); - MOZ_ASSERT(mString.empty(), "Should have no string if null"); - mIsNull = true; - } - - bool IsNull() const - { - MOZ_ASSERT(!mStringBuffer || mString.empty(), - "How could we have a stringbuffer and a nonempty string?"); - return mIsNull || (!mString.empty() && mString.ref().IsVoid()); - } - - void ToString(nsAString& aString) - { - if (IsNull()) { - SetDOMStringToNull(aString); - } else if (HasStringBuffer()) { - if (StringBufferLength() == 0) { - aString.Truncate(); - } else { - StringBuffer()->ToString(StringBufferLength(), aString); - } - } else { - aString = AsAString(); - } - } - -private: - // We need to be able to act like a string as needed - Maybe mString; - - // For callees that know we exist, we can be a stringbuffer/length/null-flag - // triple. - nsStringBuffer* mStringBuffer; - uint32_t mLength; - bool mIsNull; -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_DOMString_h diff --git a/dom/bindings/moz.build b/dom/bindings/moz.build index 6f8ddfaa45f0..22ebc26e57d2 100644 --- a/dom/bindings/moz.build +++ b/dom/bindings/moz.build @@ -19,7 +19,6 @@ EXPORTS.mozilla.dom += [ 'CallbackObject.h', 'DOMJSClass.h', 'DOMJSProxyHandler.h', - 'DOMString.h', 'Date.h', 'Errors.msg', 'Exceptions.h', diff --git a/editor/libeditor/base/InsertElementTxn.cpp b/editor/libeditor/base/InsertElementTxn.cpp index 5d5df7ed108b..6a08f5139ffe 100644 --- a/editor/libeditor/base/InsertElementTxn.cpp +++ b/editor/libeditor/base/InsertElementTxn.cpp @@ -62,7 +62,8 @@ NS_IMETHODIMP InsertElementTxn::DoTransaction(void) { nsCOMPtrnodeAsContent = do_QueryInterface(mNode); nsCOMPtrparentAsContent = do_QueryInterface(mParent); - nsString namestr = mNode->NodeName(); + nsString namestr; + mNode->GetNodeName(namestr); char* nodename = ToNewCString(namestr); printf("%p Do Insert Element of %p <%s> into parent %p at offset %d\n", static_cast(this),