tor-browser

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

test-console-custom-formatters-errors.html (5804B)


      1 <!DOCTYPE html>
      2 <html lang="en">
      3  <head>
      4    <meta charset="utf-8"/>
      5    <title>Webconsole erroneous custom formatters test page</title>
      6  </head>
      7  <body>
      8    <p>Erroneous custom formatters test page</p>
      9    <script>
     10      "use strict";
     11 
     12      window.devtoolsFormatters = [
     13        {
     14          // this header is invalid because it is not a function
     15          header: 1,
     16        },
     17        {
     18          // this header is invalid because it doesn't return JsonML
     19          header: () => 1,
     20        },
     21        {
     22          // this header is invalid because the returned array misses an element type
     23          header: () => [],
     24        },
     25        {
     26          // this header is invalid because it throws an exception
     27          header: () => { throw new Error("ERROR"); },
     28        },
     29        {
     30          header: (obj) => {
     31            return obj.hasOwnProperty("hasBodyNotAFunction") ?
     32              ["div", "hasBody not a function"] :
     33              null;
     34          },
     35          // this hasBody is invalid because it is not a function
     36          hasBody: 1,
     37        },
     38        {
     39          header: (obj) => {
     40            return obj.hasOwnProperty("hasBodyThrows") ?
     41              ["div", "hasBody throws"] :
     42              null;
     43          },
     44          // this hasBody throws an exception
     45          hasBody: () => { throw new Error("ERROR"); },
     46        },
     47        {
     48          header: (obj) => {
     49            return obj.hasOwnProperty("bodyNotAFunction") ?
     50              ["div", "body not a function"] :
     51              null;
     52          },
     53          hasBody: () => true,
     54          // this body is invalid because it is not a function
     55          body: 1,
     56        },
     57        {
     58          header: (obj) => {
     59            return obj.hasOwnProperty("bodyReturnsNull") ?
     60              ["div", "body returns null"] :
     61              null;
     62          },
     63          hasBody: () => true,
     64          // this body is invalid because it doesn't return JsonML
     65          body: () => null,
     66        },
     67        {
     68          header: (obj) => {
     69            return obj.hasOwnProperty("bodyNoJsonMl") ?
     70              ["div", "body doesn't return JsonML"] :
     71              null;
     72          },
     73          hasBody: () => true,
     74          // this body is invalid because it doesn't return JsonML
     75          body: () => 1,
     76        },
     77        {
     78          header: (obj) => {
     79            return obj.hasOwnProperty("bodyNoElementType") ?
     80              ["div", "body array misses element type"] :
     81              null;
     82          },
     83          hasBody: () => true,
     84          // this body is invalid because the returned array misses an element type
     85          body: () => [],
     86        },
     87        {
     88          header: (obj) => {
     89            return obj.hasOwnProperty("bodyThrows") ?
     90              ["div", "body throws"] :
     91              null;
     92          },
     93          hasBody: () => true,
     94          // this body is invalid because it throws an exception
     95          body: () => { throw new Error("ERROR"); },
     96        },
     97        {
     98          header: (obj) => {
     99            if (obj?.hasOwnProperty("objectTagWithNoAttribute")) {
    100              // This is invalid because "object" tag should have attributes
    101              return ["object"];
    102            }
    103            return null;
    104          },
    105        },
    106        {
    107          header: (obj) => {
    108            if (obj?.hasOwnProperty("objectTagWithoutObjectAttribute")) {
    109              // This is invalid because "object" tag should have an "object" attribute
    110              return [
    111                  "object",
    112                  { config: "something" }
    113                ];
    114            }
    115            return null;
    116          },
    117        },
    118        {
    119          header: (obj) => {
    120            if (obj?.hasOwnProperty("infiniteObjectTag")) {
    121              // This is invalid because this triggers an infinite loop (object is being
    122              // replaced by itself, which will keep triggering the custom formatter hook)
    123              return [ "object", { object: obj }];
    124            }
    125            return null;
    126          },
    127        },
    128        {
    129          // the returned value is invalid because the tagName isn't a string
    130          header: (obj) => {
    131            if (obj?.hasOwnProperty("invalidTag")) {
    132              return [ 42 ];
    133            }
    134            return null;
    135          },
    136        },
    137        {
    138          header: (obj) => {
    139            if (obj.hasOwnProperty("customFormatHeader")) {
    140              return ["span", {"style": "font-size: 3rem;"}, "custom formatted header"];
    141            }
    142            return null;
    143          },
    144          hasBody: () => false
    145        },
    146        {
    147          header: (obj) => {
    148            if (obj.hasOwnProperty("customFormatHeaderAndBody")) {
    149              return ["span", {"style": "font-style: italic;"}, "custom formatted body"];
    150            }
    151            return null;
    152          },
    153          hasBody: () => true,
    154          body: (obj) => ["span", {"style": "font-family: serif; font-size: 2rem;"}, obj.customFormatHeaderAndBody]
    155        },
    156        {
    157          header: (obj) => {
    158            if (obj.hasOwnProperty("privileged")) {
    159              // This should throw as the hooks should not have privileged access
    160              window.windowUtils.garbageCollect();
    161              return ["span", {}, "privileged"];
    162            }
    163            return null;
    164          },
    165        },
    166      ];
    167 
    168      [
    169        {},
    170        {hasBodyNotAFunction: true},
    171        {hasBodyThrows: true},
    172        {bodyNotAFunction: true},
    173        {bodyReturnsNull: true},
    174        {bodyNoJsonMl: true},
    175        {bodyNoElementType: true},
    176        {bodyThrows: true},
    177        {objectTagWithNoAttribute: true},
    178        {objectTagWithoutObjectAttribute: true},
    179        {infiniteObjectTag: true},
    180        {invalidTag: true},
    181        {privileged: true},
    182      ].forEach(variable => console.log(variable));
    183    </script>
    184  </body>
    185 </html>