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.

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

mercurial