diff --git a/src/map.js b/src/map.js index f5000ac9e1..c964e04aef 100644 --- a/src/map.js +++ b/src/map.js @@ -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); + } } } diff --git a/tests/cases/map.js b/tests/cases/map.js index 9a0bdf8b79..5bbb09f026 100644 --- a/tests/cases/map.js +++ b/tests/cases/map.js @@ -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);