зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1337537 - Avoid SystemGroup assertion during WebAudio test (r=ehsan)
MozReview-Commit-ID: 9GbXnkF4fvZ
This commit is contained in:
Родитель
70d043f2ab
Коммит
225fab4ac5
|
@ -29,10 +29,10 @@ function id(node) {
|
|||
return SpecialPowers.getPrivilegedProps(node, "id");
|
||||
}
|
||||
|
||||
SpecialPowers.addObserver(observer, "webaudio-node-demise", false);
|
||||
SpecialPowers.addAsyncObserver(observer, "webaudio-node-demise", false);
|
||||
|
||||
SimpleTest.registerCleanupFunction(function() {
|
||||
SpecialPowers.removeObserver(observer, "webaudio-node-demise");
|
||||
SpecialPowers.removeAsyncObserver(observer, "webaudio-node-demise");
|
||||
});
|
||||
|
||||
var ac = new AudioContext();
|
||||
|
|
|
@ -1213,6 +1213,38 @@ SpecialPowersAPI.prototype = {
|
|||
Services.obs.notifyObservers(subject, topic, data);
|
||||
},
|
||||
|
||||
/**
|
||||
* An async observer is useful if you're listening for a
|
||||
* notification that normally is only used by C++ code or chrome
|
||||
* code (so it runs in the SystemGroup), but we need to know about
|
||||
* it for a test (which runs as web content). If we used
|
||||
* addObserver, we would assert when trying to enter web content
|
||||
* from a runnabled labeled by the SystemGroup. An async observer
|
||||
* avoids this problem.
|
||||
*/
|
||||
_asyncObservers: new WeakMap(),
|
||||
addAsyncObserver: function(obs, notification, weak) {
|
||||
obs = Cu.waiveXrays(obs);
|
||||
if (typeof obs == 'object' && obs.observe.name != 'SpecialPowersCallbackWrapper') {
|
||||
obs.observe = wrapCallback(obs.observe);
|
||||
}
|
||||
let asyncObs = (...args) => {
|
||||
Services.tm.mainThread.dispatch(() => {
|
||||
if (typeof obs == 'function') {
|
||||
obs.call(undefined, ...args);
|
||||
} else {
|
||||
obs.observe.call(undefined, ...args);
|
||||
}
|
||||
}, Ci.nsIThread.DISPATCH_NORMAL);
|
||||
};
|
||||
this._asyncObservers.set(obs, asyncObs);
|
||||
Services.obs.addObserver(asyncObs, notification, weak);
|
||||
},
|
||||
removeAsyncObserver: function(obs, notification) {
|
||||
let asyncObs = this._asyncObservers.get(Cu.waiveXrays(obs));
|
||||
Services.obs.removeObserver(asyncObs, notification);
|
||||
},
|
||||
|
||||
can_QI: function(obj) {
|
||||
return obj.QueryInterface !== undefined;
|
||||
},
|
||||
|
|
Загрузка…
Ссылка в новой задаче