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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/web-animations-bonus-object-form-keyframes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@
// If an animation with the new syntax applies an effect, there's no need
// to load this part of the polyfill.
var element = document.documentElement;
var animation = element.animate({'opacity': ['1', '0']},
{duration: 1, fill: 'forwards'});
animation.finish();
var animated = getComputedStyle(element).getPropertyValue('opacity') == '0';
animation.cancel();
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.

try {
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.

animation.cancel();
} catch (err) {
animated = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

can drop this once it inits 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.

}
if (animated) {
return;
}
Expand Down