зеркало из https://github.com/mozilla/gecko-dev.git
Bug 773980 - Don't touch dead objects in BrowserElementParent.js. r=mounir
This commit is contained in:
Родитель
488861592f
Коммит
e3da02bc90
|
@ -136,7 +136,12 @@ function BrowserElementParent(frameLoader) {
|
|||
|
||||
let self = this;
|
||||
function addMessageListener(msg, handler) {
|
||||
self._mm.addMessageListener('browser-element-api:' + msg, handler.bind(self));
|
||||
function checkedHandler() {
|
||||
if (self._isAlive()) {
|
||||
handler.apply(self, arguments);
|
||||
}
|
||||
}
|
||||
self._mm.addMessageListener('browser-element-api:' + msg, checkedHandler);
|
||||
}
|
||||
|
||||
addMessageListener("hello", this._recvHello);
|
||||
|
@ -157,11 +162,19 @@ function BrowserElementParent(frameLoader) {
|
|||
addMessageListener('got-can-go-forward', this._gotDOMRequestResult);
|
||||
|
||||
function defineMethod(name, fn) {
|
||||
XPCNativeWrapper.unwrap(self._frameElement)[name] = fn.bind(self);
|
||||
XPCNativeWrapper.unwrap(self._frameElement)[name] = function() {
|
||||
if (self._isAlive()) {
|
||||
return fn.apply(self, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function defineDOMRequestMethod(domName, msgName) {
|
||||
XPCNativeWrapper.unwrap(self._frameElement)[domName] = self._sendDOMRequest.bind(self, msgName);
|
||||
XPCNativeWrapper.unwrap(self._frameElement)[domName] = function() {
|
||||
if (self._isAlive()) {
|
||||
return self._sendDOMRequest(msgName);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Define methods on the frame element.
|
||||
|
@ -176,6 +189,16 @@ function BrowserElementParent(frameLoader) {
|
|||
}
|
||||
|
||||
BrowserElementParent.prototype = {
|
||||
/**
|
||||
* You shouldn't touch this._frameElement or this._window if _isAlive is
|
||||
* false. (You'll likely get an exception if you do.)
|
||||
*/
|
||||
_isAlive: function() {
|
||||
return !Cu.isDeadWrapper(this._frameElement) &&
|
||||
!Cu.isDeadWrapper(this._frameElement.ownerDocument) &&
|
||||
!Cu.isDeadWrapper(this._frameElement.ownerDocument.defaultView);
|
||||
},
|
||||
|
||||
get _window() {
|
||||
return this._frameElement.ownerDocument.defaultView;
|
||||
},
|
||||
|
|
Загрузка…
Ссылка в новой задаче