Closed
Bug 344605
Opened 19 years ago
Closed 19 years ago
nsIPropertyBag2 should grow a non-throwing get() and hasKey()
Categories
(Core :: XPCOM, enhancement)
Core
XPCOM
Tracking
()
RESOLVED
FIXED
People
(Reporter: sayrer, Unassigned)
References
Details
Attachments
(2 files)
|
2.10 KB,
patch
|
darin.moz
:
review+
|
Details | Diff | Splinter Review |
|
2.72 KB,
patch
|
shaver
:
superreview+
|
Details | Diff | Splinter Review |
Using property bags from JS is a pain because getProperty throws when the key isn't found. Examples:
http://lxr.mozilla.org/seamonkey/source/browser/components/feeds/src/FeedWriter.js#67
http://lxr.mozilla.org/seamonkey/source/toolkit/components/feeds/src/FeedProcessor.js#170
| Reporter | ||
Comment 1•19 years ago
|
||
Here's how I would like it to work:
-----------------------------
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
const BAG_CONTRACTID = "@mozilla.org/hash-property-bag;1"
const Ci = Components.interfaces;
const Cc = Components.classes;
var bag = Cc[BAG_CONTRACTID].createInstance(Ci.nsIWritablePropertyBag2);
bag.setPropertyAsAString("foo", "bar");
print("\n\n***************\n");
print(" getProperty() on existing key: " + bag.getProperty("foo"));
print(" hasKey() on existing key: " + bag.hasKey("foo"));
print(" get() on existing key: " + bag.get("foo"));
try {
bag.getProperty("baz");
}
catch(e) {
print("getProperty() on non-existent key: " + e.message);
}
print(" hasKey() on non-existent key: " + bag.hasKey("baz"));
print(" get() on non-existent key: " + bag.get("baz"));
print("\n\n***************\n");
-----------------------------
Should print as follows:
***************
getProperty() on existing key: bar
hasKey() on existing key: true
get() on existing key: bar
getProperty() on non-existent key: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIWritablePropertyBag2.getProperty]
hasKey() on non-existent key: false
get() on non-existent key: null
***************
Comment 3•19 years ago
|
||
Comment on attachment 229178 [details] [diff] [review]
Patch with get() and hasKey()
You need to change the UUID of an interface when you changes its vtable layout or the signature of any of its methods.
s/Astring/AString/
r=darin otherwise
Updated•19 years ago
|
Attachment #229178 -
Flags: review?(darin) → review+
| Reporter | ||
Comment 4•19 years ago
|
||
Attachment #229931 -
Flags: superreview?(shaver)
Comment 5•19 years ago
|
||
Comment on attachment 229931 [details] [diff] [review]
fix darin's comments
sr=shaver
Attachment #229931 -
Flags: superreview?(shaver) → superreview+
| Reporter | ||
Comment 6•19 years ago
|
||
Checking in nsHashPropertyBag.cpp;
/cvsroot/mozilla/xpcom/ds/nsHashPropertyBag.cpp,v <-- nsHashPropertyBag.cpp
new revision: 1.6; previous revision: 1.5
done
Checking in nsIPropertyBag2.idl;
/cvsroot/mozilla/xpcom/ds/nsIPropertyBag2.idl,v <-- nsIPropertyBag2.idl
new revision: 1.2; previous revision: 1.1
done
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
Comment 7•19 years ago
|
||
Note bug 375779.
You need to log in
before you can comment on or make changes to this bug.
Description
•