test_bug1244222.js (994B)
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/. */ 4 5 Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true); 6 registerCleanupFunction(() => { 7 Services.prefs.clearUserPref("security.allow_eval_with_system_principal"); 8 }); 9 10 var TestUtils = { 11 QueryInterface: ChromeUtils.generateQI(["nsIXPCTestUtils"]), 12 doubleWrapFunction(fun) { return fun } 13 }; 14 15 function run_test() { 16 // Generate a CCW to a function. 17 var sb = new Cu.Sandbox(this); 18 sb.eval('function fun(x) { return x; }'); 19 Assert.equal(sb.fun("foo"), "foo"); 20 21 // Double-wrap the CCW. 22 var utils = xpcWrap(TestUtils, Ci.nsIXPCTestUtils); 23 var doubleWrapped = utils.doubleWrapFunction(sb.fun); 24 Assert.equal(doubleWrapped.echo("foo"), "foo"); 25 26 // GC. 27 Cu.forceGC(); 28 29 // Make sure it still works. 30 Assert.equal(doubleWrapped.echo("foo"), "foo"); 31 }