MCPcopy
hub / github.com/ampproject/amphtml / assert

Function assert

third_party/subscriptions-project/swg.js:2976–3002  ·  view source on GitHub ↗

* 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 d

(shouldBeTrueish, message, var_args)

Source from the content-addressed store, hash-verified

2974 * @template T
2975 */
2976function assert(shouldBeTrueish, message, var_args) {
2977 let firstElement;
2978 if (!shouldBeTrueish) {
2979 message = message || 'Assertion failed';
2980 const splitMessage = message.split('%s');
2981 const first = splitMessage.shift();
2982 let formatted = first;
2983 const messageArray = [];
2984 pushIfNonEmpty(messageArray, first);
2985 for (let i = 2; i < arguments.length; i++) {
2986 const val = arguments[i];
2987 if (val && val.tagName) {
2988 firstElement = val;
2989 }
2990 const nextConstant = splitMessage.shift();
2991 messageArray.push(val);
2992 pushIfNonEmpty(messageArray, nextConstant.trim());
2993 formatted += toString(val) + nextConstant;
2994 }
2995 const e = new Error(formatted);
2996 e.fromAssert = true;
2997 e.associatedElement = firstElement;
2998 e.messageArray = messageArray;
2999 throw e;
3000 }
3001 return shouldBeTrueish;
3002}
3003
3004/**
3005 * @param {!Array} array

Callers 13

stringToBytesFunction · 0.70
createElementFunction · 0.70
constructorMethod · 0.70
fetch_Method · 0.70
normalizeMethod_Function · 0.70
cloneMethod · 0.70
drainText_Method · 0.70
configure_Method · 0.70
showOffersMethod · 0.70
showUpdateOffersMethod · 0.70
subscribeMethod · 0.70
updateSubscriptionMethod · 0.70

Calls 3

pushIfNonEmptyFunction · 0.70
toStringFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected