-
Notifications
You must be signed in to change notification settings - Fork 30
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
try { | ||
var animation = element.animate({'opacity': ['1', '0']}, | ||
{duration: 1, fill: 'forwards'}); | ||
animation.finish(); | ||
animated = getComputedStyle(element).getPropertyValue('opacity') == '0'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can drop this once it inits to false There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
if (animated) { | ||
return; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize to false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.