Bug 1874684 - Part 28: Return DateDuration from DifferenceISODateTime. r=mgaudet
[gecko.git] / toolkit / actors / TestWindowChild.sys.mjs
blob5df64c932ccffc51a5666f8bdd7d53aa60a1318d
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/. */
6 var docShellThunks = new Map();
8 export class TestWindowChild extends JSWindowActorChild {
9   constructor() {
10     super();
11     this.sawActorCreated = false;
13     try {
14       void this.contentWindow;
15     } catch (e) {
16       this.uninitializedGetterError = e;
17     }
18   }
20   actorCreated() {
21     this.sawActorCreated = true;
22   }
24   receiveMessage(aMessage) {
25     switch (aMessage.name) {
26       case "toChild":
27         aMessage.data.toChild = true;
28         this.sendAsyncMessage("toParent", aMessage.data);
29         break;
30       case "asyncAdd":
31         let { a, b } = aMessage.data;
32         return new Promise(resolve => {
33           resolve({ result: a + b });
34         });
35       case "error":
36         return Promise.reject(new SyntaxError(aMessage.data.message));
37       case "exception":
38         return Promise.reject(
39           Components.Exception(aMessage.data.message, aMessage.data.result)
40         );
41       case "done":
42         this.done(aMessage.data);
43         break;
44       case "noncloneReply":
45         // Return a value which is non-cloneable, like a WindowProxy.
46         return this.contentWindow;
47       case "storeActor":
48         docShellThunks.set(this.docShell, this);
49         break;
50       case "checkActor": {
51         let actor = docShellThunks.get(this.docShell);
52         docShellThunks.delete(this.docShell);
54         let contentWindow;
55         let error;
56         try {
57           contentWindow = actor.contentWindow;
58         } catch (e) {
59           error = e;
60         }
61         if (error) {
62           return {
63             status: "error",
64             errorType: error.name,
65           };
66         }
67         return {
68           status: "success",
69           valueIsNull: contentWindow === null,
70         };
71       }
72     }
74     return undefined;
75   }
77   handleEvent(aEvent) {
78     this.sendAsyncMessage("event", { type: aEvent.type });
79   }
81   observe(subject, topic, data) {
82     switch (topic) {
83       case "audio-playback":
84         this.done({ subject, topic, data });
85         break;
86       default:
87         this.lastObserved = { subject, topic, data };
88         break;
89     }
90   }
92   show() {
93     return "TestWindowChild";
94   }
96   didDestroy() {
97     Services.obs.notifyObservers(this, "test-js-window-actor-diddestroy", true);
98   }