(data)
| 407 | * @visibleForTesting |
| 408 | */ |
| 409 | export 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 |
no test coverage detected