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

Add try-catch guard to object-form loading check #434

Merged
merged 3 commits into from
Apr 28, 2016
Merged

Add try-catch guard to object-form loading check #434

merged 3 commits into from
Apr 28, 2016

Conversation

suzyh
Copy link
Contributor

@suzyh suzyh commented Apr 27, 2016

The object-form-keyframes source file uses a call to Element.animate
to decide whether to load the polyfill for the object-form syntax.
If the native browser code supports Element.animate without full
support for object-form syntax, this test can throw a TypeError (see
web-animations/web-animations-js#72). In
this case, the polyfill should proceed to load the polyfill. This
patch implements this behaviour with a try-catch guard around the
Element.animate loading check.

The object-form-keyframes source file uses a call to Element.animate
to decide whether to load the polyfill for the object-form syntax.
If the native browser code supports Element.animate without full
support for object-form syntax, this test can throw a TypeError (see
web-animations/web-animations-js#72). In
this case, the polyfill should proceed to load the polyfill. This
patch implements this behaviour with a try-catch guard around the
Element.animate loading check.
var animation = element.animate({'opacity': ['1', '0']},
{duration: 1, fill: 'forwards'});
animation.finish();
animated = getComputedStyle(element).getPropertyValue('opacity') == '0';
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm concerned that if the browser throws an exception here the entire document will be hidden. I think the check should use opacity: [0, 1], not specify fill: 'forwards' and seek currentTime to 0 instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should ensure that if an animation is created, it is cancelled, regardless of whether an exception is thrown or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewritten, with an extensive comment, because I felt the reasoning behind the structure was not clear. PTAL.

In response to review comments, this patch rewrites the test animation
in the object-form-keyframes load check, to be more definite that it
will leave the element opacity untouched regardless of the outcome.
Since the logic is now not obvious, a lengthy explanatory comment is
also added.
@alancutter
Copy link
Contributor

lgtm. The comment is a bit more "what" than "why" for my liking but it's not a huge deal.

@dstoc
Copy link
Contributor

dstoc commented Apr 27, 2016

lgtm, but I'll leave a few nits that you might want to clean up.

var animated = getComputedStyle(element).getPropertyValue('opacity') == '0';
animation.cancel();
var animation = null;
var animated = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Initialize to false.

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.

@suzyh
Copy link
Contributor Author

suzyh commented Apr 27, 2016

Thanks for the reviews, all done. If you have any specific suggestions for how to improve the comment, I'll incorporate them, but I'm not sure what else to add to clarify the 'why'.

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

Successfully merging this pull request may close these issues.

3 participants