www

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

commit d22d77fedf8cb90b40a2a1dfeec2136f6baa2ef8
parent 1d9fa85c151facdd626a061bc135455459d8c8f7
Author: Dan Stillman <dstillman@zotero.org>
Date:   Sun,  4 Jun 2006 19:37:03 +0000

More helpful exceptions in itemFields methods when given an invalid fieldID or a fieldID with no associated itemTypes (neither should actually happen once things are set up right)


Diffstat:
Mchrome/chromeFiles/content/scholar/xpcom/data_access.js | 24++++++++++++++++++++++++
1 file changed, 24 insertions(+), 0 deletions(-)

diff --git a/chrome/chromeFiles/content/scholar/xpcom/data_access.js b/chrome/chromeFiles/content/scholar/xpcom/data_access.js @@ -1536,6 +1536,13 @@ Scholar.ItemFields = new function(){ if (!_fields.length){ _loadFields(); } + + _fieldCheck(fieldID); + + if (!_fields[fieldID]['itemTypes']){ + throw('No associated itemTypes for fieldID ' + fieldID); + } + return !!_fields[fieldID]['itemTypes'][itemTypeID]; } @@ -1544,6 +1551,9 @@ Scholar.ItemFields = new function(){ if (!_fields.length){ _loadFields(); } + + _fieldCheck(fieldID); + var ffid = _fields[fieldID]['formatID']; return _fieldFormats[ffid] ? _fieldFormats[ffid]['isInteger'] : false; } @@ -1565,6 +1575,20 @@ Scholar.ItemFields = new function(){ } + /** + * Check whether a fieldID is valid, throwing an exception if not + * (since it should never actually happen) + **/ + function _fieldCheck(fieldID){ + if (!_fields.length){ + _loadFields(); + } + if (typeof _fields[fieldID]=='undefined'){ + throw('Invalid fieldID ' + fieldID); + } + } + + /* * Returns hash array of itemTypeIDs for which a given field is valid */