1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
/* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
/* global noSuchMethodExistsYo1, noSuchMethodExistsYo2, noSuchMethodExistsYo3 */
export function TestInterfaceJS() {}
TestInterfaceJS.prototype = {
QueryInterface: ChromeUtils.generateQI([
"nsIDOMGlobalPropertyInitializer",
"mozITestInterfaceJS",
]),
init(win) {
this._win = win;
},
__init(anyArg, objectArg, dictionaryArg) {
this._anyAttr = undefined;
this._objectAttr = null;
this._anyArg = anyArg;
this._objectArg = objectArg;
this._dictionaryArg = dictionaryArg;
},
get anyArg() {
return this._anyArg;
},
get objectArg() {
return this._objectArg;
},
getDictionaryArg() {
return this._dictionaryArg;
},
get anyAttr() {
return this._anyAttr;
},
set anyAttr(val) {
this._anyAttr = val;
},
get objectAttr() {
return this._objectAttr;
},
set objectAttr(val) {
this._objectAttr = val;
},
getDictionaryAttr() {
return this._dictionaryAttr;
},
setDictionaryAttr(val) {
this._dictionaryAttr = val;
},
pingPongAny(any) {
return any;
},
pingPongObject(obj) {
return obj;
},
pingPongObjectOrString(objectOrString) {
return objectOrString;
},
pingPongDictionary(dict) {
return dict;
},
pingPongDictionaryOrLong(dictOrLong) {
return dictOrLong.anyMember || dictOrLong;
},
pingPongRecord(rec) {
return JSON.stringify(rec);
},
objectSequenceLength(seq) {
return seq.length;
},
anySequenceLength(seq) {
return seq.length;
},
getCallerPrincipal() {
return Cu.getWebIDLCallerPrincipal().origin;
},
convertSVS(svs) {
return svs;
},
pingPongUnion(x) {
return x;
},
pingPongUnionContainingNull(x) {
return x;
},
pingPongNullableUnion(x) {
return x;
},
returnBadUnion() {
return 3;
},
testSequenceOverload() {},
testSequenceUnion() {},
testThrowError() {
throw new this._win.Error("We are an Error");
},
testThrowDOMException() {
throw new this._win.DOMException(
"We are a DOMException",
"NotSupportedError"
);
},
testThrowTypeError() {
throw new this._win.TypeError("We are a TypeError");
},
testThrowNsresult() {
// This is explicitly testing preservation of raw thrown Crs in XPCJS
// eslint-disable-next-line mozilla/no-throw-cr-literal
throw Cr.NS_BINDING_ABORTED;
},
testThrowNsresultFromNative() {
// We want to throw an exception that we generate from an nsresult thrown
// by a C++ component.
Services.io.notImplemented();
},
testThrowCallbackError(callback) {
callback();
},
testThrowXraySelfHosted() {
this._win.Array.prototype.forEach();
},
testThrowSelfHosted() {
Array.prototype.forEach();
},
testPromiseWithThrowingChromePromiseInit() {
return new this._win.Promise(function () {
noSuchMethodExistsYo1();
});
},
testPromiseWithThrowingContentPromiseInit(func) {
return new this._win.Promise(func);
},
testPromiseWithDOMExceptionThrowingPromiseInit() {
return new this._win.Promise(() => {
throw new this._win.DOMException(
"We are a second DOMException",
"NotFoundError"
);
});
},
testPromiseWithThrowingChromeThenFunction() {
return this._win.Promise.resolve(5).then(function () {
noSuchMethodExistsYo2();
});
},
testPromiseWithThrowingContentThenFunction(func) {
return this._win.Promise.resolve(10).then(func);
},
testPromiseWithDOMExceptionThrowingThenFunction() {
return this._win.Promise.resolve(5).then(() => {
throw new this._win.DOMException(
"We are a third DOMException",
"NetworkError"
);
});
},
testPromiseWithThrowingChromeThenable() {
var thenable = {
then() {
noSuchMethodExistsYo3();
},
};
return new this._win.Promise(function (resolve) {
resolve(thenable);
});
},
testPromiseWithThrowingContentThenable(thenable) {
// Waive Xrays on the thenable, because we're calling resolve() in the
// chrome compartment, so that's the compartment the "then" property get
// will happen in, and if we leave the Xray in place the function-valued
// property won't return the function.
return this._win.Promise.resolve(Cu.waiveXrays(thenable));
},
testPromiseWithDOMExceptionThrowingThenable() {
var thenable = {
then: () => {
throw new this._win.DOMException(
"We are a fourth DOMException",
"TypeMismatchError"
);
},
};
return new this._win.Promise(function (resolve) {
resolve(thenable);
});
},
get onsomething() {
return this.__DOM_IMPL__.getEventHandler("onsomething");
},
set onsomething(val) {
this.__DOM_IMPL__.setEventHandler("onsomething", val);
},
};
|