From d22d77fedf8cb90b40a2a1dfeec2136f6baa2ef8 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 4 Jun 2006 19:37:03 +0000 Subject: [PATCH] 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) --- .../content/scholar/xpcom/data_access.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/chrome/chromeFiles/content/scholar/xpcom/data_access.js b/chrome/chromeFiles/content/scholar/xpcom/data_access.js index 40128296ee..43f6c2e15e 100644 --- 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 */