From 6dc3c1ba559b4e00f39df17dd4e1f021abc3bc66 Mon Sep 17 00:00:00 2001 From: Shane Tomlinson <stomlinson@mozilla.com> Date: Thu, 9 Aug 2012 11:43:24 +0100 Subject: [PATCH] Ensure the callback is only called once for navigator.id.get with the silent: true option. * Show a console.log message that silent has been deprecated. * Bring over some helper functions from PR #2228 to check for deprecated options, print console messages. --- resources/static/include_js/include.js | 53 +++++++++++++++++++------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/resources/static/include_js/include.js b/resources/static/include_js/include.js index 89043778a..902484308 100644 --- a/resources/static/include_js/include.js +++ b/resources/static/include_js/include.js @@ -1030,6 +1030,36 @@ } } + function defined(item) { + return typeof item !== "undefined"; + } + + function warn(message) { + try { + console.warn(message); + } catch(e) { + /* ignore error */ + } + } + + function checkDeprecated(options, field) { + if(defined(options[field])) { + warn(field + " has been deprecated"); + return true; + } + } + + function checkRenamed(options, oldName, newName) { + if (defined(options[oldName]) && + defined(options[newName])) { + throw "you cannot supply *both* " + oldName + " and " + newName; + } + else if(checkDeprecated(options, oldName)) { + options[newName] = options[oldName]; + delete options[oldName]; + } + } + function internalWatch(options) { if (typeof options !== 'object') return; @@ -1076,14 +1106,6 @@ } } - function warn(message) { - try { - console.warn(message); - } catch(e) { - /* ignore error */ - } - } - function internalRequest(options) { if (options.requiredEmail) { warn("requiredEmail has been deprecated"); @@ -1205,6 +1227,15 @@ opts.termsOfService = passedOptions.termsOfService || undefined; opts.privacyURL = passedOptions.privacyURL || undefined; opts.tosURL = passedOptions.tosURL || undefined; + + if (checkDeprecated(passedOptions, "silent")) { + // Silent has been deprecated, do nothing. Placing the check here + // prevents the callback from being called twice, once with null and + // once after internalWatch has been called. See issue #1532 + if (callback) setTimeout(function() { callback(null); }, 0); + return; + } + checkCompat(true); internalWatch({ onlogin: function(assertion) { @@ -1222,11 +1253,7 @@ } observers.login = observers.logout = observers.ready = null; }; - if (passedOptions && passedOptions.silent) { - if (callback) setTimeout(function() { callback(null); }, 0); - } else { - internalRequest(opts); - } + internalRequest(opts); }, // backwards compatibility with old API getVerifiedEmail: function(callback) { -- GitLab