commit 4e1937680f759f5aacb1ab6db43a3f930d6856ec
parent 265df6d48c5bffceeb17c56f6f00710963ba5a00
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 23 May 2017 02:04:58 -0400
Throw error if non-number is passed to Zotero.DataObjects.getAsync()
Previously, if an id was psased as a string and the id existed in the
cache, an error wouldn't be thrown, but if there id wasn't in the cache
(e.g., because it was in an unloaded library) it would. This requires an
integer in all cases.
Note that, among other things, any code that gets ids from object keys
will need to convert them to integers before passing to getAsync().
Diffstat:
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/chrome/content/zotero/xpcom/data/dataObjects.js b/chrome/content/zotero/xpcom/data/dataObjects.js
@@ -172,14 +172,16 @@ Zotero.DataObjects.prototype.getAsync = Zotero.Promise.coroutine(function* (ids,
for (let i=0; i<ids.length; i++) {
let id = ids[i];
+
+ if (!Number.isInteger(id)) {
+ throw new Error(`Invalid ${this._ZDO_object} ID '${id}' (${typeof id})`);
+ }
+
// Check if already loaded
if (this._objectCache[id]) {
toReturn.push(this._objectCache[id]);
}
else {
- if (!Number.isInteger(id)) {
- throw new Error(`Invalid ${this._ZDO_object} ID '${id}' (${typeof id})`);
- }
toLoad.push(id);
}
}