Skip to content

Commit 1bc45f1

Browse files
authored
Merge pull request #475 from alancutter/throwReversePlayInfiniteDuration
Throw InvalidStateError when calling play() on a finished, reversed, infinite duration animation
2 parents 245aaa2 + 667eba2 commit 1bc45f1

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

src/animation.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@
116116
this._playbackRate = value;
117117
this._startTime = null;
118118
if (this.playState != 'paused' && this.playState != 'idle') {
119-
this.play();
119+
this._finishedFlag = false;
120+
this._idle = false;
121+
this._ensureAlive();
122+
scope.invalidateEffects();
120123
}
121124
if (oldCurrentTime != null) {
122125
this.currentTime = oldCurrentTime;
@@ -141,7 +144,15 @@
141144
play: function() {
142145
this._paused = false;
143146
if (this._isFinished || this._idle) {
144-
this._currentTime = this._playbackRate > 0 ? 0 : this._totalDuration;
147+
if (this._playbackRate >= 0) {
148+
this._currentTime = 0;
149+
} else if (this._totalDuration < Infinity) {
150+
this._currentTime = this._totalDuration;
151+
} else {
152+
throw new DOMException(
153+
'Unable to rewind negative playback rate animation with infinite duration',
154+
'InvalidStateError');
155+
}
145156
this._startTime = null;
146157
}
147158
this._finishedFlag = false;

src/web-animations-next-animation.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,6 @@
276276
this._forEachChild(function(childAnimation) {
277277
childAnimation.playbackRate = value;
278278
});
279-
if (this.playState != 'paused' && this.playState != 'idle') {
280-
this.play();
281-
}
282279
if (oldCurrentTime !== null) {
283280
this.currentTime = oldCurrentTime;
284281
}

test/web-platform-tests-expectations.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ module.exports = {
170170
'KeyframeEffectReadOnly is not defined',
171171

172172
'Test finish() while pause-pending with negative playbackRate':
173-
'assert_equals: The start time of a pause-pending animation should be set after calling finish() expected (undefined) undefined but got (number) 100000',
173+
'assert_equals: The play state of a pause-pending animation should become "finished" after finish() is called expected "finished" but got "paused"',
174174

175175
'Test finish() while pause-pending with positive playbackRate':
176-
'assert_approx_equals: The start time of a pause-pending animation should be set after calling finish() expected NaN +/- 0.0005 but got 0',
176+
'assert_equals: The play state of a pause-pending animation should become "finished" after finish() is called expected "finished" but got "paused"',
177177

178178
'Test finish() while paused':
179179
'assert_equals: The play state of a paused animation should become "finished" after finish() is called expected "finished" but got "paused"',
@@ -226,11 +226,6 @@ module.exports = {
226226
'assert_throws: Expect InvalidStateError exception on calling pause() from idle with a negative playbackRate and infinite-duration animation function "function () {\n"use strict";\n animation.pause(); }" did not throw',
227227
},
228228

229-
'test/web-platform-tests/web-animations/interfaces/Animation/play.html': {
230-
'play() throws when seeking an infinite-duration animation played in reverse':
231-
'assert_throws: Expected InvalidStateError exception on calling play() with a negative playbackRate and infinite-duration animation function "function () {\n"use strict";\n animation.play(); }" did not throw',
232-
},
233-
234229
'test/web-platform-tests/web-animations/interfaces/Animation/playState.html': {
235230
'Animation.playState is \'paused\' after cancelling an animation, seeking it makes it paused':
236231
'assert_equals: After seeking an idle animation, it is effectively paused expected "paused" but got "idle"',
@@ -254,9 +249,6 @@ module.exports = {
254249
'reverse() when playbackRate > 0 and currentTime < 0':
255250
'assert_equals: reverse() should start playing from the animation effect end if the playbackRate > 0 and the currentTime < 0 expected 100000 but got -200000',
256251

257-
'reverse() when playbackRate > 0 and currentTime < 0 and the target effect end is positive infinity':
258-
'assert_throws: reverse() should throw InvalidStateError if the playbackRate > 0 and the currentTime < 0 and the target effect is positive infinity function "function () {\n"use strict";\n animation.reverse(); }" did not throw',
259-
260252
'reverse() when playbackRate > 0 and currentTime > effect end':
261253
'assert_equals: reverse() should start playing from the animation effect end if the playbackRate > 0 and the currentTime > effect end expected 100000 but got 200000',
262254
},

0 commit comments

Comments
 (0)