tor-browser

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

DOMMatrix-stringifier.html (2857B)


      1 <!DOCTYPE html>
      2 <title>Geometry Interfaces: DOMMatrix and DOMMatrixReadOnly stringifier</title>
      3 <link rel="help" href="https://drafts.fxtf.org/geometry/#DOMMatrix">
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script>
      7 ["DOMMatrix", "DOMMatrixReadOnly", "WebKitCSSMatrix"].forEach(constr => {
      8  const prefix = `${constr} stringifier:`;
      9 
     10  // Basic
     11  test(() => {
     12    const matrix = new self[constr]();
     13    assert_equals(String(matrix), "matrix(1, 0, 0, 1, 0, 0)");
     14  }, `${prefix} identity (2d)`);
     15 
     16  test(() => {
     17    const matrix = self[constr].fromMatrix({is2D: false});
     18    assert_equals(String(matrix), "matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)");
     19  }, `${prefix} identity (3d)`);
     20 
     21  // Non-finites
     22  [NaN, Infinity, -Infinity].forEach(num => {
     23    test(() => {
     24      const matrix = new self[constr]([1, 0, 0, 1, 0, num]);
     25      assert_throws_dom("InvalidStateError", () => String(matrix));
     26    }, `${prefix} ${num} (2d)`);
     27 
     28    test(() => {
     29      const matrix = new self[constr]([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, num, 0, 1]);
     30      assert_throws_dom("InvalidStateError", () => String(matrix));
     31    }, `${prefix} ${num} (3d)`);
     32  });
     33 
     34  // Precision
     35  [
     36    ['1/3', '0.3333333333333333'],
     37    ['1/300000', '0.0000033333333333333333'],
     38    ['1/300000000', '3.3333333333333334e-9'],
     39    ['100000 + (1/3)', '100000.33333333333'],
     40    ['Math.pow(2, 53) + 1', '9007199254740992'],
     41    ['Math.pow(2, 53) + 2', '9007199254740994'],
     42    ['Number.MAX_VALUE', '1.7976931348623157e+308'],
     43    ['Number.MIN_VALUE', '5e-324'],
     44  ].forEach(([input, expected]) => {
     45    const num = eval(input);
     46    test(() => {
     47      const matrix = new self[constr]([1, 0, 0, 1, 0, num]);
     48      assert_equals(String(matrix), `matrix(1, 0, 0, 1, 0, ${expected})`);
     49    }, `${prefix} ${input} (2d)`);
     50 
     51    test(() => {
     52      const matrix = new self[constr]([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, num, 0, 1]);
     53    assert_equals(String(matrix), `matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, ${expected}, 0, 1)`);
     54    }, `${prefix} ${input} (3d)`);
     55  });
     56 
     57  // Should not invoke getters for m11 etc
     58  function defineThrowingGetters(matrix) {
     59    Object.defineProperty(matrix, 'a', {
     60      get: () => assert_unreached('getter for a')
     61    });
     62    Object.defineProperty(matrix, 'm11', {
     63      get: () => assert_unreached('getter for m11')
     64    });
     65  }
     66 
     67  test(() => {
     68    const matrix = new self[constr]();
     69    defineThrowingGetters(matrix);
     70    assert_equals(String(matrix), "matrix(1, 0, 0, 1, 0, 0)");
     71  }, `${prefix} throwing getters (2d)`);
     72 
     73  test(() => {
     74    const matrix = self[constr].fromMatrix({is2D: false});
     75    defineThrowingGetters(matrix);
     76    assert_equals(String(matrix), "matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)");
     77  }, `${prefix} throwing getters (3d)`);
     78 });
     79 </script>