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 TestInterfaceAll() {}
6 TestInterfaceAll.prototype = {
7 QueryInterface: ChromeUtils.generateQI(["nsIXPCTestInterfaceA",
8 "nsIXPCTestInterfaceB",
9 "nsIXPCTestInterfaceC"]),
11 /* nsIXPCTestInterfaceA / nsIXPCTestInterfaceB */
12 name: "TestInterfaceAllDefaultName",
14 /* nsIXPCTestInterfaceC */
18 function newWrappedJS() {
19 return xpcWrap(new TestInterfaceAll());
23 // Shortcut the interfaces we're using.
25 a: Ci['nsIXPCTestInterfaceA'],
26 b: Ci['nsIXPCTestInterfaceB'],
27 c: Ci['nsIXPCTestInterfaceC']
30 // Run through the logic a few times.
31 for (let i = 0; i < 2; ++i)
32 play_with_tearoffs(ifs);
35 function play_with_tearoffs(ifs) {
37 // Allocate a bunch of objects, QI-ed to B.
39 for (var i = 0; i < 300; ++i)
40 instances.push(newWrappedJS().QueryInterface(ifs.b));
42 // Nothing to collect.
46 instances.forEach(function(v, i, a) { v.QueryInterface(ifs.a); });
49 instances.forEach(function(v, i, a) { v.QueryInterface(ifs.c); });
52 Assert.ok('name' in instances[10], 'Have the prop from A/B');
53 Assert.ok('someInteger' in instances[10], 'Have the prop from C');
55 // Grab tearoff reflections for a and b.
56 var aTearOffs = instances.map(function(v, i, a) { return v.nsIXPCTestInterfaceA; } );
57 var bTearOffs = instances.map(function(v, i, a) { return v.nsIXPCTestInterfaceB; } );
60 Assert.ok('name' in aTearOffs[1], 'Have the prop from A');
61 Assert.ok(!('someInteger' in aTearOffs[1]), 'Dont have the prop from C');
63 // Nothing to collect.
66 // Null out every even instance pointer.
67 for (var i = 0; i < instances.length; ++i)
71 // Nothing to collect, since we still have the A and B tearoff reflections.
74 // Null out A tearoff reflections that are a multiple of 3.
75 for (var i = 0; i < aTearOffs.length; ++i)
79 // Nothing to collect, since we still have the B tearoff reflections.
82 // Null out B tearoff reflections that are a multiple of 5.
83 for (var i = 0; i < bTearOffs.length; ++i)
87 // This should collect every 30th object (indices that are multiples of 2, 3, and 5).
90 // Kill the b tearoffs entirely.
97 var cTearOffs = instances.map(function(v, i, a) { return v ? v.nsIXPCTestInterfaceC : null; } );
100 Assert.ok(!('name' in cTearOffs[1]), 'Dont have the prop from A');
101 Assert.ok('someInteger' in cTearOffs[1], 'have the prop from C');
103 // Null out the a tearoffs.
106 // Collect all even indices.
109 // Collect all indices.
113 // Give ourselves a pat on the back. :-)
114 Assert.ok(true, "Got all the way through without crashing!");