1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 function xpcWrap(obj, iface) {
7 "@mozilla.org/supports-interface-pointer;1"
8 ].createInstance(Ci.nsISupportsInterfacePointer);
10 ifacePointer.data = obj;
11 return ifacePointer.data.QueryInterface(iface);
14 export var ReturnCodeChild = {
15 QueryInterface: ChromeUtils.generateQI(["nsIXPCTestReturnCodeChild"]),
19 case Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_THROW:
20 throw(new Error("a requested error"));
21 case Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_RETURN_SUCCESS:
23 case Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_RETURN_RESULTCODE:
24 Components.returnCode = Cr.NS_ERROR_FAILURE;
26 case Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_NEST_RESULTCODES:
27 // Use xpconnect to create another instance of *this* component and
28 // call that. This way we have crossed the xpconnect bridge twice.
30 // We set *our* return code early - this should be what is returned
31 // to our caller, even though our "inner" component will set it to
32 // a different value that we will see (but our caller should not)
33 Components.returnCode = Cr.NS_ERROR_UNEXPECTED;
34 // call the child asking it to do the .returnCode set.
35 let sub = xpcWrap(ReturnCodeChild, Ci.nsIXPCTestReturnCodeChild);
36 let childResult = Cr.NS_OK;
38 sub.doIt(Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_RETURN_RESULTCODE);
40 childResult = ex.result;
42 // write it to the console so the test can check it.
43 let consoleService = Cc["@mozilla.org/consoleservice;1"]
44 .getService(Ci.nsIConsoleService);
45 consoleService.logStringMessage("nested child returned " + childResult);