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

Function parseIfNeeded

src/iframe-helper.js:409–428  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

407 * @visibleForTesting
408 */
409export function parseIfNeeded(data) {
410 if (typeof data == 'string') {
411 if (data.charAt(0) == '{') {
412 data =
413 tryParseJson(data, (e) => {
414 dev().warn(
415 'IFRAME-HELPER',
416 'Postmessage could not be parsed. ' +
417 'Is it in a valid JSON format?',
418 e
419 );
420 }) || null;
421 } else if (isAmpMessage(data)) {
422 data = deserializeMessage(data);
423 } else {
424 data = null;
425 }
426 }
427 return /** @type {?JsonObject} */ (data);
428}
429
430/**
431 * Manages a postMessage API for an iframe with a subscription message and

Callers 2

listenerFunction · 0.90
listenForListenerFunction · 0.85

Calls 5

tryParseJsonFunction · 0.90
devFunction · 0.90
isAmpMessageFunction · 0.90
deserializeMessageFunction · 0.90
warnMethod · 0.80

Tested by

no test coverage detected