-
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
Throw TypeErrors for invalid keyframe inputs #471
Changes from 9 commits
71647e7
495bd65
e62cf1e
45d7aac
ba12393
589c40a
17382c3
1382cc6
0ff392f
f8d8bf7
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 |
---|---|---|
|
@@ -104,7 +104,7 @@ | |
return this._direction; | ||
}, | ||
set easing(value) { | ||
this._easingFunction = toTimingFunction(value); | ||
this._easingFunction = parseEasingFunction(normalizeEasing(value)); | ||
this._setMember('easing', value); | ||
}, | ||
get easing() { | ||
|
@@ -224,32 +224,39 @@ | |
var cubicBezierRe = new RegExp('cubic-bezier\\(' + numberString + ',' + numberString + ',' + numberString + ',' + numberString + '\\)'); | ||
var stepRe = /steps\(\s*(\d+)\s*,\s*(start|middle|end)\s*\)/; | ||
|
||
function toTimingFunction(easing) { | ||
function normalizeEasing(easing) { | ||
if (!styleForCleaning) { | ||
styleForCleaning = document.createElement('div').style; | ||
} | ||
styleForCleaning.animationTimingFunction = ''; | ||
styleForCleaning.animationTimingFunction = easing; | ||
var validatedEasing = styleForCleaning.animationTimingFunction; | ||
|
||
if (validatedEasing == '' && isInvalidTimingDeprecated()) { | ||
var normalizedEasing = styleForCleaning.animationTimingFunction; | ||
if (normalizedEasing == '' && isInvalidTimingDeprecated()) { | ||
throw new TypeError(easing + ' is not a valid value for easing'); | ||
} | ||
return normalizedEasing; | ||
} | ||
|
||
var cubicData = cubicBezierRe.exec(validatedEasing); | ||
function parseEasingFunction(normalizedEasing) { | ||
if (normalizedEasing == 'linear') { | ||
return linear; | ||
} | ||
var cubicData = cubicBezierRe.exec(normalizedEasing); | ||
if (cubicData) { | ||
return cubic.apply(this, cubicData.slice(1).map(Number)); | ||
} | ||
var stepData = stepRe.exec(validatedEasing); | ||
var stepData = stepRe.exec(normalizedEasing); | ||
if (stepData) { | ||
return step(Number(stepData[1]), {'start': Start, 'middle': Middle, 'end': End}[stepData[2]]); | ||
} | ||
var preset = presets[validatedEasing]; | ||
var preset = presets[normalizedEasing]; | ||
if (preset) { | ||
return preset; | ||
} | ||
// Easing is invalid, this should never be reached. | ||
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. 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. 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. Updated comment. |
||
// Fall back to linear in the interest of not crashing the page. | ||
return linear; | ||
}; | ||
} | ||
|
||
function calculateActiveDuration(timing) { | ||
return Math.abs(repeatedDuration(timing) / timing.playbackRate); | ||
|
@@ -345,11 +352,13 @@ | |
shared.calculateActiveDuration = calculateActiveDuration; | ||
shared.calculateTimeFraction = calculateTimeFraction; | ||
shared.calculatePhase = calculatePhase; | ||
shared.toTimingFunction = toTimingFunction; | ||
shared.normalizeEasing = normalizeEasing; | ||
shared.parseEasingFunction = parseEasingFunction; | ||
|
||
if (WEB_ANIMATIONS_TESTING) { | ||
testing.normalizeTimingInput = normalizeTimingInput; | ||
testing.toTimingFunction = toTimingFunction; | ||
testing.normalizeEasing = normalizeEasing; | ||
testing.parseEasingFunction = parseEasingFunction; | ||
testing.calculateActiveDuration = calculateActiveDuration; | ||
testing.calculatePhase = calculatePhase; | ||
testing.PhaseNone = PhaseNone; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,18 +17,7 @@ module.exports = { | |
'Element.animate() creates an Animation object': | ||
'assert_equals: Returned object is an Animation expected "[object Animation]" but got "[object Object]"', | ||
|
||
'Element.animate() does not accept keyframes not loosely sorted by offset': | ||
'assert_throws: function "function () {\n"use strict";\n\n div.animate(subtest.input, 2000);\n }" threw object "[object Object]" ("InvalidModificationError") expected object "[object Object]" ("TypeError")', | ||
|
||
'Element.animate() does not accept keyframes with an invalid composite value': | ||
'assert_throws: function "function () {\n"use strict";\n\n div.animate(subtest.input, 2000);\n }" threw object "[object Object]" ("NotSupportedError") expected object "[object Object]" ("TypeError")', | ||
|
||
'Element.animate() does not accept keyframes with an out-of-bounded negative offset': | ||
'assert_throws: function "function () {\n"use strict";\n\n div.animate(subtest.input, 2000);\n }" did not throw', | ||
|
||
'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(). | ||
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. Has a bug been filed against Firefox for this? 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. 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. |
||
'Element.animate() does not accept property-indexed keyframes with an invalid easing value': | ||
'assert_throws: function "function () {\n"use strict";\n\n div.animate(subtest.input, 2000);\n }" did not throw', | ||
}, | ||
|
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.
Should the "property != 'easing'" test in the else clause below (line 33) now be "property != 'easingFunction'"? Or "property != 'easing' && property != 'easingFunction'"?
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.
That check is redundant, should I remove it in this patch?
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.
Can you explain why it is redundant? Do you mean just the "property != 'easing'" test or the whole condition?
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.
The whole condition. This is due to the special handling of these particular members in makePropertySpecificKeyframeGroups().