third_party/subscriptions-project/swg-gaa.js
/**
 * Throws an error if the first argument isn't trueish.
 *
 * Supports argument substitution into the message via %s placeholders.
 *
 * Throws an error object that has two extra properties:
 * - associatedElement: This is the first element provided in the var args.
 *   It can be used for improved display of error messages.
 * - messageArray: The elements of the substituted message as non-stringified
 *   elements in an array. When e.g. passed to console.error this yields
 *   native displays of things like HTML elements.
 *
 * @param {T} shouldBeTrueish The value to assert. The assert fails if it does
 *     not evaluate to true.
 * @param {string=} message The assertion message
 * @param {...*} var_args Arguments substituted into %s in the message.
 * @return {T} The value of shouldBeTrueish.
 * @template T
 */
Throws an error if the first argument isn't trueish.
Supports argument substitution into the message via %s placeholders.

Throws an error object that has two extra properties:
- associatedElement: This is the first element provided in the var args.
It can be used for improved display of error messages.
- messageArray: The elements of the substituted message as non-stringified
elements in an array.

@param {T} shouldBeTrueish The value to assert. The assert fails if it does
not evaluate to true.
@param {string=} message The assertion message
@param {...*} var_args Arguments substituted into %s in the message.
@return {T} The value of shouldBeTrueish.
@template T
Throws an error if the first argument isn ' t trueish . Supports argument substitution into the message via %s placeholders . Throws an error object that has two extra properties : - associatedElement : This is the first element provided in the var args . It can be used for improved display of error messages . - messageArray : The elements of the substituted message as non - stringified elements in an array . @param { T } shouldBeTrueish The value to assert . The assert fails if it does not evaluate to true . @param { string = } message The assertion message @param { ... * } var_args Arguments substituted into %s in the message . @return { T } The value of shouldBeTrueish . @template T
function assert(shouldBeTrueish, message, var_args) {
  let firstElement;
  if (!shouldBeTrueish) {
    message = message || 'Assertion failed';
    const splitMessage = message.split('%s');
    const first = splitMessage.shift();
    let formatted = first;
    const messageArray = [];
    pushIfNonEmpty(messageArray, first);
    for (let i = 2; i < arguments.length; i++) {
      const val = arguments[i];
      if (val && val.tagName) {
        firstElement = val;
      }
      const nextConstant = splitMessage.shift();
      messageArray.push(val);
      pushIfNonEmpty(messageArray, nextConstant.trim());
      formatted += toString(val) + nextConstant;
    }
    const e = new Error(formatted);
    e.fromAssert = true;
    e.associatedElement = firstElement;
    e.messageArray = messageArray;
    throw e;
  }
  return shouldBeTrueish;
}
function assert ( shouldBeTrueish , message , var_args ) { let firstElement ; if ( ! shouldBeTrueish ) { message = message || 'Assertion failed' ; const splitMessage = message . split ( '%s' ) ; const first = splitMessage . shift ( ) ; let formatted = first ; const messageArray = [ ] ; pushIfNonEmpty ( messageArray , first ) ; for ( let i = 2 ; i < arguments . length ; i ++ ) { const val = arguments [ i ] ; if ( val && val . tagName ) { firstElement = val ; } const nextConstant = splitMessage . shift ( ) ; messageArray . push ( val ) ; pushIfNonEmpty ( messageArray , nextConstant . trim ( ) ) ; formatted += toString ( val ) + nextConstant ; } const e = new Error ( formatted ) ; e . fromAssert = true ; e . associatedElement = firstElement ; e . messageArray = messageArray ; throw e ; } return shouldBeTrueish ; }
Throws an error if the first argument isn't trueish.
Throws an error if the first argument isn ' t trueish .