mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-02 06:22:20 +00:00
NOT PART OF THE BUILD - simple observer test to demonstrate use of weak references
This commit is contained in:
parent
b3988570b3
commit
3ad4de6403
34
js/src/xpconnect/tests/js/old/xpctest_observer.js
Normal file
34
js/src/xpconnect/tests/js/old/xpctest_observer.js
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
const observerInterface = Components.interfaces.nsIObserverService;
|
||||
const observerClazz = Components.classes["@mozilla.org/observer-service;1"];
|
||||
var observerService = observerClazz.getService(observerInterface);
|
||||
|
||||
var observer1 = {
|
||||
Observe : function(aSubject, aTopic, someData) {
|
||||
print("observer1 notified for: "+aTopic+" with: "+someData);
|
||||
},
|
||||
QueryInterface: function (iid) {
|
||||
if (iid.equals(Components.interfaces.nsISupportsWeakReference)) {
|
||||
return this;
|
||||
}
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
}
|
||||
|
||||
var observer2 = {
|
||||
Observe : function(aSubject, aTopic, someData) {
|
||||
print("observer2 notified for: "+aTopic+" with: "+someData);
|
||||
}
|
||||
}
|
||||
|
||||
const topic = "xpctest_observer_topic";
|
||||
observerService.AddObserver(observer1, topic);
|
||||
observerService.AddObserver(observer2, topic);
|
||||
|
||||
observerService.Notify(null, topic, "notification 1");
|
||||
gc();
|
||||
observer1 = null;
|
||||
observer2 = null;
|
||||
observerService.Notify(null, topic, "notification 2");
|
||||
gc();
|
||||
observerService.Notify(null, topic, "notification 3");
|
Loading…
x
Reference in New Issue
Block a user