Skip to content

Commit 7e828c1

Browse files
author
Sebastian Kippe
authored
Merge pull request #1118 from remotestorage/bugfix/1117-fix_undefined_stopped_property
Don't fail when sync instance is not defined
2 parents b85f2bb + fa2642f commit 7e828c1

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/remotestorage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,13 +701,13 @@ RemoteStorage.prototype = {
701701
* @private
702702
*/
703703
syncCycle: function () {
704-
if (this.sync.stopped) {
704+
if (!this.sync || this.sync.stopped) {
705705
return;
706706
}
707707

708708
this.on('sync-done', function () {
709709
log('[Sync] Sync done. Setting timer to', this.getCurrentSyncInterval());
710-
if (!this.sync.stopped) {
710+
if (this.sync && !this.sync.stopped) {
711711
if (this._syncTimer) {
712712
clearTimeout(this._syncTimer);
713713
this._syncTimer = undefined;

test/unit/remotestorage-suite.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,43 @@ define(['require', 'tv4', './src/eventhandling'], function (require, tv4, eventH
593593
}
594594
},
595595

596+
{
597+
desc: "#syncCycle does not register any event handlers when there is no sync instance",
598+
run: function (env, test) {
599+
env.rs.syncCycle();
600+
601+
test.assert(env.rs._handlers["sync-done"].length, 0);
602+
}
603+
},
604+
605+
{
606+
desc: "sync-done handler does not reschedule a new sync when sync is stopped",
607+
run: function (env, test) {
608+
env.rs.sync = { sync: function() {} };
609+
env.rs.syncCycle();
610+
611+
env.rs.sync.stopped = true;
612+
613+
env.rs._emit('sync-done');
614+
615+
test.assert(env.rs._syncTimer, undefined);
616+
}
617+
},
618+
619+
{
620+
desc: "sync-done handler does not reschedule a new sync when there is no sync instance",
621+
run: function (env, test) {
622+
env.rs.sync = { sync: function() {} };
623+
env.rs.syncCycle();
624+
625+
env.rs.sync = undefined;
626+
627+
env.rs._emit('sync-done');
628+
629+
test.assert(env.rs._syncTimer, undefined);
630+
}
631+
},
632+
596633
{
597634
desc: "#stopSync clears any scheduled sync calls",
598635
run: function (env, test) {

0 commit comments

Comments
 (0)