tor-browser

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

value_recursive.any.js (1446B)


      1 // META: title=IndexedDB: recursive value
      2 // META: global=window,worker
      3 // META: script=resources/support.js
      4 
      5 'use strict';
      6 
      7 function recursive_value(desc, value) {
      8  let db;
      9  const t = async_test('Recursive value - ' + desc);
     10 
     11  createdb(t).onupgradeneeded = t.step_func((e) => {
     12    db = e.target.result;
     13    db.createObjectStore('store').add(value, 1);
     14 
     15    e.target.onsuccess = t.step_func((e) => {
     16      db.transaction('store', 'readonly')
     17          .objectStore('store')
     18          .get(1)
     19          .onsuccess = t.step_func((e) => {
     20        try {
     21          JSON.stringify(value);
     22          assert_unreached(
     23              'The test case is incorrect. It must provide a recursive value that JSON cannot stringify.');
     24        } catch (e) {
     25          if (e.name == 'TypeError') {
     26            try {
     27              JSON.stringify(e.target.result);
     28              assert_unreached(
     29                  'Expected a non-JSON-serializable value back, didn\'t get that.');
     30            } catch (e) {
     31              t.done();
     32              return;
     33            }
     34          } else
     35            throw e;
     36        }
     37      });
     38    });
     39  });
     40 }
     41 
     42 const recursive = [];
     43 recursive.push(recursive);
     44 recursive_value('array directly contains self', recursive);
     45 
     46 const recursive2 = [];
     47 recursive2.push([recursive2]);
     48 recursive_value('array indirectly contains self', recursive2);
     49 
     50 const recursive3 = [recursive];
     51 recursive_value('array member contains self', recursive3);