tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug809674.js (1843B)


      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 
      6 var Bug809674 = {
      7  QueryInterface: ChromeUtils.generateQI(["nsIXPCTestBug809674"]),
      8 
      9  /* nsIXPCTestBug809674 */
     10  methodWithOptionalArgc() {},
     11 
     12  addArgs(x, y) {
     13    return x + y;
     14  },
     15  addSubMulArgs(x, y, subOut, mulOut) {
     16    subOut.value = x - y;
     17    mulOut.value = x * y;
     18    return x + y;
     19  },
     20  addVals(x, y) {
     21    return x + y;
     22  },
     23  addMany(x1, x2, x3, x4, x5, x6, x7, x8) {
     24    return x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8;
     25  },
     26 
     27  methodNoArgs() {
     28    return 7;
     29  },
     30  methodNoArgsNoRetVal() {},
     31 
     32  valProperty: {value: 42},
     33  uintProperty: 123,
     34 };
     35 
     36 function run_test() {
     37  // XPConnect wrap the object
     38  var o = xpcWrap(Bug809674, Ci.nsIXPCTestBug809674);
     39 
     40  // Methods marked [implicit_jscontext].
     41 
     42  Assert.equal(o.addArgs(12, 34), 46);
     43 
     44  var subRes = {}, mulRes = {};
     45  Assert.equal(o.addSubMulArgs(9, 7, subRes, mulRes), 16);
     46  Assert.equal(subRes.value, 2);
     47  Assert.equal(mulRes.value, 63);
     48 
     49  Assert.equal(o.addVals("foo", "x"), "foox");
     50  Assert.equal(o.addVals("foo", 1.2), "foo1.2");
     51  Assert.equal(o.addVals(1234, "foo"), "1234foo");
     52 
     53  Assert.equal(o.addMany(1, 2, 4, 8, 16, 32, 64, 128), 255);
     54 
     55  Assert.equal(o.methodNoArgs(), 7);
     56  Assert.equal(o.methodNoArgsNoRetVal(), undefined);
     57 
     58  // Attributes marked [implicit_jscontext].
     59 
     60  Assert.equal(o.valProperty.value, 42);
     61  o.valProperty = o;
     62  Assert.equal(o.valProperty, o);
     63 
     64  Assert.equal(o.uintProperty, 123);
     65  o.uintProperty++;
     66  Assert.equal(o.uintProperty, 124);
     67 
     68  // [optional_argc] is not supported.
     69  try {
     70    o.methodWithOptionalArgc();
     71    Assert.ok(false);
     72  } catch (e) {
     73    Assert.ok(true);
     74    Assert.ok(/optional_argc/.test(e))
     75  }
     76 }