tor-browser

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

context-methods.js (1454B)


      1 "use strict";
      2 
      3 // Properties to be ignored because they were added in versions of the
      4 // spec that are backward-compatible with this version
      5 const IGNORED_METHODS = [
      6  // There is no official spec for the commit API yet, the proposal link is:
      7  // https://wiki.whatwg.org/wiki/OffscreenCanvas
      8  "commit",
      9 
     10  // For WebXR integration:
     11  "makeXRCompatible",
     12 ];
     13 
     14 function assertFunction(v, f) {
     15  try {
     16    if (typeof v[f] != "function") {
     17      testFailed(`Property either does not exist or is not a function: ${f}`);
     18      return false;
     19    } else {
     20      return true;
     21    }
     22  } catch(e) {
     23    testFailed(`Trying to access the property '${f}' threw an error: ${e.toString()}`);
     24  }
     25 }
     26 
     27 function testContextMethods(gl, requiredContextMethods) {
     28  const acceptableMethods = [].concat(requiredContextMethods, IGNORED_METHODS);
     29 
     30  let passed = true;
     31  requiredContextMethods.forEach(method => {
     32    const r = assertFunction(gl, method);
     33    passed = passed && r;
     34  });
     35  if (passed) {
     36    testPassed("All WebGL methods found.");
     37  }
     38  let extended = false;
     39  for (let propertyName of Object.getOwnPropertyNames(gl)) {
     40    if (typeof gl[propertyName] == "function" && !acceptableMethods.includes(propertyName)) {
     41      if (!extended) {
     42        extended = true;
     43        testFailed("Also found the following extra methods:");
     44      }
     45      testFailed(propertyName);
     46    }
     47  }
     48 
     49  if (!extended) {
     50    testPassed("No extra methods found on WebGL context.");
     51  }
     52 }