|
16 | 16 |
|
17 | 17 | var fills = 'backwards|forwards|both|none'.split('|');
|
18 | 18 | var directions = 'reverse|alternate|alternate-reverse'.split('|');
|
| 19 | + var linear = function(x) { return x; }; |
19 | 20 |
|
20 | 21 | function cloneTimingInput(timingInput) {
|
21 | 22 | if (typeof timingInput == 'number') {
|
|
38 | 39 | this._playbackRate = 1;
|
39 | 40 | this._direction = 'normal';
|
40 | 41 | this._easing = 'linear';
|
| 42 | + this._easingFunction = linear; |
41 | 43 | }
|
42 | 44 |
|
43 | 45 | AnimationEffectTiming.prototype = {
|
|
74 | 76 | return this._fill;
|
75 | 77 | },
|
76 | 78 | set iterationStart(value) {
|
| 79 | + if (isNaN(value) || value < 0) { |
| 80 | + throw new TypeError('iterationStart must be a non-negative number, received: ' + timing.iterationStart); |
| 81 | + } |
77 | 82 | this._setMember('iterationStart', value);
|
78 | 83 | },
|
79 | 84 | get iterationStart() {
|
80 | 85 | return this._iterationStart;
|
81 | 86 | },
|
82 | 87 | set duration(value) {
|
| 88 | + if (value != 'auto' && (isNaN(value) || value < 0)) { |
| 89 | + throw new TypeError('duration must be non-negative or auto, received: ' + value); |
| 90 | + } |
83 | 91 | this._setMember('duration', value);
|
84 | 92 | },
|
85 | 93 | get duration() {
|
|
92 | 100 | return this._direction;
|
93 | 101 | },
|
94 | 102 | set easing(value) {
|
| 103 | + this._easingFunction = toTimingFunction(value); |
95 | 104 | this._setMember('easing', value);
|
96 | 105 | },
|
97 | 106 | get easing() {
|
98 | 107 | return this._easing;
|
99 | 108 | },
|
100 | 109 | set iterations(value) {
|
| 110 | + if (isNaN(value) || value < 0) { |
| 111 | + throw new TypeError('iterations must be non-negative, received: ' + value); |
| 112 | + } |
101 | 113 | this._setMember('iterations', value);
|
102 | 114 | },
|
103 | 115 | get iterations() {
|
|
150 | 162 |
|
151 | 163 | function normalizeTimingInput(timingInput, forGroup) {
|
152 | 164 | timingInput = shared.numericTimingToObject(timingInput);
|
153 |
| - var timing = makeTiming(timingInput, forGroup); |
154 |
| - timing._easingFunction = toTimingFunction(timing.easing); |
155 |
| - return timing; |
| 165 | + return makeTiming(timingInput, forGroup); |
156 | 166 | }
|
157 | 167 |
|
158 | 168 | function cubic(a, b, c, d) {
|
|
209 | 219 | var numberString = '\\s*(-?\\d+\\.?\\d*|-?\\.\\d+)\\s*';
|
210 | 220 | var cubicBezierRe = new RegExp('cubic-bezier\\(' + numberString + ',' + numberString + ',' + numberString + ',' + numberString + '\\)');
|
211 | 221 | var stepRe = /steps\(\s*(\d+)\s*,\s*(start|middle|end)\s*\)/;
|
212 |
| - var linear = function(x) { return x; }; |
213 | 222 |
|
214 | 223 | function toTimingFunction(easing) {
|
215 | 224 | if (!styleForCleaning) {
|
216 | 225 | styleForCleaning = document.createElement('div').style;
|
217 | 226 | }
|
218 | 227 | styleForCleaning.animationTimingFunction = '';
|
219 | 228 | styleForCleaning.animationTimingFunction = easing;
|
220 |
| - easing = styleForCleaning.animationTimingFunction; |
| 229 | + var validatedEasing = styleForCleaning.animationTimingFunction; |
| 230 | + |
| 231 | + if (validatedEasing == '') { |
| 232 | + throw new TypeError(easing + ' is not a valid value for easing'); |
| 233 | + } |
221 | 234 |
|
222 |
| - var cubicData = cubicBezierRe.exec(easing); |
| 235 | + var cubicData = cubicBezierRe.exec(validatedEasing); |
223 | 236 | if (cubicData) {
|
224 | 237 | return cubic.apply(this, cubicData.slice(1).map(Number));
|
225 | 238 | }
|
226 |
| - var stepData = stepRe.exec(easing); |
| 239 | + var stepData = stepRe.exec(validatedEasing); |
227 | 240 | if (stepData) {
|
228 | 241 | return step(Number(stepData[1]), {'start': Start, 'middle': Middle, 'end': End}[stepData[2]]);
|
229 | 242 | }
|
230 |
| - var preset = presets[easing]; |
| 243 | + var preset = presets[validatedEasing]; |
231 | 244 | if (preset) {
|
232 | 245 | return preset;
|
233 | 246 | }
|
|
0 commit comments