+ reversed the argument order for Utils.assert and Utils.assertThrow, per Dao's review

This commit is contained in:
Ian Gilman 2010-08-10 11:13:10 -07:00
parent 7eb0f4ccb0
commit 3381f8595e
9 changed files with 90 additions and 88 deletions

View File

@ -62,8 +62,8 @@ var drag = {
// isFauxDrag - (boolean) true if a faux drag, which is used when simply snapping.
var Drag = function(item, event, isResizing, isFauxDrag) {
try {
Utils.assert('must be an item, or at least a faux item',
item && (item.isAnItem || item.isAFauxItem));
Utils.assert(item && (item.isAnItem || item.isAFauxItem),
'must be an item, or at least a faux item');
this.isResizing = isResizing || false;
this.item = item;

View File

@ -99,7 +99,7 @@ window.GroupItem = function GroupItem(listOfEls, options) {
var rectToBe;
if (options.bounds) {
Utils.assert("options.bounds must be a Rect",Utils.isRect(options.bounds));
Utils.assert(Utils.isRect(options.bounds), "options.bounds must be a Rect");
rectToBe = new Rect(options.bounds);
}
@ -309,7 +309,7 @@ window.GroupItem.prototype = Utils.extend(new Item(), new Subscribable(), {
// Function: setActiveTab
// Sets the active <TabItem> for this groupItem
setActiveTab: function(tab) {
Utils.assert('tab must be a TabItem', tab && tab.isATabItem);
Utils.assert(tab && tab.isATabItem, 'tab must be a TabItem');
this._activeTab = tab;
},
@ -377,7 +377,7 @@ window.GroupItem.prototype = Utils.extend(new Item(), new Subscribable(), {
// Function: adjustTitleSize
// Used to adjust the width of the title box depending on groupItem width and title size.
adjustTitleSize: function() {
Utils.assert('bounds needs to have been set', this.bounds);
Utils.assert(this.bounds, 'bounds needs to have been set');
var w = Math.min(this.bounds.width - 35, Math.max(150, this.getTitle().length * 6));
var css = {width: w};
this.$title.css(css);
@ -569,7 +569,8 @@ window.GroupItem.prototype = Utils.extend(new Item(), new Subscribable(), {
$el = iQ(a);
item = Items.item($el);
}
Utils.assertThrow("shouldn't already be in another groupItem", !item.parent || item.parent == this);
Utils.assertThrow(!item.parent || item.parent == this,
"shouldn't already be in another groupItem");
item.removeTrenches();
@ -1479,8 +1480,8 @@ window.GroupItems = {
// Function: register
// Adds the given <GroupItem> to the list of groupItems we're tracking.
register: function(groupItem) {
Utils.assert('groupItem', groupItem);
Utils.assert('only register once per groupItem', this.groupItems.indexOf(groupItem) == -1);
Utils.assert(groupItem, 'groupItem');
Utils.assert(this.groupItems.indexOf(groupItem) == -1, 'only register once per groupItem');
this.groupItems.push(groupItem);
},
@ -1656,7 +1657,7 @@ window.GroupItems = {
// Utils.log('updateTabBar', this._activeGroupItem, this._activeOrphanTab);
if (!this._activeGroupItem && !this._activeOrphanTab) {
Utils.assert("There must be something to show in the tab bar!", false);
Utils.assert(false, "There must be something to show in the tab bar!");
return;
}

View File

@ -59,7 +59,7 @@
// dontPush - true if this infoItem shouldn't push away on creation; default is false
window.InfoItem = function(bounds, options) {
try {
Utils.assertThrow('bounds', Utils.isRect(bounds));
Utils.assertThrow(Utils.isRect(bounds), 'bounds');
if (typeof(options) == 'undefined')
options = {};
@ -163,7 +163,7 @@ window.InfoItem.prototype = Utils.extend(new Item(), new Subscribable(), {
// Sets the bounds with the given <Rect>, animating unless "immediately" is false.
setBounds: function(rect, immediately) {
try {
Utils.assertThrow('InfoItem.setBounds: rect must be a real rectangle!', Utils.isRect(rect));
Utils.assertThrow(Utils.isRect(rect), 'InfoItem.setBounds: rect must be a real rectangle!');
// ___ Determine what has changed
var css = {};
@ -184,8 +184,8 @@ window.InfoItem.prototype = Utils.extend(new Item(), new Subscribable(), {
return;
this.bounds = new Rect(rect);
Utils.assertThrow('InfoItem.setBounds: this.bounds must be a real rectangle!',
Utils.isRect(this.bounds));
Utils.assertThrow(Utils.isRect(this.bounds),
'InfoItem.setBounds: this.bounds must be a real rectangle!');
// ___ Update our representation
if (immediately) {
@ -214,7 +214,7 @@ window.InfoItem.prototype = Utils.extend(new Item(), new Subscribable(), {
// Set the Z order for the item's container.
setZ: function(value) {
try {
Utils.assertThrow('value must be a number', typeof(value) == 'number');
Utils.assertThrow(typeof(value) == 'number', 'value must be a number');
this.zIndex = value;
@ -250,7 +250,7 @@ window.InfoItem.prototype = Utils.extend(new Item(), new Subscribable(), {
// Sets the item's container's html to the specified value.
html: function(value) {
try {
Utils.assertThrow('value must be a string', typeof(value) == 'string');
Utils.assertThrow(typeof(value) == 'string', 'value must be a string');
this.$contents.html(value);
} catch(e) {
Utils.log(e);

View File

@ -117,13 +117,13 @@ let iQClass = function(selector, context) {
if (ret) {
if (Utils.isPlainObject(context)) {
Utils.assert('does not support HTML creation with context', false);
Utils.assert(false, 'does not support HTML creation with context');
} else {
selector = [doc.createElement(ret[1])];
}
} else {
Utils.assert('does not support complex HTML creation', false);
Utils.assert(false, 'does not support complex HTML creation');
}
return Utils.merge(this, selector);
@ -198,7 +198,7 @@ iQClass.prototype = {
// Execute a callback for every element in the matched set.
each: function(callback) {
if (typeof callback != "function") {
Utils.assert("each's argument must be a function", false);
Utils.assert(false, "each's argument must be a function");
return null;
}
for (let i = 0; this[i] != null; i++) {
@ -212,7 +212,7 @@ iQClass.prototype = {
// Adds the given class(es) to the receiver.
addClass: function(value) {
if (typeof value != "string" || !value) {
Utils.assert('requires a valid string argument', false);
Utils.assert(false, 'requires a valid string argument');
return null;
}
@ -234,7 +234,7 @@ iQClass.prototype = {
// Removes the given class(es) from the receiver.
removeClass: function(value) {
if (typeof value != "string" || !value) {
Utils.assert('does not support function argument', false);
Utils.assert(false, 'does not support function argument');
return null;
}
@ -352,7 +352,7 @@ iQClass.prototype = {
// Function: bounds
// Returns a <Rect> with the receiver's bounds.
bounds: function() {
Utils.assert('does not yet support multi-objects (or null objects)', this.length == 1);
Utils.assert(this.length == 1, 'does not yet support multi-objects (or null objects)');
let rect = this[0].getBoundingClientRect();
return new Rect(Math.floor(rect.left), Math.floor(rect.top),
Math.floor(rect.width), Math.floor(rect.height));
@ -365,7 +365,7 @@ iQClass.prototype = {
data: function(key, value) {
let data = null;
if (typeof value === "undefined") {
Utils.assert('does not yet support multi-objects (or null objects)', this.length == 1);
Utils.assert(this.length == 1, 'does not yet support multi-objects (or null objects)');
data = this[0].iQData;
if (data)
return data[key];
@ -391,7 +391,7 @@ iQClass.prototype = {
// Given a value, sets the receiver's innerHTML to it; otherwise returns
// what's already there.
html: function(value) {
Utils.assert('does not yet support multi-objects (or null objects)', this.length == 1);
Utils.assert(this.length == 1, 'does not yet support multi-objects (or null objects)');
if (typeof value === "undefined")
return this[0].innerHTML;
@ -404,7 +404,7 @@ iQClass.prototype = {
// Given a value, sets the receiver's textContent to it; otherwise returns
// what's already there.
text: function(value) {
Utils.assert('does not yet support multi-objects (or null objects)', this.length == 1);
Utils.assert(this.length == 1, 'does not yet support multi-objects (or null objects)');
if (typeof value === "undefined") {
return this[0].textContent;
}
@ -416,7 +416,7 @@ iQClass.prototype = {
// Function: val
// Given a value, sets the receiver's value to it; otherwise returns what's already there.
val: function(value) {
Utils.assert('does not yet support multi-objects (or null objects)', this.length == 1);
Utils.assert(this.length == 1, 'does not yet support multi-objects (or null objects)');
if (typeof value === "undefined") {
return this[0].value;
}
@ -429,7 +429,7 @@ iQClass.prototype = {
// Function: appendTo
// Appends the receiver to the result of iQ(selector).
appendTo: function(selector) {
Utils.assert('does not yet support multi-objects (or null objects)', this.length == 1);
Utils.assert(this.length == 1, 'does not yet support multi-objects (or null objects)');
iQ(selector).append(this);
return this;
},
@ -439,7 +439,8 @@ iQClass.prototype = {
// Appends the result of iQ(selector) to the receiver.
append: function(selector) {
let object = iQ(selector);
Utils.assert('does not yet support multi-objects (or null objects)', object.length == 1 && this.length == 1);
Utils.assert(object.length == 1 && this.length == 1,
'does not yet support multi-objects (or null objects)');
this[0].appendChild(object[0]);
return this;
},
@ -449,9 +450,9 @@ iQClass.prototype = {
// Sets or gets an attribute on the element(s).
attr: function(key, value) {
try {
Utils.assert('string key', typeof key === 'string');
Utils.assert(typeof key === 'string', 'string key');
if (typeof value === "undefined") {
Utils.assert('retrieval does not support multi-objects (or null objects)', this.length == 1);
Utils.assert(this.length == 1, 'retrieval does not support multi-objects (or null objects)');
return this[0].getAttribute(key);
}
for (let i = 0; this[i] != null; i++) {
@ -479,7 +480,7 @@ iQClass.prototype = {
if (typeof a === 'string') {
let key = a;
if (typeof b === "undefined") {
Utils.assert('retrieval does not support multi-objects (or null objects)', this.length == 1);
Utils.assert(this.length == 1, 'retrieval does not support multi-objects (or null objects)');
return window.getComputedStyle(this[0], null).getPropertyValue(key);
}
@ -533,7 +534,7 @@ iQClass.prototype = {
// in, but "this" is set to the element that was animated.
animate: function(css, options) {
try {
Utils.assert('does not yet support multi-objects (or null objects)', this.length == 1);
Utils.assert(this.length == 1, 'does not yet support multi-objects (or null objects)');
if (!options)
options = {};
@ -591,8 +592,8 @@ iQClass.prototype = {
// Function: fadeOut
// Animates the receiver to full transparency. Calls callback on completion.
fadeOut: function(callback) {
Utils.assert('does not yet support duration', typeof callback == "function"
|| typeof callback === "undefined");
Utils.assert(typeof callback == "function" || typeof callback === "undefined",
'does not yet support duration');
this.animate({
opacity: 0
@ -657,7 +658,7 @@ iQClass.prototype = {
// Binds the given function to the given event type. Also wraps the function
// in a try/catch block that does a Utils.log on any errors.
bind: function(type, func) {
Utils.assert('does not support eventData argument', typeof func == "function");
Utils.assert(typeof func == "function", 'does not support eventData argument');
let handler = function(event) {
try {
@ -691,7 +692,7 @@ iQClass.prototype = {
// Binds the given function to the given event type, but only for one call;
// automatically unbinds after the event fires once.
one: function(type, func) {
Utils.assert('does not support eventData argument', typeof func == "function");
Utils.assert(typeof func == "function", 'does not support eventData argument');
let handler = function(e) {
iQ(this).unbind(type, handler);
@ -705,7 +706,7 @@ iQClass.prototype = {
// Function: unbind
// Unbinds the given function from the given event type.
unbind: function(type, func) {
Utils.assert('Must provide a function', typeof func == "function");
Utils.assert(typeof func == "function", 'Must provide a function');
for (let i = 0; this[i] != null; i++) {
let elem = this[i];

View File

@ -145,18 +145,18 @@ window.Item.prototype = {
// Parameters:
// container - the outermost DOM element that describes this item onscreen.
_init: function(container) {
Utils.assert('Subclass must implement the Subscribable interface',
typeof(this.addSubscriber) == 'function' &&
typeof(this.removeSubscriber) == 'function' &&
typeof(this._sendToSubscribers) == 'function');
Utils.assert('container must be a DOM element', Utils.isDOMElement(container));
Utils.assert('Subclass must provide setBounds', typeof(this.setBounds) == 'function');
Utils.assert('Subclass must provide setZ', typeof(this.setZ) == 'function');
Utils.assert('Subclass must provide close', typeof(this.close) == 'function');
Utils.assert('Subclass must provide save', typeof(this.save) == 'function');
Utils.assert('Subclass must provide defaultSize', Utils.isPoint(this.defaultSize));
Utils.assert('Subclass must provide locked', this.locked);
Utils.assert('Subclass must provide bounds', Utils.isRect(this.bounds));
Utils.assert(typeof(this.addSubscriber) == 'function' &&
typeof(this.removeSubscriber) == 'function' &&
typeof(this._sendToSubscribers) == 'function',
'Subclass must implement the Subscribable interface');
Utils.assert(Utils.isDOMElement(container), 'container must be a DOM element');
Utils.assert(typeof(this.setBounds) == 'function', 'Subclass must provide setBounds');
Utils.assert(typeof(this.setZ) == 'function', 'Subclass must provide setZ');
Utils.assert(typeof(this.close) == 'function', 'Subclass must provide close');
Utils.assert(typeof(this.save) == 'function', 'Subclass must provide save');
Utils.assert(Utils.isPoint(this.defaultSize), 'Subclass must provide defaultSize');
Utils.assert(this.locked, 'Subclass must provide locked');
Utils.assert(Utils.isRect(this.bounds), 'Subclass must provide bounds');
this.container = container;
@ -239,7 +239,7 @@ window.Item.prototype = {
// Function: getBounds
// Returns a copy of the Item's bounds as a <Rect>.
getBounds: function() {
Utils.assert('this.bounds', Utils.isRect(this.bounds));
Utils.assert(Utils.isRect(this.bounds), 'this.bounds');
return new Rect(this.bounds);
},
@ -268,7 +268,7 @@ window.Item.prototype = {
// immediately - if false or omitted, animates to the new position;
// otherwise goes there immediately
setPosition: function(left, top, immediately) {
Utils.assert('this.bounds', Utils.isRect(this.bounds));
Utils.assert(Utils.isRect(this.bounds), 'this.bounds');
this.setBounds(new Rect(left, top, this.bounds.width, this.bounds.height), immediately);
},
@ -282,7 +282,7 @@ window.Item.prototype = {
// immediately - if false or omitted, animates to the new size;
// otherwise resizes immediately
setSize: function(width, height, immediately) {
Utils.assert('this.bounds', Utils.isRect(this.bounds));
Utils.assert(Utils.isRect(this.bounds), 'this.bounds');
this.setBounds(new Rect(this.bounds.left, this.bounds.top, width, height), immediately);
},
@ -290,7 +290,7 @@ window.Item.prototype = {
// Function: setUserSize
// Remembers the current size as one the user has chosen.
setUserSize: function() {
Utils.assert('this.bounds', Utils.isRect(this.bounds));
Utils.assert(Utils.isRect(this.bounds), 'this.bounds');
this.userSize = new Point(this.bounds.width, this.bounds.height);
this.save();
},
@ -573,7 +573,7 @@ window.Item.prototype = {
// Enables dragging on this item. Note: not to be called multiple times on the same item!
draggable: function() {
try {
Utils.assert('dragOptions', this.dragOptions);
Utils.assert(this.dragOptions, 'dragOptions');
var cancelClasses = [];
if (typeof(this.dragOptions.cancelClass) == 'string')
@ -728,7 +728,7 @@ window.Item.prototype = {
if (value)
$container.addClass('iq-droppable');
else {
Utils.assert('dropOptions', this.dropOptions);
Utils.assert(this.dropOptions, 'dropOptions');
$container.removeClass('iq-droppable');
}
@ -748,7 +748,7 @@ window.Item.prototype = {
if (!value) {
$container.removeClass('iq-resizable');
} else {
Utils.assert('resizeOptions', this.resizeOptions);
Utils.assert(this.resizeOptions, 'resizeOptions');
$container.addClass('iq-resizable');

View File

@ -384,10 +384,10 @@ Subscribable.prototype = {
// The refObject is used to facilitate removal if necessary.
addSubscriber: function(refObject, eventName, callback) {
try {
Utils.assertThrow("refObject", refObject);
Utils.assertThrow("callback must be a function", typeof callback == "function");
Utils.assertThrow("eventName must be a non-empty string",
eventName && typeof(eventName) == "string");
Utils.assertThrow(refObject, "refObject");
Utils.assertThrow(typeof callback == "function", "callback must be a function");
Utils.assertThrow(eventName && typeof(eventName) == "string",
"eventName must be a non-empty string");
if (!this.subscribers)
this.subscribers = {};
@ -401,7 +401,7 @@ Subscribable.prototype = {
});
if (existing.length) {
Utils.assert('should only ever be one', existing.length == 1);
Utils.assert(existing.length == 1, 'should only ever be one');
existing[0].callback = callback;
} else {
subs.push({
@ -419,9 +419,9 @@ Subscribable.prototype = {
// Removes the callback associated with refObject for the given event.
removeSubscriber: function(refObject, eventName) {
try {
Utils.assertThrow("refObject", refObject);
Utils.assertThrow("eventName must be a non-empty string",
eventName && typeof(eventName) == "string");
Utils.assertThrow(refObject, "refObject");
Utils.assertThrow(eventName && typeof(eventName) == "string",
"eventName must be a non-empty string");
if (!this.subscribers || !this.subscribers[eventName])
return;
@ -439,8 +439,8 @@ Subscribable.prototype = {
// Internal routine. Used by the Subscribable to fire events.
_sendToSubscribers: function(eventName, eventInfo) {
try {
Utils.assertThrow("eventName must be a non-empty string",
eventName && typeof(eventName) == "string");
Utils.assertThrow(eventName && typeof(eventName) == "string",
"eventName must be a non-empty string");
if (!this.subscribers || !this.subscribers[eventName])
return;
@ -498,10 +498,10 @@ let Utils = {
// ----------
// Function: assert
// Prints a stack trace along with label (as a console message) if condition is false.
assert: function Utils_assert(label, condition) {
assert: function Utils_assert(condition, label) {
if (!condition) {
let text;
if (typeof(label) == 'undefined')
if (typeof(label) != 'string')
text = 'badly formed assert';
else
text = "tabview assert: " + label;
@ -513,10 +513,10 @@ let Utils = {
// ----------
// Function: assertThrow
// Throws label as an exception if condition is false.
assertThrow: function(label, condition) {
assertThrow: function(condition, label) {
if (!condition) {
let text;
if (typeof(label) == 'undefined')
if (typeof(label) != 'string')
text = 'badly formed assert';
else
text = "tabview assert: " + label;
@ -682,15 +682,15 @@ let Utils = {
// Deep copy is not supported
if (typeof target === "boolean") {
this.assert("The first argument of extend cannot be a boolean."
+"Deep copy is not supported.", false);
this.assert(false, "The first argument of extend cannot be a boolean." +
"Deep copy is not supported.");
return target;
}
// Back when this was in iQ + iQ.fn, so you could extend iQ objects with it.
// This is no longer supported.
if (length === 1) {
this.assert("Extending the iQ prototype using extend is not supported.", false);
this.assert(false, "Extending the iQ prototype using extend is not supported.");
return target;
}

View File

@ -87,7 +87,7 @@ Storage = {
// Function: saveTab
// Saves the data for a single tab.
saveTab: function(tab, data) {
Utils.assert('tab', tab);
Utils.assert(tab, "tab");
this._sessionStore.setTabValue(tab, this.TAB_DATA_IDENTIFIER,
JSON.stringify(data));
@ -97,7 +97,7 @@ Storage = {
// Function: getTabData
// Returns the data object associated with a single tab.
getTabData: function(tab) {
Utils.assert('tab', tab);
Utils.assert(tab, "tab");
var existingData = null;
try {

View File

@ -49,7 +49,7 @@
// tab - a xul:tab
window.TabItem = function(tab) {
Utils.assert('tab', tab);
Utils.assert(tab, "tab");
this.tab = tab;
// register this as the tab's tabItem
@ -690,7 +690,7 @@ window.TabItems = {
// Function: init
// Set up the necessary tracking to maintain the <TabItems>s.
init: function() {
Utils.assert("TabManager must be initialized first", window.AllTabs);
Utils.assert(window.AllTabs, "AllTabs must be initialized first");
var self = this;
// When a tab is opened, create the TabItem
@ -739,7 +739,7 @@ window.TabItems = {
// Takes in a xul:tab.
update: function(tab) {
try {
Utils.assertThrow("tab", tab);
Utils.assertThrow(tab, "tab");
let shouldDefer = (
this.isPaintingPaused() ||
@ -767,7 +767,7 @@ window.TabItems = {
// Takes in a xul:tab.
_update: function(tab) {
try {
Utils.assertThrow("tab", tab);
Utils.assertThrow(tab, "tab");
// ___ remove from waiting list if needed
let index = this._tabsWaitingForUpdate.indexOf(tab);
@ -775,7 +775,7 @@ window.TabItems = {
this._tabsWaitingForUpdate.splice(index, 1);
// ___ get the TabItem
Utils.assertThrow("must already be linked", tab.tabItem);
Utils.assertThrow(tab.tabItem, "must already be linked");
let tabItem = tab.tabItem;
// ___ icon
@ -830,8 +830,8 @@ window.TabItems = {
// Takes in a xul:tab.
link: function(tab){
try {
Utils.assertThrow("tab", tab);
Utils.assertThrow("shouldn't already be linked", !tab.tabItem);
Utils.assertThrow(tab, "tab");
Utils.assertThrow(!tab.tabItem, "shouldn't already be linked");
new TabItem(tab); // sets tab.tabItem to itself
} catch(e) {
Utils.log(e);
@ -843,8 +843,8 @@ window.TabItems = {
// Takes in a xul:tab.
unlink: function(tab) {
try {
Utils.assertThrow("tab", tab);
Utils.assertThrow("should already be linked", tab.tabItem);
Utils.assertThrow(tab, "tab");
Utils.assertThrow(tab.tabItem, "should already be linked");
tab.tabItem._sendToSubscribers("close");
iQ(tab.tabItem.container).remove();
@ -921,8 +921,8 @@ window.TabItems = {
// Function: register
// Adds the given <TabItem> to the master list.
register: function(item) {
Utils.assert('item must be a TabItem', item && item.isAnItem);
Utils.assert('only register once per item', this.items.indexOf(item) == -1);
Utils.assert(item && item.isAnItem, 'item must be a TabItem');
Utils.assert(this.items.indexOf(item) == -1, 'only register once per item');
this.items.push(item);
},
@ -977,8 +977,8 @@ window.TabItems = {
var found = false;
try{
Utils.assert('item', item);
Utils.assert('item.tab', item.tab);
Utils.assert(item, 'item');
Utils.assert(item.tab, 'item.tab');
if (item.reconnected)
return true;

View File

@ -116,7 +116,7 @@ Trench.prototype = {
setParentItem: function Trench_setParentItem(item) {
if (!item.isAnItem) {
Utils.assert("parentItem must be an Item",false);
Utils.assert(false, "parentItem must be an Item");
return false;
}
this.parentItem = item;