From 0ff51c133c741e77a01c9947e519706d2673e4a1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 4 May 2015 15:22:26 +0200 Subject: [PATCH] Throw proper errors and remove dead code --- .../files/js/WoltLab/WCF/CallbackList.js | 4 ---- .../install/files/js/WoltLab/WCF/Dictionary.js | 1 - .../files/js/WoltLab/WCF/UI/Dropdown/Simple.js | 12 ++++-------- .../files/js/WoltLab/WCF/UI/TabMenu/Simple.js | 18 ++++++------------ 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLab/WCF/CallbackList.js b/wcfsetup/install/files/js/WoltLab/WCF/CallbackList.js index 50904720ec..20fb4ec9e1 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/CallbackList.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/CallbackList.js @@ -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; }, /** diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Dictionary.js b/wcfsetup/install/files/js/WoltLab/WCF/Dictionary.js index bbd01e22c8..5502686441 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Dictionary.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Dictionary.js @@ -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); diff --git a/wcfsetup/install/files/js/WoltLab/WCF/UI/Dropdown/Simple.js b/wcfsetup/install/files/js/WoltLab/WCF/UI/Dropdown/Simple.js index 9fd0867032..c0b42cfdff 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/UI/Dropdown/Simple.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/UI/Dropdown/Simple.js @@ -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); diff --git a/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu/Simple.js b/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu/Simple.js index 7db6b87554..e2b2d0a182 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu/Simple.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu/Simple.js @@ -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 as children for li[data-name='" + name + "'] (tab menu id: '" + this._containerId + "')."; - return false; + throw new Error("Expected exactly one 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 + "')."); } } -- 2.20.1