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

Method invoke_

src/service/action-impl.js:671–737  ·  view source on GitHub ↗

* @param {!ActionInvocation} invocation * @return {?Promise} * @private

(invocation)

Source from the content-addressed store, hash-verified

669 * @private
670 */
671 invoke_(invocation) {
672 const {method, tagOrTarget} = invocation;
673
674 // Check that this action is allowlisted (if a allowlist is set).
675 if (this.allowlist_) {
676 if (!isActionAllowlisted(invocation, this.allowlist_)) {
677 this.error_(
678 `"${tagOrTarget}.${method}" is not allowlisted ${JSON.stringify(
679 this.allowlist_
680 )}.`
681 );
682 return null;
683 }
684 }
685
686 // Handle global targets e.g. "AMP".
687 const globalTarget = this.globalTargets_[tagOrTarget];
688 if (globalTarget) {
689 return globalTarget(invocation);
690 }
691
692 // Subsequent handlers assume that invocation target is an Element.
693 const node = dev().assertElement(invocation.node);
694
695 // Handle global actions e.g. "<any-element-id>.toggle".
696 const globalMethod = this.globalMethodHandlers_[method];
697 if (globalMethod && invocation.satisfiesTrust(globalMethod.minTrust)) {
698 return globalMethod.handler(invocation);
699 }
700
701 // Handle element-specific actions.
702 const lowerTagName = node.tagName.toLowerCase();
703 if (isAmpTagName(lowerTagName)) {
704 if (node.enqueAction) {
705 node.enqueAction(invocation);
706 } else {
707 this.error_(`Unrecognized AMP element "${lowerTagName}".`, node);
708 }
709 return null;
710 }
711
712 // Special non-AMP elements with AMP ID or known supported actions.
713 const nonAmpActions = NON_AMP_ELEMENTS_ACTIONS_[lowerTagName];
714 // TODO(dvoytenko, #7063): switch back to `target.id` with form proxy.
715 const targetId = node.getAttribute('id') || '';
716 if (
717 isAmpTagName(targetId) ||
718 (nonAmpActions && nonAmpActions.indexOf(method) > -1)
719 ) {
720 const handler = node[ACTION_HANDLER_];
721 if (handler) {
722 handler(invocation);
723 } else {
724 node[ACTION_QUEUE_] = node[ACTION_QUEUE_] || [];
725 node[ACTION_QUEUE_].push(invocation);
726 }
727 return null;
728 }

Callers 3

executeMethod · 0.95
invokeActionMethod · 0.95
test-action.jsFile · 0.80

Calls 12

error_Method · 0.95
devFunction · 0.90
isActionAllowlistedFunction · 0.85
isAmpTagNameFunction · 0.85
stringifyMethod · 0.80
assertElementMethod · 0.80
satisfiesTrustMethod · 0.80
enqueActionMethod · 0.80
getAttributeMethod · 0.80
handlerFunction · 0.50
handlerMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected