tor-browser

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

sort-getter-only.js (1032B)


      1 // The property assignments in Array.prototype.sort are strict assignments.
      2 
      3 load(libdir + "asserts.js");
      4 
      5 var a = ["A", , "B", "C", "D"];
      6 var normalArrayElementDesc = Object.getOwnPropertyDescriptor(a, 0);
      7 var getterDesc = {
      8    get: function () { return "F"; },
      9    set: undefined,
     10    enumerable: true,
     11    configurable: false
     12 };
     13 Object.defineProperty(a, 1, getterDesc);
     14 
     15 // a.sort is permitted to try to delete a[1] or to try to assign a[1], but it
     16 // must try one or the other. Either one will fail, throwing a TypeError.
     17 assertThrowsInstanceOf(() => a.sort(), TypeError);
     18 
     19 // a.sort() is not permitted to delete the nonconfigurable property.
     20 assertDeepEq(Object.getOwnPropertyDescriptor(a, 1), getterDesc);
     21 
     22 // The values left in the other elements of a are unspecified; some or all may
     23 // have been deleted.
     24 for (var i = 0; i < a.length; i++) {
     25    if (i !== 1 && a.hasOwnProperty(i)) {
     26        normalArrayElementDesc.value = a[i];
     27        assertDeepEq(Object.getOwnPropertyDescriptor(a, i), normalArrayElementDesc);
     28    }
     29 }