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