1 /* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /* global noSuchMethodExistsYo1, noSuchMethodExistsYo2, noSuchMethodExistsYo3 */
7 export function TestInterfaceJS() {}
9 TestInterfaceJS.prototype = {
10 QueryInterface: ChromeUtils.generateQI([
11 "nsIDOMGlobalPropertyInitializer",
12 "mozITestInterfaceJS",
19 __init(anyArg, objectArg, dictionaryArg) {
20 this._anyAttr = undefined;
21 this._objectAttr = null;
22 this._anyArg = anyArg;
23 this._objectArg = objectArg;
24 this._dictionaryArg = dictionaryArg;
31 return this._objectArg;
34 return this._dictionaryArg;
43 return this._objectAttr;
46 this._objectAttr = val;
49 return this._dictionaryAttr;
51 setDictionaryAttr(val) {
52 this._dictionaryAttr = val;
60 pingPongObjectOrString(objectOrString) {
61 return objectOrString;
63 pingPongDictionary(dict) {
66 pingPongDictionaryOrLong(dictOrLong) {
67 return dictOrLong.anyMember || dictOrLong;
70 return JSON.stringify(rec);
72 objectSequenceLength(seq) {
75 anySequenceLength(seq) {
79 getCallerPrincipal() {
80 return Cu.getWebIDLCallerPrincipal().origin;
90 pingPongUnionContainingNull(x) {
93 pingPongNullableUnion(x) {
100 testSequenceOverload() {},
101 testSequenceUnion() {},
104 throw new this._win.Error("We are an Error");
107 testThrowDOMException() {
108 throw new this._win.DOMException(
109 "We are a DOMException",
114 testThrowTypeError() {
115 throw new this._win.TypeError("We are a TypeError");
118 testThrowNsresult() {
119 // This is explicitly testing preservation of raw thrown Crs in XPCJS
120 // eslint-disable-next-line mozilla/no-throw-cr-literal
121 throw Cr.NS_BINDING_ABORTED;
124 testThrowNsresultFromNative() {
125 // We want to throw an exception that we generate from an nsresult thrown
126 // by a C++ component.
127 Services.io.notImplemented();
130 testThrowCallbackError(callback) {
134 testThrowXraySelfHosted() {
135 this._win.Array.prototype.forEach();
138 testThrowSelfHosted() {
139 Array.prototype.forEach();
142 testPromiseWithThrowingChromePromiseInit() {
143 return new this._win.Promise(function () {
144 noSuchMethodExistsYo1();
148 testPromiseWithThrowingContentPromiseInit(func) {
149 return new this._win.Promise(func);
152 testPromiseWithDOMExceptionThrowingPromiseInit() {
153 return new this._win.Promise(() => {
154 throw new this._win.DOMException(
155 "We are a second DOMException",
161 testPromiseWithThrowingChromeThenFunction() {
162 return this._win.Promise.resolve(5).then(function () {
163 noSuchMethodExistsYo2();
167 testPromiseWithThrowingContentThenFunction(func) {
168 return this._win.Promise.resolve(10).then(func);
171 testPromiseWithDOMExceptionThrowingThenFunction() {
172 return this._win.Promise.resolve(5).then(() => {
173 throw new this._win.DOMException(
174 "We are a third DOMException",
180 testPromiseWithThrowingChromeThenable() {
183 noSuchMethodExistsYo3();
186 return new this._win.Promise(function (resolve) {
191 testPromiseWithThrowingContentThenable(thenable) {
192 // Waive Xrays on the thenable, because we're calling resolve() in the
193 // chrome compartment, so that's the compartment the "then" property get
194 // will happen in, and if we leave the Xray in place the function-valued
195 // property won't return the function.
196 return this._win.Promise.resolve(Cu.waiveXrays(thenable));
199 testPromiseWithDOMExceptionThrowingThenable() {
202 throw new this._win.DOMException(
203 "We are a fourth DOMException",
208 return new this._win.Promise(function (resolve) {
214 return this.__DOM_IMPL__.getEventHandler("onsomething");
217 set onsomething(val) {
218 this.__DOM_IMPL__.setEventHandler("onsomething", val);