From 35784406a0623d35942b1e7a2878bb235b3f1fd9 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sat, 21 Sep 2013 16:57:09 -0700 Subject: [PATCH] Default arguments ftw. --- common/content/statusline.js | 5 +---- common/modules/commands.jsm | 5 +---- common/modules/contexts.jsm | 5 +---- common/modules/dom.jsm | 13 ++++--------- common/modules/finder.jsm | 4 +--- common/modules/io.jsm | 4 ++-- common/modules/options.jsm | 4 ++-- common/modules/util.jsm | 4 ++-- 8 files changed, 14 insertions(+), 30 deletions(-) diff --git a/common/content/statusline.js b/common/content/statusline.js index 5a99f2c1..c2939856 100644 --- a/common/content/statusline.js +++ b/common/content/statusline.js @@ -377,10 +377,7 @@ var StatusLine = Module("statusline", { * @param {number} percent The zoom level, as a percentage. @optional * @param {boolean} full True if full zoom is in operation. @optional */ - updateZoomLevel: function updateZoomLevel(percent, full) { - if (arguments.length == 0) - [percent, full] = [buffer.zoomLevel, buffer.fullZoom]; - + updateZoomLevel: function updateZoomLevel(percent=buffer.zoomLevel, full=buffer.fullZoom) { if (percent == 100) this.widgets.zoomlevel.value = ""; else { diff --git a/common/modules/commands.jsm b/common/modules/commands.jsm index 87a71ba7..dc9215b6 100644 --- a/common/modules/commands.jsm +++ b/common/modules/commands.jsm @@ -971,10 +971,7 @@ var Commands = Module("commands", { parseArgs: function parseArgs(str, params) { const self = this; - function getNextArg(str, _keepQuotes) { - if (arguments.length < 2) - _keepQuotes = keepQuotes; - + function getNextArg(str, _keepQuotes=keepQuotes) { if (str.substr(0, 2) === "<<" && hereDoc) { let arg = /^<<(\S*)/.exec(str)[1]; let count = arg.length + 2; diff --git a/common/modules/contexts.jsm b/common/modules/contexts.jsm index fe71dea8..3c0ca3a9 100644 --- a/common/modules/contexts.jsm +++ b/common/modules/contexts.jsm @@ -65,10 +65,7 @@ var Group = Class("Group", { get builtin() this.modules.contexts.builtinGroups.indexOf(this) >= 0, }, { - compileFilter: function (patterns, default_ = false) { - if (arguments.length < 2) - default_ = false; - + compileFilter: function (patterns, default_=false) { function siteFilter(uri) let (match = array.nth(siteFilter.filters, f => f(uri), 0)) match ? match.result : default_; diff --git a/common/modules/dom.jsm b/common/modules/dom.jsm index 2d16c4ca..810c86eb 100644 --- a/common/modules/dom.jsm +++ b/common/modules/dom.jsm @@ -1090,12 +1090,10 @@ var DOM = Class("DOM", { * @param {string} keys Messy form. * @param {boolean} unknownOk Whether unknown keys are passed * through rather than being converted to keyname>. - * @default false + * @default true * @returns {string} Canonical form. */ - canonicalKeys: function canonicalKeys(keys, unknownOk) { - if (arguments.length === 1) - unknownOk = true; + canonicalKeys: function canonicalKeys(keys, unknownOk=true) { return this.parse(keys, unknownOk).map(this.closure.stringify).join(""); }, @@ -1122,16 +1120,13 @@ var DOM = Class("DOM", { * @param {string} keys The string to parse. * @param {boolean} unknownOk Whether unknown keys are passed * through rather than being converted to keyname>. - * @default false + * @default true * @returns {Array[Object]} */ - parse: function parse(input, unknownOk) { + parse: function parse(input, unknownOk=true) { if (isArray(input)) return array.flatten(input.map(k => this.parse(k, unknownOk))); - if (arguments.length === 1) - unknownOk = true; - let out = []; for (let match in util.regexp.iterate(/<.*?>?>|[^<]|<(?!.*>)/g, input)) { let evt_str = match[0]; diff --git a/common/modules/finder.jsm b/common/modules/finder.jsm index 3ae39696..738b1777 100644 --- a/common/modules/finder.jsm +++ b/common/modules/finder.jsm @@ -75,9 +75,7 @@ var RangeFinder = Module("rangefinder", { this.find("", mode == this.modes.FIND_BACKWARD); }, - bootstrap: function bootstrap(str, backward) { - if (arguments.length < 2 && this.rangeFind) - backward = this.rangeFind.reverse; + bootstrap: function bootstrap(str, backward=this.rangeFind && this.rangeFind.reverse) { let highlighted = this.rangeFind && this.rangeFind.highlighted; let selections = this.rangeFind && this.rangeFind.selections; diff --git a/common/modules/io.jsm b/common/modules/io.jsm index 8aeb66b4..6a997350 100644 --- a/common/modules/io.jsm +++ b/common/modules/io.jsm @@ -266,8 +266,8 @@ var IO = Module("io", { */ File: Class.Memoize(function () let (io = this) Class("File", File, { - init: function init(path, checkCWD) - init.supercall(this, path, (arguments.length < 2 || checkCWD) && io.cwd) + init: function init(path, checkCWD=true) + init.supercall(this, path, checkCWD && io.cwd) })), /** diff --git a/common/modules/options.jsm b/common/modules/options.jsm index 03bb06ef..77439afe 100644 --- a/common/modules/options.jsm +++ b/common/modules/options.jsm @@ -480,11 +480,11 @@ var Option = Class("Option", { stringlist: function stringlist(k) this.value.indexOf(k) >= 0, get charlist() this.stringlist, - regexplist: function regexplist(k, default_) { + regexplist: function regexplist(k, default_=null) { for (let re in values(this.value)) if ((re.test || re).call(re, k)) return re.result; - return arguments.length > 1 ? default_ : null; + return default_; }, get regexpmap() this.regexplist, get sitelist() this.regexplist, diff --git a/common/modules/util.jsm b/common/modules/util.jsm index bf4396a7..d6eaf80c 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -588,10 +588,10 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * @param {string} msg The trace message. * @param {number} frames The number of frames to print. */ - dumpStack: function dumpStack(msg, frames) { + dumpStack: function dumpStack(msg="Stack", frames=null) { let stack = util.stackLines(Error().stack); stack = stack.slice(1, 1 + (frames || stack.length)).join("\n").replace(/^/gm, " "); - util.dump((arguments.length == 0 ? "Stack" : msg) + "\n" + stack + "\n"); + util.dump(msg + "\n" + stack + "\n"); }, /**