1 /* vim: set ts=2 sw=2 sts=2 et tw=80: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
9 var EXPORTED_SYMBOLS = ["TestWindowChild"];
11 var docShellThunks = new Map();
13 class TestWindowChild extends JSWindowActorChild {
16 this.sawActorCreated = false;
19 void this.contentWindow;
21 this.uninitializedGetterError = e;
26 this.sawActorCreated = true;
29 receiveMessage(aMessage) {
30 switch (aMessage.name) {
32 aMessage.data.toChild = true;
33 this.sendAsyncMessage("toParent", aMessage.data);
36 let { a, b } = aMessage.data;
37 return new Promise(resolve => {
38 resolve({ result: a + b });
41 return Promise.reject(new SyntaxError(aMessage.data.message));
43 return Promise.reject(
44 Components.Exception(aMessage.data.message, aMessage.data.result)
47 this.done(aMessage.data);
50 // Return a value which is non-cloneable, like a WindowProxy.
51 return this.contentWindow;
53 docShellThunks.set(this.docShell, this);
56 let actor = docShellThunks.get(this.docShell);
57 docShellThunks.delete(this.docShell);
62 contentWindow = actor.contentWindow;
69 errorType: error.name,
74 valueIsNull: contentWindow === null,
83 this.sendAsyncMessage("event", { type: aEvent.type });
86 observe(subject, topic, data) {
88 case "audio-playback":
89 this.done({ subject, topic, data });
92 this.lastObserved = { subject, topic, data };
98 return "TestWindowChild";
102 Services.obs.notifyObservers(this, "test-js-window-actor-diddestroy", true);