* Fetches an amp-script URI by finding the associated amp-script and * calling the specified function. * * Note: the amp-script URI does not yet support function args, * even though worker-dom's callFunction does. Therefore we allow it * via extra args. * * @param {s
(uri, unusedArgs)
| 666 | * @return {Promise<*>} |
| 667 | */ |
| 668 | fetch(uri, unusedArgs) { |
| 669 | const uriParts = uri.slice('amp-script:'.length).split('.'); |
| 670 | userAssert( |
| 671 | uriParts.length === 2 && uriParts[0].length > 0 && uriParts[1].length > 0, |
| 672 | `[${TAG}]: "amp-script" URIs must be of the format "scriptId.functionIdentifier".` |
| 673 | ); |
| 674 | |
| 675 | const ampScriptId = uriParts[0]; |
| 676 | const fnIdentifier = uriParts[1]; |
| 677 | const ampScriptEl = this.ampdoc_.getElementById(ampScriptId); |
| 678 | userAssert( |
| 679 | ampScriptEl && ampScriptEl.tagName === 'AMP-SCRIPT', |
| 680 | `[${TAG}]: could not find <amp-script> with script set to ${ampScriptId}` |
| 681 | ); |
| 682 | const args = Array.prototype.slice.call(arguments, 1); |
| 683 | return ampScriptEl |
| 684 | .getImpl() |
| 685 | .then((impl) => |
| 686 | impl.callFunction.apply(impl, [fnIdentifier].concat(args)) |
| 687 | ); |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | /** |
nothing calls this directly
no test coverage detected