Throw proper errors and remove dead code
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 4 May 2015 13:22:26 +0000 (15:22 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 4 May 2015 13:22:26 +0000 (15:22 +0200)
wcfsetup/install/files/js/WoltLab/WCF/CallbackList.js
wcfsetup/install/files/js/WoltLab/WCF/Dictionary.js
wcfsetup/install/files/js/WoltLab/WCF/UI/Dropdown/Simple.js
wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu/Simple.js

index 50904720ecf3bd83e2155a7c8091d4c38cb563bb..20fb4ec9e11a493d9d0d980625b2b232e92b49d3 100644 (file)
@@ -21,12 +21,10 @@ define(['Dictionary'], function(Dictionary) {
                 * 
                 * @param       {string}        identifier      arbitrary string to group and identify callbacks
                 * @param       {function}      callback        callback function
-                * @return      {boolean}       false if callback is not a function
                 */
                add: function(identifier, callback) {
                        if (typeof callback !== 'function') {
                                throw new TypeError("Expected a valid callback as second argument for identifier '" + identifier + "'.");
-                               return false;
                        }
                        
                        if (!this._dictionary.has(identifier)) {
@@ -34,8 +32,6 @@ define(['Dictionary'], function(Dictionary) {
                        }
                        
                        this._dictionary.get(identifier).push(callback);
-                       
-                       return true;
                },
                
                /**
index bbd01e22c8130e0634576da891032a5b64c0401b..5502686441efde48704d2f66fa25cf6941a72806 100644 (file)
@@ -27,7 +27,6 @@ define(function() {
                set: function(key, value) {
                        if (typeof key !== "string") {
                                throw new TypeError("Only strings can be used as keys, rejected '" +  + "' (" + typeof key + ").");
-                               return;
                        }
                        
                        if (_hasMap) this._dictionary.set(key, value);
index 9fd0867032ba2b681cf91865555b78533c600487..c0b42cfdffc9c53d46ca9a6698368c81c7cec431 100644 (file)
@@ -69,14 +69,12 @@ define(
                        
                        var dropdown = DOMTraverse.parentByClass(button, 'dropdown');
                        if (dropdown === null) {
-                               throw "Invalid dropdown passed, button '" + DOMUtil.identify(button) + "' does not have a parent with .dropdown.";
-                               return;
+                               throw new Error("Invalid dropdown passed, button '" + DOMUtil.identify(button) + "' does not have a parent with .dropdown.");
                        }
                        
                        var menu = DOMTraverse.nextByClass(button, 'dropdownMenu');
                        if (menu === null) {
-                               throw "Invalid dropdown passed, button '" + DOMUtil.identify(button) + "' does not have a menu as next sibling.";
-                               return;
+                               throw new Error("Invalid dropdown passed, button '" + DOMUtil.identify(button) + "' does not have a menu as next sibling.");
                        }
                        
                        // move menu into global container
@@ -111,8 +109,7 @@ define(
                initFragment: function(dropdown, menu) {
                        var containerId = DOMUtil.identify(dropdown);
                        if (_dropdowns.has(dropdown)) {
-                               throw "Dropdown identified by '" + DOMUtil.identify(dropdown) + "' has already been registered.";
-                               return;
+                               throw new Error("Dropdown identified by '" + DOMUtil.identify(dropdown) + "' has already been registered.");
                        }
                        
                        _dropdowns.set(containerId, dropdown);
@@ -186,8 +183,7 @@ define(
                setAlignmentById: function(containerId) {
                        var dropdown = _dropdowns.get(containerId);
                        if (dropdown === null) {
-                               throw "Unknown dropdown identifier '" + containerId + "'.";
-                               return;
+                               throw new Error("Unknown dropdown identifier '" + containerId + "'.");
                        }
                        
                        var menu = _menus.get(containerId);
index 7db6b87554e8e0c53b8f2c1fb6ec9501ce609380..e2b2d0a182ea68c94da8eed5432b0236f376f842 100644 (file)
@@ -79,32 +79,27 @@ define(['jquery', 'Dictionary', 'DOM/Util', 'EventHandler'], function($, Diction
                                }
                                
                                if (this._tabs.has(name)) {
-                                       throw "Tab names must be unique, li[data-name='" + name + "'] (tab menu id: '" + this._containerId + "') exists more than once.";
-                                       return false;
+                                       throw new Error("Tab names must be unique, li[data-name='" + name + "'] (tab menu id: '" + this._containerId + "') exists more than once.");
                                }
                                
                                var container = this._containers.get(name);
                                if (container === null) {
-                                       throw "Expected content element for li[data-name='" + name + "'] (tab menu id: '" + this._containerId + "').";
-                                       return false;
+                                       throw new Error("Expected content element for li[data-name='" + name + "'] (tab menu id: '" + this._containerId + "').");
                                }
                                else if (container.parentNode !== this._container) {
-                                       throw "Expected content element '" + name + "' (tab menu id: '" + this._containerId + "') to be a direct children.";
-                                       return false;
+                                       throw new Error("Expected content element '" + name + "' (tab menu id: '" + this._containerId + "') to be a direct children.");
                                }
                                
                                // check if tab holds exactly one children which is an anchor element
                                if (tab.childElementCount !== 1 || tab.children[0].nodeName !== 'A') {
-                                       throw "Expected exactly one <a> as children for li[data-name='" + name + "'] (tab menu id: '" + this._containerId + "').";
-                                       return false;
+                                       throw new Error("Expected exactly one <a> as children for li[data-name='" + name + "'] (tab menu id: '" + this._containerId + "').");
                                }
                                
                                this._tabs.set(name, tab);
                        }
                        
                        if (!this._tabs.size) {
-                               throw "Expected at least one tab (tab menu id: '" + this._containerId + "').";
-                               return false;
+                               throw new Error("Expected at least one tab (tab menu id: '" + this._containerId + "').");
                        }
                        
                        if (this._isLegacy) {
@@ -191,8 +186,7 @@ define(['jquery', 'Dictionary', 'DOM/Util', 'EventHandler'], function($, Diction
                                }
                                
                                if (tab === null) {
-                                       throw "Expected a valid tab name (tab menu id: '" + this._containerId + "').";
-                                       return;
+                                       throw new Error("Expected a valid tab name (tab menu id: '" + this._containerId + "').");
                                }
                        }