www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit e22d7a8459204437bb39fd178f8c26426e80ac8f
parent 241df13954b98dd6175ad75564df3d30a2f8afd9
Author: Dan Stillman <dstillman@zotero.org>
Date:   Fri, 27 Oct 2017 03:21:00 -0400

Fix some property access issues

- Return `undefined` instead of throwing an error trying to access
  `libraryTypeID` on a Zotero.Feed -- this fixes a test failure with
  the latest Chai, which annoyingly runs inspect() on an object passed
  to .include() regardless of whether the test succeeds
- Make some deprecated properties non-enumerable to avoid unnecessary
  logging when the object is dumped

Diffstat:
Mchrome/content/zotero/xpcom/data/collection.js | 3++-
Mchrome/content/zotero/xpcom/data/feed.js | 5+++++
Mchrome/content/zotero/xpcom/data/item.js | 6++++--
Mchrome/content/zotero/xpcom/data/library.js | 3++-
Mtest/tests/feedTest.js | 7+++++++
5 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js @@ -80,7 +80,8 @@ Zotero.defineProperty(Zotero.Collection.prototype, 'parent', { set: function(val) { Zotero.debug("WARNING: Zotero.Collection.prototype.parent has been deprecated -- use .parentID or .parentKey", 2); this.parentID = val; - } + }, + enumerable: false }); Zotero.defineProperty(Zotero.Collection.prototype, 'treeViewID', { diff --git a/chrome/content/zotero/xpcom/data/feed.js b/chrome/content/zotero/xpcom/data/feed.js @@ -114,6 +114,11 @@ Zotero.defineProperty(Zotero.Feed.prototype, 'isFeed', { Zotero.defineProperty(Zotero.Feed.prototype, 'libraryTypes', { value: Object.freeze(Zotero.Feed._super.prototype.libraryTypes.concat(['feed'])) }); + +Zotero.defineProperty(Zotero.Feed.prototype, 'libraryTypeID', { + get: () => undefined +}); + Zotero.defineProperty(Zotero.Feed.prototype, 'unreadCount', { get: function() { return this._feedUnreadCount; } }); diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js @@ -105,7 +105,8 @@ Zotero.defineProperty(Zotero.Item.prototype, 'itemID', { get: function() { Zotero.debug("Item.itemID is deprecated -- use Item.id"); return this._id; - } + }, + enumerable: false }); Zotero.defineProperty(Zotero.Item.prototype, 'libraryID', { get: function() { return this._libraryID; }, @@ -2685,7 +2686,8 @@ Zotero.defineProperty(Zotero.Item.prototype, 'attachmentMIMEType', { get: function() { Zotero.debug(".attachmentMIMEType deprecated -- use .attachmentContentType"); return this.attachmentContentType; - } + }, + enumerable: false }); /** diff --git a/chrome/content/zotero/xpcom/data/library.js b/chrome/content/zotero/xpcom/data/library.js @@ -142,7 +142,7 @@ Zotero.defineProperty(Zotero.Library.prototype, 'libraryTypeID', { return Zotero.Groups.getGroupIDFromLibraryID(this._libraryID); default: - throw new Error(`Cannot return library type id for ${this._libraryType} library`); + throw new Error(`Tried to get library type id for ${this._libraryType} library`); } } }); @@ -169,6 +169,7 @@ Zotero.defineProperty(Zotero.Library.prototype, 'name', { return Zotero.getString('pane.collections.library'); } + // This property is provided by the extending objects (Group, Feed) for other library types throw new Error('Unhandled library type "' + this._libraryType + '"'); } }); diff --git a/test/tests/feedTest.js b/test/tests/feedTest.js @@ -50,6 +50,13 @@ describe("Zotero.Feed", function() { }); }); + describe("#libraryTypeID", function () { + it("should be undefind", function* () { + let feed = yield createFeed(); + assert.isUndefined(feed.libraryTypeID); + }); + }); + describe("#url", function() { it("should throw if trying to set an invalid URL", function *() { let feed = new Zotero.Feed({ name: 'Test ' + Zotero.randomString() });