From edf9f70a868932e22cb2c445f2d7d92adf425726 Mon Sep 17 00:00:00 2001 From: "peter%propagandism.org" Date: Thu, 9 Oct 2003 16:15:29 +0000 Subject: [PATCH] Move voidable string into xpcom. Part of fix for bug 221387 (XPathExpression.createExpression doesn't throw NAMESPACE_ERR). r=bz, sr=dbaron. git-svn-id: svn://10.0.0.236/trunk@147799 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js/src/xpconnect/src/xpcprivate.h | 35 ------------------- .../js/src/xpconnect/src/xpcwrappednative.cpp | 4 +-- mozilla/xpcom/string/obsolete/nsString2.cpp | 18 ++++++++++ mozilla/xpcom/string/obsolete/nsString2.h | 15 ++++++++ 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/mozilla/js/src/xpconnect/src/xpcprivate.h b/mozilla/js/src/xpconnect/src/xpcprivate.h index c839fcbf5a1..e8659c00205 100644 --- a/mozilla/js/src/xpconnect/src/xpcprivate.h +++ b/mozilla/js/src/xpconnect/src/xpcprivate.h @@ -2383,41 +2383,6 @@ protected: nsBufferHandle mBufferHandle; }; -// "voidable" nsAString implementation -class XPCVoidableString : public nsAutoString -{ -public: - XPCVoidableString() : - nsAutoString(), mIsVoid(PR_FALSE) - { } - - char_type* GetWritableFragment(nsWritableFragment& aFragment, - nsFragmentRequest aRequest, - PRUint32 aOffset) - { - mIsVoid = PR_FALSE; - - return nsAutoString::GetWritableFragment(aFragment, aRequest, aOffset); - } - - PRBool IsVoid() const - { - return mIsVoid; - } - - void SetIsVoid(PRBool aVoid) - { - if(aVoid && !mIsVoid) { - Truncate(); - } - - mIsVoid = aVoid; - } - -protected: - PRBool mIsVoid; -}; - // readable string conversions, static methods only class XPCStringConvert { diff --git a/mozilla/js/src/xpconnect/src/xpcwrappednative.cpp b/mozilla/js/src/xpconnect/src/xpcwrappednative.cpp index 5eb322a8ad4..4670b58e1dd 100644 --- a/mozilla/js/src/xpconnect/src/xpcwrappednative.cpp +++ b/mozilla/js/src/xpconnect/src/xpcwrappednative.cpp @@ -1606,7 +1606,7 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx, #define PARAM_AUTOSTRING_COUNT 1 #if PARAM_AUTOSTRING_COUNT - XPCVoidableString autoStrings[PARAM_AUTOSTRING_COUNT]; + nsVoidableString autoStrings[PARAM_AUTOSTRING_COUNT]; int autoStringIndex = 0; #endif @@ -1808,7 +1808,7 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx, } #endif dp->SetValIsDOMString(); - if(!(dp->val.p = new XPCVoidableString())) + if(!(dp->val.p = new nsVoidableString())) { JS_ReportOutOfMemory(ccx); goto done; diff --git a/mozilla/xpcom/string/obsolete/nsString2.cpp b/mozilla/xpcom/string/obsolete/nsString2.cpp index 79c07fcad5e..2b87c4d559e 100644 --- a/mozilla/xpcom/string/obsolete/nsString2.cpp +++ b/mozilla/xpcom/string/obsolete/nsString2.cpp @@ -1330,6 +1330,24 @@ nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() { AddNullTerminator(*this); } +PRUnichar* nsVoidableString::GetWritableFragment(nsWritableFragment& aFragment,nsFragmentRequest aRequest,PRUint32 aOffset) { + mIsVoid = PR_FALSE; + + return nsAutoString::GetWritableFragment(aFragment, aRequest, aOffset); +} + +PRBool nsVoidableString::IsVoid() const { + return mIsVoid; +} + +void nsVoidableString::SetIsVoid(PRBool aVoid) { + if (aVoid && !mIsVoid) { + Truncate(); + } + + mIsVoid = aVoid; +} + void NS_ConvertASCIItoUTF16::Init( const char* aCString, PRUint32 aLength ) { diff --git a/mozilla/xpcom/string/obsolete/nsString2.h b/mozilla/xpcom/string/obsolete/nsString2.h index 5b75f18b9d0..6f1b9dc5c98 100644 --- a/mozilla/xpcom/string/obsolete/nsString2.h +++ b/mozilla/xpcom/string/obsolete/nsString2.h @@ -482,6 +482,21 @@ public: PRUnichar mBuffer[kDefaultStringSize]; }; +class nsVoidableString : public nsAutoString +{ +public: + nsVoidableString() : + nsAutoString(), + mIsVoid(PR_FALSE) { } + + char_type* GetWritableFragment(nsWritableFragment& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset); + PRBool IsVoid() const; + void SetIsVoid(PRBool aVoid); + +protected: + PRBool mIsVoid; +}; + // NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsAutoString, PRUnichar) class NS_COM NS_ConvertASCIItoUTF16