From e22d7a8459204437bb39fd178f8c26426e80ac8f Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 27 Oct 2017 03:21:00 -0400 Subject: [PATCH] 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 --- chrome/content/zotero/xpcom/data/collection.js | 3 ++- chrome/content/zotero/xpcom/data/feed.js | 5 +++++ chrome/content/zotero/xpcom/data/item.js | 6 ++++-- chrome/content/zotero/xpcom/data/library.js | 3 ++- test/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 index bbbbf6009..3a0f5bf75 100644 --- 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 index 840059209..9a4baec33 100644 --- 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 index 3ecab174f..be389764b 100644 --- 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 index 6abcb4be0..153fd5a7d 100644 --- 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 index 90d3fa25e..15e793798 100644 --- 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() });