Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amp action macro cleanup #20841

Merged
merged 26 commits into from Feb 27, 2019
Merged

Amp action macro cleanup #20841

merged 26 commits into from Feb 27, 2019

Conversation

alabiaga
Copy link
Contributor

@alabiaga alabiaga commented Feb 13, 2019

  • do not allow a macro to recursively call itself.
  • add examples page.

@alabiaga
Copy link
Contributor Author

@choumx Hey Will note that you referred to the amp-bind-macro and its check for ensuring it refers to macros that were predefined before it. For the amp-action macro this isn't an issue as when we hit the trigger code path in the action macro, it is already guaranteed to be defined. The existence of the target/amp-component that it will invoke is also getting checked in the actions service.
https://github.com/ampproject/amphtml/blob/master/src/service/action-impl.js#L524

isRecursiveInvocation_(invocation) {
return invocation.source.getAttribute('id')
=== this.element.getAttribute('id')
&& invocation.source.tagName === 'AMP-ACTION-MACRO';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to worry about cycles generally. I.e. not just x -> x but x -> y -> x.

@alabiaga
Copy link
Contributor Author

alabiaga commented Feb 14, 2019 via email

*/
isRecursiveInvocation_(invocation) {
return invocation.caller.getAttribute('id')
=== this.element.getAttribute('id');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other check should cover this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

* @private
*/
isInvalidMacroReference_(invocationRegistrationId) {
return invocationRegistrationId <= this.element['registrationId'];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new to me. Fancy. done.

@@ -75,9 +81,16 @@ export class AmpActionMacro extends AMP.BaseElement {
arg, this.element);
}
}
if (invocation.caller.tagName === 'AMP-ACTION-MACRO') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invocation.caller.tagName.toLowerCase() === TAG

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* @return {boolean}
* @private
*/
isInvalidMacroReference_(invocationRegistrationId) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Single caller of a simple function -- can be inlined.

@alabiaga
Copy link
Contributor Author

@choumx friendly ping

@@ -75,9 +75,13 @@ export class AmpActionMacro extends AMP.BaseElement {
arg, this.element);
}
}
if (invocation.caller.tagName.toLowerCase() === TAG) {
userAssert(this.isValidMacroReference_(
invocation.caller),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Move to previous line.

userAssert(this.isValidMacroReference_(
invocation.caller),
'Action macro with ID "%s" cannot reference itself or macros defined '
+ 'after it', this.element.getAttribute('id'));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"amp-action-macro#%s may only reference macros that precede it."

@alabiaga
Copy link
Contributor Author

thanks!

@alabiaga alabiaga merged commit bddfe6e into ampproject:master Feb 27, 2019
noranazmy pushed a commit to noranazmy/amphtml that referenced this pull request Mar 22, 2019
* toggle maybeChangeHeight in layers after remeasures to indicate to runtime that doc height could have changed

* cleanup

* revert resources-impl change

* revert this change from master

* .

* e.g. of invalid call

* counter can simply be an incrementing num

* choumx comments
bramanudom pushed a commit to bramanudom/amphtml that referenced this pull request Mar 22, 2019
* toggle maybeChangeHeight in layers after remeasures to indicate to runtime that doc height could have changed

* cleanup

* revert resources-impl change

* revert this change from master

* .

* e.g. of invalid call

* counter can simply be an incrementing num

* choumx comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants