js/src/jit-test/tests/arrays/sort-getter-only.js

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 // The property assignments in Array.prototype.sort are strict assignments.
     3 load(libdir + "asserts.js");
     5 var a = ["A", , "B", "C", "D"];
     6 var normalArrayElementDesc = Object.getOwnPropertyDescriptor(a, 0);
     7 var getterDesc = {
     8     configurable: false,
     9     enumerable: true,
    10     get: function () { return "F"; },
    11     set: undefined
    12 };
    13 Object.defineProperty(a, 1, getterDesc);
    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);
    19 // a.sort() is not permitted to delete the nonconfigurable property.
    20 assertDeepEq(Object.getOwnPropertyDescriptor(a, 1), getterDesc);
    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 }

mercurial