tor-browser

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

test_xpcwn_instanceof.js (1133B)


      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 // Tests for custom `instanceof` behavior via XPC_SCRIPTABLE_WANT_HASINSTANCE.
      6 
      7 add_task(function id_instanceof() {
      8  // ID objects are instances of Components.ID.
      9  let id = Components.ID("{f2f5c784-7f6c-43f5-81b0-45ff32c312b1}");
     10  Assert.equal(id instanceof Components.ID, true);
     11  Assert.equal({} instanceof Components.ID, false);
     12  Assert.equal(null instanceof Components.ID, false);
     13 
     14  // Components.ID has a Symbol.hasInstance function.
     15  let desc = Object.getOwnPropertyDescriptor(Components.ID, Symbol.hasInstance);
     16  Assert.equal(typeof desc, "object");
     17  Assert.equal(typeof desc.value, "function");
     18 
     19  // Test error handling when calling this function with unexpected values.
     20  Assert.throws(() => desc.value.call(null), /At least 1 argument required/);
     21  Assert.throws(() => desc.value.call(null, 1), /unexpected this value/);
     22  Assert.throws(() => desc.value.call({}, {}), /NS_ERROR_XPC_BAD_OP_ON_WN_PROTO/);
     23 });