Skip to content

Commit

Permalink
Merge pull request #911 from OpenGeoscience/catch-animation-frame-errors
Browse files Browse the repository at this point in the history
Catch errors in animation frame callbacks
  • Loading branch information
jbeezley authored Aug 30, 2018
2 parents 8cc705f + fd8dc0a commit 2746002
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -1803,7 +1803,11 @@ var map = function (arg) {

/* The first entry is the reference to the window.requestAnimationFrame. */
for (var i = 1; i < queue.length; i += 1) {
queue[i].apply(this, arguments);
try {
queue[i].apply(this, arguments);
} catch (err) {
console.error(err);
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions tests/cases/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,20 @@ describe('geo.core.map', function () {
expect(queue3).not.toEqual(queue2);
unmockAnimationFrame();
});
it('animationQueue with bad callback', function () {
mockAnimationFrame();
var error = sinon.stub(console, 'error', function () {}),
m = createMap(),
called = 0,
start = new Date().getTime();
m.scheduleAnimationFrame(function () { throw new Error('fail'); });
m.scheduleAnimationFrame(function () { called += 1; });
stepAnimationFrame(start);
unmockAnimationFrame();
expect(called).toBe(1);
expect(error.calledOnce).toBe(true);
console.error.restore();
});
it('autoResize', function () {
var m = createMap();
expect(m.autoResize()).toBe(true);
Expand Down

0 comments on commit 2746002

Please sign in to comment.