tor-browser

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

proxytrapshelper-overrides.js (2281B)


      1 // Copyright (C) 2016 Jordan Harband. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 description: allowProxyTraps helper should default throw on all the proxy trap named methods being invoked
      6 esid: pending
      7 author: Jordan Harband
      8 includes: [proxyTrapsHelper.js]
      9 ---*/
     10 var overrides = {
     11    getPrototypeOf: function () {},
     12    setPrototypeOf: function () {},
     13    isExtensible: function () {},
     14    preventExtensions: function () {},
     15    getOwnPropertyDescriptor: function () {},
     16    has: function () {},
     17    get: function () {},
     18    set: function () {},
     19    deleteProperty: function () {},
     20    defineProperty: function () {},
     21    enumerate: function () {},
     22    ownKeys: function () {},
     23    apply: function () {},
     24    construct: function () {},
     25 };
     26 var traps = allowProxyTraps(overrides);
     27 
     28 function assertTrapSucceeds(trap) {
     29    if (typeof traps[trap] !== 'function') {
     30        throw new Test262Error('trap ' + trap + ' is not a function');
     31    }
     32    if (traps[trap] !== overrides[trap]) {
     33        throw new Test262Error('trap ' + trap + ' was not overriden in allowProxyTraps');
     34    }
     35    var threw = false;
     36    try {
     37        traps[trap]();
     38    } catch (e) {
     39        threw = true;
     40    }
     41    if (threw) {
     42        throw new Test262Error('trap ' + trap + ' threw an error');
     43    }
     44 }
     45 
     46 function assertTrapThrows(trap) {
     47    if (typeof traps[trap] !== 'function') {
     48        throw new Test262Error('trap ' + trap + ' is not a function');
     49    }
     50    var failedToThrow = false;
     51    try {
     52        traps[trap]();
     53        failedToThrow = true;
     54    } catch (e) {}
     55    if (failedToThrow) {
     56        throw new Test262Error('trap ' + trap + ' did not throw an error');
     57    }
     58 }
     59 
     60 assertTrapSucceeds('getPrototypeOf');
     61 assertTrapSucceeds('setPrototypeOf');
     62 assertTrapSucceeds('isExtensible');
     63 assertTrapSucceeds('preventExtensions');
     64 assertTrapSucceeds('getOwnPropertyDescriptor');
     65 assertTrapSucceeds('has');
     66 assertTrapSucceeds('get');
     67 assertTrapSucceeds('set');
     68 assertTrapSucceeds('deleteProperty');
     69 assertTrapSucceeds('defineProperty');
     70 assertTrapSucceeds('ownKeys');
     71 assertTrapSucceeds('apply');
     72 assertTrapSucceeds('construct');
     73 
     74 // enumerate should always throw because the trap has been removed
     75 assertTrapThrows('enumerate');
     76 
     77 reportCompare(0, 0);