addon-sdk/source/lib/sdk/deprecated/errors.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 module.metadata = {
michael@0 8 "stability": "deprecated"
michael@0 9 };
michael@0 10
michael@0 11 function logToConsole(e) {
michael@0 12 console.exception(e);
michael@0 13 }
michael@0 14
michael@0 15 var catchAndLog = exports.catchAndLog = function(callback,
michael@0 16 defaultResponse,
michael@0 17 logException) {
michael@0 18 if (!logException)
michael@0 19 logException = logToConsole;
michael@0 20
michael@0 21 return function() {
michael@0 22 try {
michael@0 23 return callback.apply(this, arguments);
michael@0 24 } catch (e) {
michael@0 25 logException(e);
michael@0 26 return defaultResponse;
michael@0 27 }
michael@0 28 };
michael@0 29 };
michael@0 30
michael@0 31 exports.catchAndLogProps = function catchAndLogProps(object,
michael@0 32 props,
michael@0 33 defaultResponse,
michael@0 34 logException) {
michael@0 35 if (typeof(props) == "string")
michael@0 36 props = [props];
michael@0 37 props.forEach(
michael@0 38 function(property) {
michael@0 39 object[property] = catchAndLog(object[property],
michael@0 40 defaultResponse,
michael@0 41 logException);
michael@0 42 });
michael@0 43 };
michael@0 44
michael@0 45 /**
michael@0 46 * Catch and return an exception while calling the callback. If the callback
michael@0 47 * doesn't throw, return the return value of the callback in a way that makes it
michael@0 48 * possible to distinguish between a return value and an exception.
michael@0 49 *
michael@0 50 * This function is useful when you need to pass the result of a call across
michael@0 51 * a process boundary (across which exceptions don't propagate). It probably
michael@0 52 * doesn't need to be factored out into this module, since it is only used by
michael@0 53 * a single caller, but putting it here works around bug 625560.
michael@0 54 */
michael@0 55 exports.catchAndReturn = function(callback) {
michael@0 56 return function() {
michael@0 57 try {
michael@0 58 return { returnValue: callback.apply(this, arguments) };
michael@0 59 }
michael@0 60 catch (exception) {
michael@0 61 return { exception: exception };
michael@0 62 }
michael@0 63 };
michael@0 64 };

mercurial