tor-browser

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

compare-array-falsy-arguments.js (1133B)


      1 // Copyright (C) 2020 Alexey Shvayka. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 description: >
      6    compareArray gracefully handles nullish arguments.
      7 includes: [compareArray.js]
      8 ---*/
      9 
     10 function assertThrows(func, errorMessage) {
     11    var caught = false;
     12    try {
     13        func();
     14    } catch (error) {
     15        caught = true;
     16        assert.sameValue(error.constructor, Test262Error);
     17        assert.sameValue(error.message, errorMessage);
     18    }
     19 
     20    assert(caught, `Expected ${func} to throw, but it didn't.`);
     21 }
     22 
     23 assertThrows(() => assert.compareArray(), "Actual argument [undefined] shouldn't be primitive. ");
     24 assertThrows(() => assert.compareArray(null, []), "Actual argument [null] shouldn't be primitive. ");
     25 assertThrows(() => assert.compareArray(null, [], "foo"), "Actual argument [null] shouldn't be primitive. foo");
     26 
     27 assertThrows(() => assert.compareArray([]), "Expected argument [undefined] shouldn't be primitive. ");
     28 assertThrows(() => assert.compareArray([], undefined, "foo"), "Expected argument [undefined] shouldn't be primitive. foo");
     29 
     30 reportCompare(0, 0);