B2G/gecko/dom/tests/mochitest/bugs/utils_bug260264.js
/**
 * This function takes an accessor function, a new value, and a callback
 * function.  It assigns the new value to the accessor, saving the old value,
 * then calls the callback function with the new and old values.  Before
 * returning, |hold| sets the accessor back to the old value, even if the
 * callback function misbehaved (i.e., threw).
 *
 * For sanity's sake, |hold| also ensures that the accessor still has the new
 * value at the time the old value is reassigned.  The accessor's value might
 * have changed to something entirely different during the execution of the
 * callback function, but it must have changed back.
 *
 * Without such a mechanism it would be very difficult to verify that these
 * tests leave the browser's preferences/privileges as they were originally.
 */
This function takes an accessor function, a new value, and a callback
function.  It assigns the new value to the accessor, saving the old value,
then calls the callback function with the new and old values.  Before
returning, |hold| sets the accessor back to the old value, even if the
callback function misbehaved .

For sanity's sake, |hold| also ensures that the accessor still has the new
value at the time the old value is reassigned.  The accessor's value might
have changed to something entirely different during the execution of the
callback function, but it must have changed back.

Without such a mechanism it would be very difficult to verify that these
tests leave the browser's preferences/privileges as they were originally.
This function takes an accessor function a new value and a callback function . It assigns the new value to the accessor saving the old value then calls the callback function with the new and old values . Before returning |hold| sets the accessor back to the old value even if the callback function misbehaved . For sanity ' s sake |hold| also ensures that the accessor still has the new value at the time the old value is reassigned . The accessor ' s value might have changed to something entirely different during the execution of the callback function but it must have changed back . Without such a mechanism it would be very difficult to verify that these tests leave the browser ' s preferences / privileges as they were originally .
function hold(accessor, value, body) {
  var old_value = accessor(value);
  try { return body(value, old_value) }
  finally {
    old_value = accessor(old_value);
    if (old_value !== value)
      throw [accessor, value, old_value];
  }
}
function hold ( accessor , value , body ) { var old_value = accessor ( value ) ; try { return body ( value , old_value ) } finally { old_value = accessor ( old_value ) ; if ( old_value !== value ) throw [ accessor , value , old_value ] ; } }
This function takes an accessor function, a new value, and a callback
 function.
This function takes an accessor function a new value and a callback function .