From c0fdb39f76965b974447f4acefeb6fdafad0c0e5 Mon Sep 17 00:00:00 2001 From: "jbetak%netscape.com" Date: Tue, 2 May 2000 05:08:39 +0000 Subject: [PATCH] 37408 String bundle doesn't offer a scriptable enumerator r=be --- intl/strres/public/nsIStringBundle.idl | 12 +- intl/strres/src/nsStringBundle.cpp | 42 +++++-- intl/strres/tests/StringBundleTest.cpp | 69 ++++++------ xpcom/ds/MANIFEST | 1 - xpcom/ds/MANIFEST_IDL | 6 +- xpcom/ds/Makefile.in | 2 +- xpcom/ds/makefile.win | 2 +- xpcom/ds/nsIPersistentProperties.h | 103 +----------------- ...rties.idl => nsIPersistentProperties2.idl} | 8 +- xpcom/ds/nsPersistentProperties.cpp | 91 +++++++++++----- xpcom/ds/nsPersistentProperties.h | 25 +++-- xpcom/tests/PropertiesTest.cpp | 22 ++-- xpinstall/packager/packages-mac | 1 + xpinstall/packager/packages-unix | 1 + xpinstall/packager/packages-win | 1 + xpinstall/src/nsInstall.cpp | 26 +++-- 16 files changed, 202 insertions(+), 210 deletions(-) rename xpcom/ds/{nsIPersistentProperties.idl => nsIPersistentProperties2.idl} (93%) diff --git a/intl/strres/public/nsIStringBundle.idl b/intl/strres/public/nsIStringBundle.idl index 2f3d7ae6d196..00aca1222500 100644 --- a/intl/strres/public/nsIStringBundle.idl +++ b/intl/strres/public/nsIStringBundle.idl @@ -42,7 +42,17 @@ interface nsIStringBundle : nsISupports { wstring GetStringFromID(in long aID); wstring GetStringFromName([const] in wstring aName); - nsIBidirectionalEnumerator GetEnumeration(); + + /* + Don't use - nsIEnumerator and its subinterfaces have been deprecated + */ + [noscript] nsIBidirectionalEnumerator GetEnumeration(); + + /* + Implements nsISimpleEnumerator, replaces nsIEnumerator + */ + nsISimpleEnumerator getSimpleEnumeration(); + }; [scriptable, uuid(D85A17C0-AA7C-11d2-9B8C-00805F8A16D9)] diff --git a/intl/strres/src/nsStringBundle.cpp b/intl/strres/src/nsStringBundle.cpp index c091b07e4dd7..d8fa0e41b464 100644 --- a/intl/strres/src/nsStringBundle.cpp +++ b/intl/strres/src/nsStringBundle.cpp @@ -124,12 +124,12 @@ nsStringBundle::GetStringFromID(PRInt32 aID, nsString& aResult) name.AppendInt(aID, 10); nsresult ret = mProps->GetStringProperty(name, aResult); -#ifdef DEBUG_tao +#ifdef DEBUG_tao_ char *s = aResult.ToNewCString(); printf("\n** GetStringFromID: aResult=%s, len=%d\n", s?s:"null", aResult.Length()); delete s; -#endif /* DEBUG_tao */ +#endif /* DEBUG_tao_ */ return ret; } @@ -139,13 +139,13 @@ nsStringBundle::GetStringFromName(const nsString& aName, nsString& aResult) { NS_ENSURE_TRUE(mProps, NS_ERROR_FAILURE); nsresult ret = mProps->GetStringProperty(aName, aResult); -#ifdef DEBUG_tao +#ifdef DEBUG_tao_ char *s = aResult.ToNewCString(), *ss = aName.ToNewCString(); printf("\n** GetStringFromName: aName=%s, aResult=%s, len=%d\n", ss?ss:"null", s?s:"null", aResult.Length()); delete s; -#endif /* DEBUG_tao */ +#endif /* DEBUG_tao_ */ return ret; } @@ -195,14 +195,26 @@ NS_IMETHODIMP nsStringBundle::GetEnumeration(nsIBidirectionalEnumerator** elements) { nsAutoCMonitor(this); - if (!elements) - return NS_ERROR_INVALID_POINTER; + if (!elements) + return NS_ERROR_INVALID_POINTER; - nsresult ret = mProps->EnumerateProperties(elements); + nsresult ret = mProps->EnumerateProperties(elements); - return ret; + return ret; } +NS_IMETHODIMP +nsStringBundle::GetSimpleEnumeration(nsISimpleEnumerator** elements) +{ + if (!elements) + return NS_ERROR_INVALID_POINTER; + + nsresult ret = mProps->SimpleEnumerateProperties(elements); + + return ret; +} + + nsresult nsStringBundle::GetInputStream(const char* aURLSpec, nsILocale* aLocale, nsIInputStream*& in) { @@ -278,7 +290,7 @@ nsStringBundle::GetInputStream(const char* aURLSpec, nsILocale* aLocale, nsIInpu nsresult nsStringBundle::OpenInputStream(nsString& aURLStr, nsIInputStream*& in) { -#ifdef DEBUG_tao +#ifdef DEBUG_tao_ { char *s = aURLStr.ToNewCString(); printf("\n** nsStringBundle::OpenInputStream: %s\n", s?s:"null"); @@ -352,6 +364,7 @@ public: NS_IMETHOD GetStringFromID(PRInt32 aID, PRUnichar ** aResult); NS_IMETHOD GetStringFromName(const PRUnichar *aName, PRUnichar ** aResult); NS_IMETHOD GetEnumeration(nsIBidirectionalEnumerator ** aResult); + NS_IMETHOD GetSimpleEnumeration(nsISimpleEnumerator** elements); }; NS_IMPL_ISUPPORTS(nsExtensibleStringBundle, NS_GET_IID(nsIStringBundle)); @@ -527,6 +540,13 @@ nsresult nsExtensibleStringBundle::GetEnumeration(nsIBidirectionalEnumerator ** return NS_ERROR_NOT_IMPLEMENTED; } +nsresult nsExtensibleStringBundle::GetSimpleEnumeration(nsISimpleEnumerator ** aResult) +{ + // XXX write me + *aResult = NULL; + return NS_ERROR_NOT_IMPLEMENTED; +} + ///////////////////////////////////////////////////////////////////////////////////////// #define MAX_CACHED_BUNDLES 10 @@ -564,7 +584,7 @@ private: nsStringBundleService::nsStringBundleService() : mBundleMap(MAX_CACHED_BUNDLES, PR_TRUE) { -#ifdef DEBUG_tao +#ifdef DEBUG_tao_ printf("\n++ nsStringBundleService::nsStringBundleService ++\n"); #endif NS_INIT_REFCNT(); @@ -706,7 +726,7 @@ NS_IMETHODIMP nsStringBundleService::CreateBundle(const char* aURLSpec, nsILocale* aLocale, nsIStringBundle** aResult) { -#ifdef DEBUG_tao +#ifdef DEBUG_tao_ printf("\n++ nsStringBundleService::CreateBundle ++\n"); { nsString aURLStr(aURLSpec); diff --git a/intl/strres/tests/StringBundleTest.cpp b/intl/strres/tests/StringBundleTest.cpp index d721d03148f2..f4e326f8be61 100644 --- a/intl/strres/tests/StringBundleTest.cpp +++ b/intl/strres/tests/StringBundleTest.cpp @@ -221,47 +221,54 @@ main(int argc, char *argv[]) nsIBidirectionalEnumerator* propEnum = nsnull; ret = bundle->GetEnumeration(&propEnum); if (NS_FAILED(ret)) { - printf("cannot get enumeration\n"); - return 1; + printf("cannot get enumeration\n"); + return 1; } ret = propEnum->First(); if (NS_FAILED(ret)) { - printf("enumerator is empty\n"); - return 1; + printf("enumerator is empty\n"); + return 1; } cout << endl << "Key" << "\t" << "Value" << endl; cout << "---" << "\t" << "-----" << endl; while (NS_SUCCEEDED(ret)) { - nsIPropertyElement* propElem = nsnull; - ret = propEnum->CurrentItem((nsISupports**)&propElem); - if (NS_FAILED(ret)) { - printf("failed to get current item\n"); - return 1; - } - nsString* key = nsnull; - nsString* val = nsnull; - ret = propElem->GetKey(&key); - if (NS_FAILED(ret)) { - printf("failed to get current element's key\n"); - return 1; - } - ret = propElem->GetValue(&val); - if (NS_FAILED(ret)) { - printf("failed to get current element's value\n"); - return 1; - } - char* keyCStr = key->ToNewCString(); - char* valCStr = val->ToNewCString(); - if (keyCStr && valCStr) - cout << keyCStr << "\t" << valCStr << endl; - delete[] keyCStr; - delete[] valCStr; - delete key; - delete val; - ret = propEnum->Next(); + nsIPropertyElement* propElem = nsnull; + ret = propEnum->CurrentItem((nsISupports**)&propElem); + if (NS_FAILED(ret)) { + printf("failed to get current item\n"); + return 1; + } + + PRUnichar *pKey = nsnull; + PRUnichar *pVal = nsnull; + + ret = propElem->GetKey(&pKey); + if (NS_FAILED(ret)) { + printf("failed to get current element's key\n"); + return 1; + } + ret = propElem->GetValue(&pVal); + if (NS_FAILED(ret)) { + printf("failed to get current element's value\n"); + return 1; + } + + nsAutoString keyAdjustedLengthBuff(pKey); + nsAutoString valAdjustedLengthBuff(pVal); + + char* keyCStr = keyAdjustedLengthBuff.ToNewCString(); + char* valCStr = valAdjustedLengthBuff.ToNewCString(); + if (keyCStr && valCStr) + cout << keyCStr << "\t" << valCStr << endl; + delete[] keyCStr; + delete[] valCStr; + delete[] pKey; + delete[] pVal; + + ret = propEnum->Next(); } return 0; diff --git a/xpcom/ds/MANIFEST b/xpcom/ds/MANIFEST index 36c34ad96017..9012b32365c3 100644 --- a/xpcom/ds/MANIFEST +++ b/xpcom/ds/MANIFEST @@ -9,7 +9,6 @@ nsHashtableEnumerator.h nsIArena.h nsIByteBuffer.h nsIObserverList.h -nsIPersistentProperties.h nsISimpleEnumerator.h nsISizeOfHandler.h nsIUnicharBuffer.h diff --git a/xpcom/ds/MANIFEST_IDL b/xpcom/ds/MANIFEST_IDL index 4d3f6cff9625..7cf124299703 100644 --- a/xpcom/ds/MANIFEST_IDL +++ b/xpcom/ds/MANIFEST_IDL @@ -6,6 +6,8 @@ nsIObserver.idl nsIObserverService.idl nsIProperties.idl nsIStopwatch.idl -nsIProperties.idl -nsIStopwatch.idl +nsIProperties.idl +nsIPersistentProperties2.idl +nsIStopwatch.idl + nsISupportsArray.idl diff --git a/xpcom/ds/Makefile.in b/xpcom/ds/Makefile.in index 099935abe059..9b740d1e971e 100644 --- a/xpcom/ds/Makefile.in +++ b/xpcom/ds/Makefile.in @@ -80,7 +80,6 @@ EXPORTS = \ nsIArena.h \ nsIByteBuffer.h \ nsIObserverList.h \ - nsIPersistentProperties.h \ nsISimpleEnumerator.h \ nsISizeOfHandler.h \ nsIUnicharBuffer.h \ @@ -115,6 +114,7 @@ XPIDLSRCS = \ nsISupportsArray.idl \ nsISupportsIterators.idl \ nsISupportsPrimitives.idl \ + nsIPersistentProperties2.idl \ $(NULL) EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) diff --git a/xpcom/ds/makefile.win b/xpcom/ds/makefile.win index f524efa239a3..7a5d22aa333c 100644 --- a/xpcom/ds/makefile.win +++ b/xpcom/ds/makefile.win @@ -39,7 +39,6 @@ EXPORTS = \ nsIArena.h \ nsIByteBuffer.h \ nsIObserverList.h \ - nsIPersistentProperties.h \ nsISimpleEnumerator.h \ nsISizeOfHandler.h \ nsIUnicharBuffer.h \ @@ -75,6 +74,7 @@ XPIDLSRCS = \ .\nsISupportsArray.idl \ .\nsISupportsIterators.idl \ .\nsISupportsPrimitives.idl \ + .\nsIPersistentProperties2.idl \ $(NULL) ################################################################################ diff --git a/xpcom/ds/nsIPersistentProperties.h b/xpcom/ds/nsIPersistentProperties.h index 349e53020edf..773a52adaf9b 100644 --- a/xpcom/ds/nsIPersistentProperties.h +++ b/xpcom/ds/nsIPersistentProperties.h @@ -1,101 +1,8 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsIProperties_h___ -#define nsIProperties_h___ +#ifndef __gen_nsIPersistentProperties_h__ +#define __gen_nsIPersistentProperties_h__ -#include "nsIProperties.h" -#include "nsIEnumerator.h" -#include "nsISupportsArray.h" -#include "nsID.h" -#include "nsIInputStream.h" -#include "nsIOutputStream.h" -#include "nsString.h" +// "soft" switch over to an IDL generated header file +#include "nsIPersistentProperties2.h" -// {1A180F60-93B2-11d2-9B8B-00805F8A16D9} -#define NS_IPERSISTENTPROPERTIES_IID \ -{ 0x1a180f60, 0x93b2, 0x11d2, \ - { 0x9b, 0x8b, 0x0, 0x80, 0x5f, 0x8a, 0x16, 0xd9 } } - -#define NS_IPERSISTENTPROPERTIES_CID \ -{ 0x2245e573, 0x9464, 0x11d2, \ - { 0x9b, 0x8b, 0x0, 0x80, 0x5f, 0x8a, 0x16, 0xd9 } } - -// {2245E573-9464-11d2-9B8B-00805F8A16D9} -//NS_DECLARE_ID(kPersistentPropertiesCID, -// 0x2245e573, 0x9464, 0x11d2, 0x9b, 0x8b, 0x0, 0x80, 0x5f, 0x8a, 0x16, 0xd9); -static NS_DEFINE_CID(kPersistentPropertiesCID, NS_IPERSISTENTPROPERTIES_CID); - -#define NS_PERSISTENTPROPERTIES_PROGID "component://netscape/persistent-properties" -#define NS_PERSISTENTPROPERTIES_CLASSNAME "Persistent Properties" - -class nsIPersistentProperties : public nsIProperties -{ -public: - static const nsIID& GetIID() { static nsIID iid = NS_IPERSISTENTPROPERTIES_IID; return iid; } - - NS_IMETHOD Load(nsIInputStream* aIn) = 0; - NS_IMETHOD Save(nsIOutputStream* aOut, const nsString& aHeader) = 0; - NS_IMETHOD Subclass(nsIPersistentProperties* aSubclass) = 0; - - /** - * Enumerates the properties in the supplied enumerator. - * @return NS_ERROR_FAILURE if no properties to enumerate - */ - NS_IMETHOD EnumerateProperties(nsIBidirectionalEnumerator** aResult) = 0; - - // XXX these 2 methods will be subsumed by the ones from - // nsIProperties once we figure this all out - NS_IMETHOD GetStringProperty(const nsString& aKey, nsString& aValue) = 0; - NS_IMETHOD SetStringProperty(const nsString& aKey, nsString& aNewValue, - nsString& aOldValue) = 0; -}; - -//////////////////////////////////////////////////////////////////////////////// - -// {C23C10B3-0E1A-11d3-A430-0060B0EB5963} -#define NS_IPROPERTYELEMENT_IID \ -{ 0xc23c10b3, 0xe1a, 0x11d3, \ - { 0xa4, 0x30, 0x0, 0x60, 0xb0, 0xeb, 0x59, 0x63 } } - -// {579C0568-0E1B-11d3-A430-0060B0EB5963} -//NS_DECLARE_ID(kPropertyElementCID, -// 0x579c0568, 0xe1b, 0x11d3, 0xa4, 0x30, 0x0, 0x60, 0xb0, 0xeb, 0x59, 0x63); -#define NS_IPROPERTYELEMENT_CID \ -{ 0x579c0568, 0xe1b, 0x11d3, \ - { 0xa4, 0x30, 0x0, 0x60, 0xb0, 0xeb, 0x59, 0x63 } } -static NS_DEFINE_CID(kPropertyElementCID, NS_IPROPERTYELEMENT_CID); - -class nsIPropertyElement : public nsISupports -{ -public: - static const nsIID& GetIID() { static nsIID iid = NS_IPROPERTYELEMENT_IID; return iid; } - - NS_IMETHOD SetKey(nsString* aKey) = 0; - NS_IMETHOD SetValue(nsString* aValue) = 0; - NS_IMETHOD GetKey(nsString** aReturnKey) = 0; - NS_IMETHOD GetValue(nsString** aReturnValue) = 0; -}; - -//////////////////////////////////////////////////////////////////////////////// - -#endif // nsIProperties_h___ +#endif /* __gen_nsIPersistentProperties_h__ */ diff --git a/xpcom/ds/nsIPersistentProperties.idl b/xpcom/ds/nsIPersistentProperties2.idl similarity index 93% rename from xpcom/ds/nsIPersistentProperties.idl rename to xpcom/ds/nsIPersistentProperties2.idl index 137dbee55858..f149dec147a8 100644 --- a/xpcom/ds/nsIPersistentProperties.idl +++ b/xpcom/ds/nsIPersistentProperties2.idl @@ -39,10 +39,10 @@ [scriptable, uuid(283EE646-1AEF-11D4-98B3-00C04fA0CE9A)] interface nsIPropertyElement : nsISupports { - [noscript] void SetKey(in nsStringPtr aKey); - [noscript] void SetValue(in nsStringPtr aValue); - wstring getKey(); - wstring getValue(); + [noscript] void SetKey(in nsStringPtr aKey); + [noscript] void SetValue(in nsStringPtr aValue); + wstring getKey(); + wstring getValue(); }; diff --git a/xpcom/ds/nsPersistentProperties.cpp b/xpcom/ds/nsPersistentProperties.cpp index 074bd5c6383e..80d911bf53dd 100644 --- a/xpcom/ds/nsPersistentProperties.cpp +++ b/xpcom/ds/nsPersistentProperties.cpp @@ -31,6 +31,7 @@ #include "nsIUnicharInputStream.h" #include "nsProperties.h" #include "pratom.h" +#include "nsEnumeratorUtils.h" static PLHashNumber HashKey(const PRUnichar *aString) @@ -249,27 +250,57 @@ AddElemToArray(PLHashEntry* he, PRIntn i, void* arg) NS_IMETHODIMP nsPersistentProperties::EnumerateProperties(nsIBidirectionalEnumerator** aResult) { - if (!mTable) - return NS_ERROR_FAILURE; + if (!mTable) + return NS_ERROR_FAILURE; - nsISupportsArray* propArray; - nsresult rv = NS_NewISupportsArray(&propArray); - if (rv != NS_OK) - return rv; + nsISupportsArray* propArray; + nsresult rv = NS_NewISupportsArray(&propArray); + if (rv != NS_OK) + return rv; - // Step through hash entries populating a transient array + // Step through hash entries populating a transient array PRIntn n = PL_HashTableEnumerateEntries(mTable, AddElemToArray, (void *)propArray); if ( n < (PRIntn) mTable->nentries ) return NS_ERROR_OUT_OF_MEMORY; - // Convert array into enumerator - rv = NS_NewISupportsArrayEnumerator(propArray, aResult); - if (rv != NS_OK) - return rv; + // Convert array into enumerator + rv = NS_NewISupportsArrayEnumerator(propArray, aResult); + if (rv != NS_OK) + return rv; - return NS_OK; + return NS_OK; } +NS_IMETHODIMP +nsPersistentProperties::SimpleEnumerateProperties(nsISimpleEnumerator** aResult) +{ + nsCOMPtr iterator; + + if (!mTable) + return NS_ERROR_FAILURE; + + nsISupportsArray* propArray; + nsresult rv = NS_NewISupportsArray(&propArray); + if (rv != NS_OK) + return rv; + + // Step through hash entries populating a transient array + PRIntn n = PL_HashTableEnumerateEntries(mTable, AddElemToArray, (void *)propArray); + if ( n < (PRIntn) mTable->nentries ) + return NS_ERROR_OUT_OF_MEMORY; + + // Convert array into enumerator + rv = NS_NewISupportsArrayEnumerator(propArray, getter_AddRefs(iterator)); + // Convert nsIEnumerator into nsISimpleEnumerator + rv = NS_NewAdapterEnumerator(aResult, iterator); + + if (rv != NS_OK) + return rv; + + return NS_OK; +} + + PRInt32 nsPersistentProperties::Read() { @@ -383,43 +414,43 @@ nsPropertyElement::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) NS_IMPL_ISUPPORTS1(nsPropertyElement, nsIPropertyElement) NS_IMETHODIMP -nsPropertyElement::GetKey(nsString** aReturnKey) +nsPropertyElement::GetKey(PRUnichar **aReturnKey) { - if (aReturnKey) - { - *aReturnKey = mKey; - return NS_OK; - } + if (aReturnKey) + { + *aReturnKey = (PRUnichar *) mKey->ToNewUnicode(); + return NS_OK; + } - return NS_ERROR_INVALID_POINTER; + return NS_ERROR_INVALID_POINTER; } NS_IMETHODIMP -nsPropertyElement::GetValue(nsString** aReturnValue) +nsPropertyElement::GetValue(PRUnichar **aReturnValue) { - if (aReturnValue) - { - *aReturnValue = mValue; - return NS_OK; - } + if (aReturnValue) + { + *aReturnValue = (PRUnichar *) mValue->ToNewUnicode(); + return NS_OK; + } - return NS_ERROR_INVALID_POINTER; + return NS_ERROR_INVALID_POINTER; } NS_IMETHODIMP nsPropertyElement::SetKey(nsString* aKey) { - mKey = aKey; + mKey = aKey; - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsPropertyElement::SetValue(nsString* aValue) { - mValue = aValue; + mValue = aValue; - return NS_OK; + return NS_OK; } //////////////////////////////////////////////////////////////////////////////// diff --git a/xpcom/ds/nsPersistentProperties.h b/xpcom/ds/nsPersistentProperties.h index ba00da05133b..2f084bffbe4b 100644 --- a/xpcom/ds/nsPersistentProperties.h +++ b/xpcom/ds/nsPersistentProperties.h @@ -41,6 +41,7 @@ public: NS_IMETHOD Save(nsIOutputStream* aOut, const nsString& aHeader); NS_IMETHOD Subclass(nsIPersistentProperties* aSubclass); NS_IMETHOD EnumerateProperties(nsIBidirectionalEnumerator* *aResult); + NS_IMETHOD SimpleEnumerateProperties(nsISimpleEnumerator** aResult); // XXX these 2 methods will be subsumed by the ones from // nsIProperties once we figure this all out @@ -65,23 +66,23 @@ protected: class nsPropertyElement : public nsIPropertyElement { public: - nsPropertyElement(); - virtual ~nsPropertyElement(); + nsPropertyElement(); + virtual ~nsPropertyElement(); - NS_DECL_ISUPPORTS + NS_DECL_ISUPPORTS - static NS_METHOD - Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); + static NS_METHOD + Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); - // nsIPropertyElement methods: - NS_IMETHOD GetKey(nsString** aReturnKey); - NS_IMETHOD GetValue(nsString** aReturnValue); - NS_IMETHOD SetKey(nsString* aKey); - NS_IMETHOD SetValue(nsString* aValue); + // nsIPropertyElement methods: + NS_IMETHOD GetKey(PRUnichar **aReturnKey); + NS_IMETHOD GetValue(PRUnichar **aReturnValue); + NS_IMETHOD SetKey(nsString* aKey); + NS_IMETHOD SetValue(nsString* aValue); protected: - nsString* mKey; - nsString* mValue; + nsString* mKey; + nsString* mValue; }; #endif /* nsPersistentProperties_h___ */ diff --git a/xpcom/tests/PropertiesTest.cpp b/xpcom/tests/PropertiesTest.cpp index 9a85b705333a..85bd8e2ca9af 100644 --- a/xpcom/tests/PropertiesTest.cpp +++ b/xpcom/tests/PropertiesTest.cpp @@ -175,26 +175,32 @@ main(int argc, char* argv[]) printf("failed to get current item\n"); return 1; } - nsString* key = nsnull; - nsString* val = nsnull; - ret = propElem->GetKey(&key); + + PRUnichar *pKey = nsnull; + PRUnichar *pVal = nsnull; + + ret = propElem->GetKey(&pKey); if (NS_FAILED(ret)) { printf("failed to get current element's key\n"); return 1; } - ret = propElem->GetValue(&val); + ret = propElem->GetValue(&pVal); if (NS_FAILED(ret)) { printf("failed to get current element's value\n"); return 1; } - char* keyCStr = key->ToNewCString(); - char* valCStr = val->ToNewCString(); + + nsAutoString keyAdjustedLengthBuff(pKey); + nsAutoString valAdjustedLengthBuff(pVal); + + char* keyCStr = keyAdjustedLengthBuff.ToNewCString(); + char* valCStr = valAdjustedLengthBuff.ToNewCString(); if (keyCStr && valCStr) cout << keyCStr << "\t" << valCStr << endl; delete[] keyCStr; delete[] valCStr; - delete key; - delete val; + delete[] pKey; + delete[] pVal; ret = propEnum->Next(); } diff --git a/xpinstall/packager/packages-mac b/xpinstall/packager/packages-mac index c1032b3d5650..a864bafee07d 100644 --- a/xpinstall/packager/packages-mac +++ b/xpinstall/packager/packages-mac @@ -195,6 +195,7 @@ viewer:defaults:pref:xpinstall.js viewer:defaults:profile:* viewer:res:arrow.gif viewer:res:charsetalias.properties +viewer:res:acceptlanguage.properties viewer:res:charsetData.properties viewer:res:charsetTitles.properties viewer:res:entityTables:* diff --git a/xpinstall/packager/packages-unix b/xpinstall/packager/packages-unix index ba0180baaf11..beaaac1e49da 100644 --- a/xpinstall/packager/packages-unix +++ b/xpinstall/packager/packages-unix @@ -227,6 +227,7 @@ bin/res/SchemaConcat.tbl bin/res/URLFieldSchema.tbl bin/res/arrow.gif bin/res/charsetalias.properties +bin/res/acceptlanguage.properties bin/res/unixcharset.properties bin/res/charsetData.properties bin/res/charsetTitles.properties diff --git a/xpinstall/packager/packages-win b/xpinstall/packager/packages-win index e7d384ea3e6e..19a3275972fd 100644 --- a/xpinstall/packager/packages-win +++ b/xpinstall/packager/packages-win @@ -208,6 +208,7 @@ bin\res\wincharset.properties bin\res\charsetalias.properties bin\res\charsetData.properties bin\res\charsetTitles.properties +bin/res/acceptlanguage.properties bin\res\entityTables\* bin\res\rdf\article.gif bin\res\rdf\document.gif diff --git a/xpinstall/src/nsInstall.cpp b/xpinstall/src/nsInstall.cpp index 4e15d9d4776a..beda3adcd012 100644 --- a/xpinstall/src/nsInstall.cpp +++ b/xpinstall/src/nsInstall.cpp @@ -1269,16 +1269,22 @@ nsInstall::LoadResources(JSContext* cx, const nsString& aBaseName, jsval* aRetur ret = propEnum->CurrentItem((nsISupports**)&propElem); if (NS_FAILED(ret)) goto cleanup; - nsString* key = nsnull; - nsString* val = nsnull; - ret = propElem->GetKey(&key); + + PRUnichar *pKey = nsnull; + PRUnichar *pVal = nsnull; + + ret = propElem->GetKey(&pKey); if (NS_FAILED(ret)) goto cleanup; - ret = propElem->GetValue(&val); + ret = propElem->GetValue(&pVal); if (NS_FAILED(ret)) goto cleanup; - char* keyCStr = key->ToNewCString(); - PRUnichar* valCStr = val->ToNewUnicode(); + + nsAutoString keyAdjustedLengthBuff(pKey); + nsAutoString valAdjustedLengthBuff(pVal); + + char* keyCStr = keyAdjustedLengthBuff.ToNewCString(); + PRUnichar* valCStr = valAdjustedLengthBuff.ToNewUnicode(); if (keyCStr && valCStr) { JSString* propValJSStr = JS_NewUCStringCopyZ(cx, (jschar*) valCStr); @@ -1287,10 +1293,10 @@ nsInstall::LoadResources(JSContext* cx, const nsString& aBaseName, jsval* aRetur delete[] keyCStr; delete[] valCStr; } - if (key) - delete key; - if (val) - delete val; + if (pKey) + delete[] pKey; + if (pVal) + delete[] pVal; ret = propEnum->Next(); }