зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1012887 - DataStoreCursorImpl.jsm must check if the window is still available, r=gene
This commit is contained in:
Родитель
6310198c94
Коммит
8dd76ef9c7
|
@ -27,6 +27,7 @@ const REVISION_REMOVED = 'removed';
|
|||
const REVISION_VOID = 'void';
|
||||
const REVISION_SKIP = 'skip'
|
||||
|
||||
Cu.import('resource://gre/modules/Services.jsm');
|
||||
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
||||
|
||||
/**
|
||||
|
@ -87,6 +88,8 @@ this.DataStoreCursor.prototype = {
|
|||
contractID: '@mozilla.org/dom/datastore-cursor-impl;1',
|
||||
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsISupports]),
|
||||
|
||||
_shuttingdown: false,
|
||||
|
||||
_window: null,
|
||||
_dataStore: null,
|
||||
_revisionId: null,
|
||||
|
@ -102,6 +105,20 @@ this.DataStoreCursor.prototype = {
|
|||
this._window = aWindow;
|
||||
this._dataStore = aDataStore;
|
||||
this._revisionId = aRevisionId;
|
||||
|
||||
Services.obs.addObserver(this, "inner-window-destroyed", false);
|
||||
|
||||
let util = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindowUtils);
|
||||
this._innerWindowID = util.currentInnerWindowID;
|
||||
},
|
||||
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
let wId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
|
||||
if (wId == this._innerWindowID) {
|
||||
Services.obs.removeObserver(this, "inner-window-destroyed");
|
||||
this._shuttingdown = true;
|
||||
}
|
||||
},
|
||||
|
||||
// This is the implementation of the state machine.
|
||||
|
@ -109,6 +126,11 @@ this.DataStoreCursor.prototype = {
|
|||
stateMachine: function(aStore, aRevisionStore, aResolve, aReject) {
|
||||
debug('StateMachine: ' + this._state);
|
||||
|
||||
// If the window has been destroyed we cannot create the Promise object.
|
||||
if (this._shuttingdown) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (this._state) {
|
||||
case STATE_INIT:
|
||||
this.stateMachineInit(aStore, aRevisionStore, aResolve, aReject);
|
||||
|
@ -387,6 +409,11 @@ this.DataStoreCursor.prototype = {
|
|||
next: function() {
|
||||
debug('Next');
|
||||
|
||||
// If the window has been destroyed we cannot create the Promise object.
|
||||
if (this._shuttingdown) {
|
||||
throw Cr.NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
let self = this;
|
||||
return new this._window.Promise(function(aResolve, aReject) {
|
||||
self._dataStore._db.cursorTxn(
|
||||
|
|
Загрузка…
Ссылка в новой задаче