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

Throw TypeErrors for invalid keyframe inputs #471

Merged
merged 10 commits into from
Jul 22, 2016
Merged

Throw TypeErrors for invalid keyframe inputs #471

merged 10 commits into from
Jul 22, 2016

Conversation

alancutter
Copy link
Contributor

Throw TypeErrors for the following scenarios:

  • Invalid easing on keyframe.
  • Unsorted keyframe offsets as input.
  • Out of bounds keyframe offset.

This change builds upon #470.

@alancutter alancutter changed the title Throw Throw TypeErrors for invalid keyframe inputs Jun 15, 2016
@alancutter
Copy link
Contributor Author

I wonder if we should be deprecating these first before throwing TypeErrors.

'Element.animate() does not accept keyframes with an out-of-bounded positive offset':
'assert_throws: function "function () {\n"use strict";\n\n div.animate(subtest.input, 2000);\n }" did not throw',

// Seems to be a bug in Firefox 47? The TypeError is thrown but disappears by the time it bubbles up to assert_throws().
Copy link
Contributor

Choose a reason for hiding this comment

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

Has a bug been filed against Firefox for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a bit convoluted to reproduce in a bug report, given that Firefox is going to ship element.animate() in the next version I'm not sure it's worth the effort.

@suzyh
Copy link
Contributor

suzyh commented Jun 24, 2016

I don't think deprecation is necessary before the TypeErrors you're adding here, particularly since people would need to deliberately upgrade their version of the polyfill to get them (as opposed to just getting them by a push from us).

@@ -297,6 +301,7 @@
return keyframes;
}

shared.easingFunctionSymbol = window.Symbol ? Symbol('easingFunction') : '_easingFunction';
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed offline, given that nothing else in the polyfill uses window.Symbol in this way, and it is not always available, I would rather just use _easingFunction throughout.

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

suzyh commented Jul 11, 2016

I found myself taking a careful look at the code in keyframe-interpolations.js to check whether each "easingFunction" was supposed to have an underscore to start or not. This suggests to me that we need to either (a) refactor the code to make it obvious when things are being mixed up (e.g. by having Interpolations and PropertySpecificKeyframes defined as separate classes in their own files), or (b) make them all the same, or (c) add tests to help catch stupid mistakes when changing this code. WDYT?

@alancutter
Copy link
Contributor Author

It kind of is separated by files already. normalize-keyframes.js is processing user input and its output should in theory be able to be used again as user input, this is why we underscore it as it may get exposed to the user again.
In keyframe-interpolations.js we're creating internal structures that should never be shown to the user, this is hinted at by the lack of underscore properties.

You've made me realise a potential bug where normalizeKeyframes() doesn't handle the presence of _easingFunction in a keyframe very well.

@alancutter
Copy link
Contributor Author

Also I originally did mix up the use of underscore in this code accidentally, the mistake was caught by multiple tests as keyframe easing no longer functioned.

@alancutter
Copy link
Contributor Author

Discussed offline that instead of storing _easingFunction on the normalised keyframe we can store it in a global cache that interpolations look up later on to reuse the parsing work. Reminder that parsing must happen in normalizeKeyframes() in order for easing TypeErrors to be thrown at the correct time.

@alancutter
Copy link
Contributor Author

Turns out there's no need for caching. I've split toTimingFunction() up into normalizeEasing() and parseEasingFunction() which are called during normalisation and interpolation creation respectively as separate actions. PTAL.

if (preset) {
return preset;
}
// Easing is invalid, this should never be reached.
Copy link
Contributor

@suzyh suzyh Jul 22, 2016

Choose a reason for hiding this comment

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

Nit: Elaborate this comment slightly (or add a comment to the start of the function) to explain that this is because parseEasingFunction has as a precondition that it be passed a valid, normalized easing string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated comment.

@suzyh
Copy link
Contributor

suzyh commented Jul 22, 2016

lgtm with nit

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.

2 participants